Cannot make ADC with DMA Sampling work when using Sequencer (UTIL_SEQ).
Hello!
I'm a university student with some experience with STM.
I'm working on an STM32WB55 DevBoard and an STM32WB5MMG-based custom board, they both are programmed with same code when i compile and works perfectly.
Regardless, the specific board names are irrelevant (And not worth discussing), just know that i'm working in general with STM32WB BLE products to make the following:
-The ADC Samples a value read from a single pin at a frequency of 10kHz, driven via TRGO by TIM2 Timer.
-The Sampling occurs with DMA (ADC started with HAL_ADC_Start_DMA), and after it fills an array, the sampling operation stops and restarts on a second array.
-In the while the sampling has started on the second array, the first array of samples is transferred via SPI to a Micro SD Card.
-Once the second array is filled, sampling is restarted on the first array, and the second is transferred via SPI to a Micro SD Card.
-This double buffering ping-pongs from the moment ADC reading with DMA and TIM are started and lasts for some seconds ( Timed imprecisely by "HAL_Delay(10000)" ), after which the TIM and Adc Reading with DMA are stopped and the file is closed.
All of this worked perfectly, with decent precision, as i was able to generate a Sinewave with a specific frequency (1kHz, 2kHz, 5kHz..) with an external signal generator apparatus, wire it to the ADC pin, and after the data was collected and put the SD Card in the PC, I could see the peaks that i wanted in the FFT/Signal Spectrum at the right frequency.
As it worked, it makes no sense discussing the methodology of this before someone decides to go full stackoverflow and give tips to irrelevant matters.
The problem came however when I decided to have this operation triggered by bluetooth using the BLE Stack of STM32WB, so that i could start several tests at my command via BLE without the need of plugging/unplugging the power to the board to force the restart.
These operations occur without any issue until i make the STM32 Sequencer work, by looping in the while MX_APPE_Process();.
It already happened to me when using the STM32WL family (LoRa) that i had to discard the sequencer as any operation i tried to register as a task that required the use of DMA or simply reading from external peripherals (like USART) would simply not work and generate errors in transfer, no matter the priority settings i changed in the NVIC settings on the IOC file.
I tried nevertheless to implement this on the P2P Server example, and have the ADC reading with DMA and the TIM start when i send a certain digit over a BLE service.
No matter what i tried, although the commands of HAL_ADC_Start_DMA and HAL_TIM_Base_Start are executed in a task of the sequencer (and later stopped by another task), the callback HAL_ADC_ConvCpltCallback gets never called,
and for what i could see from debugging the program setting breakpoints, registers report a transfer error in DMA.
I've tried the following:
-Set everything else on max priority 1, DMA, TIM, and SPI on priority 0 on NVIC settings.
-Through an if statement, the sequencer (MX_APPE_Process) is not called in the while loop in main when the the reading of ADC is occurring on that moment, the if becomes true again (calling the sequencer) when the seconds of desired reading time have been reached and the ADC reading has been stopped.
-DMA priority changed to very high, even made this change in the registers during debug.
-Disabling the BLE Stack (all of them) tasks while doing the reading.
-Data width changes on DMA (I believe them unnecessary as it worked without changing them before).
-Disabled all the Critical Sections in the UTIL_SEQ_Run, in case they interfered with the interrupts of DMA.
And many more things i've likely forgot, but the result was always the same: the DMA error (DMA BUSY, i think?), reading doesn't occur.
Please, i need help. Ask for anything and i shall send it.
Summary / TL;DR :
I was sampling ADC with DMA, controlled by TIM (TRGO) at 10kHz without issues before running the sequencer utility.
After the UTIL_SEQ Sequencer ("MX_APPE_Process()" command) has run at least once I'm unable to read anything with from ADC with DMA anymore, and that even if i refuse to execute the sequencer commands while performing the readings.