2023-11-28 04:57 AM
hello experts ,my device is stm32f103c8t6 ,cubeide 1.14.0
it shows 64kb flash in ide but shows 128kb in stmcube programmer ,my issue is if i write flash from inside the programme while mcu running then it writes fine but when i erase the page and try to write again it does not write , my code is here ,
HAL_FLASH_Unlock();
HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, 0x0800FC00,1000);// page 63
//write fine until here
HAL_Delay(100);
FLASH_PageErase(0x0800FC00); //page 63
//erase page ok but after using erase it doesnt wite anything
HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, 0x0800FC04,1000);//defaults
HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, 0x0800FC06,100);//d
do anyone know problem ?
i am trying to use a memory page as eeprom
Solved! Go to Solution.
2023-11-28 01:00 PM
I used this method and it worked thanks everyone
erasePage63();
// Function to erase page number 63
void erasePage63(void) {
FLASH_EraseInitTypeDef eraseInitStruct;
uint32_t pageError = 0;
// Erase settings
eraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES; // Erase type: Page erase
// 0x08000000 + (63 * 1024) = 0x0800FC00 //63 is page no and you can use different
eraseInitStruct.PageAddress = 0x0801FC00; // Start address of page 63
eraseInitStruct.NbPages = 1; // Number of pages to erase
// Erase page
HAL_FLASHEx_Erase(&eraseInitStruct, &pageError);
if (pageError != 0) {
// An error occurred during erasing
// Handle the error here
}
}
2023-11-28 05:26 AM
Hello @ahmash
Try to read out the PER bit value of the FLASH_CR register after the erase.
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2023-11-28 06:22 AM
> FLASH_PageErase(0x0800FC00); //page 63
To erase a page, call HAL_FLASHEx_Erase, not FLASH_PageErase.
2023-11-28 01:00 PM
I used this method and it worked thanks everyone
erasePage63();
// Function to erase page number 63
void erasePage63(void) {
FLASH_EraseInitTypeDef eraseInitStruct;
uint32_t pageError = 0;
// Erase settings
eraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES; // Erase type: Page erase
// 0x08000000 + (63 * 1024) = 0x0800FC00 //63 is page no and you can use different
eraseInitStruct.PageAddress = 0x0801FC00; // Start address of page 63
eraseInitStruct.NbPages = 1; // Number of pages to erase
// Erase page
HAL_FLASHEx_Erase(&eraseInitStruct, &pageError);
if (pageError != 0) {
// An error occurred during erasing
// Handle the error here
}
}