0

I want to use all SRAM of an Arduino by writing the code in assembly. But does the bootloader use some SRAM while the program is running, and if the answer is yes would changing that data lead to failure or does the data stored there get corrupted? Thanks for reaching out.

asked Oct 25, 2022 at 10:46

1 Answer 1

5

You did not specify what type of Arduino you are using. My answer is for the AVR-based ones.

The bootloader does use RAM while it is running. However, once it handles control to your program, the microcontroller is all yours: you are free to use all the RAM.

Id did not check with optiboot but, it is possible that the bootloader leaves some stuff in the stack. The C runtime of the avr-libc takes care of this: one of the first things it does is to reset the stack pointer. If you link with the avr-libc, you will find the stack empty. If you don't, I suggest you set the stack pointer to RAMEND at the beginning of your program, just in case.

answered Oct 25, 2022 at 11:42
3
  • 1
    I expecting that it didn't, but apparently optiboot as it was compiled for UNO leaves 2 bytes on the stack, entering application code with SP = 0x8FD. It doesn't matter for the reason you pointed out, but it's fun useless trivia I guess. =) Commented Oct 25, 2022 at 13:58
  • Whether you need those two bytes depends on an architecture detail: is the stack pointer written, then decremented or the other way round on the avr cpu? Commented Oct 25, 2022 at 15:33
  • 2
    @PMF: On AVR, the stack pointer is post-decremented when writing to the stack. Commented Oct 25, 2022 at 15:53

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.