STMicroelectronics / STM32CubeF4

STM32Cube MCU Full Package for the STM32F4 series - (HAL + LL Drivers, CMSIS Core, CMSIS Device, MW libraries plus a set of Projects running on all boards provided by ST (Nucleo, Evaluation and Discovery Kits))
Other
869 stars 418 forks source link

fix IS_ADC_CHANNEL() bug on STM32F411xE variants #36

Closed TheCodeSharman closed 3 years ago

TheCodeSharman commented 4 years ago

This PR fixes an issue where the following is returning false for the STM32F411xE chip:

IS_ADC_CHANNEL(ADC_CHANNEL_TEMPSENSOR)

As a result of this the example code on the Wiki for reading the internal temperature sensor returns a result of -266 because analogRead(ATEMP) always returns 0 indicating an error.

Note: Reviewing the code it looks like the definition of ADC_CHANNEL_TEMPSENSOR is inconsistent with the definition of IS_ADC_CHANNEL for other boards too? I've only made the minimal changes for the board I own however.

fpistm commented 4 years ago

Reviewing the code it looks like the definition of ADC_CHANNEL_TEMPSENSOR is inconsistent with the definition of IS_ADC_CHANNEL for other boards too? I've only made the minimal changes for the board I own however.

I can confirm, it seems not consistent, Channel is 18 but bitwise OR operator with ADC_CHANNEL_DIFFERENCIATION_TEMPSENSOR_VBAT

https://github.com/STMicroelectronics/STM32CubeF4/blob/5d01400afd60410f6e049cbd19179a67d44d53fd/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_adc_ex.h#L222-L226

So the IS_ADC_CHANNEL is not consistent for several other MCU: https://github.com/STMicroelectronics/STM32CubeF4/blob/5d01400afd60410f6e049cbd19179a67d44d53fd/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_adc_ex.h#L305-L317

If the ADC_CHANNEL_DIFFERENCIATION_TEMPSENSOR_VBAT is correct then full patch should be:

@@ -304,17 +304,17 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeConfigChannel(ADC_HandleTypeDef* hadc, ADC_
   */
 #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) || \
     defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F410Tx) || defined(STM32F410Cx) || \
-    defined(STM32F410Rx) || defined(STM32F411xE) || defined(STM32F412Zx) || defined(STM32F412Vx) || \
-    defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx)
+    defined(STM32F410Rx) || defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || \
+    defined(STM32F412Cx)
 #define IS_ADC_CHANNEL(CHANNEL) ((CHANNEL) <= ADC_CHANNEL_18)
-#endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F401xC || STM32F401xE || STM32F410xx || STM32F411xE ||
-          STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx || STM32F413xx || STM32F423xx */
+#endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F401xC || STM32F401xE || STM32F410xx || STM32F412Zx ||
+          STM32F412Vx || STM32F412Rx || STM32F412Cx */

-#if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || \
-    defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
+#if defined(STM32F411xE) || defined(STM32F413xx) || defined(STM32F423xx) || defined(STM32F427xx) || defined(STM32F437xx) || \
+    defined(STM32F429xx) || defined(STM32F439xx) defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
 #define IS_ADC_CHANNEL(CHANNEL) (((CHANNEL) <= ADC_CHANNEL_18)  || \
                                  ((CHANNEL) == ADC_CHANNEL_TEMPSENSOR))
-#endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */
+#endif /* STM32F411xE || STM32F413xx || STM32F423xx || STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */

 #define IS_ADC_MODE(MODE) (((MODE) == ADC_MODE_INDEPENDENT)                 || \
                            ((MODE) == ADC_DUALMODE_REGSIMULT_INJECSIMULT)   || \
RKOUSTM commented 4 years ago

Hi @TheCodeSharman,

Thank you for your suggestion and contribution. Our development teams will be notified to fix this. A fix will be implemented and made available in future release.

Thank you once again for your contribution.

With regards,

RKOUSTM commented 4 years ago

Hi @fpistm,

Thank you for your suggestion and contribution.

With regards,

RKOUSTM commented 4 years ago

ST Internal Reference: 92349

RKOUSTM commented 3 years ago

Hi @TheCodeSharman,

I hope you are fine. The issue you reported has been fixed in the frame of version v1.26.0 of the STM32CubeF4 published recently on GitHub.

Thank you again for having reported.

With regards,