2021-11-02 09:24 AM
Hi everyone! I have recently developed a firmware in STM32CubeIDE for my STM32H743ZIT6 that implements a Spi communication with an external ADC using the DMA and MDMA.
The code works fine but now I have noticed that the MDMA does not call anymore the callback "MDMA_RepBlockCompleteCallback" when I define a new variable.
Please refer to the attached picture:
A) The MDMA stops working when "variable1" is defined (line 88) and set to 1 (line 214). This variable has been created just for the purposes of this test and it is not used elsewhere in the code apart from lines 88 and 214.
B) if I comment out the "variable1" definition and initialization, everything works fine again.
Do you know why there is this problem and how can I solve it?
I also use the MPU, if this can help. Please let me know if you need another part of the code or file to debug this problem.
Thanks,
Andrea
2021-11-02 09:40 AM
When changing unrelated things in the code gets things to work, the answer is typically elsewhere. Perhaps an out of bounds write, or a failed memory allocation, or a stack overflow, or use of an uninitialized variable.
Also ensure your method for verifying MDMA_RepBlockCompleteCallback is run is robust, such as toggling a pin, rather than something that the debugger may be missing, such as a breakpoint.
In either case, debugging the code and seeing where the processor is at to ensure it's not stuck in a loop would be step 1.
2021-11-02 10:25 AM
Dear TDK, thanks for your answer. When I run the code in Debug mode I don't see the processor stuck in a loop, it simply continues doing its job and waits forever for the event "MDMA_RepBlockCompleteCallback".
Since the code works perfectly when "variable1" is not declared, I also think there may be a problem with the memory allocation, however, I don't know how to debug this. Also because I assume this is done automatically by the compiler.
Moreover, in both cases A) and B) I don't get any error or warning when I compile the code.
2021-11-05 02:51 AM
Are you using run-time library functions like malloc()? printf() with floats?
More specifically using any of these functions from ISR or in multiple threads?
... Trying to understand if this could be related to thread-safe issues.
Easiest way to find out could be to go File > New > Other > ST > Thread-Safe Solution. Generate the thread-safe files to some existing source code folder. Choose a strategy. Be careful with your choice. Carefully consider if halting the target in the wrong state could lead to damaging your hardware.
If not, rely on strategy#3 for bare-metal or strategy#5 for FreeRTOS.
If you now instead get stuck in the Error_Handler then it is clear that you have some issues with thread-safety.
Quite an easy test for you to make.