大家好,我现在遇到FLASH写入的问题,我使用的是HAL库。
1、正常写入,整bank擦除,能够成功写入flash
2、写入后卡死,擦除几个page,无法写入,并且程序卡死
以下为卡死的代码:
/* Unlock the Flash to enable the flash control register access *************/
HAL_FLASH_Unlock();
/* Erase the user Flash area
(area defined by FLASH_USER_START_ADDR and FLASH_USER_END_ADDR) ***********/
/* Get the 1st page to erase */
FirstPage = GetPage(ADDR_FLASH_PAGE_500);
/* Get the number of pages to erase from 1st page */
NbOfPages = GetPage(ADDR_FLASH_PAGE_501) - FirstPage + 1;
/* Get the bank */
BankNumber = GetBank(ADDR_FLASH_PAGE_500);
/* Fill EraseInit structure*/
EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;
EraseInitStruct.Banks = BankNumber;
EraseInitStruct.Page = FirstPage;
EraseInitStruct.NbPages = NbOfPages;
if (HAL_FLASHEx_Erase(&EraseInitStruct, &PAGEError) != HAL_OK)
{
printf("Erase error
");
}
else
{
// printf("Erase OK
");
}
--------------------------------------------------------------------------------------------------------
写入
Address = ((uint32_t)ADDR_FLASH_PAGE_500);
status = FLASH_If_Write(Address, (uint32_t*) ramsource, 512 / 4);
-------------------------------------------------------------------------------------------------------
摘抄部分写入函数:卡死在这里
uint32_t FLASH_If_Write(uint32_t destination, uint32_t *p_source, uint32_t length)
{
uint32_t status = FLASHIF_OK;
uint32_t bank_to_erase, error = 0;
uint32_t i = 0;
uint32_t bank_active =0;
uint8_t retry=0;
FLASH_EraseInitTypeDef pEraseInit;
//----------------------------------卡死在这里----------------------这里就卡主了-----------------------程序无法运行下去
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, destination, *((uint64_t *)(p_source + 2*i))) == HAL_OK)
{
printf("HAL_FLASH_Program HAL_OK
");
}
--------------------------------------------------------------------------------------------------------------------------------------
请问下大家,为什么整个bank擦除能用,擦除几页就不能用?
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
你好,我现在测试的地址是第500页,我现在的STM32L476是由512页的。没有溢出
一周热门 更多>