This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Flashing value to gpregret

How do I write a value to gpregret when flashing the chip?

Basically, what I need to do is be able to detect the first time the chip is powered on so I can go into a special test mode. Once everything is verified as working, the app will clear gpregret, reset the chip, and everything will run as normal.

Thanks for the help.

Parents
  • Well you could try adding a section into your binary at the correct address to write it. However it's not going to do what you want because even if you wrote it, GPREGRET isn't preserved over a power on reset.

    Why don't you write to the customer area of the UICR (again by adding a UICR section to your binary), something like 0x55555555, then when you've finished the test, enable writes to Flash and set it to 0x0000000. Or don't write it at all, it'll be 0xFFFFFFFF on first powerup, then write it to anything else.

Reply
  • Well you could try adding a section into your binary at the correct address to write it. However it's not going to do what you want because even if you wrote it, GPREGRET isn't preserved over a power on reset.

    Why don't you write to the customer area of the UICR (again by adding a UICR section to your binary), something like 0x55555555, then when you've finished the test, enable writes to Flash and set it to 0x0000000. Or don't write it at all, it'll be 0xFFFFFFFF on first powerup, then write it to anything else.

Children
Related