Adding new STM32 target mcu

I have an STM32L4S7ZIT. The MCU is not found on a nucleo board. So I bought a Nucleo L4a6zg board and replaced the MCU with mine. I developed a simple code with the CubeIDE to try my modified nucleo board. The simple code works without any problem.

Now I want to develop a simple code for my modified nucleo using mbed-os. However, STM32L4S7ZIT is not among the supported MCUs in v6.16. I folowed below steps to add the MCU/custom board as a new target:

  1. Generated PinNames.h, PeripheralPins.c and CMakeLists.txt, folowing the instructions in the readme file in TARGET_STM folder. I generated these from the working *.ioc file
  2. Created TARGET_STM32L4S7xI folder. In this folder created NUCLEO_L4Custom and TOOLCHAIN_[ARM/GCC_ARM/IAR] folders. I downloaded the corresponding .S files from this repository. Copied the linker files form TARGET_STM32L4S5xI. I am compiling with GCC_ARM.
  3. Copied the generated files at the first step to my NUCLEO_L4Custom folder.
  4. From TARGET_STM32L4S5xI, copied CMakeLists.txt, cmsis_nvic.h and system_clock.c to my TARGET_STM32L4S7xI folder.
  5. Modified a bit the CMakeLists.txt in order to set the correct .S and .ld file paths.
  6. Added MCU_STM32L4S7xI and NUCLEO_L4Custom to targets.json. It simply it looks like this:
"MCU_STM32L4S7xI": {
        "inherits": [
        "public": false,
        "components_add": [
        "extra_labels_add": [
        "macros_add": [
    "NUCLEO_L4Custom": {
        "inherits": [
        "supported_form_factors": [
        "device_name": "STM32L4S7ZITx",
        "detect_code": [
        "device_has_add": [

The code compiles but it does not run. I also added DISCO_F407VG as another target. When I compile for that board it works without any problem. However, TARGET_STM32F407xG is already available in the official release. I just had to add the discovery board as a new target.

I believe copying the files from TARGET_STM32L4S5xI (step 4) is correct because S5, 7, 9 MCUs are explained in the same datasheet and their core hw architecture is the same. I also compared those files with L4R5 and noticed they are identical except the .S and .ld file paths in cmake_lists.txt. So, using the same linker, system_clock.c, cmsis_nvic.h should be okay. I did no modifications in arm_pack_manager json files. I found this but it is quite old and not valid for the latest os version. Where is my mistake? Do I miss any steps or do I do a mistake while adding the new mcu? There is not a comprehensive documentation about how to add a new STM32 target and the above steps are what I understand by reading all the documentations I found and going through the file structure.

Okay it seems this is the solution. I found it after resolving the problem by myself.


If you propose a pull request to add MCU_STM32L4S7xI support, I will be pleased to approve it :slight_smile:
See STM32 : add MCU_STM32L4P5xG and MCU_STM32L412xB support by jeromecoutant · Pull Request #15215 · ARMmbed/mbed-os · GitHub as an example


Hello. I compile my code only with GCC_ARM. I do not know whether I have to modify the startup instructions for the ARM and IAR toolchains as well. Probably the binary file will not work if someone use one of these two toolchains.

Moreover, I am trying to compile the code with cli2. I folowed the instructions but it does not work neither for the discovery nor for the modified nucleo board. I had to modify the CMakeLists.txt in my custom target folder at the beginning. It was missing. Then I modified the cmakelists.txt files exactly how it is explained in the guide. But still not working. I have the same issue with this thread. My targets are already created in the targets folder. So, I skipped the instructions related to the custom_targets.json. In the end I had to modify only the cmakelists.txt files. I did it but I could not get it work up to now.

I think you need to share your Github branch

Hello. This is my repo. Master is the untouched v6.16. GitHub - hckar/mbed-os-patch. Thank you

Maybe check Patch review · jeromecoutant/mbed@1b18b3a · GitHub

1 Like

Hello. Thank you for your support. I modifed it. Now it compiles both for my custom board and for disco_f407.