NuttX的移植笔记 1

最近情况还行,静下心写写代码。之前的那块429找不到了,手头有一块L4的IOT的板子,具体型号:B-L475E-IOT01A。但是官方配置文件中并没有发现这块板子,想着要继续研究NuttX就的往上面移植了。距离上次研究NuttX也隔了不少时间了。期间也接触了ESP8266,和嵌入式同事聊天,接触了涂鸦云,最后确定了研究系统的必要性,因为这玩意必须要跑系统啊。最明显的就是,涂鸦云跑的是FreeRTOS,有时候有问题没办法调试,除了看串口打印之外一点办法也没有,这样一说,NuttX可交互式的调式岂不是很爽。


移植之前并没有做过,但是首先可以确定一件事。需要调整的东西都在nuttx文件中。只要把板子的相关东西放在config文件夹中就可以了。

1. 读 README.txt

Board-Specific Configurations
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This directory contains the board support for logic for all boards supported
by NuttX.  This directory is retained in a separate repository and is a Sub-
Module of NuttX and will appear as nuttx/configs when the NuttX repository
is cloned.

The nuttx/configs directory is a part of the internal OS.  It there should
contain only OS bring-up logic and driver initialization logic.  THERE SHOULD
BE NO APPLICATION CALLABLE LOGIC IN THIS DIRECTORY.

If you have board-specific, application callable logic, that logic should not
go here.  Please consider using a sub-directory under apps/platform instead.

Table of Contents
^^^^^^^^^^^^^^^^^

  o Board-Specific Configurations  [主板定义配置]
  o Summary of Files               [摘要]
  o Configuration Variables        [配置变量]
  o Supported Boards               [支持的主板]
  o Configuring NuttX              [配置NuttX]
  o Building Symbol Tables         [建立符号表]

Board-Specific Configurations
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The NuttX configuration consists of:

o Processor architecture specific files.  These are the files contained
  in the arch/<arch-name>/ directory.
  [处理器架构特定文件]

o Chip/SoC specific files.  Each processor processor architecture
  is embedded in chip or System-on-a-Chip (SoC) architecture.  The
  full chip architecture includes the processor architecture plus
  chip-specific interrupt logic, general purpose I/O (GIO) logic, and
  specialized, internal peripherals (such as UARTs, USB, etc.).

  These chip-specific files are contained within chip-specific
  sub-directories in the arch/<arch-name>/ directory and are selected
  via the CONFIG_ARCH_name selection
  [处理器片上的资源]

o Board specific files.  In order to be usable, the chip must be
  contained in a board environment.  The board configuration defines
  additional properties of the board including such things as
  peripheral LEDs, external peripherals (such as network, USB, etc.).
  [主板上的资源]

  These board-specific configuration files can be found in the
  configs/<board-name>/ sub-directories and are discussed in this
  README.  Additional configuration information maybe available in
  board-specific configs/<board-name>/README.txt files.

The configs/ subdirectory contains configuration data for each board.  These
board-specific configurations plus the architecture-specific configurations in
the arch/ subdirectory completely define a customized port of NuttX.

Directory Structure     [目录结构]
^^^^^^^^^^^^^^^^^^^

The configs directory contains board specific configurationlogic.  Each
board must provide a subdirectory <board-name> under configs/ with the
following characteristics:


  <board-name>
  |-- README.txt
  |-- include/
  |   `-- (board-specific header files)
  |-- src/
  |   |-- Makefile
  |   `-- (board-specific source files)
  |-- <config1-dir>
  |   |-- Make.defs
  |   `-- defconfig
  |-- <config2-dir>
  |   |-- Make.defs
  |   `-- defconfig
  ...

Configuring NuttX
^^^^^^^^^^^^^^^^^

Configuring NuttX requires only copying

  configs/<board-name>/<config-dir>/Make.def to ${TOPDIR}/Make.defs
  configs/<board-name>/<config-dir>/defconfig to ${TOPDIR}/.config

tools/configure.sh
  There is a script that automates these steps.  The following steps will
  accomplish the same configuration:

    cd tools
   ./configure.sh <board-name>/<config-dir>

  There is an alternative Windows batch file that can be used in the
  windows native enironment like:

    cd ${TOPDIR}\tools
    configure.bat <board-name>\<config-dir>

  See tools/README.txt for more information about these scripts.

  And if your application directory is not in the standard loction (../apps
  or ../apps-<version>), then you should also specify the location of the
  application directory on the command line like:

    cd tools
    ./configure.sh -a <app-dir> <board-name>/<config-dir>

Building Symbol Tables
^^^^^^^^^^^^^^^^^^^^^^

Symbol tables are needed at several of the binfmt interfaces in order to bind
a module to the base code.  These symbol tables can be tricky to create and
will probably have to be tailored for any specific application, balancing
the number of symbols and the size of the symbol table against the symbols
required by the applications.

The top-level System.map file is one good source of symbol information
(which, or course, was just generated from the top-level nuttx file
using the GNU 'nm' tool).

There are also common-separated value (CSV) values in the source try that
provide information about symbols.  In particular:

  nuttx/syscall/syscall.csv - Describes the NuttX RTOS interface, and
  nuttx/lib/libc.csv        - Describes the NuttX C library interface.

There is a tool at nuttx/tools/mksymtab that will use these CSV files as
input to generate a generic symbol table.  See nuttx/tools/README.txt for
more information about using the mksymtab tool.

并没有什么直接从参考的东西。那就参照其他主板来写好了。我删除看起来不是stm芯片的其他配置文件,这样就没有很多其他东西了。
(这里是个伏笔)

2. 创建目录结构

这个就不必多说了,touch + mkdir搞定。

3. 生成 一份标准的的工程

需要配置好所有外设。那果断是CubeMX了,现在也支持这块开发板了,想之前买这块板的时候还不支持呢,要手动设置。我不需要什么IDE,直接MakeFile就行了。文件生成在了core文件夹下。还是分为src和inc两分,关于板资源配置在main.h文件中。重要的东西就在这里面了,虽然后来证明这玩意根本用不上。

4. board.h

看了几个板的配置文件,全都有board.h,所以,第一个文件就写这个吧。

4.1. 框架

首先搭个框架(可以直接跳到4.3

/************************************************************************************
 * configs/B-L475E-IOT01A/include/board.h
 *
 *   Copyright (C) 2016 Godenfreemans. All rights reserved.
 *   Author: Godenfreemans@gmail.com
 *
 ************************************************************************************/
#ifndef __CONFIG_B-L475E-IOT01A_INCLUDE_BOARD_H
#define __CONFIG_B-L475E-IOT01A_INCLUDE_BOARD_H

/************************************************************************************
 * Included Files
 ************************************************************************************/

#include <nuttx/config.h>

#ifndef __ASSEMBLY__
# include <stdint.h>
#endif

/************************************************************************************
 * Pre-processor Definitions
 ************************************************************************************/
/* Clocking *************************************************************************/
/* LED definitions ******************************************************************/
/* Button definitions ***************************************************************/
/* Alternate function pin selections ************************************************/


#endif  /* __CONFIG_B-L475E-IOT01A_INCLUDE_BOARD_H */

4.2. 时钟部分

下来先写时钟部分。时钟部分是在stm32l4xx_hal_conf.h文件中。整体上就是CubeMX中时钟的布局图,使用的是MSI+PLL得到最大80M的总线速度。将它里面的的时钟定义部分拷贝过来,删除定义和注释语句。

/* Clocking *************************************************************************/
#define HSE_VALUE                   ((uint32_t)8000000U)    /*!< Value of the External oscillator in Hz */
#define HSE_STARTUP_TIMEOUT         ((uint32_t)100U)        /*!< Time out for HSE start up, in ms */
#define MSI_VALUE                   ((uint32_t)4000000U)    /*!< Value of the Internal oscillator in Hz*/
#define HSI_VALUE                   ((uint32_t)16000000U)   /*!< Value of the Internal oscillator in Hz*/
#define HSI48_VALUE                 ((uint32_t)48000000U)   /*!< Value of the Internal High Speed oscillator for USB FS/SDMMC/RNG in Hz.
                                                            The real value my vary depending on manufacturing process variations.*/
#define LSI_VALUE                   ((uint32_t)32000U)
#define LSE_VALUE                   ((uint32_t)32768U)      /*!< Value of the External oscillator in Hz*/
#define LSE_STARTUP_TIMEOUT         ((uint32_t)5000U)       /*!< Time out for LSE start up, in ms */
#define EXTERNAL_SAI1_CLOCK_VALUE   ((uint32_t)2097000U)    /*!< Value of the SAI1 External clock source in Hz*/
#define EXTERNAL_SAI2_CLOCK_VALUE   ((uint32_t)2097000U)    /*!< Value of the SAI2 External clock source in Hz*/

F7的配置文件中有这么些东西:

/* The STM32F7 Discovery board provides the following clock sources:
 *
 *   X1:  24 MHz oscillator for USB OTG HS PHY and camera module (daughter board)
 *   X2:  25 MHz oscillator for STM32F746NGH6 microcontroller and Ethernet PHY.
 *   X3:  32.768 KHz crystal for STM32F746NGH6 embedded RTC
 *
 * So we have these clock source available within the STM32
 *
 *   HSI: 16 MHz RC factory-trimmed
 *   LSI: 32 KHz RC
 *   HSE: On-board crystal frequency is 25MHz
 *   LSE: 32.768 kHz
 */

#define STM32_BOARD_XTAL        25000000ul

#define STM32_HSI_FREQUENCY     16000000ul
#define STM32_LSI_FREQUENCY     32000
#define STM32_HSE_FREQUENCY     STM32_BOARD_XTAL
#define STM32_LSE_FREQUENCY     32768

那就简单了,我也不用改,用宏定义就行了。

#define STM32_HSI_FREQUENCY     HSI_VALUE
#define STM32_LSI_FREQUENCY     LSI_VALUE
#define STM32_HSE_FREQUENCY     HSE_VALUE
#define STM32_LSE_FREQUENCY     LSE_VALUE

(这里发现个问题,应该先吧定义配置了,现在不配置就没有生成config.h文件,不生成这个文件很多代码里的定义都是灰色的。光构架里关于RCC的就有四个文件,全部都有对config.h的需要。),所以,手动创建该文件,我猜测这个文件的位置应该是在nuttx/include/nuttx/config.h,在这里创建该文件并定义参数:

#define CONFIG_STM32L4_STM32L475XX
#define CONFIG_STM32L4_STM32L4X5

这样就行了,构架中关于L4的文件就都应该是正常的了,重建。检查所有的关于L4的文件,发现还有地方有注释:

nuttx/arch/arm/src/stm32l4/stm32l4x5xx_rcc.c:670
这里写着:

#  error stm32l4_stdclockconfig(), must have one of STM32L4_BOARD_USEHSI, STM32L4_BOARD_USEMSI, STM32L4_BOARD_USEHSE defined

再加上函数stm32l4_stdclockconfig函数前的宏定义:

#ifndef CONFIG_ARCH_BOARD_STM32L4_CUSTOM_CLOCKCONFIG

说明这三个宏定义需要我们自己来写。

刚刚因为眼瞎看错了东西在NuttX那儿发了一个问题,结果。。。。。

4.3. 发现些好东西

刚刚全局搜索的时候发现一个L4系列的其他板子,借鉴一下。

所以,文件很快就能写出来。其中引脚复用去这个文件内可以查找的到。

nuttx/arch/arm/src/stm32l4/chip/stm32l4x5xx_pinmap.h

DMA的部分先不写了。最后,board.h文件如下:

/************************************************************************************
 * configs/B-L475E-IOT01A/include/board.h
 *
 *   Copyright (C) 2016 Godenfreemans. All rights reserved.
 *   Author: Godenfreemans@gmail.com
 *
 ************************************************************************************/

#ifndef __CONFIG_B-L475E-IOT01A_INCLUDE_BOARD_H
#define __CONFIG_B-L475E-IOT01A_INCLUDE_BOARD_H

/************************************************************************************
 * Included Files
 ************************************************************************************/

#include <nuttx/config.h>
#ifndef __ASSEMBLY__
# include <stdint.h>
#endif

/************************************************************************************
 * Pre-processor Definitions
 ************************************************************************************/
#include <B-L475E-IOT01A-clocking.h>

/* DMA Channel/Stream Selections ****************************************************/
// TODO:Add DMA.

/* LED definitions ******************************************************************/

#define BOARD_LED_GRN     0
#define BOARD_NLEDS       1

#define BOARD_LED_GRN_BIT (1 << BOARD_LED_GRN)

/* None of the LEDs are used by the board port unless CONFIG_ARCH_LEDS is defined.
 * In that case, the white LED (only) will be controlled.  Usage by the board port
 * is defined in include/board.h and src/stm32_autoleds.c.  The white LED will be
 * used to encode OS-related events as follows:
 *
 *   ------------------- ---------------------------- ------
 *   SYMBOL                  Meaning                  LED
 *   ------------------- ---------------------------- ------   */

#define LED_STARTED      0 /* NuttX has been started  OFF      */
#define LED_HEAPALLOCATE 0 /* Heap has been allocated OFF      */
#define LED_IRQSENABLED  0 /* Interrupts enabled      OFF      */
#define LED_STACKCREATED 1 /* Idle stack created      ON       */
#define LED_INIRQ        2 /* In an interrupt         N/C      */
#define LED_SIGNAL       2 /* In a signal handler     N/C      */
#define LED_ASSERTION    2 /* An assertion failed     N/C      */
#define LED_PANIC        3 /* The system has crashed  FLASH    */
#undef  LED_IDLE         0 /* MCU is is sleep mode    Not used */

/* Button definitions ***************************************************************/

#define BUTTON_POWER       0
#define NUM_BUTTONS        1
#define BUTTON_POWER_BIT   (1 << BUTTON_POWER)

/* Alternate function pin selections ************************************************/

/* USART */

#define GPIO_USART1_TX GPIO_USART1_TX_2 // PB7  |  <=====>  |  TX  ST-LINK
#define GPIO_USART1_RX GPIO_USART1_RX_2 // PB6  |  <=====>  |  RX  ST-LINK

#define GPIO_USART3_TX GPIO_USART3_TX_4 // PD8  |  <=====>  |  RX  ISM43362
#define GPIO_USART3_RX GPIO_USART3_RX_4 // PD9  |  <=====>  |  TX  ISM43362

/* I2C */

#define GPIO_I2C2_SDA GPIO_I2C2_SDA_1   // PB11  |  -----SDA-----
#define GPIO_I2C2_SCL GPIO_I2C2_SCL_1   // PB10  |  -----SCL-----

/* QUADSPI */

#define GPIO_QSPI_CLK GPIO_QSPI_CLK_2           // PE10  |  <=====>  |  SCLK  MX25R6435F
#define GPIO_QSPI_NCS GPIO_QSPI_NCS_2           // PE11  |  <=====>  |  CS    MX25R6435F
#define GPIO_QSPI_BK1_IO0 GPIO_QSPI_BK1_IO0_2   // PE12  |  <=====>  |  IO0   MX25R6435F
#define GPIO_QSPI_BK1_IO1 GPIO_QSPI_BK1_IO1_2   // PE13  |  <=====>  |  IO1   MX25R6435F
#define GPIO_QSPI_BK1_IO2 GPIO_QSPI_BK1_IO2_2   // PE14  |  <=====>  |  IO2   MX25R6435F
#define GPIO_QSPI_BK1_IO3 GPIO_QSPI_BK1_IO3_2   // PE15  |  <=====>  |  IO3   MX25R6435F

/* SPI */

#define GPIO_SPI3_SCK  GPIO_SPI3_SCK_2  // PC10  |  <=====>  |  SCK   BT module
#define GPIO_SPI3_MISO GPIO_SPI3_MISO_2 // PC11  |  <=====>  |  MISO  BT module
#define GPIO_SPI3_MOSI GPIO_SPI3_MOSI_2 // PC12  |  <=====>  |  MOSI  BT module

/* OTG FS */

#define GPIO_OTGFS_DM GPIO_OTGFS_DM     // PA11  | ¯\/¯¯\/¯ | DM  USB CONNECTOR
#define GPIO_OTGFS_DP GPIO_OTGFS_DP     // PA12  | _/\__/\_ | DP  USB CONNECTOR




#endif  /* __CONFIG_B-L475E-IOT01A_INCLUDE_BOARD_H */

好了,先告一段落。

  • 5
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值