H7/CubeMX critical bugs with LL and ADC3
ADC3 is broken when using the LL interface.
1) This is because it gets initialized with invalid resolution bits:
CubeMX currently generates:
ADC_InitStruct.Resolution = LL_ADC_RESOLUTION_12B;
ADC_InitStruct.LowPowerMode = LL_ADC_LP_MODE_NONE;
LL_ADC_Init(ADC3, &ADC_InitStruct);
But this needs to be:
ADC_InitStruct.Resolution = __LL_ADC12_RESOLUTION_TO_ADC3(LL_ADC_RESOLUTION_12B);
This results in bogus values.
2) Initialization delay is broken:
uint32_t wait_loop_index;
wait_loop_index = ((LL_ADC_DELAY_INTERNAL_REGUL_STAB_US * (SystemCoreClock / (100000 * 2))) / 10);
while (wait_loop_index != 0) {
wait_loop_index--;
}
This is because the whole wait loop is doing exactly nothing and there is no reason for the compiler to not optimize it out. This can be easily fixed by declaring the loop index as "volatile uint32_t wait_loop_index;".
Also note that this tends to block SIGNIFICANTLY longer than intended; with execution from RAM@550MHz I get ~110µs delay instead of 10µs (pipeline to blame?). Delay precision can be fixed by stuffing the loop body with NOPs, but thats kinda wasting instruction memory. IMO the nicest fix would be to turn the DWT block on, use the cycle counter for the delay and restore it to previous state after (maybe a "LL_Usleep(uint32_t usec)" also useable elsewhere?).
Workaround:
Manually fix these every time after generating code...
Affected:
STMCubeMX 6.3.0
STMCubeIDE 1.7.0
Both with HAL: STM32 H7 1.9.0
On: STM32H730 (TFBGA100 Package)