5 years, 10 months ago.

STM32 pin configuration relationship to Mbed OS

I am confused as to how far the Mbed OS reaches. Wherever I am wrong in this description, use terms incorrectly, or don't make any contextual sense, please correct me....

When using STM32CubeMX, this software generates C code that configures the functionality of the pins on a specific MCU. It doesn't matter which MCU it is, but in my case I am using the STM32L475VG. The development board I have been working with is the DISCO_L475VG_IOT01A, but we are making custom board with the STM32L475VG and would like to use Mbed OS. Therefore I would like to create a new target for this new board within Mbed OS. I want to know where specifically the code from the CubeMX software goes inside the Mbed OS target in order to configure the MCU pins. I have searched through the target files in folders for different boards within the same MCU part number folder, but have seen no code that configures the hardware pin functionality. The code that is generated by CubeMX looks very similar to code that is in some higher-level target "device" folders, which aren't redefined at the board level, which leads me to believe that the code in the device folder doesn't perform any hardware configuration. Do I have to use a different tool to perform hardware configuration, and then follow the steps outlined in https://os.mbed.com/teams/ST/wiki/steps-to-create-a-new-STM32-platform, or is all the hardware configured within the Mbed OS code?

1 Answer

5 years, 10 months ago.

Hi Jack,

Glad to help with this. First, here is a link to an online article which explains the process for adding a custom Mbed-OS target: https://os.mbed.com/docs/mbed-os/v5.10/tools/adding-and-configuring-targets.html . You will see in the documentation that it will be possible for you to create a custom target that will be able to "inherit" settings from the DISCO_L475VG_IOT01A for the STM32L475VG. If you would like to see these settings, you can open the "mbed-os\targets\targets.json" file and search for "DISCO_L475VG_IOT01A".

Please note that if you are working with the Mbed CLI to compile your code, any changes that you make (in "custom_targets.json", etc) to enable a custom target will be picked up automatically when you compile.

However, if you are using a separate IDE (like uVision 5, IAR, Eclipse, etc) you will need to "mbed export" the custom target settings from the command line in order for your code to compile properly in your IDE. Any time that the custom target settings change, you will need to re-export the project in order for your IDE to pick up the changes you make.

Best regards,

Tres, Team Mbed

The custom_targets.json and targets.json files do not configure pins, and I do not want to inherit the pin configuration from the DISCO_L475VG_IOT01A board. How do I perform this configuration within Mbed?

posted by Jack Rademacher 04 Feb 2019

Please take a look at "PinNames.h". This is where the pin configuration is specified/mapped. For the DISCO_L475VG_IOT01A board you will find this file here: "mbed-os\targets\TARGET_STM\TARGET_STM32L4\TARGET_STM32L475xG\TARGET_DISCO_L475VG_IOT01A\PinNames.h"

posted by Tres Hill 04 Feb 2019

Ok, so to clarify, when creating a new target board with an already supported MCU, and when working with mbed-os, is the STM32CubeMX software even needed? From this PinNames.h file it looks like mbed-os does the configuration under the hood. Is this correct?

posted by Jack Rademacher 05 Feb 2019

I haven't used the STM32CubeMX software, but I don't think you need it. Yes. You can map the pins for the Mbed-OS using PinNames.h.

posted by Tres Hill 05 Feb 2019