2024-11-08 02:53 AM - last edited on 2024-11-08 03:28 AM by Pavel A.
Hello.
I am creating a program to write data to multiple FLASH memories using the STM32C031.
I have set FLASH page13,14,15 as new pages to be written, but only page13, which is the first page to be rewritten with FLASH, is rewritten, while page14 and 15 are not rewritten properly and the value is only changed to 0x00.
However, if the pages to be written are page12,13,15 or page12,14,15 and one page is skipped, the contents to be written can be successfully written on three consecutive pages.
At this time, the deletion and writing procedures of FLASH use exactly the same program as when it is not possible to write.
Is there anything we can do to make it so that we can successfully write on three consecutive pages?
Best Regards,
void Write(){
uint16_t i;
__disable_irq();
huart1.Instance->CR1 &= ~0x04;
FLASH_UNLOCK();
FLASH_DELETE(0x0D);
for(i=0;i<256;i++){
FLASH_Write(0x08006800+i*0x00000008,buff[i+1]);
}
FLASH_DELETE(0x0E);
for(i=0;i<256;i++){
FLASH_Write(0x08007000+i*0x00000008,buff[i+257]);
}
FLASH_DELETE(0x0F);
for(i=0;i<64;i++){
FLASH_Write(0x08007800+i*0x00000008,buff[i+513]);
}
for(i=0;i<4;i++){
FLASH_Write(0x08007B20+i*0x00000008,data[i]);
}
huart1.Instance->CR1 |= 0x04;
__enable_irq();
}
2024-11-08 01:45 PM
Dear @shank ,
can you let us know if the code above and all routines are executed from Flash addresses or from RAM , try to move to RAM all of the FLASH functions and see if still the same . Also check if there are ERRORS flags set after first Erase or Programming . Having 0x00 written means the flash was not erased properly and may be interrupted , or accidentally Programmed to 0x00 . Let us know
Ciao
STOne-32
2024-11-08 01:57 PM
What library is this?
Provided example is very superfical
It should be possible to erase pages, one at a time, or several, and then write to them consecutively.
You're case/issue here isn't sufficiently compelling, you're going to need to present this a lot better.
Perhaps start by inspecting/reviewing the code you're calling, and what errors or failures that might be having.
2024-11-12 03:46 AM
Thank you for your response.
I recognize that my program starts with FLASH. I feel that the verification by moving the program to RAM would exceed the RAM capacity of the STM32C031 since there is currently 30KB of FLASH program, is there any way to verify this?
The current FLASH writing program is below. Please let us know if there are any modifications to the program.
<main.c/FLASH program>
void FLASH_UNLOCK(){
while ((FLASH->SR & FLASH_SR_BSY1) != 0);
if ((FLASH->CR & FLASH_CR_LOCK) != 0){
FLASH->KEYR = 0x45670123;
FLASH->KEYR = 0xCDEF89AB;
}
}
void FLASH_DELETE(uint16_t page){
while ((FLASH->SR & FLASH_SR_BSY1) != 0);
while ((FLASH->SR & FLASH_SR_CFGBSY) != 0);
FLASH->CR |= FLASH_CR_PER;
FLASH->CR |= (FLASH_CR_PNB & (page<<3));
FLASH->CR |= FLASH_CR_STRT;
while ((FLASH->SR & FLASH_SR_CFGBSY) != 0);
FLASH->CR &= ~FLASH_CR_PER;
}
void FLASH_Write(uint32_t address, uint64_t data){
while ((FLASH->SR & FLASH_SR_BSY1) != 0);
while ((FLASH->SR & FLASH_SR_CFGBSY) != 0);
uint32_t data2 = (uint32_t)(data>>32);
FLASH->CR |= FLASH_CR_PG;
*(__IO uint32_t*)address =(uint32_t)data;
*(__IO uint32_t*)(address+4) =data2;
while ((FLASH->SR & FLASH_SR_CFGBSY) != 0);
if ((FLASH->SR & FLASH_SR_EOP) != 0){
FLASH->SR &= ~FLASH_SR_EOP;
}else{
err_flg = 1;
}
FLASH->CR &= ~FLASH_CR_PG;
}
Best Regards,