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

uVision5 still skips codes under -O0 optimization level

Hi,

I am new to Keil and I am implementing some crypto algorithms on a platform using ARM cortex M23. The platform has 3KB RAM and 30KB ROM.

When I debug, if the plain text size is small (2048bytes), everything is fine. But if I increase the size of plain text to 3072 or 4096, the encryption will be skipped and I cannot see the result.

I added breakpoint right before and after the encryption function call but it doesn't stop. It goes back to the beginning of the whole program directly after I click "step over" before function call.

It seems like the text is too large to be encrypted correctly, maybe there is an overflow? But the builder did not report any error, the RO/RW size does not exceed 30KB/3KB either.

I saw many people suggest to lower the optimization level of Keil, but I am always at -O0, why this still happens?

Thanks in advance.

Parents
  • I am using a open source library, so I don't know much details about how the author allocates stack and heap.. but I will manage that.

    The stack and heap is usually not defined in the library. You define both in the startup files or in your linker scatter file.

    By the way, how can I know whether there is stack overflow?

    There is no stack overflow exception unless you don't use the MPU for the stack. A stack overflow will overwrite other variables or the application will crash when returning from a subroutine. In the map file, you see where the stack is located. This application note 316 tells you how to analyze the stack consumption:

    https://developer.arm.com/documentation/kan316/latest/

    Even if you don't use a Real-Time OS, you should read the paragraph "Main stack watermarking". Then you could see the current stack consumption in the uVision debugger.

    I didn't keep the string in RAM, I kept it in ROM. And the encrypted string is 128bits, so I don't think it will run out RAM space.

    OK, this looks reasonable.

    Where can I see the Exceptions dialog?

    Menu 'Peripherals - Core Peripherals - Fault Reports'.

    Total RW  Size (RW Data + ZI Data)              1032 (   1.01kB)

    This looks extremely low but might be correct.

Reply
  • I am using a open source library, so I don't know much details about how the author allocates stack and heap.. but I will manage that.

    The stack and heap is usually not defined in the library. You define both in the startup files or in your linker scatter file.

    By the way, how can I know whether there is stack overflow?

    There is no stack overflow exception unless you don't use the MPU for the stack. A stack overflow will overwrite other variables or the application will crash when returning from a subroutine. In the map file, you see where the stack is located. This application note 316 tells you how to analyze the stack consumption:

    https://developer.arm.com/documentation/kan316/latest/

    Even if you don't use a Real-Time OS, you should read the paragraph "Main stack watermarking". Then you could see the current stack consumption in the uVision debugger.

    I didn't keep the string in RAM, I kept it in ROM. And the encrypted string is 128bits, so I don't think it will run out RAM space.

    OK, this looks reasonable.

    Where can I see the Exceptions dialog?

    Menu 'Peripherals - Core Peripherals - Fault Reports'.

    Total RW  Size (RW Data + ZI Data)              1032 (   1.01kB)

    This looks extremely low but might be correct.

Children