Set up mbed project environment (for mbed-cli and SW4STM32)

( 日本語版はこちら )

This section summarizes how to set up an environment of mbed project with any version of the mbed-os library (can be developed with both mbed-cli and SW4STM32).

The following sections describe how to set up mbed project on macOS, but the same method can be used on Windows.

1. mbed-cli environment setup

Create an appropriate working directory and work in that directory.

mkdir sample
cd sample

Start git with git init and create sample programs of main.cpp in the working directory.

git init

mbed project configuration

mbed new creates .mbed file. You can create only .mbed file with --create-only.

mbed new . --create-only

Specify target and toolchain. In this case, NUCLEO_L476RG and GCC_ARM are specified here.

mbed target NUCLEO_L476RG
mbed toolchain GCC_ARM

Import an arbitrary version of mbed-os with mbed add. Here, we import mbed-os 5.13.1 as an example.

mbed add     

Create mbed_app.json and profile.json as needed. If you want to create profile.json, add the line PROFILE=profile.json in the .mbed file.

At this time, the .mbed file is as follows.



Perform mbed compile and check that the compilation goes through.

mbed compile

2. SW4STM32 environment setup

Set up a project just before mbed compile as described above.

Make the project ready for edditing with SW4STM32 by mbed export -i sw4stm32.

mbed export -i sw4stm32

Configuration on SW4STM32

Open SW4STM32 and import the project for SW4STM32 that you created above. (In the above example, specify the sample directory as the import destination.)

If the sample directory is not in the Workspace of SW4STM32, then select File -> Import -> General -> Existing Projects into Workspace. (Check "Copy projects into workspace" in the option box).

Build the imported project and make sure that it is successful.

However, if you find the following error, you should modify asm volatile in line 190 of mbed-os/platform/mbed_toolchain.h to __asm volatile.

~/SW4workspace/sample/mbed-os/platform/mbed_toolchain.h:190:37: error: expected ';' before 'volatile'
 #define MBED_COMPILER_BARRIER() asm volatile("" : : : "memory")

Team Settings

If you do not see Commit or Push to Upstream etc. when you right click the imported project, select Team and do the following.

Right click on the imported project and select Team -> Share project. Select Git and click Next and click Finish.