Skip to content

Commit adfd0f5

Browse files
committed
Fix multi-DAC support for STM32F302x8 compatibility
- Add conditional compilation for DAC2 support - STM32F302x8 only supports DAC1, STM32F334x8 supports both DAC1 and DAC2 - Use preprocessor directives to handle variant differences - Fixes build errors on STM32F302x8 while maintaining full functionality on STM32F334x8 - Resolves mjh9585's comment about missing DAC support on F334 variants
1 parent bf9a7ed commit adfd0f5

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

src/core/io/platform/f3xx/DACf3xx.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ DACf3xx::DACf3xx(Pin pin, DACPeriph dacPeriph) : DACBase(pin, dacPeriph), halDac
3636
halDac.Instance = DAC1;
3737
break;
3838
case DACPeriph::TWO:
39+
#ifdef DAC2
3940
halDac.Instance = DAC2;
41+
#else
42+
halDac.Instance = DAC1; // DAC2 not available on this variant
43+
#endif
4044
break;
4145
default:
4246
halDac.Instance = DAC1; // Default fallback
@@ -120,7 +124,11 @@ void DACf3xx::initGPIO() {
120124
__HAL_RCC_DAC1_CLK_ENABLE();
121125
break;
122126
case DACPeriph::TWO:
127+
#ifdef __HAL_RCC_DAC2_CLK_ENABLE
123128
__HAL_RCC_DAC2_CLK_ENABLE();
129+
#else
130+
__HAL_RCC_DAC1_CLK_ENABLE(); // DAC2 not available on this variant
131+
#endif
124132
break;
125133
default:
126134
__HAL_RCC_DAC1_CLK_ENABLE(); // Default fallback
@@ -144,7 +152,7 @@ uint32_t DACf3xx::getChannelFromPin() {
144152
if (pin == Pin::PA_4) {
145153
return DAC_CHANNEL_1;
146154
} else if (pin == Pin::PA_5) {
147-
#if defined(DAC_CHANNEL2_SUPPORT)
155+
#ifdef DAC_CHANNEL_2
148156
return DAC_CHANNEL_2; // STM32F334 supports PA_5 (DAC_CHANNEL_2)
149157
#else
150158
return DAC_CHANNEL_1; // STM32F302 doesn't support PA_5, use CHANNEL_1
@@ -163,8 +171,13 @@ DACf3xx::Channel_Support DACf3xx::getChannelSupport(Pin pin) {
163171
support.channel = DAC_CHANNEL_1;
164172
} else if (pin == Pin::PA_5) {
165173
support.dac1 = 0; // PA_5 doesn't support DAC1
174+
#ifdef DAC_CHANNEL_2
166175
support.dac2 = 1; // PA_5 supports DAC2 (on STM32F334)
167176
support.channel = DAC_CHANNEL_2;
177+
#else
178+
support.dac2 = 0; // PA_5 doesn't support DAC2 (on STM32F302)
179+
support.channel = DAC_CHANNEL_1;
180+
#endif
168181
} else {
169182
// Default fallback
170183
support.dac1 = 1;

0 commit comments

Comments
 (0)