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

Program Memory Constants

Note: This was originally posted on 22nd July 2013 at http://forums.arm.com

I am using a Cortex-M0 with Keil uVision4.  How are constants located in program memory and how can these program memory constants be changed by code?
Parents
  • Note: This was originally posted on 25th July 2013 at http://forums.arm.com

    There are two parts to the problem:

    1. getting the compiler to store the constants in just one place in FLASH

    2. updating that place.

    The surest way of accomplishing #1 would be to define the the constants in a separate asm file.  But, using asm is probably a bit overkill; if you define them in a separate C file (and don't let the compiler optimize across source files) you'll probably be fine:

    calibration.h

    struct CalibrationData {
      ...
    };
    extern const struct CalibrationData mycal;


    constants.c:

    #include "calibration.h"


    extern const struct CalibrationData mycal __attribute__((section("cal_data"))) = {
      ...
    };


    Now you can specify where in FLASH to place the "cal_data" section in the scatter file/linker script.  You're code can find the values with mycal.foo, &mycal and sizeof(mycal).

    I can't really help with part #2; it is specific to the microcontroller and FLASH parts that you're using.  Find out from the manufacturer(s) if they have examples/libraries to do In-Application FLASH Programming (IAP).
Reply
  • Note: This was originally posted on 25th July 2013 at http://forums.arm.com

    There are two parts to the problem:

    1. getting the compiler to store the constants in just one place in FLASH

    2. updating that place.

    The surest way of accomplishing #1 would be to define the the constants in a separate asm file.  But, using asm is probably a bit overkill; if you define them in a separate C file (and don't let the compiler optimize across source files) you'll probably be fine:

    calibration.h

    struct CalibrationData {
      ...
    };
    extern const struct CalibrationData mycal;


    constants.c:

    #include "calibration.h"


    extern const struct CalibrationData mycal __attribute__((section("cal_data"))) = {
      ...
    };


    Now you can specify where in FLASH to place the "cal_data" section in the scatter file/linker script.  You're code can find the values with mycal.foo, &mycal and sizeof(mycal).

    I can't really help with part #2; it is specific to the microcontroller and FLASH parts that you're using.  Find out from the manufacturer(s) if they have examples/libraries to do In-Application FLASH Programming (IAP).
Children
No data