PX4源码解析(一):bootloader

1. 简介


阅读PX4的代码不能用裸机的思维去读,不能一开始就去找main函数,PX4的代码运用了自己的OS:Nuttx。

本文的环境:

  • 硬件: Holybro Pixhawk 4 (FMUv5)
  • 固件: px4_fmu-v5_default

2. fmu(主处理器STM32F765)的bootloader


fmu的bootloader放在下面路径中的main.c

./PX4-Autopilot/platforms/nuttx/src/bootloader/stm/stm32_common

在这里插入图片描述
开头注释说明了这是f7的bootloader,最下面有一个bootloader_main函数
首先进行一些初始化、检查bootloader寄存器标志位、检查force-bootloader pins等,最主要的是下面两段代码:

  1. 尝试进入 app
    	/* Try to boot the app if we think we should just go straight there */
    	/* 尝试进入 app ,如果我们认为不需要进入 bootloader  */
    	if (try_boot) {
    
    		/* set the boot-to-bootloader flag so that if boot fails on reset we will stop here */
    #ifdef BOARD_BOOT_FAIL_DETECT
    		board_set_rtc_signature(BOOT_RTC_SIGNATURE);
    #endif
    
    		/* try to boot immediately */
    		/* 进入 app  */
    		jump_to_app();
    
    		// If it failed to boot, reset the boot signature and stay in bootloader
    		board_set_rtc_signature(BOOT_RTC_SIGNATURE);
    
    		/* booting failed, stay in the bootloader forever */
    		timeout = 0;
    	}
    
  2. 死循环运行 bootloader
    	while (1) {
    		/* run the bootloader, come back after an app is uploaded or we time out */
    		/* 运行 bootloader  */
    		bootloader(timeout);
    
    		/* if the force-bootloader pins are strapped, just loop back */
    		if (board_test_force_pin()) {
    			continue;
    		}
    
    #if INTERFACE_USART
    
    		/* if the USART port RX line is still receiving a break, just loop back */
    		if (board_test_usart_receiving_break()) {
    			continue;
    		}
    
    #endif
    
    		/* set the boot-to-bootloader flag so that if boot fails on reset we will stop here */
    #ifdef BOARD_BOOT_FAIL_DETECT
    		board_set_rtc_signature(BOOT_RTC_SIGNATURE);
    #endif
    
    		/* look to see if we can boot the app */
    		jump_to_app();
    
    		/* launching the app failed - stay in the bootloader forever */
    		timeout = 0;
    	}
    

3. io(协处理器STM32F100)的bootloader


4. 参考

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值