本文主要是介绍STM8L151系列 (OTA) Bootloader功能的开启 和 关闭,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
IAR软件,使用官方halt库
#define OPT_BL_ADDR_L 0x480B
#define OPT_BL_ADDR_H 0x480C
void enable_ota_action(void)
{
uint16_t optbl = 0;
FLASH_DeInit();
FLASH_Unlock(FLASH_MemType_Data);//解锁EEPROM区域(注意type是Data)
// [ROP]默认为0xAA; Read Out Protection OFF;屏蔽读保护;
optbl = ((uint16_t)FLASH_ReadByte(OPT_BL_ADDR_L) << 8) | FLASH_ReadByte(OPT_BL_ADDR_H);
if (optbl != 0x55AA)
{
printf("[OPTBL] en: 0x%X\r\n", optbl);
// OPTBL: Option Byte 可选的字节
FLASH_ProgramOptionByte(OPT_BL_ADDR_L, 0x55); // [BLCHECK1]为0x55; BootLoader Check1 Enabled;
FLASH_ProgramOptionByte(OPT_BL_ADDR_H, 0xAA); // [BLCHECK2]为0xAA; BootLoader Check2 Enabled;
}
FLASH_Lock(FLASH_MemType_Data);
}
void disable_ota_action(void)
{
uint16_t optbl = 0;
FLASH_DeInit();
FLASH_Unlock(FLASH_MemType_Data);//解锁EEPROM区域(注意type是Data)
// [ROP]默认为0xAA; Read Out Protection OFF;屏蔽读保护;
// FLASH_GetReadOutProtectionStatus(xx); FLASH_ReadOptionByte();
// https://github.com/Spider84/PLX_Extends/blob/master/main.c
optbl = ((uint16_t)FLASH_ReadByte(OPT_BL_ADDR_L) << 8) | FLASH_ReadByte(OPT_BL_ADDR_H);
if (optbl != 0x0000)
{
printf("[OPTBL] dis: 0x%X\r\n", optbl);
// OPTBL: Option Byte 可选的字节
FLASH_ProgramOptionByte(OPT_BL_ADDR_L, 0x00); // [BLCHECK1]为0x00; BootLoader Check1 Disabled;
FLASH_ProgramOptionByte(OPT_BL_ADDR_H, 0x00); // [BLCHECK2]为0x00; BootLoader Check2 Disabled;
}
FLASH_Lock(FLASH_MemType_Data);
}
这篇关于STM8L151系列 (OTA) Bootloader功能的开启 和 关闭的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!