首先我按照art-pi的例子进行qboot的移植,移植后跳转一直不怎么正常,检查过内存映射的数据读取是正常的,大多时候都不能正常跳转,偶尔会跳转成功。
然后我以为是中断的问题, 我将开中断的函数注释掉了, 然后app的rtthread初始化的时候应该会开这个中断,现在的话大多时候都是能够正常跳转的, 但是还是偶尔出现卡死的情况。(后来发现是错觉)
同样的步骤我在另一个工程里面,没有添加fal sfud qboot相关组件包, 直接main里面做跳转是100%成功的, 但是想着qboot这个方案比较完整,想直接拿过来用。
代码如下:
void qbt_jump_to_app(void)
{
typedef void (*app_func_t)(void);
app_func_t app_func;
struct rt_qspi_device *device = NULL;
u32 stk_addr = 0;
u32 reset_handler = 0;
const u8 send[4] = {0x03, 0x00, 0x00, 0x00};
u8 recv[8] = {0};
device = (struct rt_qspi_device *)rt_device_find(QBOOT_QSPI_FLASH_DEVICE_NAME);
if(device == RT_NULL)
{
LOG_E("no found qspi flash.");
return;
}
rt_qspi_send_then_recv(device, send, sizeof(send), recv, sizeof(recv));
stk_addr = recv[0];
stk_addr += ((u32)recv[1] << 8);
stk_addr += ((u32)recv[2] << 16);
stk_addr += ((u32)recv[3] << 24);
reset_handler = recv[4];
reset_handler += ((u32)recv[5] << 8);
reset_handler += ((u32)recv[6] << 16);
reset_handler += ((u32)recv[7] << 24);
LOG_I("stk_addr :\t\t0x%08X", stk_addr);
LOG_I("reset_handler :\t0x%08X",reset_handler);
stk_addr &= 0x3FF00000;
if(((reset_handler & 0xff000000) != QSPI_BASE) ||
(stk_addr != 0x20000000 && stk_addr != 0x24000000 &&
stk_addr != 0x30000000 && stk_addr != 0x38000000))
{
LOG_E("No legitimate application.");
return;
}
W25QXX_Reset();
W25QXX_Init();
W25Q_Memory_Mapped_Enable();
rt_thread_delay(100);
LOG_I("Jump to application running ... 0x%#X, 0x%#X\n", *(uint32_t *)(QSPI_BASE), *(uint32_t *)(QSPI_BASE + 4));
#if (__MPU_PRESENT == 1)
HAL_MPU_Disable();
#endif
SCB_DisableICache();
SCB_DisableDCache();
__set_PRIMASK(1);
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
for(int i = 0; i < 8; i++)
{
NVIC->ICER[i] = 0xffffffff;
NVIC->ICPR[i] = 0xffffffff;
}
//__set_PRIMASK(0);
__set_MSP(stk_addr);
__set_CONTROL(0);
app_func = (app_func_t) (reset_handler);
app_func();
LOG_I("Qboot jump to application fail.");
}
下面是两次的启动日志, 第二次直接卡死, 我debug调试也不知道从哪下手,求助下大佬!
\ | /
RT - Thread Operating System
/ | \ 4.1.1 build Mar 1 2023 10:27:57
2006 - 2022 Copyright by RT-Thread team
[D/main] Hello RT-Thread!
msh >[D/main] Hello RT-Thread!
[D/main] Hello RT-Thread!
[D/main] Hello RT-Thread!
[D/main] Hello RT-Thread!
\ | /
RT - Thread Operating System
/ | \ 4.1.1 build Mar 1 2023 11:10:40
2006 - 2022 Copyright by RT-Thread team
[1] D/drv.qspi: qspi init success!
[5] I/SFUD: Warning: Read SFDP parameter header information failed. The W25Q128 is not support JEDEC SFDP.
[15] I/SFUD: Find a flash chip. Size is 16777216 bytes.
[21] I/SFUD: W25Q128 flash device is initialize success.
[27] D/drv.qspi: qspi init success!
[30] I/SFUD: Probe SPI flash W25Q128 by SPI device qspi10 success.
[D/FAL] (fal_flash_init:47) Flash device | stm32_onchip | addr: 0x08000000 | len: 0x00020000 | blk_size: 0x00020000 |initialized finish.
[D/FAL] (fal_flash_init:47) Flash device | W25Q128 | addr: 0x00000000 | len: 0x01000000 | blk_size: 0x00001000 |initialized finish.
[I/FAL] ==================== FAL partition table ====================
[I/FAL] | name | flash_dev | offset | length |
[I/FAL] -------------------------------------------------------------
[I/FAL] | bl | stm32_onchip | 0x00000000 | 0x00020000 |
[I/FAL] | app | W25Q128 | 0x00000000 | 0x00100000 |
[I/FAL] | factory | W25Q128 | 0x00100000 | 0x00700000 |
[I/FAL] | download | W25Q128 | 0x00800000 | 0x00800000 |
[I/FAL] =============================================================
[I/FAL] RT-Thread Flash Abstraction Layer initialize success.
msh >
Qboot startup ...
Qboot version : V1.0.5 2020.10.05
Product name : Qboot Logo
Product version : v1.00 2023.02.23
Product mcu : stm32H750VB
Press [Enter] key into shell in 5 s :
[5172] I/Qboot: stk_addr : 0x240009F4
[5176] I/Qboot: reset_handler : 0x9000E6B9
[5281] I/Qboot: Jump to application running ... 0x240009F4, 0x9000E6B9
\ | /
RT - Thread Operating System
/ | \ 4.1.1 build Mar 1 2023 10:27:57
2006 - 2022 Copyright by RT-Thread team
[D/main] Hello RT-Thread!
msh >[D/main] Hello RT-Thread!
[D/main] Hello RT-Thread!
[D/main] Hello RT-Thread!
[D/main] Hello RT-Thread!
[D/main] Hello RT-Thread!
[D/main] Hello RT-Thread!
[D/main] Hello RT-Thread!
[D/main] Hello RT-Thread!
[D/main] Hello RT-Thread!
[D/main] Hello RT-Thread!
\ | /
RT - Thread Operating System
/ | \ 4.1.1 build Mar 1 2023 11:10:40
2006 - 2022 Copyright by RT-Thread team
[1] D/drv.qspi: qspi init success!
[5] I/SFUD: Warning: Read SFDP parameter header information failed. The W25Q128 is not support JEDEC SFDP.
[15] I/SFUD: Find a flash chip. Size is 16777216 bytes.
[21] I/SFUD: W25Q128 flash device is initialize success.
[27] D/drv.qspi: qspi init success!
[30] I/SFUD: Probe SPI flash W25Q128 by SPI device qspi10 success.
[D/FAL] (fal_flash_init:47) Flash device | stm32_onchip | addr: 0x08000000 | len: 0x00020000 | blk_size: 0x00020000 |initialized finish.
[D/FAL] (fal_flash_init:47) Flash device | W25Q128 | addr: 0x00000000 | len: 0x01000000 | blk_size: 0x00001000 |initialized finish.
[I/FAL] ==================== FAL partition table ====================
[I/FAL] | name | flash_dev | offset | length |
[I/FAL] -------------------------------------------------------------
[I/FAL] | bl | stm32_onchip | 0x00000000 | 0x00020000 |
[I/FAL] | app | W25Q128 | 0x00000000 | 0x00100000 |
[I/FAL] | factory | W25Q128 | 0x00100000 | 0x00700000 |
[I/FAL] | download | W25Q128 | 0x00800000 | 0x00800000 |
[I/FAL] =============================================================
[I/FAL] RT-Thread Flash Abstraction Layer initialize success.
msh >
Qboot startup ...
Qboot version : V1.0.5 2020.10.05
Product name : Qboot Logo
Product version : v1.00 2023.02.23
Product mcu : stm32H750VB
Press [Enter] key into shell in 5 s :
[5172] I/Qboot: stk_addr : 0x240009F4
[5176] I/Qboot: reset_handler : 0x9000E6B9
[5281] I/Qboot: Jump to application running ... 0x240009F4, 0x9000E6B9