From e04ebdd90f9e331fa6ae3edbbf0c56d19bcec6a3 Mon Sep 17 00:00:00 2001 From: Scheiffler Date: Thu, 6 Apr 2023 11:41:09 -0500 Subject: [PATCH 1/2] Adding SFE configuration in MAX32520 Flash example to fix read errors. --- Examples/MAX32520/Flash/README.md | 23 +++++++++++---------- Examples/MAX32520/Flash/main.c | 33 ++++++++++++++++++++++++++++--- 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/Examples/MAX32520/Flash/README.md b/Examples/MAX32520/Flash/README.md index 81077064b8d..93e1e48c598 100644 --- a/Examples/MAX32520/Flash/README.md +++ b/Examples/MAX32520/Flash/README.md @@ -52,29 +52,29 @@ After flashing and launching the example, an LED on the board will blink once ev ``` ***** Flash Control Example ***** -Press Push Button 1 (PB1/SW1) to continue... +Press SW2 to continue... ---(Critical)--- -Successfully erased page 64 of flash (addr 0x1007e000) -Writing magic value 0xfeedbeef to address 0x1007e000... -Done! +Erasing page 64 of flash (addr 0x101fc000)... +Writing magic value 0xfeedbeef to address 0x101fc000... Writing test pattern... Done! ---------------- -> Interrupt! (Flash operation done) +Verifying test pattern... +Successfully verified test pattern! Now reset or power cycle the board... - ``` At this point, the "magic" and test pattern values have been written to flash. Press SW5 to reset the board, after which the application will restart. Push PB1 to continue the application again, which will print out the following contents: ``` ***** Flash Control Example ***** -Press Push Button 1 (PB1/SW1) to continue... +Press SW2 to continue... -** Magic value 0xfeedbeef found at address 0x1007e000! ** +** Magic value 0xfeedbeef found at address 0x101fc000! ** (Flash modifications have survived a reset and/or power cycle.) @@ -82,17 +82,16 @@ Verifying test pattern... Successfully verified test pattern! ---(Critical)--- -Erasing magic... Buffering page... Erasing page... +Erasing magic in buffer... Re-writing from buffer... -New magic value: 0xabcd1234 +New magic value: 0x4428fad1 ---------------- -> Interrupt! (Flash operation done) -Verifying test pattern... -Successfully verified test pattern! +Verifying test pattern erase... +Successfully erased test pattern! Flash example successfully completed. - ``` diff --git a/Examples/MAX32520/Flash/main.c b/Examples/MAX32520/Flash/main.c index 5d4ab3cf618..0f46360130e 100644 --- a/Examples/MAX32520/Flash/main.c +++ b/Examples/MAX32520/Flash/main.c @@ -52,6 +52,7 @@ #include "uart.h" #include "led.h" #include "pb.h" +#include "sfe.h" /***** Definitions *****/ #define TEST_ADDRESS (MXC_FLASH_MEM_BASE + MXC_FLASH_MEM_SIZE) - (1 * MXC_FLASH_PAGE_SIZE) @@ -70,13 +71,19 @@ volatile uint32_t isr_flags; /***** Functions *****/ //****************************************************************************** - int button_pressed = 0; void button_handler() { button_pressed = 1; } +//****************************************************************************** +void sfe_init(void) +{ + MXC_SFE_Init(); + MXC_SFE_SetFlashAddress(TEST_ADDRESS, TEST_ADDRESS + MXC_FLASH_PAGE_SIZE); +} + //****************************************************************************** void FLC0_IRQHandler(void) @@ -195,6 +202,24 @@ int validate_test_pattern() return err; } +int validate_test_pattern_erase() +{ + int err = 0; + + printf("Verifying test pattern erase...\n"); + uint32_t readval = 0; + for (uint32_t addr = TEST_ADDRESS + 4; addr < TEST_ADDRESS + MXC_FLASH_PAGE_SIZE; addr += 4) { + MXC_FLC_Read(addr, &readval, 4); + if (readval == TEST_VALUE) { + printf("Failed to verify erase at address 0x%x with error code %i!", addr, err); + return E_ABORT; + } + } + + printf("Successfully erased test pattern!\n\n"); + return err; +} + int erase_magic() { /* @@ -243,9 +268,11 @@ int main(void) { int err = 0; + sfe_init(); + printf("\n\n***** Flash Control Example *****\n"); #ifndef BOARD_MAX32520FTHR - printf("Press Push Button 1 (PB1/SW1) to continue...\n\n"); + printf("Press SW2 to continue...\n\n"); PB_RegisterCallback(0, (pb_callback)button_handler); while (!button_pressed) { @@ -307,7 +334,7 @@ int main(void) if (err) return err; - err = validate_test_pattern(); + err = validate_test_pattern_erase(); if (err) return err; From 17aadda9ab5b7d5f09e146de900042a79965398d Mon Sep 17 00:00:00 2001 From: Scheiffler Date: Thu, 6 Apr 2023 11:56:01 -0500 Subject: [PATCH 2/2] Reslving clang-format errors. --- Examples/MAX32520/Flash/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Examples/MAX32520/Flash/main.c b/Examples/MAX32520/Flash/main.c index 0f46360130e..fa11497f352 100644 --- a/Examples/MAX32520/Flash/main.c +++ b/Examples/MAX32520/Flash/main.c @@ -80,8 +80,8 @@ void button_handler() //****************************************************************************** void sfe_init(void) { - MXC_SFE_Init(); - MXC_SFE_SetFlashAddress(TEST_ADDRESS, TEST_ADDRESS + MXC_FLASH_PAGE_SIZE); + MXC_SFE_Init(); + MXC_SFE_SetFlashAddress(TEST_ADDRESS, TEST_ADDRESS + MXC_FLASH_PAGE_SIZE); } //******************************************************************************