STM32

= TL;DR [Too Long; Didn't Read] = You can download THIS Quickstart script to guide you through the process.

= Introduction =

This is starting page for Linux on STMicroelectronics STM32 microcontrollers family. These pages are not meant to replace official STMicroelectronics support.

= Supported Boards =

STM32F429i-Discovery
The STM32F429 Discovery kit has the following features:
 * STM32F429 MCU (ARM Cortex-M4 up to 180MHz, 2MB internal flash, 256KB internal RAM)
 * 8MB SDRAM
 * USB OTG Full-Speed
 * 2.4" LCD
 * MEMS motion sensor
 * STLink/V2 (debugging)
 * Extension headers

= Toolchains =

You will need 2 separate toolchains, one for building the Kernel and Bootloader and the other for building userspace.

Baremetal Toolchain
Version known to work here.

OSELAS Toolchain
Pengutronix provides OSELAS (arm-cortexm3-uclinuxeabi-gcc-4.7.2) toolchain for Cortex-M MCUs.

Buildroot
Alternatively you can use Kamil Lulko's Buildroot fork which generates a uClibc toolchain.

The fork also builds a Kernel and U-boot; however, since many STM32 boards are low on resources some prefer to use AFBoot-STM32 (see below) to save space. In which case it's better to build Kernel, Bootloader and Buildroot as separate entities.

= Bootloaders =

AFBoot-STM32
AFBoot-STM32 has been developed by Andreas Färber and is available on his GitHub page.

The main advantage of this bootloader is its size (less than 2KB). Indeed, the STM32F429 only has 2MB internal flash for Bootloader, Kernel, Rootfs and DTB.

A fork compatible with mainline Kernel (from v4.2-rc1) is available here.

The following commands cover the later version. git clone https://github.com/mcoquelin-stm32/afboot-stm32.git cd afboot-stm32 make stm32f429i-disco make flash_stm32f429i-disco

Note: The last command uses OpenOCD to flash the bootloader onto the board, so it needs to be installed (not just built in a src directory) for this to work.

U-Boot
U-Boot STM32 port to mainline has been done by Kamil Lulko. The port is based on U-Boot fork from Emcraft, distributed on their GitHub page git clone git://git.denx.de/u-boot.git cd u-boot make ARCH=arm CROSS_COMPILE=arm-none-eabi- stm32f429-discovery_defconfig make ARCH=arm CROSS_COMPILE=arm-none-eabi-

Note that mainline Kernel requires some patches on top to work with U-Boot port, these patches are available on Kamil GitHub.

= Linux Kernel =

Mainline Kernel
STM32F429 Discovery board basic support has been merged in Kernel v4.2-rc1.

STM32F469 Discovery board needs the following changes at the time of writing

--- a/arch/arm/boot/dts/stm32f429-disco.dts +++ b/arch/arm/boot/dts/stm32f429-disco.dts @@ -58,7 +58,8 @@ -               reg = ; +              reg = ; };         aliases { -              serial0 = &usart1; +              serial0 = &usart3; };  };  @@ -70,6 +72,7 @@          clock-frequency = ; }; -&usart1 { +&usart3 { status = "okay"; };

--- a/arch/arm/configs/stm32_defconfig +++ b/arch/arm/configs/stm32_defconfig @@ -21,7 +21,7 @@ CONFIG_EMBEDDED=y CONFIG_ARM_SINGLE_ARMV7M=y CONFIG_ARCH_STM32=y CONFIG_SET_MEM_PARAM=y -CONFIG_DRAM_BASE=0x90000000 +CONFIG_DRAM_BASE=0x00000000

STM32 maintainer git repository is hosted on kernel.org.

Steps to build mainline kernel for STM32f429i-Discovery board: git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git cd linux make ARCH=arm CROSS_COMPILE=arm-none-eabi- stm32_defconfig make ARCH=arm CROSS_COMPILE=arm-none-eabi-

Produced files are xipImage to be written at address 0x08008000, and arch/arm/boot/dts/stm32f429-disco.dtb DTB file to be written at address 0x08004000.

stm32_defconfig file generates binaries compatible with afboot-stm32 fork.

Emcraft Kernel
Emcraft shares its kernel based on uClinux Kernel v2.6.33 on his GitHub page.

Andreas Färber's Kernel
For ARM TechSymposium Europe 2014 Andreas Färber presented a 3.19-rcX based kernel for the STM32F429I-DISCO at the openSUSE booth. Most of this work was superseded by Maxime; some drivers remain to be forward-ported.

= User Space =

Busybox
Below link is a prebuilt minimal Busybox to be used as a Ramdisk:



Buildroot
A fork of Buildroot has been done by Kamil Lulko to add STM32 support.

The git repo is available here.

It builds Kernel, U-Boot and RootFS (busybox).

= Debug = OpenOCD in combination with GDB can be used to debug through the STLink interface.

In one terminal: openocd -f board/stm32f469discovery.cfg

Then, in a separate terminal: cd  && make debug_stm32f469i-disco

= Flash Tools =

OpenOCD
OpenOCD can be used to write binaries to internal flash.

Be aware that OpenOCD needs to be installed (not just built in a src directory) for this to work.

Usage example openocd -f board/stm32f429discovery.cfg \ -c "init" \ -c "reset init" \ -c "flash probe 0" \ -c "flash info 0" \ -c "flash write_image erase arch/arm/boot/dts/stm32f429-disco.dtb 0x08004000" \ -c "flash write_image erase arch/arm/boot/xipImage 0x08008000" \ -c "reset run" \ -c "shutdown"

Texane
STlink tool from Texane can be found here.

Once built, you'll need to copy the udev rule for your STLink device to /etc and reload udev cp 49-stlinkv*.rules /etc/udev/rules.d udevadm control --reload-rules udevadm trigger

Usage example st-flash --reset write arch/arm/boot/dts/stm32f429-disco.dtb 0x08004000 st-flash --reset write arch/arm/boot/xipImage 0x08008000