Skip to content

Conversation

@TheCodeSharman
Copy link

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
Copy link

fpistm commented Sep 4, 2020

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

#if defined(STM32F411xE) || defined(STM32F413xx) || defined(STM32F423xx) || defined(STM32F427xx) || defined(STM32F437xx) ||\
defined(STM32F429xx) || defined(STM32F439xx) || defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
#define ADC_CHANNEL_DIFFERENCIATION_TEMPSENSOR_VBAT 0x10000000U /* Dummy bit for driver internal usage, not used in ADC channel setting registers CR1 or SQRx */
#define ADC_CHANNEL_TEMPSENSOR ((uint32_t)ADC_CHANNEL_18 | ADC_CHANNEL_DIFFERENCIATION_TEMPSENSOR_VBAT)
#endif /* STM32F411xE || STM32F413xx || STM32F423xx || STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */

So the IS_ADC_CHANNEL is not consistent for several other MCU:

#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)
#define IS_ADC_CHANNEL(CHANNEL) ((CHANNEL) <= ADC_CHANNEL_18)
#endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F401xC || STM32F401xE || STM32F410xx || STM32F411xE ||
STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx || STM32F413xx || STM32F423xx */
#if 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 */

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)   || \

fpistm added a commit to stm32duino/Arduino_Core_STM32 that referenced this pull request Sep 4, 2020
Have to be fixed in STM32CubeF4:
STMicroelectronics/STM32CubeF4#36

Signed-off-by: Michael Sharman <[email protected]>
Co-authored-by: Frederic Pillon <[email protected]>
@RKOUSTM RKOUSTM self-assigned this Sep 8, 2020
@RKOUSTM
Copy link
Contributor

RKOUSTM commented Sep 8, 2020

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
Copy link
Contributor

RKOUSTM commented Sep 8, 2020

Hi @fpistm,

Thank you for your suggestion and contribution.

With regards,

@RKOUSTM
Copy link
Contributor

RKOUSTM commented Sep 8, 2020

ST Internal Reference: 92349

@RKOUSTM RKOUSTM added bug Something isn't working internal bug tracker Issue confirmed and logged into the internal bug tracking system labels Sep 8, 2020
fpistm added a commit to fpistm/Arduino_Core_STM32 that referenced this pull request Sep 11, 2020
Have to be fixed in STM32CubeF4:
STMicroelectronics/STM32CubeF4#36

Signed-off-by: Michael Sharman <[email protected]>
Co-authored-by: Frederic Pillon <[email protected]>
Signed-off-by: Frederic Pillon <[email protected]>
@RKOUSTM RKOUSTM added this to the v1.26.0 milestone Sep 28, 2020
@RKOUSTM RKOUSTM added the hal HAL-LL driver-related issue or pull-request. label Oct 8, 2020
fpistm added a commit to fpistm/Arduino_Core_STM32 that referenced this pull request Oct 30, 2020
Have to be fixed in STM32CubeF4:
STMicroelectronics/STM32CubeF4#36

Signed-off-by: Michael Sharman <[email protected]>
Co-authored-by: Frederic Pillon <[email protected]>
Signed-off-by: Frederic Pillon <[email protected]>
@RKOUSTM
Copy link
Contributor

RKOUSTM commented Mar 3, 2021

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,

@RKOUSTM RKOUSTM closed this Mar 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working hal HAL-LL driver-related issue or pull-request. internal bug tracker Issue confirmed and logged into the internal bug tracking system

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants