Skip to content

Commit

Permalink
Merge pull request #3 from JohnK1987/master
Browse files Browse the repository at this point in the history
Update the custom target example
  • Loading branch information
multiplemonomials authored Mar 2, 2024
2 parents 837d1b6 + 3136df5 commit d74bfc1
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 12 deletions.
71 changes: 63 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,76 @@
cmake_minimum_required(VERSION 3.19)
cmake_policy(VERSION 3.19)

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

#[[ Set path of mbed_app.json (necessary everytime if mbed_app.json5 is in project) ]]
set(MBED_APP_JSON_PATH mbed_app.json5)

###---------------------------------------------------------------------------------------------------
#[[ This part is dedicated for custom targets only! Settings below activate targets from
custom_targets.json5 and upload method config, otherwise functions below should be commented. ]]

#[[ Here set path for custom_targets.json5 (this is our default) ]]
set(CUSTOM_TARGETS_JSON_PATH custom_targets/custom_targets.json5)

#[[ Here you can set path for custom upload config .cmake (optional example) ]]
# set(CUSTOM_UPLOAD_CFG_PATH ${CMAKE_SOURCE_DIR}/${MBED_TARGET}/${MBED_TARGET}.cmake)

#[[ Note: For custom target you need also an upload method and we have few options how you can do that
- use the variable CUSTOM_UPLOAD_CFG_PATH above
- use default expected path for custom targets upload methods where you create your own config
MY_PROJECT/custom_targets/upload_method_cfg
- of course you can do it by yourself directly via cmake in this file
For more visit https://github.com/mbed-ce/mbed-os/wiki/Upload-Methods ]]

### End of block
######################################################################################################

### include app.cmake (necessary everytime) ###
include(mbed-os/tools/cmake/app.cmake)

# Include folder with the custom targets.
# This needs to be done before add_subdirectory(mbed-os).
######################################################################################################
### Block of including project folders

#[[ If using a custom target, the subdirectory containing the custom target must be included before
the mbed-os subdir, otherwise the next line should be commented]]
add_subdirectory(custom_targets)

###--------------------------------------------------------------------------------------------------
## Add mbed-os subdirectory (necessary everytime)
add_subdirectory(mbed-os)

###--------------------------------------------------------------------------------------------------
## Add another subdirectory, for example subdirectory of a library (if needed)
#add_subdirectory(YourLibrary)

### End of block
######################################################################################################

### Set up your project name (necessary everytime)
project(mbed-ce-custom-targets)

# add subdirectories and build targets here

mbed_finalize_build()
### add executable (necessary everytime)
add_executable(main main.cpp)

### Set post build (necessary everytime)
mbed_set_post_build(main)

######################################################################################################
### Link libraries block
#[[For more about this configuraion visit wiki page MbedOS-configuration ]]

#[[link MbedOS and its libraries (necessary everytime)]]
target_link_libraries(main mbed-os)

### link user library (if needed)
#target_link_libraries(main YourLibrary)

### End of block
######################################################################################################

### Build finalize does necessary configuration for debug in most cases (necessary everytime)
mbed_finalize_build()
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Mbed CE Custom Targets Example

This project shows how to use Mbed OS Community Edition to create custom targets.
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.

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).

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

## How to set up this project:

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`
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)
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).
3. Set up the CMake project for editing. Use one of the target names listed above. We have three ways to do this:
3. Set up the CMake project for editing. We have three ways to do this:
- On the [command line](https://github.com/mbed-ce/mbed-os/wiki/Project-Setup:-Command-Line)
- Using the [CLion IDE](https://github.com/mbed-ce/mbed-os/wiki/Project-Setup:-CLion)
- Using the [VS Code IDE](https://github.com/mbed-ce/mbed-os/wiki/Project-Setup:-VS-Code)
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.

29 changes: 29 additions & 0 deletions cmake-variants.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
buildType:
default: Develop
choices:
Develop:
short: Develop
long: Emit debug information but also optimize
buildType: Develop
Debug:
short: Debug
long: Emit debug information and don't optimize
buildType: Debug
Release:
short: Release
long: Optimize generated code
buildType: Release
board:
# Fill name of your targer which has to corespond to
# target name in custom_targets.json5 file
default: L452RE_SIMPLE
choices:
YOUR_MBED_TARGET:
short: L452RE_SIMPLE
settings:
MBED_TARGET: L452RE_SIMPLE
# Fill your upload method according to variants below
# - universal: NONE, MBED, JLINK, PYOCD, OPENOCD
# - target specific: STLINK, STM32CUBE, LINKSERVER, PICOTOOL, ARDUINO_BOSSAC
# For more visit - https://github.com/mbed-ce/mbed-os/wiki/Upload-Methods#upload-method-list
UPLOAD_METHOD: STM32CUBE
File renamed without changes.
14 changes: 14 additions & 0 deletions custom_targets/upload_method_cfg/L452RE_CUSTOM_CLOCK.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## Example of custom uploud method for L452RE_CUSTOM_CLOCK


# General config parameters
# -------------------------------------------------------------
set(UPLOAD_METHOD_DEFAULT OPENOCD)

# Config options for OPENOCD
# -------------------------------------------------------------
# We set TRUE to enable OpenOCD
set(OPENOCD_UPLOAD_ENABLED TRUE)
# Here set a path to requested OpenOCD config. In this case we use already implemented one.
set(OPENOCD_CHIP_CONFIG_COMMANDS
-f ${CMAKE_SOURCE_DIR}/mbed-os/targets/upload_method_cfg/openocd_cfgs/s/stm32l452re.cfg)
13 changes: 13 additions & 0 deletions custom_targets/upload_method_cfg/L452RE_CUSTOM_PINMAP.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Example of custom uploud method for L452RE_CUSTOM_PINMAP


# General config parameters
# -------------------------------------------------------------
set(UPLOAD_METHOD_DEFAULT STM32CUBE)

# Config options for STM32Cube
# -------------------------------------------------------------

set(STM32CUBE_UPLOAD_ENABLED TRUE)
set(STM32CUBE_CONNECT_COMMAND -c port=SWD reset=HWrst)
set(STM32CUBE_GDBSERVER_ARGS --swd)
13 changes: 13 additions & 0 deletions custom_targets/upload_method_cfg/L452RE_SIMPLE.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Example of custom uploud method for L452RE_SIMPLE


# General config parameters
# -------------------------------------------------------------
set(UPLOAD_METHOD_DEFAULT STM32CUBE)

# Config options for STM32Cube
# -------------------------------------------------------------

set(STM32CUBE_UPLOAD_ENABLED TRUE)
set(STM32CUBE_CONNECT_COMMAND -c port=SWD reset=HWrst)
set(STM32CUBE_GDBSERVER_ARGS --swd)
11 changes: 11 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "mbed.h"

DigitalOut led(LED1); // fill your pin

int main(){
printf("mbed-ce-custom-targets\n");
while(1){
led = !led;
thread_sleep_for(500);
}
}
2 changes: 1 addition & 1 deletion mbed-os
Submodule mbed-os updated 3433 files
File renamed without changes.

0 comments on commit d74bfc1

Please sign in to comment.