Closed faunel closed 1 month ago
I don't think this is a library error. The ADC stops when data from the buffer is not retrieved in time and it overflows. In this case, an Overrun error is set in the register. To solve this problem, the following steps should be followed:
Set the minimum ADC speed (SampleTime::Cycles_480, Clock::Pclk2_div_8). Optimize the code to retrieve data from the DMA buffer as quickly as possible. If a faster ADC is needed, a second DMA buffer can be used by enabling it. This will allow data to be retrieved faster and avoid overflow. For example, you can set Cycles_56 and everything will work.
However, in any case, the DMA interrupt handler must have the highest priority, and the code must be optimized to not interfere with this handler's quick operation, for example, by not blocking it in other tasks when using RTIC. The main goal is to retrieve data from the DMA buffer as quickly as possible to prevent it from overflowing.
The ADC does not work in continuous mode if there is a small delay after starting (transfer.start) A delay of 1 ms is sufficient (line delay.delay_ms(1);).
I tested this on two boards - STM32F401CE, STM32F411CE (Black pill) And the issue occurs on both.
Also, the ADC can suddenly stop working if there is a blocking operation in the task for a few milliseconds during the process. There are no errors in this case.
Also, in single mode, if we start the ADC in the interrupt handler, the ADC can also suddenly stop working. This manifests at a start frequency of 100 kHz, Pclk2_div_2, and a small number of cycles (Cycles_112 or less).
Added a project with an example in the attachment. adc_bug.zip