Use flash key defines/constants when writing to flash
This commit is contained in:
parent
bfcbb77570
commit
8745c22268
1 changed files with 5 additions and 4 deletions
9
rand.c
9
rand.c
|
@ -1,5 +1,6 @@
|
|||
#include "rand.h"
|
||||
#include "ch32fun.h"
|
||||
#include "ch32v003hw.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#define BUILD_SEED \
|
||||
|
@ -51,11 +52,11 @@ void rand_reseed() {
|
|||
// See:
|
||||
// https://github.com/cnlohr/ch32v003fun/blob/2ac62072272f2ccd2122e688a9e0566de3976a94/examples/flashtest/flashtest.c
|
||||
void rand_save_to_flash() {
|
||||
FLASH->KEYR = 0x45670123; // Unlock flash
|
||||
FLASH->KEYR = 0xCDEF89AB;
|
||||
FLASH->KEYR = FLASH_KEY1; // Unlock flash
|
||||
FLASH->KEYR = FLASH_KEY2;
|
||||
|
||||
FLASH->MODEKEYR = 0x45670123; // Unlock programming mode
|
||||
FLASH->MODEKEYR = 0xCDEF89AB;
|
||||
FLASH->MODEKEYR = FLASH_KEY1; // Unlock programming mode
|
||||
FLASH->MODEKEYR = FLASH_KEY2;
|
||||
|
||||
// Erase the flash page
|
||||
FLASH->CTLR = CR_PAGE_ER;
|
||||
|
|
Loading…
Add table
Reference in a new issue