1. 程式人生 > >秉火stm32f429移植u-boot

秉火stm32f429移植u-boot

秉火stm32f429移植u-boot

參考: 《STM32F429i-Discovery 移植併成功跑起來u-boot 2016.05》作者:tcjy1000,連結: https://blog.csdn.net/tcjy1000/article/details/51475438

硬體平臺: 使用秉火stm32f429的核心板,搭配挑戰者野火stm32的底板。
MCU: stm329igt6,1MB的內部flash,256KB的RAM。
核心板: 8MB的外部SDRAM,IS42S16400J。16MB的外部SPI flash,winbond 25Q128FV。
終端: 使用USART1做為終端,波特率115200。
移植參考模板:

意法半導體公司的stm32開發板 STM32F429-descovery。該開發板和秉火的STM32F429開發板資源非常類似,只需要修改時鐘和SDRAM的部分配置就可以了。
U-Boot版本: u_boot-2016.09,該版本u-boot已經支援stm32f429-descovery。下載地址:https://linux.linuxidc.com/index.php?folder=cHViL3UtYm9vdA==
交叉編譯環境: 交叉編譯器下載地址:https://launchpad.net/gcc-arm-embedded/+download

第一步:配置編譯環境

我使用的CentOS虛擬機器,使用root許可權(其實沒必要)
在根目錄下建立一個資料夾:mkdir stm32f429ig


將上面下載的交叉編譯器和u-boot原始碼放到這個目錄下。
解壓交叉編譯器gcc-arm-none-eabi-5_4-2016q3-20160926-linux.tar.bz2/opt/ 目錄下。
tar xjvf gcc-arm-none-eabi-5_4-2016q3-20160926-linux.tar.bz2 -C /opt/

[[email protected] stm32f429ig]# ls
gcc-arm-none-eabi-5_4-2016q3-20160926-linux.tar.bz2  u-boot-2016.09.tar.bz2
[[email protected] stm32f429ig]# tar xjvf gcc-arm-none-eabi-5_4-2016q3-20160926-linux.tar.bz2 -C /opt/

在環境變數中加入該路徑以方便呼叫。在 .bashrc的最後一句加入 export PATH=$PATH:/opt/gcc-arm-none-eabi-5_4-2016q3/bin
vim ~/.bashrc

# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

export PATH=$PATH:/opt/gcc-arm-none-eabi-5_4-2016q3/bin

source ~/.bashrc 使修改的環境變數立即生效。
使用echo $PATH命令檢視環境變數是否設定成功,使用which arm-none-eabi-gccarm-none-eabi-gcc -v命令檢視交叉編譯環境是否安裝成功。

[[email protected] stm32f429ig]# vim ~/.bashrc 
[[email protected] stm32f429ig]# source ~/.bashrc
[[email protected] stm32f429ig]# echo $PATH
/usr/lib/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/cj/bin:/opt/gcc-arm-none-eabi-5_4-2016q3/bin:/opt/gcc-arm-none-eabi-5_4-2016q3/bin
[[email protected] stm32f429ig]# which arm-none-eabi-gcc
/opt/gcc-arm-none-eabi-5_4-2016q3/bin/arm-none-eabi-gcc
[[email protected] stm32f429ig]# arm-none-eabi-gcc -v
Using built-in specs.
COLLECT_GCC=arm-none-eabi-gcc
COLLECT_LTO_WRAPPER=/opt/gcc-arm-none-eabi-5_4-2016q3/bin/../lib/gcc/arm-none-eabi/5.4.1/lto-wrapper
Target: arm-none-eabi
Configured with: /home/build/work/GCC-5-build/src/gcc/configure --target=arm-none-eabi --prefix=/home/build/work/GCC-5-build/install-native --libexecdir=/home/build/work/GCC-5-build/install-native/lib --infodir=/home/build/work/GCC-5-build/install-native/share/doc/gcc-arm-none-eabi/info --mandir=/home/build/work/GCC-5-build/install-native/share/doc/gcc-arm-none-eabi/man --htmldir=/home/build/work/GCC-5-build/install-native/share/doc/gcc-arm-none-eabi/html --pdfdir=/home/build/work/GCC-5-build/install-native/share/doc/gcc-arm-none-eabi/pdf --enable-languages=c,c++ --enable-plugins --disable-decimal-float --disable-libffi --disable-libgomp --disable-libmudflap --disable-libquadmath --disable-libssp --disable-libstdcxx-pch --disable-nls --disable-shared --disable-threads --disable-tls --with-gnu-as --with-gnu-ld --with-newlib --with-headers=yes --with-python-dir=share/gcc-arm-none-eabi --with-sysroot=/home/build/work/GCC-5-build/install-native/arm-none-eabi --build=i686-linux-gnu --host=i686-linux-gnu --with-gmp=/home/build/work/GCC-5-build/build-native/host-libs/usr --with-mpfr=/home/build/work/GCC-5-build/build-native/host-libs/usr --with-mpc=/home/build/work/GCC-5-build/build-native/host-libs/usr --with-isl=/home/build/work/GCC-5-build/build-native/host-libs/usr --with-cloog=/home/build/work/GCC-5-build/build-native/host-libs/usr --with-libelf=/home/build/work/GCC-5-build/build-native/host-libs/usr --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --with-pkgversion='GNU Tools for ARM Embedded Processors' --with-multilib-list=armv6-m,armv7-m,armv7e-m,armv7-r,armv8-m.base,armv8-m.main
Thread model: single
gcc version 5.4.1 20160919 (release) [ARM/embedded-5-branch revision 240496] (GNU Tools for ARM Embedded Processors) 
[[email protected] stm32f429ig]# 

還有一些其它的配套軟體需要安裝:
yum install ncurses //不知道是不是必須的,反正安裝了保險
yum install ncurses-devel //不安裝的話make menuconfig出錯
yum install swig

第二步:解壓u-boot,測試編譯環境

解壓u-boot:tar xjvf u-boot-2016.09.tar.bz2
進入 u-boot-2016.09目錄下:cd u-boot-2016.09.tar.bz2
執行編譯命令:
make mrproper
make stm32f429-discovery_defconfig
make menuconfig \\不需要做任何修改
make ARCH=arm CROSS_COMPILE=arm-none-eabi-

[[email protected] stm32f429ig]# ls
gcc-arm-none-eabi-5_4-2016q3-20160926-linux.tar.bz2  u-boot-2016.09.tar.bz2
u-boot-2016.09
[[email protected] stm32f429ig]# cd u-boot-2016.09
[[email protected] u-boot-2016.09]# make mrproper
[[email protected] u-boot-2016.09]# make stm32f429-discovery_defconfig
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/kconfig/conf.o
  SHIPPED scripts/kconfig/zconf.tab.c
  SHIPPED scripts/kconfig/zconf.lex.c
  SHIPPED scripts/kconfig/zconf.hash.c
  HOSTCC  scripts/kconfig/zconf.tab.o
  HOSTLD  scripts/kconfig/conf
#
# configuration written to .config
#
[[email protected] u-boot-2016.09]# make menuconfig
  HOSTCC  scripts/kconfig/mconf.o
  HOSTCC  scripts/kconfig/lxdialog/checklist.o
  HOSTCC  scripts/kconfig/lxdialog/util.o
  HOSTCC  scripts/kconfig/lxdialog/inputbox.o
  HOSTCC  scripts/kconfig/lxdialog/textbox.o
  HOSTCC  scripts/kconfig/lxdialog/yesno.o
  HOSTCC  scripts/kconfig/lxdialog/menubox.o
  HOSTLD  scripts/kconfig/mconf
scripts/kconfig/mconf  Kconfig


*** End of the configuration.
*** Execute 'make' to start the build or try 'make help'.

[[email protected] u-boot-2016.09]# make ARCH=arm CROSS_COMPILE=arm-none-eabi-
scripts/kconfig/conf  --silentoldconfig Kconfig
  CHK     include/config.h
  UPD     include/config.h
  ...
  CFG     u-boot.cfg
[[email protected] u-boot-2016.09]# ls
api        configs   fs        MAINTAINERS  snapshot.commit  u-boot.cfg
arch       disk      include   Makefile     System.map       u-boot.lds
board      doc       Kbuild    net          test             u-boot.map
cmd        drivers   Kconfig   post         tools            u-boot-nodtb.bin
common     dts       lib       README       u-boot           u-boot.srec
config.mk  examples  Licenses  scripts      u-boot.bin       u-boot.sym
[[email protected] u-boot-2016.09]# 

以上命令順利執行說明編譯環境配置成功,恭喜你!
如果你不幸沒有順利完成以上命令,請自行百度解決辦法。

第三步:修改u-boot以適應秉火stm32f429開發板

進入 u-boot-2016.09目錄
修改 ./include/configs/stm32f429-discovery.h,這個標頭檔案定義了外部晶振的頻率,stm32f429-discovery使用的是8MHZ的晶振,而秉火stm32f429開發板使用的是25MHZ的晶振。

[[email protected] u-boot-2016.09]# vim include/configs/stm32f429-discovery.h 
<stm32f429-discovery.h>
	#define CONFIG_STM32_SERIAL

	/* #define CONFIG_STM32_HSE_HZ           8000000 */

	#define CONFIG_STM32_HSE_HZ             25000000

	#define CONFIG_SYS_CLK_FREQ             180000000 /* 180 MHz */

	#define CONFIG_SYS_HZ_CLOCK             1000000 /* Timer is clocked at 1MHz */

修改 ./arch/arm/mach-stm32/stm32f4/clock.c,這個檔案裡定義了鎖相環的引數。這些鎖相環的引數可以使用ST公司提供的STM32CubeMX軟體獲得。
在這裡插入圖片描述

[[email protected] u-boot-2016.09]# vim arch/arm/mach-stm32/stm32f4/clock.c
<clock.c>
...
#if !defined(CONFIG_STM32_HSE_HZ)
#error "CONFIG_STM32_HSE_HZ not defined!"
#else
#if (CONFIG_STM32_HSE_HZ == 8000000)
#if (CONFIG_SYS_CLK_FREQ == 180000000)
/* 180 MHz */
struct pll_psc sys_pll_psc = {
        .pll_m = 8,
        .pll_n = 360,
        .pll_p = 2,
        .pll_q = 8,
        .ahb_psc = AHB_PSC_1,
        .apb1_psc = APB_PSC_4,
        .apb2_psc = APB_PSC_2
};
#else
/* default 168 MHz */
struct pll_psc sys_pll_psc = {
        .pll_m = 8,
        .pll_n = 336,
        .pll_p = 2,
        .pll_q = 7,
        .ahb_psc = AHB_PSC_1,
        .apb1_psc = APB_PSC_4,
        .apb2_psc = APB_PSC_2
};
#endif
#else
/***************** add for binghuo stm32f429 ************************/
        #if (CONFIG_STM32_HSE_HZ == 25000000)
        #if (CONFIG_SYS_CLK_FREQ == 180000000)
        /* 180 MHz */
        struct pll_psc sys_pll_psc = {
                .pll_m = 15,
                .pll_n = 216,
                .pll_p = 2,
                .pll_q = 8,     //not care
                .ahb_psc = AHB_PSC_1,
                .apb1_psc = APB_PSC_4,
                .apb2_psc = APB_PSC_2
        };
        #else
        /* default 168 MHz */
        struct pll_psc sys_pll_psc = {
                .pll_m = 25,
                .pll_n = 336,
                .pll_p = 2,
                .pll_q = 7,     //not care
                .ahb_psc = AHB_PSC_1,
                .apb1_psc = APB_PSC_4,
                .apb2_psc = APB_PSC_2
        };
        #endif
        #else
/****************************** end *********************************/
        #error "No PLL/Prescaler configuration for given CONFIG_STM32_HSE_HZ exists"
        #endif
#endif
#endif  //now add

int configure_clocks(void)
{
...

修改 ./board/st/stm32f429-discovery/stm32f429-discovery.c, 該檔案定義了SDRAM的管腳定義和時序。stm32f429-discovery和秉火stm32f429開發板使用的是同一款SDRAM,所以SDRAM的時序不需要修改。但是stm32f429-discovery使用的是stm32f429zit6, LQFP144封裝。而秉火stm32f429開發板使用的是stm32f429igt6,LQFP176封裝。由於兩片stm32的管腳不相容,所以SDRAM介面定義需要修改。
其實也只有 SDRAM_NESDRAM_CKE 兩個管腳不一樣而已。注意一定要將GPIOH的時鐘使能加進去。

<stm32f429-discovery.c>
...
static const struct stm32_gpio_dsc ext_ram_fmc_gpio[] = {
        /* Chip is LQFP144, see DM00077036.pdf for details */
        {STM32_GPIO_PORT_D, STM32_GPIO_PIN_10}, /* 79, FMC_D15 */
        {STM32_GPIO_PORT_D, STM32_GPIO_PIN_9},  /* 78, FMC_D14 */
        {STM32_GPIO_PORT_D, STM32_GPIO_PIN_8},  /* 77, FMC_D13 */
        {STM32_GPIO_PORT_E, STM32_GPIO_PIN_15}, /* 68, FMC_D12 */
        {STM32_GPIO_PORT_E, STM32_GPIO_PIN_14}, /* 67, FMC_D11 */
        {STM32_GPIO_PORT_E, STM32_GPIO_PIN_13}, /* 66, FMC_D10 */
        {STM32_GPIO_PORT_E, STM32_GPIO_PIN_12}, /* 65, FMC_D9 */
        {STM32_GPIO_PORT_E, STM32_GPIO_PIN_11}, /* 64, FMC_D8 */
        {STM32_GPIO_PORT_E, STM32_GPIO_PIN_10}, /* 63, FMC_D7 */
        {STM32_GPIO_PORT_E, STM32_GPIO_PIN_9},  /* 60, FMC_D6 */
        {STM32_GPIO_PORT_E, STM32_GPIO_PIN_8},  /* 59, FMC_D5 */
        {STM32_GPIO_PORT_E, STM32_GPIO_PIN_7},  /* 58, FMC_D4 */
        {STM32_GPIO_PORT_D, STM32_GPIO_PIN_1},  /* 115, FMC_D3 */
        {STM32_GPIO_PORT_D, STM32_GPIO_PIN_0},  /* 114, FMC_D2 */
        {STM32_GPIO_PORT_D, STM32_GPIO_PIN_15}, /* 86, FMC_D1 */
        {STM32_GPIO_PORT_D, STM32_GPIO_PIN_14}, /* 85, FMC_D0 */
        {STM32_GPIO_PORT_E, STM32_GPIO_PIN_1},  /* 142, FMC_NBL1 */
        {STM32_GPIO_PORT_E, STM32_GPIO_PIN_0},  /* 141, FMC_NBL0 */
        {STM32_GPIO_PORT_G, STM32_GPIO_PIN_5},  /* 90, FMC_A15, BA1 */
        {STM32_GPIO_PORT_G, STM32_GPIO_PIN_4},  /* 89, FMC_A14, BA0 */
        {STM32_GPIO_PORT_G, STM32_GPIO_PIN_1},  /* 57, FMC_A11 */
        {STM32_GPIO_PORT_G, STM32_GPIO_PIN_0},  /* 56, FMC_A10 */
        {STM32_GPIO_PORT_F, STM32_GPIO_PIN_15}, /* 55, FMC_A9 */
        {STM32_GPIO_PORT_F, STM32_GPIO_PIN_14}, /* 54, FMC_A8 */
        {STM32_GPIO_PORT_F, STM32_GPIO_PIN_13}, /* 53, FMC_A7 */
        {STM32_GPIO_PORT_F, STM32_GPIO_PIN_12}, /* 50, FMC_A6 */
        {STM32_GPIO_PORT_F, STM32_GPIO_PIN_5},  /* 15, FMC_A5 */
        {STM32_GPIO_PORT_F, STM32_GPIO_PIN_4},  /* 14, FMC_A4 */
        {STM32_GPIO_PORT_F, STM32_GPIO_PIN_3},  /* 13, FMC_A3 */
        {STM32_GPIO_PORT_F, STM32_GPIO_PIN_2},  /* 12, FMC_A2 */
        {STM32_GPIO_PORT_F, STM32_GPIO_PIN_1},  /* 11, FMC_A1 */
        {STM32_GPIO_PORT_F, STM32_GPIO_PIN_0},  /* 10, FMC_A0 */
//      {STM32_GPIO_PORT_B, STM32_GPIO_PIN_6},  /* 136, SDRAM_NE */
        {STM32_GPIO_PORT_H, STM32_GPIO_PIN_6},  /* 136, SDRAM_NE */
        {STM32_GPIO_PORT_F, STM32_GPIO_PIN_11}, /* 49, SDRAM_NRAS */
        {STM32_GPIO_PORT_G, STM32_GPIO_PIN_15}, /* 132, SDRAM_NCAS */
        {STM32_GPIO_PORT_C, STM32_GPIO_PIN_0},  /* 26, SDRAM_NWE */
//      {STM32_GPIO_PORT_B, STM32_GPIO_PIN_5},  /* 135, SDRAM_CKE */
        {STM32_GPIO_PORT_H, STM32_GPIO_PIN_7},  /* 135, SDRAM_CKE */
        {STM32_GPIO_PORT_G, STM32_GPIO_PIN_8},  /* 93, SDRAM_CLK */
};
static int fmc_setup_gpio(void)
{
        int rv = 0;
        int i;

        clock_setup(GPIO_B_CLOCK_CFG);
        clock_setup(GPIO_C_CLOCK_CFG);
        clock_setup(GPIO_D_CLOCK_CFG);
        clock_setup(GPIO_E_CLOCK_CFG);
        clock_setup(GPIO_F_CLOCK_CFG);
        clock_setup(GPIO_G_CLOCK_CFG);
        clock_setup(GPIO_H_CLOCK_CFG);  //new add

        for (i = 0; i < ARRAY_SIZE(ext_ram_fmc_gpio); i++) {
                rv = stm32_gpio_config(&ext_ram_fmc_gpio[i],
                                &gpio_ctl_fmc);
                if (rv)
                        goto out;
        }

out:
        return rv;
}


...

執行編譯命令make ARCH=arm CROSS_COMPILE=arm-none-eabi-
將生成的u-boot.bin下載到秉火stm32f429開發板中就可以看到u-boot的輸出了。

第四步:下載u-boot.bin到秉火stm32f429開發板,欣賞成果。

下載工具: J-Link v9
下載地址: 0x08000000
啟動配置: boot0,boot1接地,從內部flash啟動。

在這裡插入圖片描述

在這裡插入圖片描述
在這裡插入圖片描述

載入Linux映象還未驗證,網路功能未配置,待續。。。