STM32 HAL 内部FLASH傻瓜式教程 各种型号单片机都适用主要解决网上例程HAL库无法写入问题
1、简介
本文主要针对网上例程FLASH无法写入问题,傻瓜式操作。
2、BSP_Flash.c
#include "BSP_Flash.h"
uint32_t FlashData;
uint32_t Flashaddr = 0x08020000;
static uint8_t stmflash_get_error_status(void)
{uint32_t res;res = FLASH->SR;if (res & (1 << 0))return 1; /* BSY = 1 , 忙 */if (res & (1 << 2))return 2; /* PGERR = 1 , 编程错误*/if (res & (1 << 4))return 3; /* WRPRTERR = 1 , 写保护错误 */return 0; /* 没有任何错误 操作完成. */
}static uint8_t stmflash_wait_done(uint32_t time)
{uint8_t res;do{res = stmflash_get_error_status();if (res != 1){break; /* 非忙, 无需等待了, 直接退出 */}