Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Variable in flash memory - how to write?

Variable in flash memory - how to write?

Scheduled Pinned Locked Moved C / C++ / MFC
adobebusinessperformancetutorialquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    elelont2
    wrote on last edited by
    #1

    Hi, I read that i can set a variable in flash memory like this (PIC32):

    uint8 Gain_factor_Den_17[128] __attribute__((space(prog), section(".table_flash_control")));

    But what happens when i change that variable, flash has some requirements (e.g. need to erase page before writing etc). Who will handle that?

    J 1 Reply Last reply
    0
    • E elelont2

      Hi, I read that i can set a variable in flash memory like this (PIC32):

      uint8 Gain_factor_Den_17[128] __attribute__((space(prog), section(".table_flash_control")));

      But what happens when i change that variable, flash has some requirements (e.g. need to erase page before writing etc). Who will handle that?

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      The variable is read only for your program. It is up to you to handle writing to it. See the Microchip article Data EEPROM Emulation for PIC18, PIC24, dsPIC, PIC32[^]. There is also a library that emulates an EEPROM using the program flash memory. But you should take care of the limited write endurance of your PIC device. If you need to change the variable frequently, you should use an external EEPROM.

      E 1 Reply Last reply
      0
      • J Jochen Arndt

        The variable is read only for your program. It is up to you to handle writing to it. See the Microchip article Data EEPROM Emulation for PIC18, PIC24, dsPIC, PIC32[^]. There is also a library that emulates an EEPROM using the program flash memory. But you should take care of the limited write endurance of your PIC device. If you need to change the variable frequently, you should use an external EEPROM.

        E Offline
        E Offline
        elelont2
        wrote on last edited by
        #3

        Thanks for the response, but i am still a little confused. Just theoretically, what happens if i were to write:

        uint8 Table[128] __attribute__((space(prog), section(".table_flash_control"))); // Create variable in flash memory
        ...
        Table[0] = 13; // Is it written to flash now?

        Unfortunately i cannot try it, just trying to understand the logic. I am aware that the flash memory has only some certain write lifespan.

        J 1 Reply Last reply
        0
        • E elelont2

          Thanks for the response, but i am still a little confused. Just theoretically, what happens if i were to write:

          uint8 Table[128] __attribute__((space(prog), section(".table_flash_control"))); // Create variable in flash memory
          ...
          Table[0] = 13; // Is it written to flash now?

          Unfortunately i cannot try it, just trying to understand the logic. I am aware that the flash memory has only some certain write lifespan.

          J Offline
          J Offline
          Jochen Arndt
          wrote on last edited by
          #4

          The flash memory of the PIC controllers is the program memory where code is stored. You can initialize the variable at compile time and it will be written together with the program code. To write to the program memory by the running program you need to execute special instructions. For the PIC 32 see section 5. Flash Programming[^ PDF] of the PIC32 Family Reference Manual. A compiler or assembler may provide functions or macros to perform the writing or compilers may have built-in support for writing. So the answer if the value is written depends on the used compiler. But if the compiler does not support writing to flash memory, you will get an error at compile time.

          E 1 Reply Last reply
          0
          • J Jochen Arndt

            The flash memory of the PIC controllers is the program memory where code is stored. You can initialize the variable at compile time and it will be written together with the program code. To write to the program memory by the running program you need to execute special instructions. For the PIC 32 see section 5. Flash Programming[^ PDF] of the PIC32 Family Reference Manual. A compiler or assembler may provide functions or macros to perform the writing or compilers may have built-in support for writing. So the answer if the value is written depends on the used compiler. But if the compiler does not support writing to flash memory, you will get an error at compile time.

            E Offline
            E Offline
            elelont2
            wrote on last edited by
            #5

            Thanks, that clears it up!

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups