|
我在 STM32L476RET6 上遇到无法擦除指定 Flash 页。调用 HAL_StatusTypeDef set_update_flag(void) {
// Unlock the Flash to enable the flash control register access
HAL_StatusTypeDef status = HAL_FLASH_Unlock();
if (status != HAL_OK) {
// Unlock failed, handle accordingly
return status;
}
// Define the page and bank for the erase operation
FLASH_EraseInitTypeDef EraseInitStruct;
uint32_t PageError = 0;
EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;
EraseInitStruct.Banks = FLASH_BANK_1;
EraseInitStruct.Page = 255; // Targeting the last page for the erase operation
EraseInitStruct.NbPages = 1;
// Erase the page
status = HAL_FLASHEx_Erase(&EraseInitStruct, &PageError);
if (status != HAL_OK) {
// Erase failed, handle accordingly
HAL_FLASH_Lock(); // Make sure to lock the flash again before returning
return status;
}
// Set the update flag to 1
status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, UPDATE_FLAG_ADDRESS, 0x0000000100000001);
if (status != HAL_OK) {
// Program failed, handle accordingly
HAL_FLASH_Lock(); // Make sure to lock the flash again before returning
return status;
}
HAL_FLASH_Lock(); // Lock the Flash to disable the flash control register access
return HAL_OK;
}
擦除函数无报错返回 |
TrustZone大家有人用过了吗?
STM32_Cryptographic st加密库V3.0.0移植以后啥也没改,AES256ECB模式加解密都不对
STM32H743VGT6无法串口烧录 请教原因 请进来看下
怎么联系st代表
TIM2输入捕获,DMA开启中断传输输入捕获数据,TIM6计时
带浮点运算功能的小尺寸MCU
功能安全MCU选型及开发技术支持
STM32在ATE测试机上的测试方法
STM32F417ZGT6芯片的可靠性数据。
关于ClassB的移植后的RAM自检导致控制流计数器损坏问题。
微信公众号
手机版
厂家有现成的例程,可以跑跑或参考一下
STM32Cube_FW_L4_V1.18.2\Projects\NUCLEO-L476RG\Examples\FLASH\FLASH_EraseProgram