PROGMEM vs SRAM

Understanding the language, error messages, etc.

PROGMEM vs SRAM

Postby AntonyPrince » Fri Aug 08, 2014 5:06 pm

I was looking over the menu example and it shows the menu items being stored in PROGMEM. I looked up the Arduino PROGMEM function and it states that this function is used to store variables to program flash memory rather than SRAM. My question is, what is the reasoning behind storing these in PROGMEM vs SRAM? I'm creating dynamic menus that will have different options depending on the current situation and I wanted to know if there were any performance advantages/disadvantages and why these values should be stored in PROGMEM instead of SRAM. I'm new to developing for Arduino, so be easy on me. :)
User avatar
AntonyPrince
 
Posts: 21
Joined: Thu Aug 07, 2014 1:07 am
Location: Virginia, United States

Re: PROGMEM vs SRAM

Postby AntonyPrince » Fri Aug 08, 2014 5:17 pm

As an aside to that, I noticed the compiler mentions that the SRAM size can be explicitly set in the board description file. Anyone know what the SRAM specification is for the Gamebuino so I can add it to the boards.txt file and get the IDE to shut up about it?
User avatar
AntonyPrince
 
Posts: 21
Joined: Thu Aug 07, 2014 1:07 am
Location: Virginia, United States

Re: PROGMEM vs SRAM

Postby rodot » Fri Aug 08, 2014 5:23 pm

The atmega328P (the microcontroller of the gamebuino) has 2KB of RAM (of which about 0.7KB are used by the library), and 32KB of flash (aka program memory, rom, progmem...). So you understand that RAM is a very scarce resource you want to spare. That's why we store strings in progmem.

You're right, I forgot to add the RAM size (2048) on the getting started page. I just added it. This is what your Gamebuino in boards.txt should look like now:
Code: Select all
##############################################################
gamebuino.name=Gamebuino
gamebuino.upload.tool=avrdude
gamebuino.upload.protocol=arduino
gamebuino.upload.maximum_size=30592
gamebuino.upload.maximum_ram_size=2048
gamebuino.upload.speed=115200
gamebuino.bootloader.low_fuses=0xff
gamebuino.bootloader.high_fuses=0xda
gamebuino.bootloader.extended_fuses=0x05
gamebuino.bootloader.path=gamebuino_boot
gamebuino.bootloader.file=gamebuino_boot.hex
gamebuino.bootloader.unlock_bits=0x3F
gamebuino.bootloader.lock_bits=0x0F
gamebuino.build.mcu=atmega328p
gamebuino.build.f_cpu=16000000L
gamebuino.build.core=arduino
gamebuino.build.variant=standard
##############################################################
User avatar
rodot
Site Admin
 
Posts: 1290
Joined: Mon Nov 19, 2012 11:54 pm
Location: France

Re: PROGMEM vs SRAM

Postby AntonyPrince » Fri Aug 08, 2014 5:26 pm

Makes perfect sense. I figured it was something along those lines. Thanks for clarifying, Rodot. And also thank you for creating this great device and the the community to support it!
User avatar
AntonyPrince
 
Posts: 21
Joined: Thu Aug 07, 2014 1:07 am
Location: Virginia, United States


Return to Programming Questions

Who is online

Users browsing this forum: No registered users and 7 guests