mbed-os/targets/TARGET_STM
Jay Sridharan afba4e1eb5
Merge upstream changes into mbed-ce (#117)
* Fix for calculating CAN timing settings.

NominalPrescaler value needs to be as high as possible to ensure a good approximation of the target CAN speed.
Previous usage of macro IS_FDCAN_DATA_TSEG1 refers to (unsupported by Mbed ) FDCAN CAN controller settings and leads to too low prescaler values.
Usage Macro IS_FDCAN_NOMINAL_TSEG1 yields optimum results.
See also correct macro usage in line #158.

* Add complete support of DHCP relay interface ID option

RFC3315 specifies the following: "The relay agent MAY send the Interface-id
option to identify the interface on which the client message was received.
If a relay agent  receives a Relay-reply message with an Interface-id
option, the relay agent relays the message to the client through the
interface identified by the option."

The current implementation of the DHCP relay reply handling, the interface
ID field from the server response is ignored. Managing the interface ID
is very important especially as DHCP requests/replies use link-local
addresses. The consequence of this is that the interface must always be
specified because the routing layer cannot guess the correct interface.
Moreover, Mbed provides a mechanism to enable/disable the interface ID
option on a DHCP relay instance, so it is important to fully support it.

The reason why this issue has not been discoverd until now is that the DHCP
relay is mainly used on systems that use only one interface (such as Wi-SUN
routers). By default, when no interface ID is specified for the socket, the
latter will choose 6loWPAN interface by default. This means that if two
interfaces are used on the same device, the 6loWPAN interface is always
selected.

The commit adds code to retrieve the interface-id value contained within
the DHCP relay reply message and write it to a control message header
that is added to the socket message. This tells the socket which
interface to choose. If the interface-id option is not enabled on the
relay, this procedure is simply ignored.

* Support Nuvoton target NUMAKER_IOT_M467

1.  Based on alpha version BSP (85564a2716548e7b6d6a79a490c6d94a24cf9bcf)
2.  Continuing above, tweak BSP:
    (1) Add EPWM_ConfigOutputChannel2() to enable below 1Hz and below 1% duty cycle for PWM output (m460_epwm.h/c).
    (2) Add dummy RTC_WaitAccessEnable() for consistency with previous ports (m460_rtc.h).
3.  Target NuMaker-M467HJ V0.1 board temporarily
4.  Support Arduino UNO form factor for NUMAKER_IOT_M467 target
5.  Enable export to Keil/IAR project
    -   tools/arm_pack_manager/index.json
    -   tools/export/iar/iar_definitions.json

* M467: Fix Greentea reset_reason test failure

HRESETRF is combined reset flag. Filter it out to avoid interference with reset reason check.

* M467: Support HyperRAM

1.  For GCC, support multi-block .data/.bss initialization
2.  HyperRAM is mapped to two regions: 0x0A000000 and 0x80000000
    According to default system address map, 0x0A000000 is located at 'Code' region and 0x80000000 at 'RAM' region.
    With MPU enabled on Mbed OS, 'Code' region is write-never and 'RAM' region execute-never.
    0x80000000 is chosen because 'RAM' regioin is naturally for HyperRAM.
3.  Configurable multi-function pins for HBI
4.  To locate code/data at external HyperRAM:
    -   Specify __attribute__((section(".text.nu.exthyperram"))) for RO/.text/readonly section type
        Invoke mbed_mpu_manager_lock_ram_execution()/mbed_mpu_manager_unlock_ram_execution() to run HyperRAM code
    -   Specify __attribute__((section(".data.nu.exthyperram"))) for RW/.data/readwrite section type
    -   Specify __attribute__((section(".bss.nu.exthyperram"))) for ZI/.bss/zeroinit section type
5.  Add readme

* Config for M460 EMAC

* Add M460 EMAC driver

* Adjust M460 EMAC RX/TX buffer

* M467: Fix EMAC compile error with IAR

* M467: Support Crypto SHA/ECC H/W

1.  Prepare crypto common code
2.  Support list
    -   SHA
    -   ECC
    NOTE: AES/RSA are to support in other works
    NOTE: Compared to M487, M467's SHA supports context save & restore (DMA Cascade mode) and so no software fallback is needed.
    NOTE: M467's ECC, following M487, goes partial-module replacement and it can just improve primitives e.g. point addition/doubling by 2X,
          and cannot improve high level point multiplication because MbedTLS doesn’t open it.
          To improve performance best, full-module replacement is needed.
    NOTE: Continuing above, add support for Montgomery curve

* M467 H/W AES self-test pass

* M467 Support crypto GCM H/W

* M467: GCM support one simple mode instead of using composite GHASH & CTR MODE

* Update M467 AES-GCM to pass AWS-IoT test

* Update M467 AES-GCM for H/W gcm in-buffer creteria

* M467: Improve Crypto H/W wait helper routine

Add crypto_xxx_wait2 helper routine to replace crypto_xxx_wait for Crypto H/W control

* M467: Seed PRNG with TRNG for SCAP

According to TRM, it is suggested PRNG be seeded by TRNG on every Crypto H/W reset.

* M467: Support Crypto RSA H/W

1.  Crypto RSA H/W supports 1024/2048/3072/4096 key bits. Fall back to software implementation for other key bits.
2.  For decrypt, if MBEDTLS_RSA_NO_CRT isn't defined, go CRT, or normal.
3.  For decrypt, when blinding (f_rng != NULL), enable SCAP mode.
4.  Recover from Crypto RSA H/W failure:
    (1) Enable timed-out wait to escape from RSA H/W trap
    (2) On RSA H/W timeout, stop this RSA H/W operation
    (3) Fall back to S/W implementation on failure

NOTE: RSA 4096 key bits can fail with default mbedtls configuration MBEDTLS_MPI_MAX_SIZE.
      Enlarge MBEDTLS_MPI_MAX_SIZE to 1024 or larger if this feature is required.
NOTE: Fixed in BSP RSA driver, for non-CRT+SCAP mode, temporary buffer for MADDR6 requires to be key length plus 128 bits.
NOTE: Fixed in BSP RSA driver, DMA buffer must be 4-word aligned, or RSA H/W will trap.

* M467 Support crypto AES-CCM H/W with one-shot & cascade mode

* M467: Support Crypto ECC H/W in full-module replacement

1.  Replace ecp.c full-module, and other ec modules dependent on ecp.c (ecdh.c/ecdsa.c/ecjpake.c) will improve followingly.
2.  Recover from Crypto ECC H/W failure:
    (1) Enable timed-out wait to escape from ECC H/W trap
    (2) On ECC H/W timeout, stop this ECC H/W operation
    (3) Fall back to S/W implementation on failure
3.  Support Short Weierstrass curve
4.  Support Montgomery curve
    Montgomery curve has the form: B y^2 = x^3 + A x^2 + x
    (1) In S/W impl, A is used as (A + 2) / 4. Figure out its original value for engine.
        2eb06e7620/connectivity/mbedtls/include/mbedtls/ecp.h (L219-L220)
    (2) In S/W impl, B is unused. Actually, B is 1 for Curve25519/Curve448 and needs to configure to engine.
        2eb06e7620/connectivity/mbedtls/include/mbedtls/ecp.h (L221-L222)
    (3) In S/W impl, y-coord is absent, but engine needs it. Deduce it from x-coord following:
        https://tools.ietf.org/id/draft-jivsov-ecc-compact-05.html
        https://www.rieselprime.de/ziki/Modular_square_root
    NOTE: Fix Curve448 has wrong order value
          https://github.com/Mbed-TLS/mbedtls/pull/5811

* M467: Disable SCAP in RSA H/W

This is to follow designer's resolution.

* M467: support fullspeed usb device

* M467: Fix mbedtls_ecp_point_cmp() call with null argument

Guard from null argument passed to mbedtls_ecp_point_cmp() in ECC H/W port

* M467: Make mbedtls H/W port removable

Some M460 chips don't support AES/SHA/ECC/RSA H/W.
Make them removable from mbedtls H/W port through '"target.macros_remove": ["MBEDTLS_CONFIG_HW_SUPPORT"]'.

* Added TMPM4NR Platform

New Platform for Toshiba Added

* Removed UTF8 Chars

* M467: I2C: Fix potential role switch failure

Fix in i2c_do_trsn(), interrupt doesn't change back to enabled due to premature return.

* M467: Exclude UNO SPI pins from FPGA CI Test Shield test

UNO D8/D9/D10/D11/D12/D13 can wire to on-board SPI flash.
Exclude these pins from FPGA CI Test Shield test.

* M467: Adjust UART pinmap to pass FPGA CI Test Shield test

* M467: Support NuMaker-IoT-M467 board

Pinout comparison between NuMaker-M467HJ and NuMaker-IoT-M467 boards:
1.  UNO are unchanged
2.  LEDs are unchanged
3.  Buttons are unchanged, except button names
4.  NuMaker-M467HJ has HBI but NuMaker-IoT-M467 does
5.  NuMaker-M467HJ doesn't have ESP8266 but NuMaker-IoT-M467 does
6.  SDHC are unchanged

* Nuvoton: I2C: Fix potential role switch failure

Fix in i2c_do_trsn(), interrupt doesn't change back to enabled due to premature return.

Fix targets:
-   NUMAKER_PFM_NANO130
-   NUMAKER_PFM_NUC472
-   NUMAKER_PFM_M453
-   NUMAKER_PFM_M487/NUMAKER_IOT_M487
-   NUMAKER_IOT_M252
-   NUMAKER_IOT_M263A
-   NU_M2354

* Update can_api.c

Modified comment as discussed.

* M467: Remove invalid UTF-8 byte sequence

* Replace MAX32660, MAX32670 I2C driver with final one in MSDK
- apply clang-format
- Fix i2c repeated start issue

Signed-off-by: Sadik.Ozer <sadik.ozer@analog.com>

* Add proper support for NUCLEO-H723ZG.

- add board specific EMAC setup to connectivity/drivers/emac/TARGET_STM/TARGET_STM32H7
  - stm32h7_eth_init.c was derived from the NUCLEO-H743ZI2 code whilst comparing to the output of STM32CubeIDE
- complete board specific code in targets/TARGET_STM/TARGET_STM32H7/TARGET_STM32H723xG
  - PeripheralPins.c and PinNames.h were created by targets/TARGET_STM/tools/STM32_gen_PeripheralPins.py
  - ST ZIO connector pins in PinNames.h have been adapted from NUCLEO-H743ZI2
  - CONSOLE_TX and CONSOLE_RX have been interchanged in PinNames.h to match the actual board layout
  - startup_stm32h723xx.S was derived from startup_stm32h743xx.S
  - stm32h723xg.ld was completely rewritten to match the actual MCU including:
    - split heap support
    - SRAM2 and SRAM4 support
    - crash dump support
    - proper use of DTCM as stack
  - system_clock.c has been changed to support the maximal main clock speed of 550 MHz
- fix handling of HS in FS mode for the target board in targets/TARGET_STM/USBPhy_STM32.cpp
- add board definition to targets/targets.json and correct linker setup for the chip

Signed-off-by: Daniel Starke <daniel-email@gmx.net>

* Fix I2C for MCU_STM32H723xG

Add I2C configuration to MCU_STM32H723xG in target.json as suggested by @jeromecoutant.

Signed-off-by: Daniel Starke <daniel-email@gmx.net>

* Correct MAX32620 boards macro for USB library.

* Limit NUCLEO_H723ZG toolchain to GCC_ARM

Limit NUCLEO_H723ZG toolchain to GCC_ARM only.
This is the only toolchain this target has been tested with yet.

Signed-off-by: Daniel Starke <daniel-email@gmx.net>

* M2354 support FS-USBD and update TF-M for USB PHY select

* Rethink STM32 I2C v2 HAL

* Add documentation for I2C_EVENT macros

* Add some additional I2C error codes

* Added TMPM4GR Platform

New Platform for Toshiba Added

* Resolve delimeter issues for target.json

* Fix compile error on static pinmap targets

* github: Fix click version

Signed-off-by: Martin Kojtal <martin.kojtal@arm.com>

Signed-off-by: Sadik.Ozer <sadik.ozer@analog.com>
Signed-off-by: Daniel Starke <daniel-email@gmx.net>
Signed-off-by: Martin Kojtal <martin.kojtal@arm.com>
Co-authored-by: chdelfs <109847651+chdelfs@users.noreply.github.com>
Co-authored-by: YannCharbon <yann.charbon@ik.me>
Co-authored-by: Chun-Chieh Li <ccli8@nuvoton.com>
Co-authored-by: cyliangtw <cyliang@nuvoton.com>
Co-authored-by: Deepak V. Shreshti <DeepakVS@TOSHIBA-TSIP.COM>
Co-authored-by: Martin Kojtal <martin.kojtal@arm.com>
Co-authored-by: Sadik.Ozer <sadik.ozer@analog.com>
Co-authored-by: Daniel Starke <daniel-email@gmx.net>
Co-authored-by: Ahmet Alincak <Ahmet.Alincak@maximintegrated.com>
Co-authored-by: Jamie Smith <smit109@usc.edu>
Co-authored-by: Jamie Smith <jsmith@crackofdawn.onmicrosoft.com>
2022-12-31 20:20:01 -08:00
..
TARGET_STM32F0 Rethink STM32 I2C v2 HAL (#78) 2022-11-20 17:46:30 -08:00
TARGET_STM32F1 STM32F1: add MCU_STM32F103xC support 2022-03-31 15:31:47 +02:00
TARGET_STM32F2 STM32: increase i2c slave rx limit. 2022-01-28 11:58:52 +01:00
TARGET_STM32F3 Rethink STM32 I2C v2 HAL (#78) 2022-11-20 17:46:30 -08:00
TARGET_STM32F4 Make STM32F412xE targets build 2022-06-16 16:05:34 +02:00
TARGET_STM32F7 Rethink STM32 I2C v2 HAL (#78) 2022-11-20 17:46:30 -08:00
TARGET_STM32G0 Rethink STM32 I2C v2 HAL (#78) 2022-11-20 17:46:30 -08:00
TARGET_STM32G4 Rethink STM32 I2C v2 HAL (#78) 2022-11-20 17:46:30 -08:00
TARGET_STM32H7 Merge upstream changes into mbed-ce (#117) 2022-12-31 20:20:01 -08:00
TARGET_STM32L0 Rethink STM32 I2C v2 HAL (#78) 2022-11-20 17:46:30 -08:00
TARGET_STM32L1 STM32: increase i2c slave rx limit. 2022-01-28 11:58:52 +01:00
TARGET_STM32L4 Rethink STM32 I2C v2 HAL (#78) 2022-11-20 17:46:30 -08:00
TARGET_STM32L5 Rethink STM32 I2C v2 HAL (#78) 2022-11-20 17:46:30 -08:00
TARGET_STM32U5 Rethink STM32 I2C v2 HAL (#78) 2022-11-20 17:46:30 -08:00
TARGET_STM32WB Rethink STM32 I2C v2 HAL (#78) 2022-11-20 17:46:30 -08:00
TARGET_STM32WL Rethink STM32 I2C v2 HAL (#78) 2022-11-20 17:46:30 -08:00
tools STM32L1: add support of MCU_STM32L151xB 2021-11-10 10:12:28 +01:00
CMakeLists.txt STM32U5: generic STM32 driver files update 2021-09-10 11:16:16 +02:00
PeripheralPins.h STM32F1: add more alternate functions 2021-09-17 15:37:56 +02:00
PinNamesTypes.h STM32L152: Added ADC Bank_B functionality. 2021-05-24 23:44:02 +05:30
PortNames.h
README.md STM32: readme update for MBED_SLEEP_TRACING_ENABLED 2021-11-08 09:46:20 +01:00
USBPhyHw.h STM32F3 - enable USB_DEVICE for NUCLEO_F303ZE 2021-09-28 16:36:12 +02:00
USBPhy_STM32.cpp Merge upstream changes into mbed-ce (#117) 2022-12-31 20:20:01 -08:00
analogin_api.c
analogout_api.c STM32: AnalogOut: do not call HAL_DAC_Start in dac_write 2021-03-12 09:56:41 +01:00
can_api.c Merge upstream changes into mbed-ce (#117) 2022-12-31 20:20:01 -08:00
device.h Rethink STM32 I2C v2 HAL (#78) 2022-11-20 17:46:30 -08:00
gpio_api.c STM32U5: generic STM32 driver files update 2021-09-10 11:16:16 +02:00
gpio_irq_api.c GPIO: Use uintptr_t for gpio_irq_api context 2022-01-26 18:12:52 +00:00
gpio_object.h STM32WL : ADDING STM32 SUPPORT 2021-02-05 08:04:31 +00:00
hal_tick_overrides.c STM32 common filess astyle 2021-05-25 14:45:30 +02:00
i2c_api.c Rethink STM32 I2C v2 HAL (#78) 2022-11-20 17:46:30 -08:00
lp_ticker.c STM32G0: introduce sub family for custom boards 2021-09-22 11:46:54 +02:00
lp_ticker_defines.h STM32: Add LP_TICKER and US_TICKER optimisation define 2021-04-20 10:40:53 +02:00
mbed_crc_api.c
mbed_overrides.c add RTC from HSE to target STM32F1 2021-09-01 14:42:04 +02:00
mbed_rtx.h Add SPDX license identifier to Arm files 2020-10-15 10:47:27 +01:00
nvic_addr.h Add SPDX license identifier to Arm files 2020-10-15 10:47:27 +01:00
ospi_api.c B_U585I_IOT02A supports OSPI 2021-11-18 12:26:21 +01:00
pinmap.c STM32H7 ADC : dual pad feature update 2021-06-03 10:42:35 +02:00
port_api.c
pwmout_api.c removed pin_mode api call from pwmout_init_direct api 2021-04-08 18:13:10 +05:30
qspi_api.c STM32 OSPI/QSPI : correct GPIO free 2021-03-18 14:53:00 +01:00
reset_reason.c Add SPDX license identifier to Arm files 2020-10-15 10:47:27 +01:00
rtc_api.c STM32L1: build error with STM32L151xB MCU 2022-02-15 15:39:04 +01:00
rtc_api_hal.h add RTC from HSE to target STM32F1 2021-09-01 14:42:04 +02:00
serial_api.c Fix serial low speed baud 2022-05-13 11:16:15 +02:00
serial_api_hal.h
sleep.c STM32 common filess astyle 2021-05-25 14:45:30 +02:00
stm32_assert.h
stm_i2c_api.h Fix compilation of I2C code on static pinmap targets (#110) 2022-12-04 00:17:49 -08:00
stm_spi_api.c Fix STM32 SPI async API for STM32H7 (SPI_IP_VERSION_V2) 2022-01-15 14:51:41 +03:00
trng_api.c STM32U5: generic STM32 driver files update 2021-09-10 11:16:16 +02:00
us_ticker.c STM32WL : ADDING STM32 SUPPORT 2021-02-05 08:04:31 +00:00
us_ticker_defines.h
watchdog_api.c STM32U5: generic STM32 driver files update 2021-09-10 11:16:16 +02:00

README.md

README for Mbed OS STM32 targets

Table of Contents

ST TOOLS

USB drivers

Mandatory: get the latest USB driver in order to make available all the USB interfaces provided by the ST-LINK:

  • ST Debug
  • Virtual COM port
  • ST Bridge interfaces

Default Windows USB drivers will not setup full capabilities.

https://www.st.com/en/development-tools/stsw-link009.html

Mandatory: get the latest ST-Link Firmware:

https://www.st.com/en/development-tools/stsw-link007.html

You could have some issue to connect your board if you didn't install full USB drivers.

Note that with the latest FW version, you are able to check the version number easily with a simple "mbedls":

$ mbedls
| platform_name       | platform_name_unique   | mount_point | serial_port | target_id                | interface_version |
|---------------------|------------------------|-------------|-------------|--------------------------|-------------------|
| DISCO_H747I         | DISCO_H747I[0]         | D:          | COM13       | 081402210D03E72132477E08 | V3J7M2            |
| DISCO_L475VG_IOT01A | DISCO_L475VG_IOT01A[0] | E:          | COM9        | 07640221683B630A577FF553 | V2J37M26          |
$ mbedtools detect
Board name       Serial number             Serial port    Mount point(s)    Build target(s)    Interface Version
---------------  ------------------------  -------------  ----------------  -----------------  -------------------
NUCLEO-U575ZI-Q  0022003c5553500d20393256  COM25          D:                NUCLEO_U575ZI_Q    V3J7M3

STM32 Cube

https://www.st.com/en/embedded-software/stm32cube-mcu-packages.html

There is one STM32Cube package for each individual STM32 MCU family.

It includes:

  • The hardware abstraction layer (HAL) enabling portability between different STM32 devices via standardized API calls
  • Low-layer (LL) APIs, a light-weight, optimized, expert oriented set of APIs designed for both performance and runtime efficiency
  • A collection of middleware components including RTOS, USB library, file system, TCP/IP stack, touch-sensing library or graphics library (depending on the STM32 series)
  • BSP drivers, based on HAL drivers.

Part of STM32Cube files are copied in each targets/TARGET_STM/TARGET_STM32<xx>/STM32Cube_FW directory:

  • CMSIS header files in CMSIS sub-directory
  • HAL and LL files in STM32<XX>xx_HAL_Driver sub-directory

Mbed OS HAL calls ST porting layer, which calls ST HAL and LL API.

Note that all ST HAL and LL files are available:

  • you can then develop some applications with direct ST HAL and LL call, even if feature is not supported in Mbed OS
  • BSP for LCD, AUDIO, SENSORS, etc... are not available in Mbed OS, but you should be able to use it in your local application.

Each STM32Cube package is also available in Github. This table summarizes the STM32Cube versions currently used in Mbed OS master branch :

STM32 Serie Cube version Github source
F0 1.11.2 https://github.com/STMicroelectronics/STM32CubeF0
F1 1.8.3 https://github.com/STMicroelectronics/STM32CubeF1
F2 1.6.0 https://github.com/STMicroelectronics/STM32CubeF2
F3 1.11.2 https://github.com/STMicroelectronics/STM32CubeF3
F4 1.26.1 https://github.com/STMicroelectronics/STM32CubeF4
F7 1.16.1 https://github.com/STMicroelectronics/STM32CubeF7
G0 1.5.0 https://github.com/STMicroelectronics/STM32CubeG0
G4 1.4.0 https://github.com/STMicroelectronics/STM32CubeG4
H7 1.9.0 https://github.com/STMicroelectronics/STM32CubeH7
L0 1.12.0 https://github.com/STMicroelectronics/STM32CubeL0
L1 1.10.2 https://github.com/STMicroelectronics/STM32CubeL1
L4 1.17.0 https://github.com/STMicroelectronics/STM32CubeL4
L5 1.4.0 https://github.com/STMicroelectronics/STM32CubeL5
U5 1.0.0 https://github.com/STMicroelectronics/STM32CubeU5
WB 1.11.1 https://github.com/STMicroelectronics/STM32CubeWB
WL 1.1.0 https://github.com/STMicroelectronics/STM32CubeWL

In Mbed OS repository, we try to minimize the difference between "official" and copied files.

STM32CubeMX

STM32CubeMX is a graphical tool that allows a very easy configuration of all STM32

https://www.st.com/en/development-tools/stm32cubemx.html

Tool is not used in Mbed OS, but it can be useful for you.

STM32CubeProgrammer

It provides an easy-to-use and efficient environment for reading, writing and verifying device memory.

https://www.st.com/en/development-tools/stm32cubeprog.html

Tool is not used in Mbed OS, but it can be useful for you.

STM32 families

STM32WB

STM32WB README

STM32WL

STM32WL README

STM32H7

STM32H7 README

Custom boards

It should be "easy" to add your custom board with a STM32 MCU in Mbed OS

You can also check in https://github.com/ARMmbed/stm32customtargets

STM32 organisation

STM32 root directory is https://github.com/ARMmbed/mbed-os/tree/master/targets/TARGET_STM

This contains:

  • all STM32 families directories: F0, F1, F2, F3, F4, F7, G0, G4, H7, L0, L1, L4, L5, U5, WB, WL
  • Mbed OS porting layer common for all

Each STM32 family contains several "sub-families".

Each STM32 Part Number defines a sub-family: STM32F401 / STM32F407 / STM32F429 / ...

But also each STM32 Part Number with different FLASH size : STM32F401xC / STM32F401xE

Mbed OS porting layer specific for this family are placed here.

Example in TARGET_STM32G0:

  • TARGET_STM32G031x8
  • TARGET_STM32G071xB
  • ...

Each STM32 sub-family contains:

  • toolchains files
  • board specific files

Add a custom board

ST provides the complete support for few NUCLEO and DISCO boards.

Locate one of these boards with the minimum difference with your chosen MCU.

Copy paste, and update!

Board specific files (pinmap)

2 files in Mbed OS:

  • PeripheralPins.c
  • PinNames.h

It is recommended to use a python script to generate those files

https://github.com/ARMmbed/mbed-os/blob/master/targets/TARGET_STM/tools/STM32_gen_PeripheralPins.py

This script is using MCU database from https://github.com/STMicroelectronics/STM32_open_pin_data.git repo

$ python targets/TARGET_STM/tools/STM32_gen_PeripheralPins.py -h

SScript version 1.19

Checking STM32_open_pin_data repo...
*** git clone done

usage: STM32_gen_PeripheralPins.py [-h] (-l | -b | -m xml | -t HW | -c CUSTOM)
                                   [-g]

Script will generate PeripheralPins.c thanks to the xml files description available in STM32_open_pin_data GitHub repo

More information in targets/TARGET_STM/README.md

optional arguments:
  -h, --help            show this help message and exit
  -l, --list            list available mcu xml files description in STM32CubeMX
  -b, --boards          list available boards description in STM32CubeMX
  -m xml, --mcu xml     specify the mcu xml file description in STM32CubeMX to use (use double quotes).
                           Parameter can be a filter like L496 if you want to parse all L496 chips (-m STM32 to parse all).
  -t HW, --target HW    specify the board file description in STM32CubeMX to use (use double quotes).
                           Parameter can be a filter like L496 (only the first file found will be parsed).
  -c CUSTOM, --custom CUSTOM
                        specify a custom board .ioc file description to use (use double quotes).
  -g, --gpio            Add GPIO PinMap table

Once generated, you have to check and comment pins that can not be used (specific HW, internal ADC channels, remove PWM using us ticker timer, ...)

How to generate files for a custom boards based on a STM32F427 MCU:

$ python targets/TARGET_STM/tools/STM32_gen_PeripheralPins.py -l | grep F427
STM32F427A(G-I)Hx.xml
STM32F427I(G-I)Hx.xml
STM32F427I(G-I)Tx.xml
STM32F427V(G-I)Tx.xml
STM32F427Z(G-I)Tx.xml

$ python targets/TARGET_STM/tools/STM32_gen_PeripheralPins.py -m "STM32F427V(G-I)Tx.xml"

Script version 1.19

Checking STM32_open_pin_data repo...
        Already up to date.

STM32_open_pin_data DB version STM32CubeMX-DB.6.0.10

 * Output directory: targets_custom\TARGET_STM\TARGET_STM32F4\TARGET_STM32F427xG\TARGET_STM32F427VGT
 * Generating PeripheralPins.c and PinNames.h with 'STM32_open_pin_data\mcu\STM32F427V(G-I)Tx.xml'
 * GPIO file: STM32_open_pin_data\mcu\IP\GPIO-STM32F427_gpio_v1_0_Modes.xml
 * I/O pins found: 135 connected: 0

 * Output directory: targets_custom\TARGET_STM\TARGET_STM32F4\TARGET_STM32F427xI\TARGET_STM32F427VIT
 * Generating PeripheralPins.c and PinNames.h with 'STM32_open_pin_data\mcu\STM32F427V(G-I)Tx.xml'
 * GPIO file: STM32_open_pin_data\mcu\IP\GPIO-STM32F427_gpio_v1_0_Modes.xml
 * I/O pins found: 135 connected: 0

Use of custom_targets.json

https://os.mbed.com/docs/mbed-os/latest/porting/porting-a-custom-board.html

Example with a board based on STM32F103C8 (like BluePill):

  • MCU_STM32F103x8 generic configuration is already available in targets.json file
$ python targets/TARGET_STM/tools/STM32_gen_PeripheralPins.py -m "STM32F103C(8-B)Tx.xml"
// PeripheralPins.c and PinNames.h template files are created in targets_custom/TARGET_STM/TARGET_STM32F1/TARGET_STM32F103x8/TARGET_STM32F103C8T directory

$ mv TARGET_STM32F103C8T TARGET_BLUEPILL_F103C8
// Edit PeripheralPins.c and PinNames.h to match your board configuration

// Create a custom_targets.json with:
{
    "BLUEPILL_F103C8": {
        "inherits": [
            "MCU_STM32F103x8"
        ],
        "overrides": {
            "clock_source": "USE_PLL_HSE_XTAL"
        },
        "device_has_remove": [
            "STDIO_MESSAGES"
        ],
        "device_name": "STM32F103C8"
    }
}

Example with a board based on STM32H745ZI

  • this is dual core MCU with CM4 and CM7
  • MCU_STM32H745I_CM4 and MCU_STM32H745I_CM7 generic configuration is already available in targets.json file
$ python targets/TARGET_STM/tools/STM32_gen_PeripheralPins.py -m "STM32H745ZITx.xml"
// PeripheralPins.c and PinNames.h template files are created in targets_custom/TARGET_STM/TARGET_STM32H7/TARGET_STM32H745xI/TARGET_STM32H745ZIT directory

$ mv TARGET_STM32H745ZIT TARGET_H745ZI_BOARD
// Edit PeripheralPins.c and PinNames.h to match your board configuration

// Create a custom_targets.json with:
{
    "H745ZI_BOARD_CM4": {
        "inherits": [
            "MCU_STM32H745I_CM4"
        ],
        "extra_labels_add": [
            "H745ZI_BOARD"
        ]
    },
    "H745ZI_BOARD_CM7": {
        "inherits": [
            "MCU_STM32H745I_CM7"
        ],
        "extra_labels_add": [
            "H745ZI_BOARD"
        ]
    }
}

Make your custom board public

We will be happy to add every public board in https://github.com/ARMmbed/stm32customtargets

Make a Pull request, we will check consistency and build.

ST specific implementation

Pin configuration

It can be useful to have a look on files that describes pin configuration for your board:

  • targets/TARGET_STM/TARGET_STM32XX/TARGET_STM32XXXXX/TARGET_XXXXX/PeripheralPins.c
  • targets/TARGET_STM/TARGET_STM32XX/TARGET_STM32XXXXX/TARGET_XXXXX/PinNames.h

Alternate feature

You can easily see the alternate functions for each pin.

Ex:

    {PC_10,      UART_3,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)},
    {PC_10_ALT0, UART_4,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_UART4)},
  • If your application is using PC_10 pin for UART, drivers will configure UART3 instance.
  • If your application is using PC_10_ALT0 pin for UART, drivers will configure UART4 instance.

The same alternate choice feature is also used for PWM, ADC, SPI, etc...

Conflict pins

Sometimes there are some conflicts in pin use.

Ex:

    {PA_5,       SPI_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI1)}, // Connected to LD2 [green led]

==> You can use PA_5 pin as SPI, only if your application is not using LED...

Sometimes, pin is explicitly removed by default to avoid issues (but you can uncomment the line for your custom board)

//  {PB_4,       UART_2,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)}, // Connected to same instance as STDIO 

Clock selection

System clock

System Core Clock is based on an high-speed clock.

  • the HSI is the high-speed internal (MCU) clock with low accuracy
  • the HSE is the high-speed external clock with higher accuray

For each target, a default choice has been made in the "clock_source" config settings in the targets.json file.

For main targets, it is something like:

    "clock_source": {
        "value": "USE_PLL_HSE_EXTC|USE_PLL_HSI",

Meaning that:

  • PLL with the external HSE clock is first configured
  • if it fails, PLL with HSI is then configured

Low power clock

Low power ticker and RTC are based on an low-speed clock.

  • the LSI is the low-speed internal clock with low accuracy
  • the LSE is the low-speed external clock connected to 32.768 kHz quartz crystal

In targets.json file, it is supposed that a LSE is provided in the board

"config": {
    "lse_available": {
        "value": "1"

You can change this in you local mbed_app.json:

{
    "target_overrides":
    {
        "XXXX": {
            "target.lse_available": "0"
        }
    }
}

I2C Timing calculation algorithm

I2C drivers version 2 use I2C timing register.

Enable I2C timing algorithm by setting the value of i2c_timing_value_algo target config to true

"i2c_timing_value_algo": {
                "help": "If value was set to true I2C timing algorithm is 
                enabled. Enabling may leads to performance issue. Keeping this
                false and changing system clock will trigger assert.",
                "value": false
            }

Default configuration disables I2C timing algorithm. If user need to use different system clock speed other than default system clock configuration. Then I2C timing calculation algorithm need to enable. To enable

"i2c_timing_value_algo": {
                "value": true
            }

Sleep feature

ST MCUs feature several low-power modes, please check Reference Manual of each one for more details.

  • MBED sleep mode is usually mapped to ST SLEEP mode:

    • CPU clock is off
    • all peripherals can run and wake up the CPU when an interrupt or an event occurs
  • MBED deepsleep mode is mapped to ST STOP2 mode:

    • all clocks in the VCORE domain are stopped
    • the PLL, the MSI, the HSI and the HSE are disabled
    • the LSI and the LSE can be kept running
    • RTC can remain active

Detailed sleep Mbed OS description : https://os.mbed.com/docs/mbed-os/latest/apis/power-management-sleep.html

  • debug profile is disabling deepsleep
  • deepsleep can also be disabled by application or drivers using sleep_manager_lock_deep_sleep()
  • deep-sleep-latency value is configured to 4 by default for STM32
  • trace with MBED_SLEEP_TRACING_ENABLED macro is set by default with low verbosity
    "target_overrides": {
        "*": {
            "platform.deepsleep-stats-enabled": true,
            "platform.deepsleep-stats-verbose": false
        },

WiFi configuration

https://github.com/ARMmbed/wifi-ism43362

https://os.mbed.com/teams/ST/wiki/How-to-make-wifi-tests

Ethernet configuration

Depending on your PHY, you will have to customize several configuration values:

  • the number of RX buffers
  • the number of TX buffers
  • thread size
  • PHY address
  • media interface
  • AutoNegotiation mode
  • DuplexMode mode
  • Speed mode
  • PHY register Offset
  • Speed mask information in the PHY status register
  • Duplex mask information in the PHY status register

Check the default values in: https://github.com/ARMmbed/mbed-os/blob/master/connectivity/drivers/emac/TARGET_STM/mbed_lib.json

Option is also to define your own HAL_ETH_MspInit function, you then have to add USE_USER_DEFINED_HAL_ETH_MSPINIT macro.

Custom IRQ Handler and Callback from user application

To use the custom IRQ Handler and the callbacks, you need to add USE_USER_DEFINED_HAL_ETH_IRQ_CALLBACK macro inside any of the JASON file in either targets.json or in mbed_app.json file.

For example in the targets.json, you need to add this line in your target: "macros_add": ["USE_USER_DEFINED_HAL_ETH_IRQ_CALLBACK"], or for example in the mbed_app.json, you need to add: "macros": ["USE_USER_DEFINED_HAL_ETH_IRQ_CALLBACK"]

By doing the any of the above json files, the corresponding user defined custom apis like HAL_ETH_RxCpltCallback() and STM_HAL_ETH_Handler() can be called from the user application.

Changing default MAC address in STM32

To change the default MAC address in STM32, If we have the function mbed_otp_mac_address() in the user application,the default ethernet address can be changed. Because as this is defined as weak in mbed-os/connectivity/drivers/emac/TARGET_STM/stm32xx_emac.cpp

#include "platform/mbed_toolchain.h"
MBED_WEAK uint8_t mbed_otp_mac_address(char *mac).

Please find the code snippet here for reference:

..
uint8_t mbed_otp_mac_address(char *mac);
uint8_t mbed_otp_mac_address(char *mac)
{
	unsigned char ST_mac_addr[6] = {0x00, 0x88, 0xe0,0x90,0x80,0x70}; // New User mac address
	// printf("%s:%s\n",__FILE__,__func__);
	memcpy(mac,ST_mac_addr,sizeof(ST_mac_addr));
	return 1;
}

int main()
{
	// Bring up the ethernet interface
	printf("Ethernet socket example\n");
	uint8_t MyMAC[6];
	printf("return of set_mac_address:%d\n",net.set_mac_address(MyMAC,sizeof(MyMAC)));

	net.connect();
	printf("MAC address %s\n",net.get_mac_address());
...

Asynchronous SPI limitation

The current Asynchronous SPI implementation will not be able to support high speeds (MHz Range). The maximum speed supported depends on

  • core operating frequency
  • depth of SPI FIFOs (if available).

For application that require optimized maximum performance, the recommendation is to implement the DMA-based SPI transfer. The SPI DMA transfer support shall be implemented on a case-by-case based on below example https://github.com/ABOSTM/mbed-os/tree/I2C_SPI_DMA_IMPLEMENTATION_FOR_STM32L4

CAN receive interrupt problem due to mutex and resolution

In bxCAN and earlier versions the receive interrupt flags can be cleared only on performing a read operation in ST MCUs But can_read() cannot be used in interrupt context as it is gaurded by lock operation and mbed does not allow locks in interrupt context. Hence the Rx interrupt is disabled for a while and read is deferred to thread context, the interrupt is enabled on a successful read.

As an other option RawCAN (with unlocked CAN apis) is also available and can be used directly, if only one thread is accessing the CAN interface.

While using RxInterrupt with the CAN object the receive ISR callback registered should defer read to thread context. A simple example is as shown below:

#include "mbed.h"

Ticker ticker;
Thread canReadThread;

DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);

CAN can1(PD_0 ,PD_1);

EventQueue queue(32 * EVENTS_EVENT_SIZE);

int counter = 0xABCD;
CANMessage msg;

void canRead(){
        if(can1.read(msg)) {
            if(msg.id==1100)
                led2 = !led2;
            if(msg.id==1102){
                led3 = !led3;
            }
        }
}

void canISR(){
    queue.call(canRead);
    led3 = !led3;
}

int main() {

    can1.frequency(100000);
    can1.mode(CAN::Normal);

    can1.attach(canISR, CAN::RxIrq);

    canReadThread.start(callback(&queue, &EventQueue::dispatch_forever));

    while(1) {
    }
}

Mbed OS Wiki pages

https://os.mbed.com/teams/ST/wiki/

https://os.mbed.com/teams/ST/wiki/STDIO

https://os.mbed.com/teams/ST/wiki/How-to-enable-flash-dual-bank

https://os.mbed.com/teams/ST/wiki/Nucleo-144pins-ethernet-spi-conflict