2021-05-26 04:14 AM
my pagesize is 256 bytes, and 90k is about 351 pages
for(i = 0; i < pages; i++)
{
W25qxx_ReadPage((uint8_t *)u32_databuf, EXT_FLASH_ADDR_APP_START + i,0, w25qxx.PageSize);
ProgramInternalFlash(APP_BASE_ADDR + i * w25qxx.PageSize, u32_databuf,w25qxx.PageSize);
}
void ProgramInternalFlash(uint32_t u32_intFlashstart, uStruct_u32 *pData ,uint32_t data_len)
{
HAL_FLASH_Unlock();
/* Fill EraseInit structure*/
EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;
EraseInitStruct.PageAddress = u32_intFlashstart;
EraseInitStruct.NbPages = data_len / FLASH_PAGE_SIZE;
if (HAL_FLASHEx_Erase(&EraseInitStruct, &PAGEError) != HAL_OK)
{
Error_Handler();
}
Address = u32_intFlashstart;
uint16_t i = 0;
while (Address < u32_intFlashstart + data_len)
{
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, Address,pData[i].u32_buf) == HAL_OK)
{
Address = Address + 4;
i += 1;
}
else
{
Error_Handler();
}
}
HAL_FLASH_Lock();
}
2021-05-26 05:35 AM
Perhaps it is your W25Q routines which are slowing. See how fast it runs without those for a test/baseline.
2021-05-26 05:59 AM
No, I have comment the code W25qxx_ReadPage, the result is same.
2021-05-26 06:03 AM
is there any DMA code to move memory to internal flash code example or use interrupt for flash code?
2021-05-26 06:32 AM
It's possible erasing all pages at once would be faster than one at a time.
There is HAL_FLASH_Program_IT, but unlikely to help if the bottleneck is the flash erase/write speed.
2021-05-26 07:08 AM
i use the code below follow the code examples on page938 of RM0376 Reference manual , it will reduce the time to 9 seconds.The note was under the code Note: This function must be loaded in RAM. I'm not sure can this code run in flash? and why only program half page instead of 1 page?
/**
* This function programs a half page. It is executed from the RAM.
* The Programming bit (PROG) and half-page programming bit (FPRG)
* is set at the beginning and reset at the end of the function,
* in case of successive programming, these two operations
* could be performed outside the function.
* This function waits the end of programming, clears the appropriate
* bit in the Status register and eventually reports an error.
* Param flash_addr is the first address of the half-page to be programmed
* data is the 32-bit word array to program
* Retval None
*/
__RAM_FUNC void FlashHalfPageProg(uint32_t flash_addr, uint32_t *data)
{
uint8_t i;
/* (1) Set the PROG and FPRG bits in the FLASH_PECR register
to enable a half page programming */
/* (2) Perform the data write (half-word) at the desired address */
/* (3) Wait until the BSY bit is reset in the FLASH_SR register */
/* (4) Check the EOP flag in the FLASH_SR register */
/* (5) clear it by software by writing it at 1 */
/* (6) Reset the PROG and FPRG bits to disable programming */
FLASH->PECR |= FLASH_PECR_PROG | FLASH_PECR_FPRG; /* (1) */
for (i = 0; i < ((FLASH_PAGE_SIZE/2) / 4); i++)
{
*(__IO uint32_t*)(flash_addr) = *data++; /* (2) */
}
while ((FLASH->SR & FLASH_SR_BSY) != 0) /* (3) */
{
/* For robust implementation, add here time-out management */
}
if ((FLASH->SR & FLASH_SR_EOP) != 0) /* (4) */
{
FLASH->SR = FLASH_SR_EOP; /* (5) */
}
else
{
/* Manage the error cases */
}
FLASH->PECR &= ~(FLASH_PECR_PROG | FLASH_PECR_FPRG); /* (6) */
}
2021-05-26 07:17 AM
Thank you for your advice. i have moved all erase code before write code.
firstly i EraseInternalFlash(APP_BASE_ADDR,APP_LENGTH ); erase all my app code.