简体   繁体   中英

Clearing the stm32f4-discovery flash programatically

I'm having a problem clearing the stm32f429 discovery board flash after creating a window using stemwin library. If I use the code below, flash will be cleared correctly:

EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;
EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3;
EraseInitStruct.Sector = FLASH_SECTOR_22;
EraseInitStruct.NbSectors = 1;
HAL_FLASH_Unlock();
uint32_t sectorError = 0;
if(HAL_FLASHEx_Erase(&EraseInitStruct,&sectorError)!=HAL_OK)
{
    return HAL_FLASH_GetError();
}

HAL_FLASH_Lock();

CreateWindow();

But if I bring the CreateWindow() function to top of the code, flash will not be cleared. Here is CreateWindow() function:

WM_HWIN CreateWindow(void)
{
hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate),       _cbDialog, WM_HBKWIN, 0, 0);

hMultiPage = MULTIPAGE_CreateEx(0, -20, 320, 260, WM_GetClientWindow(hWin),   WM_CF_SHOW, 0, 0);
MULTIPAGE_SetSkin(hMultiPage,MULTIPAGE_SKIN_FLEX);

hPage1 = GUI_CreateDialogBox(_aDialogCreate2, GUI_COUNTOF(_aDialogCreate2),  _cbDialogPage1,       WM_UNATTACHED, 0, 0);
MULTIPAGE_AddPage(hMultiPage, hPage1, "Settings");

hPage2 = GUI_CreateDialogBox(_aDialogCreate3, GUI_COUNTOF(_aDialogCreate3), _cbDialogPage2,       WM_UNATTACHED, 0, 0);
MULTIPAGE_AddPage(hMultiPage, hPage2, "Run");

MULTIPAGE_SelectPage(hMultiPage,0);

return hWin;
}

These 2 things has nothing to do between. There could be a problem, however, that you want to delete sector where data are located (maybe images or similar) for your GUI.

Technically, there is no other option here.

Also, check which value "SectorError" variables has after function completes?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM