Installing FreeRTOS to STM32H7 SOM via Ethernet Print

 

This application note explains how to install FreeRTOS to the STM32H7 System-On-Module using the Ethernet interface as the download channel.

Refer to Understanding STM32H7 SOM Boot Architecture as a pre-requisite to understanding the installation procedure.

Hardware Set-Up

The following hardware set-up is required for installation of the software to the STM32H7 SOM:

  • STM32H7-SOM Rev 1A soldered onto the STM32H7-BSB Rev 1A or STM32H7-BSB Rev 2A baseboard.
  • The microUSB cable connected to the P1 connector on the baseboard (to provide the STM32H7 serial console to the development host).
  • The TST-LINK/V2 debugger/programmer connected to the 20-pin P3 ARM JTAG connector on the baseboard.

Connecting STM32H7-SOM Starter Kit to the Local Network

Connecting the Kit with the STM32H7-BSB Rev 1A

The Waveshare LAN8720 ETH board connected to the P2 header with a special cable. The pin-out is as follows:

STM32H7 Function BSB ETH Name LAN8720 Comment
3V3 P2.1 P2.1 VCC
3V3 P2.2 P2.2 VCC
GND P2.3 P2.3 GND
GND P2.4 P2.4 GND
PC1 ETH_MDC P2.5 P2.5 MDC MDC
PA2 ETH_MDIO P2.6 P2.6 MDIO MDIO
PA7 RMII_CRS_DV P2.7 P2.7 CRS_DV CRS_DV/MODE2
PA1 RMII_REF_CLK P2.8 P2.8 R_RXCLK 50MHz from LAN8720
PC5 RMII_RXD1 P2.9 P2.9 RXD1 RXD1/MODE1
PC4 RMII_RXD0 P2.10 P2.10 RXD0 RXD0/MODE0
PG13 RMII_TXD0 P2.11 P2.11 TXD0 TXD0
PG11 RMII_TXEN P2.12 P2.12 TX_EN TXEN
PG10 - P2.13 - - -
PG12 RMII_TXD1 P2.14 P2.14 TXD1 TXD1

The following picture illustrates the above hardware set-up:

Hardware Setup

Connecting the Kit with the STM32H7-BSB Rev 2A

Connect Ethernet cable to the J5 Ethernet connector on the baseboard.

The following picture illustrates the this hardware set-up:

Hardware Setup

Installing FreeRTOS to Flash

Installable Images

The images to be installed onto the STM32H7 SOM can be obtained using one of the two approaches, as follows:

  1. Build the images from the sources, as documented in Building FreeRTOS.
  2. Use the prebuilt images provided by Emcraft. The prebuilt images can be found in the location documented in Release Notes.

Installing U-Boot SPL to Internal Flash

Step through the following procedure to install the U-Boot SPL to the internal Flash of the STM32H750:

  1. Run the following command on the Linux development host:

    $ st-flash write u-boot-spl.bin 0x08000000
    st-flash 1.7.0-120-gbeffed4
    2023-10-03T14:41:17 INFO common.c: H74x/H75x: 128 KiB SRAM, 45069 KiB flash in at least 128 KiB pages.
    file u-boot-spl.bin md5 checksum: b262768ecdb3a41d7380ad9f3a3b1a6, stlink checksum: 0x005232a9
    2023-10-03T14:41:17 INFO common.c: Attempting to write 62085 (0xf285) bytes to stm32 address:
    134217728 (0x8000000)
    2023-10-03T14:41:17 WARN common.c: unaligned len 0xf285 -- padding with zero
    2023-10-03T14:41:18 INFO common.c: Flash page at addr: 0x08000000 erased
    2023-10-03T14:41:18 INFO common.c: Finished erasing 1 pages of 131072 (0x20000) bytes
    2023-10-03T14:41:18 INFO common.c: Starting Flash write for H7
    62086/62086 bytes written
    2023-10-03T14:41:19 INFO common.c: Starting verification of write complete
    2023-10-03T14:41:19 INFO common.c: Flash written and verified! jolly good!

  2. Verify that the U-Boot SPL has been successfully installed. Reset the SOM by pressing the S3 button on the carrier board and confirm that the following output appears on the serial UART console:
  3. U-Boot SPL 2019.04-emcraft-h7-2.0.0-g5445b38714 (Apr 19 2023 - 14:03:32 +0400)
    Hit 's' key to enter spl shell:
    Trying to boot from SPI

Installing U-Boot "Proper" to QSPI Flash

Step through the following procedure to install the U-Boot "Proper" to the QSPI Flash:

  1. On the development host, make sure that your serial terminal utility (such as picocom) is not connected to the board serial console (/dev/ttyUSB1 in this example). Exit the utility or just kill it, for example:
  2. [sasha_d@workbench ~]$ killall picocom [sasha_d@workbench ~]$

  3. Run the following command on the Linux development host:

    [sasha_d@workbench stm32h7]$ ./u-boot-upstream/board/emcraft/stm32h7-som/stm32h7-som-prog.kermit /dev/ttyUSB1 u-boot-upstream/u-boot.img
    Reset the board to start programming u-boot-upstream/u-boot.img via /dev/ttyUSB1.

  4. Reset the SOM by pressing the S3 button on the carrier board.
  5. Wait for the kermit utility to load the U-Boot image (observe the progress indicators).
  6. The script will exit successfully at the end of the installation procedure:

    ... STM32H7-SOM U-Boot > Successfully programmed u-boot-upstream/u-boot.img to SPI NAND at 0x00000000 ubi part system ... STM32H7-SOM U-Boot > ubi create env1 0x8000 Creating dynamic volume env1 of size 32768 STM32H7-SOM U-Boot > ubi create env2 0x8000 Creating dynamic volume env2 of size 32768 STM32H7-SOM U-Boot > [sasha_d@workbench stm32h7]$

  7. Connect to the SOM console using a serial terminal utility, for example:

    [sasha_d@workbench ~]$ picocom -b 115200 /dev/ttyUSB1

  8. Verify that the U-Boot "proper" has been successfully installed. Reset the SOM by pressing the S3 button on the carrier board and confirm that the following output appears on the serial UART console:
  9. U-Boot SPL 2019.04--00057-g53e40e44f4-dirty (May 01 2023 - 21:11:52 +0300) Hit 's' key to enter spl shell: Trying to boot from SPI U-Boot 2019.04--00057-g53e40e44f4-dirty (May 01 2023 - 21:11:52 +0300) Model: STMicroelectronics STM32H7 SOM DRAM: 32 MiB SF: Detected n25q512ax3 with page size 256 Bytes, erase size 4 KiB, total 64 MiB Flash: 128 KiB MMC: STM32 SDMMC2: 0 Loading Environment from UBI... ubi0: default fastmap pool size: 190 ubi0: default fastmap WL pool size: 95 ubi0: attaching mtd2 ubi0: scanning is finished ubi0: attached mtd2 (name "system", size 15 MiB) ubi0: PEB size: 4096 bytes (4 KiB), LEB size: 3968 bytes ubi0: min./max. I/O unit sizes: 1/256, sub-page size 1 ubi0: VID header offset: 64 (aligned 64), data offset: 128 ubi0: good PEBs: 3840, bad PEBs: 0, corrupted PEBs: 0 ubi0: user volume: 2, internal volumes: 1, max. volumes count: 23 ubi0: max/mean erase counter: 2/1, WL threshold: 4096, image sequence number: 0 ubi0: available PEBs: 3790, total reserved PEBs: 50, PEBs reserved for bad PEB handling: 0 Read 16384 bytes from volume env1 to d1e70620 Read 16384 bytes from volume env2 to d1e74640 *** Warning - bad CRC, using default environment In: serial Out: serial Err: serial Volume splash not found! splash_screen_display: ubi_volume_read error=19 Net: Error: ethernet@40028000 address not set. eth-1: ethernet@40028000 Hit any key to stop autoboot: 0 ERROR: Active image set is invalid STM32H7-SOM U-Boot >

Configuring Network in U-Boot

Step through the following procedure to configure the network parameters in U-Boot:

  1. Set the MAC address of the Ethernet interface (you can choose an arbitrary address for development purposes but make sure that it is unique within your LAN):

    STM32H7-SOM U-Boot > setenv -f ethaddr STM32H7-SOM U-Boot > setenv ethaddr 12:34:56:78:9a:bc STM32H7-SOM U-Boot >

  2. Set the IP address of the board to a value that makes sense for your LAN, for example:

    STM32H7-SOM U-Boot > setenv ipaddr 172.17.0.66 STM32H7-SOM U-Boot >

  3. Set the TFTP server IP address, for example:
  4. STM32H7-SOM U-Boot > setenv serverip 172.17.0.1 STM32H7-SOM U-Boot >

  5. Save the network parameters in the QSPI Flash:

    STM32H7-SOM U-Boot > saveenv Saving Environment to UBI... ubi0: detaching mtd2 ... Writing to redundant UBI... done OK STM32H7-SOM U-Boot >

  6. Try to download a non-existent file from the TFTP server and confirm that the File not found error is reported:

    STM32H7-SOM U-Boot > tftp dummy Using ethernet@40028000 device TFTP from server 172.17.0.1; our IP address is 172.17.0.66 Filename 'dummy'. Load address: 0xd0400000 Loading: * TFTP error: 'File not found' (1) ... Copy the FreeRTOS image to the TFTP server and try to download it: STM32H7-SOM U-Boot > tftp freertos_stm32h750.img ethernet@40028000 Waiting for PHY auto negotiation to complete. done Using ethernet@40028000 device TFTP from server 172.17.0.1; our IP address is 172.17.0.66 Filename 'freertos_stm32h750.img'. Load address: 0xd0400000 Loading: ###### 14.6 KiB/s done Bytes transferred = 79070 (134de hex) STM32H7-SOM U-Boot >

Installing FreeRTOS to QSPI Flash

Step through the following procedure to install the FreeRTOS to the QSPI Flash:

  1. Create the pair of the redundant 4 MB UBI volumes for the FreeRTOS images (this step can be skipped if the volumes have been already created earlier):

    STM32H7-SOM U-Boot > ubi create rtos1 0x400000 Creating dynamic volume rtos1 of size 4194304 STM32H7-SOM U-Boot > ubi create rtos2 0x400000 Creating dynamic volume rtos2 of size 4194304 STM32H7-SOM U-Boot >

  2. Initialize and save the boot variables:

    STM32H7-SOM U-Boot > setenv boot1_valid 1 STM32H7-SOM U-Boot > setenv boot2_active 0 STM32H7-SOM U-Boot > setenv upgrade_available 0 STM32H7-SOM U-Boot > setenv bootcount 0 STM32H7-SOM U-Boot > saveenv Saving Environment to UBI... ubi0: detaching mtd2 ... Writing to redundant UBI... done OK STM32H7-SOM U-Boot >

  3. Download the FreeRTOS image from the TFTP server:

    STM32H7-SOM U-Boot > tftp freertos_stm32h750.img ethernet@40028000 Waiting for PHY auto negotiation to complete. done Using ethernet@40028000 device TFTP from server 172.17.0.1; our IP address is 172.17.0.66 Filename 'freertos_stm32h750.img'. Load address: 0xd0400000 Loading: ###### 14.6 KiB/s done Bytes transferred = 79070 (134de hex) STM32H7-SOM U-Boot >

  4. Install the FreeRTOS image to the QSPI Flash:

    STM32H7-SOM U-Boot > ubi write $loadaddr rtos1 $filesize 79070 bytes written to volume rtos1 STM32H7-SOM U-Boot >

  5. Verify that the FreeRTOS has been successfully installed. Reset the SOM by pressing the S3 button on the carrier board and confirm that the following output appears on the serial UART console:

    U-Boot SPL 2019.04--00057-g53e40e44f4-dirty (May 01 2023 - 21:11:52 +0300) Hit 's' key to enter spl shell: Trying to boot from SPI U-Boot 2019.04--00057-g53e40e44f4-dirty (May 01 2023 - 21:11:52 +0300) Model: STMicroelectronics STM32H7 SOM [15/1941] DRAM: 32 MiB SF: Detected n25q512ax3 with page size 256 Bytes, erase size 4 KiB, total 64 MiB Flash: 128 KiB MMC: STM32 SDMMC2: 0 Loading Environment from UBI... ubi0: default fastmap pool size: 190 ubi0: default fastmap WL pool size: 95 ubi0: attaching mtd2 ubi0: scanning is finished ubi0: attached mtd2 (name "system", size 15 MiB) ubi0: PEB size: 4096 bytes (4 KiB), LEB size: 3968 bytes ubi0: min./max. I/O unit sizes: 1/256, sub-page size 1 ubi0: VID header offset: 64 (aligned 64), data offset: 128 ubi0: good PEBs: 3840, bad PEBs: 0, corrupted PEBs: 0 ubi0: user volume: 4, internal volumes: 1, max. volumes count: 23 ubi0: max/mean erase counter: 2/1, WL threshold: 4096, image sequence number: 0 ubi0: available PEBs: 1674, total reserved PEBs: 2166, PEBs reserved for bad PEB handling: 0 Read 16384 bytes from volume env1 to d1e70620 Read 16384 bytes from volume env2 to d1e74640 OK In: serial Out: serial Err: serial Volume splash not found! splash_screen_display: ubi_volume_read error=19 Net: eth0: ethernet@40028000 Hit any key to stop autoboot: 0 Booting Image #1 No size specified -> Using max size (4198144) Read 4198144 bytes from volume rtos1 to d0400000 ## Loading kernel from FIT Image at d0400000 ... Using 'config-1' configuration Verifying Hash Integrity ... sha1,rsa2048:dev+ OK Trying 'kernel' kernel subimage Description: FreeRTOS Image Type: Kernel Image Compression: uncompressed Data Start: 0xd04000d0 Data Size: 77376 Bytes = 75.6 KiB Architecture: ARM OS: Linux Load Address: 0xd0600000 Entry Point: 0xd0610279 Hash algo: sha1 Hash value: 413d02bfc42ad673db4f077d8f84dd4e48d2de79 Verifying Hash Integrity ... sha1+ OK Loading Kernel Image ... OK Starting kernel ... STM32H7 SOM FreeRTOS CLI, www.emcraft.com Type help to view a list of available commands. CLI>

Enabling LCD and Splash Screen on Starter Kit with LCD

If your starter kit includes the LCD, it can be enabled in software by installing the U-Boot splash screen image to the QSPI Flash. Step through the following procedure to install the stm32h7-splash-24bpp.bmp picture as the splash screen:

  1. Create the 2 MB UBI volume for the splash screen image (this step can be skipped if the volume has been already created earlier):

    STM32H7-SOM U-Boot > ubi create splash 0x200000 Creating dynamic volume splash of size 2097152 STM32H7-SOM U-Boot >

  2. Download the splash screen image from the TFTP server:

    STM32H7-SOM U-Boot > tftp stm32h7-splash-24bpp.bmp Using ethernet@40028000 device TFTP from server 172.17.0.1; our IP address is 172.17.0.66 Filename 'stm32h7-splash-24bpp.bmp'. Load address: 0xd0400000 Loading: ########################### 1.7 MiB/s done Bytes transferred = 391736 (5fa38 hex) STM32H7-SOM U-Boot >

  3. Install the splash screen image to the QSPI Flash:

    STM32H7-SOM U-Boot > ubi write $loadaddr splash $filesize 391736 bytes written to volume splash STM32H7-SOM U-Boot >

Upgrading U-Boot "Proper" via Ethernet

Step through the following procedure to upgrade the U-Boot "Proper" via Ethernet using the previously installed U-Boot:

  1. Download the U-Boot image from the TFTP server:

    STM32H7-SOM U-Boot > tftp u-boot.img ethernet@40028000 Waiting for PHY auto negotiation to complete. done Using ethernet@40028000 device TFTP from server 172.17.0.1; our IP address is 172.17.0.66 Filename 'u-boot.img'. Load address: 0xd0400000 Loading: ################################## 91.8 KiB/s done Bytes transferred = 490985 (77de9 hex) STM32H7-SOM U-Boot >

  2. Install the U-Boot image to the QSPI Flash:

    STM32H7-SOM U-Boot > mtd erase u-boot Erasing 0x00000000 ... 0x000fffff (256 eraseblock(s)) STM32H7-SOM U-Boot > mtd write u-boot $loadaddr 0 $filesize Writing 490985 byte(s) at offset 0x00000000 STM32H7-SOM U-Boot >

Troubleshooting Ethernet

Here are some troubleshooting tips, in case tftpboot does not work for you from U-Boot:

  • As trivial as it sounds make sure that the board is connected to the LAN with an Ethernet cable.
  • Suppose you are still not getting your file from the TFTP server. It is possible that the problem is on the host side - you must set up a TFTP server correctly. Just google for "how to set up a tftp server" and follow the advice from some top articles.
  • Make sure you have copied a file you are trying to download to the TFTP server directory on the host.
  • Disable the firewall on the host since get enabled, it will block TFTP requests from the target.
  • On the target, make sure that you have set ipaddr and serverip correctly. Check ethaddr and make sure that you don't have another embedded board (eg. another STM32H7 SOM) configured for the same MAC address.