2016-07-15 05:35 AM
Hi All,
I'm using STM32L475, STM32CubeMX 4.15.1, STM32L4 firmware library 1.5.1 and the code generated by STM32CubeMX. When initializing ADC1 and ADC2 the ADC2 initialization, MX_ADC2_Init(), sometimes calls ErrorHandler() because HAL_ADCEx_MultiModeConfigChannel() is returning and error.HAL_ADCEx_MultiModeConfigChannel(), stm32l4xx_hal_adc_ex.c, is called with hadc->Instance = ADC2; therefore, ADC_MULTI_SLAVE(hadc, &tmphadcSlave) sets tmphadcSlave->Instance = NULL. When ADC_IS_CONVERSION_ONGOING_REGULAR(&tmphadcSlave) is called a NULL pointer, tmphadcSlave->Instance->CR, is dereferenced and leads to unexpected results.The NULL pointer deference can be fixed by changing macro ADC_IS_CONVERSION_ONGOING_REGULAR, stm32l4xx_hal_adc.h, to#define ADC_IS_CONVERSION_ONGOING_REGULAR(__HANDLE__) \
(( !(__HANDLE__)->Instance || (((__HANDLE__)->Instance->CR) & ADC_CR_ADSTART) == RESET \ ) ? RESET : SET)With this change ADC_IS_CONVERSION_ONGOING_REGULAR will return RESET when Instance is NULL.HAL_ADCEx_MultiModeConfigChannel() also calls macro ADC_IS_ENABLE(&tmphadcSlave). ADC_IS_ENABLE should also check for NULL before using tmphadcSlave->Instance.#define ADC_IS_ENABLE(__HANDLE__) \
(( (__HANDLE__)->Instance && \ ((((__HANDLE__)->Instance->CR) & (ADC_CR_ADEN | ADC_CR_ADDIS)) == ADC_CR_ADEN) && \ ((((__HANDLE__)->Instance->ISR) & ADC_FLAG_RDY) == ADC_FLAG_RDY) \ ) ? SET : RESET)Is this analysis and resolution correct? I believe returning RESET is appropriate when Instance = NULL. Also, updating the macros seemed cleaner than adding NULL checks to the source; but this is debatable.Thanks and Regards,...dougSolved! Go to Solution.
2017-01-13 06:51 AM
Hi kehn.doug,
This issue is solved in CubeMX4.18.
Please, upgrade CubeMX to avoid having this issue.
BR. Eric
2016-07-21 03:34 AM
Hi kehn.doug,
Thanks for highlighting these issues.Please note that they are reported internally for farther investigation.-Mayla-To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2017-01-13 06:51 AM
Hi kehn.doug,
This issue is solved in CubeMX4.18.
Please, upgrade CubeMX to avoid having this issue.
BR. Eric