你好,我使用2.5.0版本的CH552,似乎調(diào)用__asm__ ("lcall #0x3800"); 只會重啟。但是之前2.4.0以前的芯片是可以進入bootloader的。
請問新版本的芯片是去除了這一功能還是修改了使用方式?
你好,我使用2.5.0版本的CH552,似乎調(diào)用__asm__ ("lcall #0x3800"); 只會重啟。但是之前2.4.0以前的芯片是可以進入bootloader的。
請問新版本的芯片是去除了這一功能還是修改了使用方式?
boot中存在10秒左右的超時退出時間,看現(xiàn)象這個過程應(yīng)該是跳進boot,然后退出了。
我沒有辦法確認(rèn)是不是進入了boot,但是根據(jù)波形,上電后50ms左右程序就開始執(zhí)行,lcall 0x3800后20ms左右程序就又開始了。和10秒的超時應(yīng)該沒關(guān)系。
Screen Shot 2022-04-04 at 11.00.53 PM.png
void?setup()?{ ??P1_4=0; ??pinMode(14,?OUTPUT); ??USB_CTRL?=?0; ??EA?=?0;?????????????????????//Disabling?all?interrupts?is?required. ??delayMicroseconds(50000); ??delayMicroseconds(50000); ??P1_4=1; ??__asm__?("lcall?#0x3800");??//Jump?to?bootloader?code ??while?(1); } void?loop()?{ }
maybe its now neccesarry to activate the actual boot pin too in V2.5 before executing the lcall 0x3800 to stay in the loader
您好,CH552中直接調(diào)用LCALL 3800可能意外,是因為好多寄存器沒有初始化,例如某個中斷開著,只關(guān)EA全局是不行的,因為BOOT中會再開EA而不知道其他中斷開著。
方便的話,請把你的測試代碼發(fā)一下wsh@wch.cn。我們測試分析下。
@TECH10
I believe EA=0; is sufficient for calling the bootloader. The bootloader can not use any irqs and therefore there is no reason to activate EA. If I remember correctly none of the loaders executes EA=1;?
At least this was how all loaders from 1.1 to 2.4 were working. So if LCALL 0x3800 is not working anymore as before it might be because of IAP vector is set to 0 for unknown reason or more likely because of a different bootpin evaluation,
@usbman
No, pulling P3_6 up does not help.
@TECH10?
感謝回復(fù)和提供信息。
我測試了一下代碼,以https://github.com/Blinkinlabs/ch554_sdcc?編譯 :
#include? SBIT(P1_4,?0x90,?4); void?delayMicroseconds(unsigned?short?us)?{ ????us; ????__asm__?(".even????????????????????????????????????\n" ?????????????"????mov??r6,?dpl?????????????????????????\n"?//low?8-bit ?????????????"????mov??r7,?dph?????????????????????????\n"?//high?8-bit ?????????????"????clr??c???????????????????????????????\n" ?????????????"????mov??a,#0x01?????????????????????????\n" ?????????????"????subb?a,?r6???????????????????????????\n" ?????????????"????clr??a???????????????????????????????\n" ?????????????"????subb?a,?r7???????????????????????????\n" ?????????????"????jc?skip_0us$?????????????????????????\n" ?????????????"????ret??????????????????????????????????\n"?//return?if?0?1?us??about?1.2us?total ?????????????"????nop??????????????????????????????????\n" ?????????????"skip_0us$:???????????????????????????????\n" ?????????????"????clr??c???????????????????????????????\n"?//do?some?loop?init,?not?useful?for?2us?but?better?here ?????????????"????mov??a,?#0x02????????????????????????\n" ?????????????"????subb?a,?r6???????????????????????????\n" ?????????????"????mov??r6,?a???????????????????????????\n" ?????????????"????mov??a,?#0x00????????????????????????\n" ?????????????"????subb?a,?r7???????????????????????????\n" ?????????????"????mov??r7,?a???????????????????????????\n" ????????????? ?????????????"????nop??????????????????????????????????\n"?//keep?even ?????????????"????cjne?r6,#0x00,loop24m_us$????????????\n" ?????????????"????cjne?r7,#0x00,loop24m_us$????????????\n" ?????????????"????nop??????????????????????????????????\n" ?????????????"????ret??????????????????????????????????\n"?//return?if?2us??about?2?us?total ????????????? ?????????????"loop24m_us$:?????????????????????????????\n"?//about?nus ????????????? ?????????????"????nop?\n?nop?\n?nop?\n?nop?\n?nop?\n????"?//?17?cycle ?????????????"????nop?\n?" ?????????????"loop24m_us_2$:???????????????????????????\n"??//need?more?test ????????????? ?????????????"nop?\n?nop?\n?nop?\n?nop?\n????" ?????????????"????nop?\n?nop?\n?nop?\n?nop?\n?nop?\n????" ?????????????"????nop?\n?nop?\n?????????????????????????" ????????????? ?????????????"????inc??r6??????????????????????????????\n"?//?1?cycle ?????????????"????cjne?r6,?#0,loop24m_us$??????????????\n"?//?6?cycle ?????????????"????inc??r7??????????????????????????????\n"?//?there?will?be?extra?7?cycles?for?every?256us,?ignore?for?now ?????????????"????cjne?r7,?#0,loop24m_us_2$????????????\n" ?????????????"????nop??????????????????????????????????\n" ?????????????); } void?main()?{ ???? ????SAFE_MOD?=?0x55; ????SAFE_MOD?=?0xAA; ????CLOCK_CFG?=?CLOCK_CFG?&?~?MASK_SYS_CK_SEL?|?0x06;??//?24MHz ????SAFE_MOD?=?0x00; ???? ????P1_4=1; ???? ????P1_MOD_OC?=?P1_MOD_OC?&?~(1<<4); ????P1_DIR_PU?=?P1_DIR_PU?|?(1<<4); ???? ????//test?interrupt ????//init?T0?for?millis ????/*TMOD?=?(TMOD?&?~0x0F)|(bT0_M1);//mode?2?for?autoreload ????T2MOD?=?T2MOD?&?~bT0_CLK;????//bT0_CLK=0;clk?Div?by?12 ????TH0?=?255-250+1; ????TF0?=?0; ????ET0?=?1; ????TR0?=?1; ????EA?=?1;?//millis?and?delay?needs?interrupt*/ ???? ????P1_4=0; ???? ????USB_CTRL?=?0; ????EA?=?0;?????????????????????//Disabling?all?interrupts?is?required. ????delayMicroseconds(50000); ????delayMicroseconds(50000); ???? ????P1_4=1; ???? ????__asm__?("lcall?#0x3800");??//Jump?to?bootloader?code ???? ????while?(1); }
代碼沒有任何外部依賴。
編譯后確實可以跳轉(zhuǎn)bootloader
但是如果把注釋的代碼取消注釋,即讓T0產(chǎn)生中斷,就不能跳轉(zhuǎn)bootloader
看起來問題是,新的bootloader從查詢式通信換成了中斷式通信,因此所有的中斷使能位都應(yīng)該關(guān)閉。
建議官方也把ch554_evt里的例程也更新一下。
@TECH10?
進一步測試,主代碼有這句就不能進bootloader
TMOD?=?(TMOD?&?~0x0F)|(bT0_M1);
既然bootloader不開源,還希望官方給出詳細(xì)的bootloader寄存器使用信息,以免踩坑,畢竟作為用戶遍歷所有可能的寄存器配置并不現(xiàn)實。
我這邊猜測是新版本bootloader對于使用的寄存器并沒有完全重置初值,導(dǎo)致主程序的寄存器設(shè)定影響了bootloader的執(zhí)行。
另附上可用的代碼。
????????USB_CTRL?=?0; ????????EA?=?0;?????????????????????//Disabling?all?interrupts?is?required. ????????TMOD?=?0; ????????delayMicroseconds(50000); ????????delayMicroseconds(50000); ???????? ????????__asm__?("lcall?#0x3800");??//Jump?to?bootloader?code ???????? ????????while(1);
2.5版本boot增加了超時(10s)退出機制,超時是基于定時器0定時處理,TMOD寄存器沒有完全重置初值;在跳轉(zhuǎn)boot之前需寫TMOD? = 0,除此之外無其他條件。