Skip to main content
LMI2
Senior III
November 22, 2018
Question

Single stepping doesn't run in order

  • November 22, 2018
  • 5 replies
  • 1069 views

I am single stepping through simple code. I have two similar similar lines in a loop. Single stepping only goes to the last of those lines. This is STM32F746 Discovery and Keil IDE.

while(9)
{
 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)"\0", 1, 5000)!= HAL_OK)
 {
 Error_Handler(); 
 }
HAL_Delay(100);	
 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)'\n', 1, 5000)!= HAL_OK)
 {
 Error_Handler(); 
 }
	HAL_Delay(100);
}

    This topic has been closed for replies.

    5 replies

    LMI2
    LMI2Author
    Senior III
    November 22, 2018

    I think this is the problem:

    if(HAL_UART_Transmit(&UartHandle, (uint8_t*)'\n',

    This seems to work:

    if(HAL_UART_Transmit(&UartHandle, (uint8_t*)"\n",

    Tesla DeLorean
    Guru
    November 22, 2018

    You can't make a character into a pointer, that's not how this works. The function wants the address of a buffer, not the character you want to send..

    We went over this in the previous thread.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    LMI2
    LMI2Author
    Senior III
    November 22, 2018

    I assumed that 'A' is a single byte but otherwise like "Ascii". This is what happens when I do this once or twice a year. I am really more a HW designer.

    Yes, I suspected this had something to do with optimization. I have to check compiler settings, perhaps even study some C.

    "so my first activity ist to switch off them again - afterwards no problems with stepping anymore." Good to know.

    Tesla DeLorean
    Guru
    November 22, 2018

    The core functionality and compiler optimization work against you single stepping.

    From the prior thread https://community.st.com/s/question/0D50X0000A1jvPMSQY/what-is-wrong-with-this-haluarttransmituarthandle-uint8t0

    "The CM7 is a super-scaler pipelined architecture. Multiple non-conflicting instructions execute at once, and optimization can cause apparently non-sequential/out-of-order execution. Remember the C line may compile to multiple assembler instructions, and the granularity of the debugger's understanding of the code is one C line, which may be spread around. There might also be some core level errata related to revision/patch levels, because single stepping is an unnatural state for the core to be operating in.

    I rarely use single stepping to understand what my code is doing, I can do static analysis to confirm the logic is correct, and if I want to know what the processor is doing, or likely to do, I read the assembler directly and follow that."

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    michael from rentron
    Associate II
    November 22, 2018

    please check compiler option for optimizer level, i had similar problems which are gone mit

    compiler option -O0 (Atollic) meaning: no optimization. In your toolchain the syntax may be different.

    By the way: So far i know, CubeMX always will set a higher optimizer level by generating projects - so my first activity ist to switch off them again - afterwards no problems with stepping anymore.