From 8745c2226896daee95695931d2ed0bdb806ba818 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Tue, 18 Feb 2025 00:34:48 +0100 Subject: [PATCH] Use flash key defines/constants when writing to flash --- rand.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/rand.c b/rand.c index 062a64a..d2e2c28 100644 --- a/rand.c +++ b/rand.c @@ -1,5 +1,6 @@ #include "rand.h" #include "ch32fun.h" +#include "ch32v003hw.h" #include #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;