-
Notifications
You must be signed in to change notification settings - Fork 8
Description
The problems comes from using a hard-coded macro VDDA_APPLI that is fixed to 3300mV in ADCCTRL module:
#define VDDA_APPLI (3300UL) |
As a result, if a different MCU supply voltage is used (e.g., 3V), the ADCCTRL will silently produce incorrect readings, still assuming the Vdda is 3300mV.
Steps to reproduce:
- Use NUCLEO-WBA55 or NUCLEO-WBA65 board
- Use any CubeMX example that includes ADCCTRL module and modify it to periodically print out core temperature or core voltage
- Ensure it produces plausible results (e.g., temperature around 30 degrees Celsius, core voltage around 3300mV)
- Use STLINK-V3PWR or similar to feed Vdd line with 3V instead of 3.3V using JP2 header on the Nucleo board
- Observe incorrect readings
The suggestion is to move the definition of VDDA_APPLI from adc_ctrl.c into application configuration header (app_conf.h) as this is clearly an application-specific parameter.
Going a bit further with improvements, it would be nice to treat VDDA_APPLI as a function-like macro. With this the users who want or need to use the actual reference voltage reading will be able to define VDDA_APPLI in their app_conf.h to call their function to provide the reference voltage readings, while those who are ok with a hard-coded value are still ok to use it. For example:
#define CFG_GET_VDDA_APPLI() my_get_reference_voltage_func()
vs
#define CFG_GET_VDDA_APPLI() (3300U)
Identified instances of the issue:
#define VDDA_APPLI (3300UL) VDDA_APPLI, *p_ReadValue = __LL_ADC_CALC_TEMPERATURE (VDDA_APPLI, *p_ReadValue = __LL_ADC_CALC_DATA_TO_VOLTAGE (VDDA_APPLI,
Metadata
Metadata
Assignees
Labels
Type
Projects
Status