Closed DonBrus closed 1 year ago
Hello DonBrus
Thank you for your contribution. I couldn't reproduce the issue on my side. Would it be possible to share a project that generates the problem ?
Best regards
Hello DonBrus
Thank you for your contribution. I couldn't reproduce the issue on my side. Would it be possible to share a project that generates the problem ?
Best regards
Hi @ARIOSTM, unfortunately the code is proprietary and I cannot show it here. I'll try to recreate a minimal example ASAP, although the basic steps to recreate the current situation would be:
Handle.Instance = ADC1;
Handle.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
Handle.Init.Resolution = ADC_RESOLUTION_14B;
Handle.Init.GainCompensation = 0;
Handle.Init.ScanConvMode = ADC_SCAN_DISABLE;
Handle.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
Handle.Init.LowPowerAutoWait = DISABLE;
Handle.Init.ContinuousConvMode = DISABLE;
Handle.Init.NbrOfConversion = 1;
Handle.Init.DiscontinuousConvMode = DISABLE;
Handle.Init.ExternalTrigConv = ADC_EXTERNALTRIG_T6_TRGO;
Handle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING;
Handle.Init.DMAContinuousRequests = DISABLE;
Handle.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH;
Handle.Init.Overrun = ADC_OVR_DATA_PRESERVED;
Handle.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;
Handle.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DR;
Handle.Init.OversamplingMode = DISABLE;
HAL_ADCEx_Calibration_Start(&Handle, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED);
The device will then either hang or have an incorrect operation when sampling from ADC1. I've tested this code on multiple devices and the issue arises consistently; adding the fix I've posted in the OP mitigates it. Again I'll try to reproduce the issue with a simple makefile and see if I can provide more details on a MWE
@ARIOSTM I've published a basic makefile project as its own repo (to avoid bundling the whole cube library in a .zip). Just make all
from root directory; I've used linux to build so I'm not sure it also works on windows out of the box.
A couple of notes:
As mentioned in the OP, if you launch this program without any modification to the library it will crash the whole system; if you add my modification inside the calibration procedure it'll work. Let me know if you need any further help in replicating this issue
Hello, Thank you these information. I downloaded your project and compiled it.
I will now test it and come back to you as soon as possible with updates.
Hello DonBrus
I reproduced the issue thanks to your program. It appears to be dependent on the clock configuration, the compiler and the optimization option selected.
The 9 read accesses to CALFACT2 mentioned in the Reference Manual are referring to the different calibration factor stored in the ADC_CALFACT2 register. They can be accessed by changing the ADC_CR_CALINDEX[3:0] value and therefore, to read all calibration factor, 9 accesses to ADC_CALFACT2 are needed.
However, you were right adding some kind of delay/loop between each access to the ADC register solve the issue.
Thanks again for reporting this issue and for the information you provided. We are still investigating to find the root cause. We will provide a fix in a future release.
In the meantime, I suggest to use a Data Memory Barrier (DMB) as a workaround. By inserting it between the access to ADC_CR_CALINDEX and ADC_CALFACT2 and again before the access to ADC_CALFACT.
MODIFY_REG(hadc->Instance->CR, ADC_CR_CALINDEX, 0x9UL << ADC_CR_CALINDEX_Pos);
__DMB();
MODIFY_REG(hadc->Instance->CALFACT2, 0x00FF0000UL, 0x00020000UL);
__DMB();
SET_BIT(hadc->Instance->CALFACT, ADC_CALFACT_LATCH_COEF);
Please let me know if this work for you or if you have any questions.
Best Regards,
ST Internal Reference: 160779
ST Internal Reference: 160779
Hello,
I hope you are fine. The issue you reported has been fixed in the frame of version v1.4.0 of the STM32CubeU5 published recently on GitHub. Thank you again for having reported.
Describe the set-up
Describe the bug
When performing the calibration procedure for the ADC1 peripheral through the _HAL_ADCEx_CalibrationStart function, with mode=ADC_CALIB_OFFSET and for single ended channels, the system will either hang/crash or the ADC peripheral won't work correctly, though the configuration is correct. I pinned the problem to the following part of the RM: Reading calibration factor procedure (under section 33.4.8)
These nine access are effectively not performed in the aforementioned function, as interacting with CALFACT2 takes place in the following part of code (stm32u5xx_hal_adc_ex:203):
How to reproduce the bug
stm32u5xx_hal_adc_ex.c::HAL_ADCEx_Calibration_Start
Additional context
Following the advice contained in the RM (i.e. performing 9 read accesses to CALFACT2), I managed to solve the issue by adding the following lines in _HAL_ADCEx_CalibrationStart (from line 213 onwards):
I tried removing one of the loops as just a single one should suffice but that didn't solve the problem.
Notes: