nuttx/boards/arm/stm32h7/stm32h747i-disco
Nathan Hartman 4716fc929d arch/stm32h7 - Fix HEAP clobbering static data in SRAM4
Normally, statically allocated data goes in .bss, followed by the
initial stack, followed by HEAP. However, any data that is statically
allocated in SRAM4 with __attribute__ ((section (".sram4"))) will
clobber, and be clobbered by, the HEAP.

On STM32H7, BDMA can only access SRAM4. Therefore any BDMA buffers (or
any other data) placed in SRAM4 will expose this problem. In one case,
this manifested as a failure of NSH to start, because the SPI6 BDMA
buffers clobbered the /dev/console inode structs, which the OS
allocated earlier.

This PR ensures that only the rest of SRAM4, after any static data, is
added to the heap. This PR also allows SRAM4 to be completely excluded
from the heap by a new Kconfig, CONFIG_STM32H7_SRAM4EXCLUDE, similar
to what CONFIG_STM32H7_DTCMEXCLUDE does for the DTCM region.

Change required in linker scripts:

Every STM32H7 linker script must replace this:

    .sram4 :
    {
    } > sram4

with this:

    .sram4_reserve (NOLOAD) :
    {
        *(.sram4)
        . = ALIGN(4);
        _sram4_heap_start = ABSOLUTE(.);
    } > sram4

or link will fail with: undefined reference to '_sram4_heap_start'.

The Release Notes should document this for users with out-of-tree
boards.

arch/arm/src/stm32h7/Kconfig:

    * Add config STM32H7_SRAM4EXCLUDE to allow excluding all of SRAM4
      from the HEAP.

arch/arm/src/stm32h7/stm32_allocateheap.c:

    * Only when including SRAM4 in the heap, define HAVE_SRAM4,
      SRAM4_START, SRAM4_END, and SRAM4_HEAP_START.

    * Add "Private Data" section.

    * Add extern for_sram4_heap_start, which must be defined in the
      board's linker script.

    * arm_addregion(): Only add SRAM4 to the heap when configured to
      do so, i.e., unless CONFIG_STM32H7_SRAM4EXCLUDE is defined, and
      only add the portion of SRAM4 that is past any static data.

boards/arm/stm32h7/nucleo-h743zi/scripts/flash.ld:
boards/arm/stm32h7/nucleo-h743zi/scripts/kernel.space.ld:
boards/arm/stm32h7/nucleo-h743zi2/scripts/flash.ld:
boards/arm/stm32h7/stm32h747i-disco/scripts/flash.ld:
boards/arm/stm32h7/stm32h747i-disco/scripts/kernel.space.ld:

    * Update all in-tree STM32H7 board linker scripts as described in
      "Change required in linker scripts" above.

Testing:

    * Successfully built all of the following configurations:

      nucleo-h743zi2:jumbo
      nucleo-h743zi2:nsh
      nucleo-h743zi:nxlines_oled
      nucleo-h743zi:elf
      nucleo-h743zi:otg_fs_host
      nucleo-h743zi:nsh
      nucleo-h743zi:netnsh
      nucleo-h743zi:pwm
      stm32h747i-disco:nsh

    * Tested with custom board.

    * nxstyle.

References:

[1] See the dev@nuttx.a.o mailing list discussion started 2021/03/25:
    "How to ensure HEAP will not overlap static DMA buffer?"
    https://lists.apache.org/thread.html/recf2bb9043f8c9f53c10917e2adb2ec64fe35dc5e6f9a695a7ac6ecc%40%3Cdev.nuttx.apache.org%3E

[2] See arm_addregion() in arch/arm/src/stm32h7/stm32_allocateheap.c

Thanks to Gregory Nutt and David Sidrane for suggestions and reviews.
2021-03-30 17:22:46 -03:00
..
configs/nsh fs: delete NFILE_DESCRIPTORS for allocating dynamically 2021-03-17 06:46:42 -07:00
include boards/arm/stm32h7/stm32h747i-disco: fix style issues 2020-05-07 10:29:01 -06:00
kernel board: stm32: Author Gregory Nutt: update licenses to Apache 2021-03-20 19:22:58 -07:00
scripts arch/stm32h7 - Fix HEAP clobbering static data in SRAM4 2021-03-30 17:22:46 -03:00
src boards: Author David Sidrane: update licenses to Apache 2021-03-22 19:28:38 -07:00
Kconfig Reviewed by David Sidrane. 2019-11-18 14:03:38 -06:00
README.txt Remove exra whitespace from files (#189) 2020-01-31 09:24:49 -06:00

README
======

  This README discusses issues unique to NuttX configurations for the
  STMicro STM32H747I-DISCO development board featuring the STM32H747I
  MCU. The STM32H747I is a Cortex-M7 and -M4 dual core with 2MBytes Flash
  memory and 1MByte SRAM. The board features:

  - On-board ST-Link v3E for programming and debugging,
  - 4 color user LEDs
  - One pushbuttons (user and reset)
  - Four-way joystick controller with select key
  - 32.768 kHz crystal oscillator
  - USB OTG HS with Micro-AB connectors
  - Ethernet connector compliant with IEEE-802.3-2002
  - Board connectors:
    - Camera
    - USB with Micro-AB
    - SWD
    - Ethernet RJ45
    - Arduino Uno V3
    - Pmod
    - STMod+

  Refer to the http://www.st.com website for further information about this
  board (search keyword: STM32H747I-DISCO)

Contents
========

  - STATUS
  - Serial Console
  - Configurations

STATUS
======

  2019-11-16:  This port is still incomplete!

Serial Console
==============

  1. Virtual Console.

    The virtual console uses Serial Port 1 (USART1).

      ----------------- ---
      VCOM Signal       Pin
      ----------------- ---
      SERIAL_RX         PA10
      SERIAL_TX         PA9
      ----------------- ---

    These signals are internally connected to the on board ST-Link.

  The virtual console is the default serial console in all
  configurations unless otherwise stated in the description of the
  configuration.

Configurations
==============

  Information Common to All Configurations
  ----------------------------------------
  Each STM32H747I-DISCO configuration is maintained in a sub-directory and
  can be selected as follow:

    tools/configure.sh [options] stm32h747i-disco:<subdir>

  Where options should specify the host build platform (-l for Linux, -c for
  Cygwin under Windows, etc.).  Try 'tools/configure.sh -h' for the complete
  list of options.

  Before starting the build, make sure that (1) your PATH environment variable
  includes the correct path to your toolchain, and (2) you have the correct
  toolchain selected in the configuration.

  And then build NuttX by simply typing the following.  At the conclusion of
  the make, the nuttx binary will reside in an ELF file called, simply, nuttx.

    make

  The <subdir> that is provided above as an argument to the tools/configure.sh
  must be is one of the following.

  NOTES:

  1. These configurations use the mconf-based configuration tool.  To
     change any of these configurations using that tool, you should:

     a. Build and install the kconfig-mconf tool.  See nuttx/README.txt
        see additional README.txt files in the NuttX tools repository.

     b. Execute 'make menuconfig' in nuttx/ in order to start the
        reconfiguration process.

  2. Unless stated otherwise, all configurations generate console
     output on the ST-Link VCOM, USART1.

  3. Unless otherwise stated, the configurations are setup for Linux by
     default:

     Build Setup:
       CONFIG_HOST_LINUX=y                     : Linux host operating system

  4. All of these configurations use the general arm-none-eabi toolchain for
     Linux  That toolchain selection can easily be reconfigured using 'make
     menuconfig'.

  5. These configurations all assume that you are loading code using
     something like the ST-Link v3E JTAG.  None of these configurations are
     setup to use the DFU bootloader but should be easily reconfigured to
     use that bootloader if so desired.

  Configuration Sub-directories
  -----------------------------

  nsh:

    This configuration provides a basic NuttShell configuration (NSH)
    for the board.  The default console is the VCOM on USART1.