cancel
Showing results for 
Search instead for 
Did you mean: 

While(1) Not Executing

BitCurious
Associate III

I am using STM32 with the following peripherals:

  • TIM7 for frequency generation
  • ADC with DMA
  • DAC with DMA
  • TIM Interrupt (TIM_IT)

My setup:

  • Clock: 150 MHz
  • Prescaler (PSC:( 3-1
  • Auto-reload register (ARR:( 13-1
  • 128 samples for DAC to generate a 30 kHz signal

When using these settings, the ADC half-complete and complete callbacks are triggered correctly, meaning ADC DMA is working. However, nothing seems to happen in the while(1) loop in main().

What do you think could be causing this?

Could it be related to TIM7 interrupt priority, DMA behavior, or CPU being blocked?
Is the DMA transfer taking over completely, preventing execution in while(1)?
Any insights or suggestions would be greatly appreciated!

14 REPLIES 14

Does the 30 kHz signal waveform really change every period? 
I am constantly getting a 30khz sine wave (i checked it with osciloscope)

Do you really need the DAC for generating the waveform?
Other than that, how can i? with function generator?

In your in stm32g4xx_it.c code snippet, the user code block  in line 4 rsp. 18 is the point to insert your own code. For speed tests, just add a return statement thereby skipping the call into HAL (and of course the funtionality).  

 


@BitCurious wrote:

do you mean in stm32g4xx_it.c ?


Yes. To convince you that even you comment the callbacks the interrupt still fired and the IRQ handler is executed.

But I recommend to disable the ADC NVIC config and check if you reach the while loop.

 

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.
PS:
1 - This is NOT an online support (https://ols.st.com) but a collaborative space.
2 - Please be polite in your reply. Otherwise, it will be reported as inappropriate and you will be permanently blacklisted from my help.

I could not turn off the NVIC for ADC as it is enabled by default when using DMA.
However, I disabled the NVIC for TIM7 and started the timer normally using HAL_TIM_Base_Start(&htim7);.
Now, everything works as expected
while(1) is working.

Thank you! Now, I am hoping to work with 128 samples to generate a 30 kHz sine wave using the DAC.


> The DMA is handling ADC sampling, and the ADC complete callback stores the processed values. 

I don't understand what you are doing here.
If you have more than one ADC channel, you would want to use DMA to move a complete sequence, and get a DMA_TC interrupt when finished.
In this case, you don't need or want an ADC interrupt, as you want to work on a consistent ADC data set.

And for a single-channel ADC conversion, using DMA is overkill.

> Real_Sum += (int32_t)adc_buffer[i] * Reference_Sinus[i];

I suppose the "Reference_Sinus" and "Reference_Cosinus" arrays are scaled sin/cos value tables.
This code should take very few instruction and processing time, and not be a problem.

As a side note, you would only need one table for sin/cos, as sin(x) = cos(x + PI/2).