This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Code runs in line-by-line debugging but not otherwise. Some functions only run if defined as macros

I am writing code for the STM32F031K6T6 MCU using the Keil uVision. The IDE information is shown in the image below: 

Keil info

The C/C++ options for Target are configured as shown here:

C/C++

I started a new project, selected the chip, and configured the run-time environment as below:

Initial config

I initialized the clock and configured the Flash registers for the appropriate latency. I tested the frequency using MCO and it seems correct. I also initialized some GPIOs, UART, and the SysTick. The peripheral registered is modified as expected as seen on the System View for the respective peripheral in the debugging mode.

The problem is that some functions, such as functions for sending and receiving data via UART and some functions that use GPIO ports only work in debugging mode when I run the code line-by-line. If I click the run button the code gets stuck and the chip stops responding. I still see the VAL and CURRENT registers of the SysTick updating.

This is an example of a function that works:

This is an example of a function that doesn’t work:

The macros used in the function above are defined as below:

The GPIO pins used in the function above are initialized as follows:

And the us_Delay() function is based on SysTick. These are defined as:

Now, this is the same UV_LED_Driver(uint32_t d) function defined as a macro (Runs as expected):

This is the main():

Interestingly, if I define the functions as macros, they behave as desired. I finally tested the code on a STM32F429ZIT chip and it worked well, given the needed modifications in the initialization of the main clock and the GPIO. Has anyone ever experienced anything similar or happens to know what could be causing this issue? I know that I could walk around this issue using CubeMX but I would like to find out what is causing this problem.

Thank you.

0