Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding SFE configuration in MAX32520 Flash example #539

Merged
merged 2 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions Examples/MAX32520/Flash/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,47 +52,46 @@ 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.)

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.

```
33 changes: 30 additions & 3 deletions Examples/MAX32520/Flash/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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()
{
/*
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -307,7 +334,7 @@ int main(void)
if (err)
return err;

err = validate_test_pattern();
err = validate_test_pattern_erase();
if (err)
return err;

Expand Down