踩过的坑分享出来:
官方FLASH写入数据的例程是没错的,
但是遇到复杂情况
HAL_FLASHEx_Erase返回结果不是HAL_OK怎么办?
我天真的直接搬运过去用了。
官方例程部分源代码是
- if (HAL_FLASHEx_Erase(&EraseInitStruct, &PAGEError) != HAL_OK)
- {
- /*
- Error occurred while page erase.
- User can add here some code to deal with this error.
- PAGEError will contain the faulty page and then to know the code error on this page,
- user can call function 'HAL_FLASH_GetError()'
- */
- /* Infinite loop */
-
- printf("\n\r Error occurred while page erase. \n\r");
- }
复制代码
按照我经验必须修改为下面代码
- while(HAL_FLASHEx_Erase(&EraseInitStruct, &PAGEError) != HAL_OK)
- {
- //
- __nop();
- }
复制代码
为什么我会踩到这个坑呢?
因为我做OTA升级,APP部分跑的任务比较多,必须运行到第2次HAL_FLASHEx_Erase才能返回HAL_OK,于是就循环等待咯。
|