×
嵌入式 > 技术百科 > 详情

STM8L151系列 (OTA) Bootloader功能的开启 和 关闭

发布时间:2024-05-21 发布时间:
|

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%Xrn", 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();

// /zixunimg/eeworldimg/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%Xrn", 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);

}


『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
德州仪器推出稳压误差仅为1%的无电容LDO产品