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

STM32F469i-Discovery
The STM32F469 Discovery kit has the following features:
 * STM32F469 MCU (ARM Cortex-M4 up to 180MHz, 2MB internal flash, 256KB internal RAM)
 * 16MB SDRAM
 * 16MB QSPI NOR
 * USB OTG Full-Speed
 * 4" DSI LCD
 * SD-Card
 * MEMS motion sensor & microphones
 * STLink/V2-1 (debugging + UART(ACM profile))
 * Extension headers (Arduino compatible)

STM32F746g-Discovery
The STM32F746 Discovery kit has the following features:
 * STM32F746NGH6 MCU (ARM Cortex-M7 up to 216MHz, 1MB internal flash, 340KB internal RAM)
 * 8MB SDRAM
 * 16MB QSPI NOR
 * USB OTG Full-Speed
 * 4.3" 480x272 color LCD-TFT
 * SD-Card
 * MEMS motion sensor & microphones
 * STLink/V2-1 (debugging + UART(ACM profile))
 * Extension headers (Arduino compatible)
 * Ethernet

STM32F769i-Discovery
The STM32F769 Discovery kit has the following features:
 * STM32F769NIH6 MCU (ARM Cortex-M7 up to 216MHz, 2MB internal flash, 512KB internal RAM)
 * 16MB SDRAM
 * 64MB QSPI NOR
 * USB OTG Full-Speed
 * 4" DSI LCD
 * SD-Card
 * MEMS motion sensor & microphones
 * STLink/V2-1 (debugging + UART(ACM profile))
 * Extension headers (Arduino compatible)
 * Ethernet

= Buildroot =

Buildroot provides an easy way to build a complete system from scratch. Francois Dugast has put together on his Github page some Buildroot configurations and patches for STM32 which allow building a toolchain, U-Boot, a Linux kernel, a Busybox-based user space and OpenOCD for flashing:
 * Buildroot for the STM32F429i-Discovery board
 * Buildroot for the STM32F746g-Discovery board
 * Buildroot for the STM32F769i-Discovery board

Alternatively, a system can be build without Buildroot as described in the following sections.

= 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
Mainline U-Boot supports various STM32F4 and STM32F7 boards. Default configurations (defconfig) files are available for stm32f429-discovery, stm32f429-evaluation, stm32f469-discovery, stm32f746-disco, stm32h743-disco and stm32h743-eval. 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-

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.

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
Mainline kernel supports various STM32F4 and STM32F7 boards. The default configuration file for STM32 is stm32_defconfig. There are device tree (DTS) for stm32429i-eval, stm32746g-eval, stm32f429-disco, stm32f469-disco, stm32f746-disco, stm32f769-disco, stm32h743i-disco and stm32h743i-eval.

The STM32 maintainer Git repository was mcoquelin (kernel.org) until 4.6 but is now atorgue (kernel.org).

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 (when?)

--- 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

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.

Angelos Mouzakitis's Kernel
Angelos Mouzakitis has developed a LCD driver to Emcraft's uClinux Kernel v2.6.33, available on his GitHub page.

= 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.

git clone git://git.code.sf.net/p/openocd/code openocd cd openocd git submodule init && git submodule update && ./bootstrap && ./configure --enable-stlink && make && sudo make install

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