cancel
Showing results for 
Search instead for 
Did you mean: 

DMA Freezes CPU STM32F401

alig_ones
Associate II

I am using STM32F401, I had an application which communicates via USART1 by using DMA2. Both RX and TX DMAs are working fine. So I added a bootloader and moved application to 0x08008100. Bootloader is using same USART1 and DMA2. Now bootloader is working fine but I have problem with application.

All I changed in application is start address. Bootloader jumps to application, timer interrupt is working fine and toggles LED. When it receives or transmits a data via DMA it stops, LED is not toggling anymore. When debugging I tried these:

* SCB->VTOR is already set as 0x08008100. Timer interrupt is working fine.

* I changed application's start address back to 0x08000000 and its working fine. 

* I removed USART and DMA code from bootloader so it only jumps to application. It didn't solve the problem (it lloks like not deinitialize-initialize issue).

* I added USART and DMA to bootloader back. In the application I didn't use DMA when sending data with USART, it could send without any problem. I tried this a few times, it stops when sending data with USART DMA but keeps working when sending without DMA.

* In the application, I added HAL_DMA_DeInit before HAL_DMA_Init, it stops before even trying to send message.

 

How can I solve this issue? Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Super User

Can VTOR be set to multiple of 0x100? Seems small. Pretty sure it needs to be a multiple of 0x200.

Should be able to debug the application in STM32CubeIDE at whatever offset you have it at, step through, see the issue.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

6 REPLIES 6
Andrew Neil
Super User

@alig_ones wrote:

 When it receives or transmits a data via DMA it stops


Microcontrollers don't just "stop".

Use the debugger to find what, exactly, it is actually doing in this state.  And how it got there.

Is it, perhaps, stuck in the Hard Fault handler? Or some other "error handler" which just spins in a loop?

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

Sorry I meant its stuck in somewhere, is it possible to debug application code when using bootloader? I tried with bootloader now and I saw this error:

alig_ones_0-1759840998080.png

which means its in Hard Fault handler:

alig_ones_1-1759841062552.png

When I check call stack I see:

alig_ones_2-1759841236417.png

alig_ones_3-1759841305465.png

It fails in HAL_DMA_DeInit function. I was calling this function before initialization of DMA. I removed it.

After removing It keeps toggling LED but transmits data only once, then it doesn't send data (in the timer interrupt, I send test byte and toggle LED). Actually this was the my earlier problem, to solve it I added and removed many things (like HAL_DMA_DeInit ) whole day and forgot root cause. So I can summarize the issue: After jumping to application I send data with HAL_UART_Transmit_DMA function, data is sent once.

 


@alig_ones wrote:

 is it possible to debug application code when using bootloader?


Sure - you can connect the debugger to a running target

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
TDK
Super User

Can VTOR be set to multiple of 0x100? Seems small. Pretty sure it needs to be a multiple of 0x200.

Should be able to debug the application in STM32CubeIDE at whatever offset you have it at, step through, see the issue.

If you feel a post has answered your question, please click "Accept as Solution".

That was the problem, with 0x200 offset its working fine again, thank you very much @TDK and @Andrew Neil . I am using VS Code (it has useful features like git history, file timeline, code snippets, finding files functions etc.) but have less debug features unfortunately. I will try to use STM32CubeIDE. Thanks again.


@alig_ones wrote:

 VS Code (it has useful features like git history, file timeline, code snippets, finding files functions etc.) .


CubeIDE (being Eclipse) can do Git integration and finding files functions etc ...

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.