Nec78K0系列BootSwap问题与解决方法

<1> Preprocessing

The following preprocessing of bootswapping is performed.

− Setting of hardware environment

− Declaring start of self programming

− Setting of software environment

− Initializing entry RAM

− Checking voltage level

 

<1>准备

下面的操作是为了bootswap做准备:

◇     设置硬件环境

◇     声明self programming开始

◇     设置软件环境

◇     初始化entry RAM

◇     Checking voltage level

 

<2> Erasing boot cluster 1

Blocks 4 to 7 are erased by callingthe block erase function FlashBlockErase.

Remark The block erase function eraseseach block one by one.

 

<2> 擦写 boot cluster 1

用FlashBlockErase函数擦写Blocks 4 to 7

Remark The block erase function eraseseach block one by one.

<3> Copying new boot programto boot cluster 1

The new boot program (program to beallocated to 0000H to 0FFFH after processing of boot swapping) is written

to 1000F to 1FFFH by calling the word write functionFlashWordWrite.

Remark The word write function writes datain word units (256 bytes max.).

 

<3> 拷贝新的boot程序到boot cluster 1

调用FlashWordWrite函数,把新的boot程序(boot swap后程序的地址被定位到0000Hto 0FFFH)被写到1000F-1FFFH范围地址内

Remark The word write function writes datain word units (256 bytes max.).

<4> Verifying boot cluster 1

Blocks 4 to 7 are verified bycalling the block verify function FlashBlockVerify.

Remark The block verify function verifieseach block one by one.

 

<4> 核实boot cluster 1

调用block核实函数FlashBlockVerify, 来进行核实 Blocks 4 到7范围内的内容

Remark The block verify function verifieseach block one by one.

 

<5> Reading set status of boot swapping

The set status of boot swapping canbe read by calling the get information function FlashGetInfo.

 

<5> 读boot swap 设置的状态

调用获取信息FlashGetInfo 函数来,获得Boot swap 设置的状态

 

<6> Setting of boot swap bit

Set the boot swap bit to “executeboot swapping (0)” by calling the set information function FlashSetInfo.

 

<6> 设置boot swap bit位

调用设置信息FlashSetInfo函数来设置boot swap bit 为“execute boot swapping (0)”

<7> Occurrence of event

Boot cluster 1 is used as a bootprogram area when an external reset is generated.

 

<7> 事件发生

Reset后,Boot cluster 1作为boot启动程序启动

<8> End of swap processing(boot cluster 1)

Operations <2> to <7>complete the swap processing of boot cluster 1

If rewriting of boot cluster 0 isnot necessary, move on to end processing (<12>).

If rewriting of boot cluster 0 isnecessary, execute processing of <9> and thereafter.

 

 

<8> 交换处理结束(boot cluster1)

操作<2>-<7>完成boot cluster 1的交换

如果重写boot cluster0不是必要的, 跳到<12>

如果重写boot cluster0是必要的,执行后面的处理

 

 

 

<12> End processing

As end processing of boot swapping,call the get information function FlashGetInfo to read the boot swap setting

status

 

<12>结束处理

Boot swap处理结束时, 调用FlashGetInfo函数,读boot swap设置的status

二:预想的Boot Swap

我们的想法是:每次升级boot程序时,只擦写0x1000~0x1FFFh地址范围的程序,而不论它是交换到 Boot Cluster0还是Boot Cluster1。

如下图所示:

 

◆第一次升级,由Boot0引导,擦写的是Boot1,升级结束后由Boot1引导。

以上是第一次升级结束时,在clear boot swap flag & Reset,后,已经由Boot1进行引导了。

此时地址分配情况Boot1 addr:0x0000~0x0FFF,Boot0addr:0x1000~0x1FFF。

◆然后进行了第二次升级,由Boot1引导,擦写的是Boot0(始终擦写地址0x1000~0x1FFF,而不论其是Boot0还是Boot1.),升级结束后由Boot0引导。

◆     第3次升级时,与第一次升级一样,由Boot0引导,擦写的是Boot1,升级结束后由Boot1引导。以后,如此反复进行Boot升级。

四:参考文档

1.78K0/Kx2 8-bit Single-Chip Microcontrollers FlashMemory Self Programming.pdf

2.Self-ProgrammingExamples For NEC Electronics 78K0/Kx2 Microcontrollers.pdf

3.芯片手册中文版U17260EJ5V0UD00_c.pdf


              Boot Swap问题解决方法

一:关于FlashGetInfo和FlashSetInfo函数

FlashGetInfo函数返回的boot swap flag,描述如下:

 返回值为0,表示当前程序由boot0引导,返回值为1,表示当前程序从boot1引导

 FlashSetInfo函数设置的Bit0描述如下:

★    设置Bit0=0,表示就交换两个分区,而无论当前程序由boot0或boot1引导

★    FlashSetInfo最大执行时间为790809.375us,而watchdog最大为  496ms,所以bootswap中,可能Reset.所以在FlashSetInfo函数调用前,一定要注意把内部低速振荡时钟(watchdog用)给停掉,函数执行后再允许振荡。

 

选项字节的设置

 option.inc片段

OPTION_BYTE_WDT EQU 7EH 
;******************************************************************************
; bit 65 = 11 = 100% window open period
; bit 4 = 1 = WDT enabled
; bit 321 = 111 = 496.48 ms.
; bit 0 = 0 = internal-osc can be stopped by software
;******************************************************************************

option.asm片段

OPTION: DB OPTION_BYTE + OPTION_BYTE_WDT ;

 

boot_Main.c片段

    LSRSTOP =1;     //软件停止watchdog时钟,RCM BIT1                     

    #ifdefUPDATE_WATCHDOG_RESET

        WDTE = 0xAC;                       

#endif

    nucStatus =FlashSetInfo(aucType);         

LSRSTOP=0;  //软件开始watchdog时钟,RCMBIT1

二:一些测试

☆     FlashGetInfo如果返回0,FlashSetInfo设置Bit0=0,然后再FlashGetInfo返回1

☆     FlashGetInfo如果返回1,FlashSetInfo设置Bit0=0,然后再FlashGetInfo返回0

☆     FlashGetInfo如果返回0,FlashSetInfo设置Bit0=1,然后再FlashGetInfo返回0

☆     Boot swap flag 不因程序重新download而改变

 

三:Boot Swap测试

以下BootSwap测试,两引导区交替引导,每次升级结束后Set Bit0=0, 均能交换。

 注意事项:一旦设置了Bit0=0,Reset后,Bit0的值一直是0,不会变成1,这时就要注意把Bit0设置成1 ,因为引导程序在执行的过程中,可能会Reset,这样的话MCU,就会交换两个分区



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值