本测试仅用于测试硬件复位原因寄存器功能、scratch寄存器复活保留功能、软件复位功能。不属于自动化测试范畴。
测试目标
本测试例程主要有两个目的:
- 观察reset flag寄存器是否能准确记录重启原因。
- 观察scratch寄存器在重启后是否能保持数据。
测试方法
本测试的核心操作是读取reset flag寄存器和scratch寄存器。按照芯片设计,这两个寄存器在重启之后不会更改。创造不同的重启原因,需要执行芯片重启,而芯片重启后首先启动rom代码,因此直接使用rom代码的下载功能,在每次重启之后将测试例程重新下载到芯片并执行。程序会自动切换到不同的复位模式,所以只需要连续多次下载(连续7次),就能测试所有的复位选项。
测试项目
本测试例程较为简单,在程序执行之后,初始化流程主要包含3个:
- 初始化串口用于打印。
- 初始化gptimer用于延时。
- 关闭所有看门狗,在实际测试中,发现每次芯片复位之后看门狗依然在执行,如果看门狗复位时间设置较短,会导致在下载过程或者例程执行过程中出现芯片复位,导致测试中断,因此每次例程执行时需要先关闭所有看门狗,且看门狗复位时间应当设置较长时间(本测试例程中设置为30s,能保证下载和执行不被中断)。
具体测试项目包含如下3个:
读取reset flag寄存器
程序读取reset flag寄存器,检查上次复位的原因并通过串口打印出来。同时清除掉对应的标志位。
reset flag寄存器的定义如下:
typedef union wdg_rst_flag_union { uint32_t w; struct { /* indicates that core reset has been generated by watchdog0 */ uint32_t wdg0_cpurst_flag:1; // [0] /* indicates that core reset has been generated by watchdog1 */ uint32_t wdg1_cpurst_flag:1; // [1] /* indicates that core reset has been generated by watchdog2 */ uint32_t wdg2_cpurst_flag:1; // [2] uint32_t reserved_0:1; // [3] /* indicates that a global reset has been generated by watchdog0 */ uint32_t wdg0_fullrst_flag:1; // [4] /* indicates that a global reset has been generated by watchdog1 */ uint32_t wdg1_fullrst_flag:1; // [5] /* indicates that a global reset has been generated by watchdog2 */ uint32_t wdg2_fullrst_flag:1; // [6] uint32_t reserved_1:1; // [7] /* indicates that a global reset has been generated by software */ uint32_t chip_soft_rst_flag:1; // [8] uint32_t reserved_2:7; // [9,15] /* this signal is used to clear the wdg0_cpurst_flag after the wdg0_cpurst_flag is up(a pulse, hardware auto clear 0 ) */ uint32_t wdg0_cpurst_flag_clr:1; // [16] /* this signal is used to clear the wdg1_cpurst_flag after the wdg1_cpurst_flag is up(a pulse, hardware auto clear 0 ) */ uint32_t wdg1_cpurst_flag_clr:1; // [17] /* this signal is used to clear the wdg2_cpurst_flag after the wdg2_cpurst_flag is up(a pulse, hardware auto clear 0 ) */ uint32_t wdg2_cpurst_flag_clr:1; // [18] uint32_t reserved_3:1; // [19] /* this signal is used to clear the wdg0_fullrst_flag after the wdg0_fullrst_flag is up(a pulse, hardware auto clear 0 ) */ uint32_t wdg0_fullrst_flag_clr:1; // [20] /* this signal is used to clear the wdg1_fullrst_flag after the wdg1_fullrst_flag is up(a pulse, hardware auto clear 0 ) */ uint32_t wdg1_fullrst_flag_clr:1; // [21] /* this signal is used to clear the wdg2_fullrst_flag after the wdg2_fullrst_flag is up(a pulse, hardware auto clear 0 ) */ uint32_t wdg2_fullrst_flag_clr:1; // [22] uint32_t reserved_4:1; // [23] /* this signal is used to clear the chip_soft_rst_flag after the chip_soft_rst_flag is up(a pulse, hardware auto clear 0 ) */ uint32_t chip_soft_rst_flag_clr:1; // [24] uint32_t reserved_5:7; // [25,31] } _b; } wdg_rst_flag_u;
由寄存器定义可知,硬件reset flag一共记录7种复位原因,分别是软件复位(调用sec_glb_chip_rst()
函数引起的复位)、看门狗02 cpu复位、看门狗02全局复位。并且复位的标志需要手动清除。
测试功能通过。
读取scratch寄存器
程序读取scratch寄存器,判断寄存器的值是否为上次复位之前写入的值。预期的结果是等于上次写入的值。
按照芯片设计,scratch寄存器仅在上电复位和按键复位时才会被重置为0。
需要注意的是,上电后启动函数会调用_init()
函数,该函数会更改scratch0、scratch1的值。
测试功能通过,软件复位和看门狗复位不影响scratch寄存器的值。
主动触发复位、修改scratch寄存器
这个测试项,实际是为前面两个测试项服务。
测试项定义了7种复位方式,分别对应reset flag寄存器中的复位标志,采用scratch5记录上次复位原因,根据上次复位原因的值主动变更本次复位原因,并自动触发复位。
每次仅触发一种复位方式,但是因为wdg1、wdg2的cpu复位信号不能被core0接收,因此在测试这两个复位标志时,需要同时打开wdg0的cpu复位。
在复位之前,更改scratch0~4寄存器的值。
测试通过。
测试日志
[16:29:42:703] BUILT V3.1.0.4, 20211014-221339 [16:29:48:324] Recieving RAM-IMAGE in xmodem : CC [16:29:50:691] 开始 xmodem 传输. 按 Ctrl+C 取消. [16:29:55:028] Transferring rstflag.bin... [16:29:55:144] 100% 17 KB 3 KB/s 00:00:05 0 错误 [16:29:55:144] [16:29:55:144] dtest_rstflag_main start [16:29:55:144] get reset register:0x00000000 [16:29:55:144] chip reset reason is power on or reset button [16:29:55:145] get scratch reg value: [16:29:55:145] 0x0000005a 0x80000000 0x00000000 0x00000000 0x00000000 0x00000000 [16:29:55:145] set scratch0 data:0x00000000 [16:29:55:145] set scratch1 data:0x01010101 [16:29:55:246] set scratch2 data:0x02020202 [16:29:55:246] set scratch3 data:0x03030303 [16:29:55:252] set scratch4 data:0x04040404 [16:29:55:259] chip will be reset by wdg0 cpurst after 30s [16:30:26:145] [16:30:26:146] BUILT V3.1.0.4, 20211014-221339 [16:30:27:862] Recieving RAM-IMAGE in xmodem : C [16:30:30:131] 开始 xmodem 传输. 按 Ctrl+C 取消. [16:30:34:505] Transferring rstflag.bin... [16:30:34:594] 100% 17 KB 4 KB/s 00:00:04 0 错误 [16:30:34:594] [16:30:34:595] dtest_rstflag_main start [16:30:34:595] get reset register:0x00000001 [16:30:34:595] chip reset reason include wdg0 cpu reset, clear data:0x00010001 [16:30:34:595] get scratch reg value: [16:30:34:595] 0x0000005a 0x80000000 0x02020202 0x03030303 0x04040404 0x00000001 [16:30:34:595] set scratch0 data:0x00000000 [16:30:34:595] set scratch1 data:0x01010101 [16:30:34:595] set scratch2 data:0x02020202 [16:30:34:595] set scratch3 data:0x03030303 [16:30:34:601] set scratch4 data:0x04040404 [16:30:34:615] chip will be reset by wdg1 cpurst after 30s [16:30:34:615] chip will be reset by wdg0 cpurst after 31s [16:31:06:566] [16:31:06:566] BUILT V3.1.0.4, 20211014-221339 [16:31:08:306] Recieving RAM-IMAGE in xmodem : C [16:31:10:550] 开始 xmodem 传输. 按 Ctrl+C 取消. [16:31:14:924] Transferring rstflag.bin... [16:31:15:025] 100% 17 KB 4 KB/s 00:00:04 0 错误 [16:31:15:025] [16:31:15:026] dtest_rstflag_main start [16:31:15:026] get reset register:0x00000003 [16:31:15:026] chip reset reason include wdg0 cpu reset, clear data:0x00010003 [16:31:15:027] chip reset reason include wdg1 cpu reset, clear data:0x00020003 [16:31:15:027] get scratch reg value: [16:31:15:028] 0x0000005a 0x80000000 0x02020202 0x03030303 0x04040404 0x00000002 [16:31:15:028] set scratch0 data:0x00000000 [16:31:15:028] set scratch1 data:0x01010101 [16:31:15:029] set scratch2 data:0x02020202 [16:31:15:029] set scratch3 data:0x03030303 [16:31:15:029] set scratch4 data:0x04040404 [16:31:15:035] chip will be reset by wdg2 cpurst after 30s [16:31:15:042] chip will be reset by wdg0 cpurst after 31s [16:31:46:977] [16:31:46:977] BUILT V3.1.0.4, 20211014-221339 [16:31:51:191] Recieving RAM-IMAGE in xmodem : C [16:31:51:633] 开始 xmodem 传输. 按 Ctrl+C 取消. [16:31:56:018] Transferring rstflag.bin... [16:31:56:145] 100% 17 KB 3 KB/s 00:00:05 0 错误 [16:31:56:145] [16:31:56:145] dtest_rstflag_main start [16:31:56:146] get reset register:0x00000005 [16:31:56:146] chip reset reason include wdg0 cpu reset, clear data:0x00010005 [16:31:56:146] chip reset reason include wdg2 cpu reset, clear data:0x00040005 [16:31:56:147] get scratch reg value: [16:31:56:147] 0x0000005a 0x80000000 0x02020202 0x03030303 0x04040404 0x00000003 [16:31:56:147] set scratch0 data:0x00000000 [16:31:56:147] set scratch1 data:0x01010101 [16:31:56:149] set scratch2 data:0x02020202 [16:31:56:166] set scratch3 data:0x03030303 [16:31:56:167] set scratch4 data:0x04040404 [16:31:56:167] chip will be reset by wdg0 fullrst after 30s [16:32:27:299] [16:32:27:299] BUILT V3.1.0.4, 20211014-221339 [16:32:28:932] Recieving RAM-IMAGE in xmodem : C [16:32:31:295] 开始 xmodem 传输. 按 Ctrl+C 取消. [16:32:36:153] Transferring rstflag.bin... [16:32:36:237] 100% 17 KB 3 KB/s 00:00:05 0 错误 [16:32:36:238] [16:32:36:238] dtest_rstflag_main start [16:32:36:238] get reset register:0x00000010 [16:32:36:238] chip reset reason include wdg0 full reset, clear data:0x00100010 [16:32:36:238] get scratch reg value: [16:32:36:238] 0x0000005a 0x80000000 0x02020202 0x03030303 0x04040404 0x00000004 [16:32:36:239] set scratch0 data:0x00000000 [16:32:36:239] set scratch1 data:0x01010101 [16:32:36:239] set scratch2 data:0x02020202 [16:32:36:239] set scratch3 data:0x03030303 [16:32:36:244] set scratch4 data:0x04040404 [16:32:36:250] chip will be reset by wdg1 fullrst after 30s [16:33:07:254] [16:33:07:254] BUILT V3.1.0.4, 20211014-221339 [16:33:08:675] Recieving RAM-IMAGE in xmodem : C [16:33:11:241] 开始 xmodem 传输. 按 Ctrl+C 取消. [16:33:16:253] Transferring rstflag.bin... [16:33:16:349] 100% 17 KB 3 KB/s 00:00:05 0 错误 [16:33:16:349] [16:33:16:349] dtest_rstflag_main start [16:33:16:349] get reset register:0x00000020 [16:33:16:350] chip reset reason include wdg1 full reset, clear data:0x00200020 [16:33:16:350] get scratch reg value: [16:33:16:350] 0x0000005a 0x80000000 0x02020202 0x03030303 0x04040404 0x00000005 [16:33:16:350] set scratch0 data:0x00000000 [16:33:16:351] set scratch1 data:0x01010101 [16:33:16:351] set scratch2 data:0x02020202 [16:33:16:351] set scratch3 data:0x03030303 [16:33:16:351] set scratch4 data:0x04040404 [16:33:16:361] chip will be reset by wdg2 fullrst after 30s [16:33:47:491] [16:33:47:491] BUILT V3.1.0.4, 20211014-221339 [16:33:52:870] Recieving RAM-IMAGE in xmodem : CC [16:33:55:485] 开始 xmodem 传输. 按 Ctrl+C 取消. [16:33:59:860] Transferring rstflag.bin... [16:33:59:946] 100% 17 KB 4 KB/s 00:00:04 0 错误 [16:33:59:946] [16:33:59:946] dtest_rstflag_main start [16:33:59:947] get reset register:0x00000040 [16:33:59:947] chip reset reason include wdg2 full reset, clear data:0x00400040 [16:33:59:947] get scratch reg value: [16:33:59:948] 0x0000005a 0x80000000 0x02020202 0x03030303 0x04040404 0x00000006 [16:33:59:948] set scratch0 data:0x00000000 [16:33:59:948] set scratch1 data:0x01010101 [16:33:59:949] set scratch2 data:0x02020202 [16:33:59:949] set scratch3 data:0x03030303 [16:33:59:954] set scratch4 data:0x04040404 [16:33:59:958] chip will be reset by soft after 5000000us [16:34:05:119] [16:34:05:120] BUILT V3.1.0.4, 20211014-221339 [16:34:10:700] Recieving RAM-IMAGE in xmodem : CC [16:34:13:104] 开始 xmodem 传输. 按 Ctrl+C 取消. [16:34:17:480] Transferring rstflag.bin... [16:34:17:531] 100% 17 KB 4 KB/s 00:00:04 0 错误 [16:34:17:533] [16:34:17:581] dtest_rstflag_main start [16:34:17:582] get reset register:0x00000100 [16:34:17:582] chip reset reason include soft reset, clear data:0x01000100 [16:34:17:582] get scratch reg value: [16:34:17:582] 0x0000005a 0x80000000 0x02020202 0x03030303 0x04040404 0x00000000 [16:34:17:582] set scratch0 data:0x00000000 [16:34:17:582] set scratch1 data:0x01010101 [16:34:17:583] set scratch2 data:0x02020202 [16:34:17:583] set scratch3 data:0x03030303 [16:34:17:583] set scratch4 data:0x04040404 [16:34:17:583] chip will be reset by wdg0 cpurst after 30s [16:34:48:584] [16:34:48:600] BUILT V3.1.0.4, 20211014-221339 [16:34:55:738] Recieving RAM-IMAGE in xmodem : CC [16:34:56:599] 开始 xmodem 传输. 按 Ctrl+C 取消. [16:35:00:966] Transferring rstflag.bin... [16:35:01:056] 100% 17 KB 4 KB/s 00:00:04 0 错误 [16:35:01:057] [16:35:01:057] dtest_rstflag_main start [16:35:01:057] get reset register:0x00000001 [16:35:01:058] chip reset reason include wdg0 cpu reset, clear data:0x00010001 [16:35:01:058] get scratch reg value: [16:35:01:059] 0x0000005a 0x80000000 0x02020202 0x03030303 0x04040404 0x00000001 [16:35:01:059] set scratch0 data:0x00000000 [16:35:01:060] set scratch1 data:0x01010101 [16:35:01:060] set scratch2 data:0x02020202 [16:35:01:060] set scratch3 data:0x03030303 [16:35:01:066] set scratch4 data:0x04040404 [16:35:01:081] chip will be reset by wdg1 cpurst after 30s [16:35:01:081] chip will be reset by wdg0 cpurst after 31s