Skip to content

Commit d74bfc1

Browse files
Merge pull request #3 from JohnK1987/master
Update the custom target example
2 parents 837d1b6 + 3136df5 commit d74bfc1

10 files changed

+149
-12
lines changed

CMakeLists.txt

+63-8
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,76 @@
11
cmake_minimum_required(VERSION 3.19)
22
cmake_policy(VERSION 3.19)
33

4-
# Initialize Mbed OS build system.
5-
# Note: This block must be before the include of app.cmake
6-
set(MBED_APP_JSON_PATH mbed_app.json)
7-
set(CUSTOM_TARGETS_JSON_PATH custom_targets.json) # This activates the custom targets in custom_targets.json
4+
#### Initialize Mbed OS build system. ####
5+
######################################################################################################
6+
### Block of including .json5 files. Files of this block must be included before the app.cmake
87

8+
#[[ Set path of mbed_app.json (necessary everytime if mbed_app.json5 is in project) ]]
9+
set(MBED_APP_JSON_PATH mbed_app.json5)
10+
11+
###---------------------------------------------------------------------------------------------------
12+
#[[ This part is dedicated for custom targets only! Settings below activate targets from
13+
custom_targets.json5 and upload method config, otherwise functions below should be commented. ]]
14+
15+
#[[ Here set path for custom_targets.json5 (this is our default) ]]
16+
set(CUSTOM_TARGETS_JSON_PATH custom_targets/custom_targets.json5)
17+
18+
#[[ Here you can set path for custom upload config .cmake (optional example) ]]
19+
# set(CUSTOM_UPLOAD_CFG_PATH ${CMAKE_SOURCE_DIR}/${MBED_TARGET}/${MBED_TARGET}.cmake)
20+
21+
#[[ Note: For custom target you need also an upload method and we have few options how you can do that
22+
- use the variable CUSTOM_UPLOAD_CFG_PATH above
23+
- use default expected path for custom targets upload methods where you create your own config
24+
MY_PROJECT/custom_targets/upload_method_cfg
25+
- of course you can do it by yourself directly via cmake in this file
26+
For more visit https://github.com/mbed-ce/mbed-os/wiki/Upload-Methods ]]
27+
28+
### End of block
29+
######################################################################################################
30+
31+
### include app.cmake (necessary everytime) ###
932
include(mbed-os/tools/cmake/app.cmake)
1033

11-
# Include folder with the custom targets.
12-
# This needs to be done before add_subdirectory(mbed-os).
34+
######################################################################################################
35+
### Block of including project folders
36+
37+
#[[ If using a custom target, the subdirectory containing the custom target must be included before
38+
the mbed-os subdir, otherwise the next line should be commented]]
1339
add_subdirectory(custom_targets)
1440

41+
###--------------------------------------------------------------------------------------------------
42+
## Add mbed-os subdirectory (necessary everytime)
1543
add_subdirectory(mbed-os)
1644

45+
###--------------------------------------------------------------------------------------------------
46+
## Add another subdirectory, for example subdirectory of a library (if needed)
47+
#add_subdirectory(YourLibrary)
48+
49+
### End of block
50+
######################################################################################################
51+
52+
### Set up your project name (necessary everytime)
1753
project(mbed-ce-custom-targets)
1854

19-
# add subdirectories and build targets here
2055

21-
mbed_finalize_build()
56+
### add executable (necessary everytime)
57+
add_executable(main main.cpp)
58+
59+
### Set post build (necessary everytime)
60+
mbed_set_post_build(main)
61+
62+
######################################################################################################
63+
### Link libraries block
64+
#[[For more about this configuraion visit wiki page MbedOS-configuration ]]
65+
66+
#[[link MbedOS and its libraries (necessary everytime)]]
67+
target_link_libraries(main mbed-os)
68+
69+
### link user library (if needed)
70+
#target_link_libraries(main YourLibrary)
71+
72+
### End of block
73+
######################################################################################################
74+
75+
### Build finalize does necessary configuration for debug in most cases (necessary everytime)
76+
mbed_finalize_build()

README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Mbed CE Custom Targets Example
22

3-
This project shows how to use Mbed OS Community Edition to create custom targets.
3+
This project shows how to use Mbed OS Community Edition to create custom targets and also defines the standard structure of custom target project from Mbed CE perspective.
44

55
This repo includes three different custom targets you can use based on the `NUCLEO_L452RE_P` target. (No real reason it's this target in particular, it's just a board I happen to use).
66

@@ -10,9 +10,11 @@ This repo includes three different custom targets you can use based on the `NUCL
1010

1111
## How to set up this project:
1212

13-
1. Clone it to your machine. Don't forget to use `--recursive` to clone the submodules: `git clone --recursive https://github.com/mbed-ce/mbed-ce-custom-targets.git`
13+
1. Clone it to your machine. Don't forget to use `--recursive` to clone the submodules: `git clone --recursive https://github.com/mbed-ce/mbed-ce-custom-targets.git`and update MbedOS with `git submodule update --remote mbed-os` (run this command from the mbed-ce-custom-targets folder)
1414
2. Set up the GNU ARM toolchain (and other programs) on your machine using [the toolchain setup guide](https://github.com/mbed-ce/mbed-os/wiki/Toolchain-Setup-Guide).
15-
3. Set up the CMake project for editing. Use one of the target names listed above. We have three ways to do this:
15+
3. Set up the CMake project for editing. We have three ways to do this:
1616
- On the [command line](https://github.com/mbed-ce/mbed-os/wiki/Project-Setup:-Command-Line)
1717
- Using the [CLion IDE](https://github.com/mbed-ce/mbed-os/wiki/Project-Setup:-CLion)
1818
- Using the [VS Code IDE](https://github.com/mbed-ce/mbed-os/wiki/Project-Setup:-VS-Code)
19+
4. Use one of the target names listed above and choose an [upload method](https://github.com/mbed-ce/mbed-os/wiki/Upload-Methods) according to your requirements. Default settings is target L452RE_SIMPLE and upload method STM32CUBE.
20+

cmake-variants.yaml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
buildType:
2+
default: Develop
3+
choices:
4+
Develop:
5+
short: Develop
6+
long: Emit debug information but also optimize
7+
buildType: Develop
8+
Debug:
9+
short: Debug
10+
long: Emit debug information and don't optimize
11+
buildType: Debug
12+
Release:
13+
short: Release
14+
long: Optimize generated code
15+
buildType: Release
16+
board:
17+
# Fill name of your targer which has to corespond to
18+
# target name in custom_targets.json5 file
19+
default: L452RE_SIMPLE
20+
choices:
21+
YOUR_MBED_TARGET:
22+
short: L452RE_SIMPLE
23+
settings:
24+
MBED_TARGET: L452RE_SIMPLE
25+
# Fill your upload method according to variants below
26+
# - universal: NONE, MBED, JLINK, PYOCD, OPENOCD
27+
# - target specific: STLINK, STM32CUBE, LINKSERVER, PICOTOOL, ARDUINO_BOSSAC
28+
# For more visit - https://github.com/mbed-ce/mbed-os/wiki/Upload-Methods#upload-method-list
29+
UPLOAD_METHOD: STM32CUBE
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## Example of custom uploud method for L452RE_CUSTOM_CLOCK
2+
3+
4+
# General config parameters
5+
# -------------------------------------------------------------
6+
set(UPLOAD_METHOD_DEFAULT OPENOCD)
7+
8+
# Config options for OPENOCD
9+
# -------------------------------------------------------------
10+
# We set TRUE to enable OpenOCD
11+
set(OPENOCD_UPLOAD_ENABLED TRUE)
12+
# Here set a path to requested OpenOCD config. In this case we use already implemented one.
13+
set(OPENOCD_CHIP_CONFIG_COMMANDS
14+
-f ${CMAKE_SOURCE_DIR}/mbed-os/targets/upload_method_cfg/openocd_cfgs/s/stm32l452re.cfg)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## Example of custom uploud method for L452RE_CUSTOM_PINMAP
2+
3+
4+
# General config parameters
5+
# -------------------------------------------------------------
6+
set(UPLOAD_METHOD_DEFAULT STM32CUBE)
7+
8+
# Config options for STM32Cube
9+
# -------------------------------------------------------------
10+
11+
set(STM32CUBE_UPLOAD_ENABLED TRUE)
12+
set(STM32CUBE_CONNECT_COMMAND -c port=SWD reset=HWrst)
13+
set(STM32CUBE_GDBSERVER_ARGS --swd)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## Example of custom uploud method for L452RE_SIMPLE
2+
3+
4+
# General config parameters
5+
# -------------------------------------------------------------
6+
set(UPLOAD_METHOD_DEFAULT STM32CUBE)
7+
8+
# Config options for STM32Cube
9+
# -------------------------------------------------------------
10+
11+
set(STM32CUBE_UPLOAD_ENABLED TRUE)
12+
set(STM32CUBE_CONNECT_COMMAND -c port=SWD reset=HWrst)
13+
set(STM32CUBE_GDBSERVER_ARGS --swd)

main.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "mbed.h"
2+
3+
DigitalOut led(LED1); // fill your pin
4+
5+
int main(){
6+
printf("mbed-ce-custom-targets\n");
7+
while(1){
8+
led = !led;
9+
thread_sleep_for(500);
10+
}
11+
}

mbed-os

Submodule mbed-os updated 3433 files

mbed_app.json mbed_app.json5

File renamed without changes.

0 commit comments

Comments
 (0)