1、下载官方NUTTX系统源码:
git clone https://bitbucket.org/nuttx/nuttx
git clone https://bitbucket.org/nuttx/apps
git clone https://bitbucket.org/nuttx/tools
2、根据系统硬件找到类似配置文件:
我们飞控板采用STM32F407VG作为主控芯片,在nuttx/configs/stm32f4discovery目录下的配置和我们系统硬件很接近,所以可以利用stm32f4discovery的配置稍作修改适应飞控板。
3、修改系统时钟:
stm32f4discovery板载8MHz系统晶振,而我使用板子是24MHz系统晶振,所以需要修改系统时钟配置(此部分可以参考PX4系统的nuttx-configs/px4fmu-v2/include/board.h的配置),在configs/stm32f4discovery/include/board.h修改如下:
根据飞控板硬件修改时钟配置:
//#define STM32_BOARD_XTAL 8000000ul
#define STM32_BOARD_XTAL 24000000ul
//#define STM32_PLLCFG_PLLM RCC_PLLCFG_PLLM(8)
#define STM32_PLLCFG_PLLM RCC_PLLCFG_PLLM(24)
根据飞控板硬件修改串口配置:
#if 0
// UART2:
// The STM32F4 Discovery has no on-board serial devices, but the console is
// brought out to PA2 (TX) and PA3 (RX) for connection to an external serial
// device. (See the README.txt file for other options)
//
// These pins selections, however, conflict with pin usage on the STM32F4DIS-BB.
#ifndef CONFIG_STM32F4DISBB
# define GPIO_USART2_RX GPIO_USART2_RX_1
# define GPIO_USART2_TX GPIO_USART2_TX_1
#endif
// UART3: (Used in pseudoterm configuration)
#define GPIO_USART3_TX GPIO_USART3_TX_1
#define GPIO_USART3_RX GPIO_USART3_RX_1
// UART6:
// The STM32F4DIS-BB base board provides RS-232 drivers and a DB9 connector
// for USART6. This is the preferred serial console for use with the STM32F4DIS-BB.
#define GPIO_USART6_RX GPIO_USART6_RX_1
#define GPIO_USART6_TX GPIO_USART6_TX_1
#else
// UARTs.
#define GPIO_USART1_RX GPIO_USART1_RX_2 // console in from IO
#define GPIO_USART1_TX GPIO_USART1_TX_2
#define GPIO_USART2_RX GPIO_USART2_RX_2
#define GPIO_USART2_TX GPIO_USART2_TX_2
#define GPIO_USART2_RTS GPIO_USART2_RTS_2
#define GPIO_USART2_CTS GPIO_USART2_CTS_2
#define GPIO_USART3_RX GPIO_USART3_RX_3
#define GPIO_USART3_TX GPIO_USART3_TX_3
#define GPIO_USART3_RTS GPIO_USART3_RTS_2
#define GPIO_USART3_CTS GPIO_USART3_CTS_2
#define GPIO_UART4_RX GPIO_UART4_RX_1
#define GPIO_UART4_TX GPIO_UART4_TX_1
#define GPIO_USART6_RX GPIO_USART6_RX_1
#define GPIO_USART6_TX GPIO_USART6_TX_1
#define GPIO_UART7_RX GPIO_UART7_RX_1
#define GPIO_UART7_TX GPIO_UART7_TX_1
// UART8 has no alternate pin config
// UART RX DMA configurations
#define DMAMAP_USART1_RX DMAMAP_USART1_RX_2
#define DMAMAP_USART6_RX DMAMAP_USART6_RX_2
#endif
4、配置NUTTX系统(详细的工具配置及编译可以参考博文“NuttX移植到STM32F4Discovery”):
清除之前的系统配置:
进入NUTTX源码根目录
sudo make distclean
重新配置系统:
cd tools/
USB调试:
./configure.sh ../configs/stm32f4discovery/usbnsh/
串口调试:
./configure.sh ../configs/stm32f4discovery/nsh
5、配置运行环境
cd ../ //回到nuttx源码根目录
sudo make menuconfig
6、编译:
在NUTTX源码根目录下:
sudo make
编译成功,生成 nuttx.bin 和 nuttx.hex。
7、使用st-link 烧写nuxtt.bin
将stlink连接电脑和板子,执行:st-util指令,如果正常会显示:
st-flash write nuttx.bin 0x8000000
9、调试:
下载完成后,断电重启板子,用USB线将板子与电脑连接上就可以与电脑通信了,通过USB与电脑通信,此时板子会被电脑识别成ttyACM*设备(通常ttyACM0是stlink,ttyACM1才是通信口)。这里使用screen命令连接nsh(nuttx的shell):
ls /dev/ttyA*
sudo screen /dev/ttyACM0
输入help可以查看命令:回车后,如果没有任何显示,按三下回车应该会有反馈。
1、下载官方NUTTX系统源码:
git clone https://bitbucket.org/nuttx/nuttx
git clone https://bitbucket.org/nuttx/apps
git clone https://bitbucket.org/nuttx/tools
2、根据系统硬件找到类似配置文件:
我们飞控板采用STM32F407VG作为主控芯片,在nuttx/configs/stm32f4discovery目录下的配置和我们系统硬件很接近,所以可以利用stm32f4discovery的配置稍作修改适应飞控板。
3、修改系统时钟:
stm32f4discovery板载8MHz系统晶振,而我使用板子是24MHz系统晶振,所以需要修改系统时钟配置(此部分可以参考PX4系统的nuttx-configs/px4fmu-v2/include/board.h的配置),在configs/stm32f4discovery/include/board.h修改如下:
根据飞控板硬件修改时钟配置:
//#define STM32_BOARD_XTAL 8000000ul
#define STM32_BOARD_XTAL 24000000ul
//#define STM32_PLLCFG_PLLM RCC_PLLCFG_PLLM(8)
#define STM32_PLLCFG_PLLM RCC_PLLCFG_PLLM(24)
根据飞控板硬件修改串口配置:
#if 0
// UART2:
// The STM32F4 Discovery has no on-board serial devices, but the console is
// brought out to PA2 (TX) and PA3 (RX) for connection to an external serial
// device. (See the README.txt file for other options)
//
// These pins selections, however, conflict with pin usage on the STM32F4DIS-BB.
#ifndef CONFIG_STM32F4DISBB
# define GPIO_USART2_RX GPIO_USART2_RX_1
# define GPIO_USART2_TX GPIO_USART2_TX_1
#endif
// UART3: (Used in pseudoterm configuration)
#define GPIO_USART3_TX GPIO_USART3_TX_1
#define GPIO_USART3_RX GPIO_USART3_RX_1
// UART6:
// The STM32F4DIS-BB base board provides RS-232 drivers and a DB9 connector
// for USART6. This is the preferred serial console for use with the STM32F4DIS-BB.
#define GPIO_USART6_RX GPIO_USART6_RX_1
#define GPIO_USART6_TX GPIO_USART6_TX_1
#else
// UARTs.
#define GPIO_USART1_RX GPIO_USART1_RX_2 // console in from IO
#define GPIO_USART1_TX GPIO_USART1_TX_2
#define GPIO_USART2_RX GPIO_USART2_RX_2
#define GPIO_USART2_TX GPIO_USART2_TX_2
#define GPIO_USART2_RTS GPIO_USART2_RTS_2
#define GPIO_USART2_CTS GPIO_USART2_CTS_2
#define GPIO_USART3_RX GPIO_USART3_RX_3
#define GPIO_USART3_TX GPIO_USART3_TX_3
#define GPIO_USART3_RTS GPIO_USART3_RTS_2
#define GPIO_USART3_CTS GPIO_USART3_CTS_2
#define GPIO_UART4_RX GPIO_UART4_RX_1
#define GPIO_UART4_TX GPIO_UART4_TX_1
#define GPIO_USART6_RX GPIO_USART6_RX_1
#define GPIO_USART6_TX GPIO_USART6_TX_1
#define GPIO_UART7_RX GPIO_UART7_RX_1
#define GPIO_UART7_TX GPIO_UART7_TX_1
// UART8 has no alternate pin config
// UART RX DMA configurations
#define DMAMAP_USART1_RX DMAMAP_USART1_RX_2
#define DMAMAP_USART6_RX DMAMAP_USART6_RX_2
#endif
4、配置NUTTX系统(详细的工具配置及编译可以参考博文“NuttX移植到STM32F4Discovery”):
清除之前的系统配置:
进入NUTTX源码根目录
sudo make distclean
重新配置系统:
cd tools/
USB调试:
./configure.sh ../configs/stm32f4discovery/usbnsh/
串口调试:
./configure.sh ../configs/stm32f4discovery/nsh
5、配置运行环境
cd ../ //回到nuttx源码根目录
sudo make menuconfig
6、编译:
在NUTTX源码根目录下:
sudo make
编译成功,生成 nuttx.bin 和 nuttx.hex。
7、使用st-link 烧写nuxtt.bin
将stlink连接电脑和板子,执行:st-util指令,如果正常会显示:
st-flash write nuttx.bin 0x8000000
9、调试:
下载完成后,断电重启板子,用USB线将板子与电脑连接上就可以与电脑通信了,通过USB与电脑通信,此时板子会被电脑识别成ttyACM*设备(通常ttyACM0是stlink,ttyACM1才是通信口)。这里使用screen命令连接nsh(nuttx的shell):
ls /dev/ttyA*
sudo screen /dev/ttyACM0
输入help可以查看命令:回车后,如果没有任何显示,按三下回车应该会有反馈。