秉火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/
[root@localhost stm32f429ig]# ls
gcc-arm-none-eabi-5_4-2016q3-20160926-linux.tar.bz2 u-boot-2016.09.tar.bz2
[root@localhost 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 functionsalias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'# Source global definitions
if [ -f /etc/bashrc ]; then. /etc/bashrc
fiexport PATH=$PATH:/opt/gcc-arm-none-eabi-5_4-2016q3/bin
source ~/.bashrc 使修改的環境變量立即生效。 使用echo $PATH命令查看環境變量是否設置成功,使用which arm-none-eabi-gcc和arm-none-eabi-gcc -v命令查看交叉編譯環境是否安裝成功。
[root@localhost stm32f429ig]# vim ~/.bashrc
[root@localhost stm32f429ig]# source ~/.bashrc
[root@localhost 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
[root@localhost stm32f429ig]# which arm-none-eabi-gcc
/opt/gcc-arm-none-eabi-5_4-2016q3/bin/arm-none-eabi-gcc
[root@localhost 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)
[root@localhost 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-
[root@localhost stm32f429ig]# ls
gcc-arm-none-eabi-5_4-2016q3-20160926-linux.tar.bz2 u-boot-2016.09.tar.bz2
u-boot-2016.09
[root@localhost stm32f429ig]# cd u-boot-2016.09
[root@localhost u-boot-2016.09]# make mrproper
[root@localhost u-boot-2016.09]# make stm32f429-discovery_defconfigHOSTCC scripts/basic/fixdepHOSTCC scripts/kconfig/conf.oSHIPPED scripts/kconfig/zconf.tab.cSHIPPED scripts/kconfig/zconf.lex.cSHIPPED scripts/kconfig/zconf.hash.cHOSTCC scripts/kconfig/zconf.tab.oHOSTLD scripts/kconfig/conf
#
# configuration written to .config
#
[root@localhost u-boot-2016.09]# make menuconfigHOSTCC scripts/kconfig/mconf.oHOSTCC scripts/kconfig/lxdialog/checklist.oHOSTCC scripts/kconfig/lxdialog/util.oHOSTCC scripts/kconfig/lxdialog/inputbox.oHOSTCC scripts/kconfig/lxdialog/textbox.oHOSTCC scripts/kconfig/lxdialog/yesno.oHOSTCC scripts/kconfig/lxdialog/menubox.oHOSTLD scripts/kconfig/mconf
scripts/kconfig/mconf Kconfig*** End of the configuration.
*** Execute 'make' to start the build or try 'make help'.[root@localhost u-boot-2016.09]# make ARCH=arm CROSS_COMPILE=arm-none-eabi-
scripts/kconfig/conf --silentoldconfig KconfigCHK include/config.hUPD include/config.h...CFG u-boot.cfg
[root@localhost 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
[root@localhost u-boot-2016.09]#
以上命令順利執行說明編譯環境配置成功,恭喜你! 如果你不幸沒有順利完成以上命令,請自行百度解決辦法。
第三步:修改u-boot以適應秉火stm32f429開發板
進入 u-boot-2016.09目錄 修改 ./include/configs/stm32f429-discovery.h ,這個頭文件定義了外部晶振的頻率,stm32f429-discovery使用的是8MHZ的晶振,而秉火stm32f429開發板使用的是25MHZ的晶振。
[root@localhost 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軟件獲得。
[root@localhost 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 addint 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_NE 和 SDRAM_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 addfor (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鏡像還未驗證,網絡功能未配置,待續。。。
總結
以上是生活随笔 為你收集整理的秉火stm32f429移植u-boot 的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔 網站內容還不錯,歡迎將生活随笔 推薦給好友。