From 74b7520159a5f7fc86f8698a5ac042d96ae4f6ee Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Tue, 14 Jun 2011 00:04:45 -0400 Subject: arm-gcc: Expanding notes on replacing pgmspace.h Thanks to James Bowman for the extra defines and typedef. --- source/arm-gcc.rst | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/source/arm-gcc.rst b/source/arm-gcc.rst index e97bb2f..5fb9a17 100644 --- a/source/arm-gcc.rst +++ b/source/arm-gcc.rst @@ -74,12 +74,23 @@ including Arduino) for use on the Maple. .. _arm-gcc-attribute-flash: -- Replacing ``PROGMEM``: You can direct the linker script provided - with libmaple to store a variable in Flash (instead of RAM) by using - the libmaple macro ``__FLASH__``, like so:: +- Replacing ``PROGMEM``: If you need to store a lot of constant data, + you can store variables in Flash (instead of RAM) by using the + libmaple macro ``__FLASH__``. Here's an example:: uint32 array[] __FLASH__ = {0, 1, 2}; - Be aware, however, that if you do that, you can only store values - which are compile-time constants, and that if you attempt to change - a variable stored in Flash, your program will crash. + This will help you save RAM when you need to store large amounts of + data, like look-up tables. + + You can only store values which are compile-time constants (like + numbers and strings, and arrays of numbers and strings) in this way. + Also, if you try to change a variable stored in Flash, your program + will crash. + + If you need to port over AVR/Arduino code that uses pgmspace.h, + these declarations may help you:: + + typedef const unsigned char prog_uchar; + #define pgm_read_byte_near(x) (*(prog_uchar*)x) + #define pgm_read_byte(x) (*(prog_uchar*)x) -- cgit v1.2.3