Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the custom target example #3

Merged
merged 13 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ jobs:
- name: Build project for ${{ matrix.mbed_target }}
run: |
mkdir build && cd build
cmake .. -GNinja -DMBED_TARGET=${{ matrix.mbed_target }}
cmake .. -GNinja -DUPLOAD_METHOD=NONE -DMBED_TARGET=${{ matrix.mbed_target }}
ninja mbed-os # need to build mbed-os explicitly, or it will not be compiled because there are no executables that use it.
70 changes: 63 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,77 @@
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 intended to custom targets5 and activates the custom_targets.json5
multiplemonomials marked this conversation as resolved.
Show resolved Hide resolved
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 below
- 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 your self dierectly via cmake in this file

For regular targets we use mbed-os/tree/master/targets/upload_method_cfg ]]
multiplemonomials marked this conversation as resolved.
Show resolved Hide resolved

### 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

#[[ In case of custom targets must be the folder included before mbed-os subdirectory
multiplemonomials marked this conversation as resolved.
Show resolved Hide resolved
otherwise should be the next line 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

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

######################################################################################################
### 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
######################################################################################################

### Set post build (necessary everytime)
mbed_set_post_build(main)
multiplemonomials marked this conversation as resolved.
Show resolved Hide resolved

### 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` (call it in project folder)
multiplemonomials marked this conversation as resolved.
Show resolved Hide resolved
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 requirments. Default settings is target L452RE_SIMPLE and upload method STM32CUBE.
multiplemonomials marked this conversation as resolved.
Show resolved Hide resolved

27 changes: 27 additions & 0 deletions cmake-variants.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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
# variants are: NONE, MBED, STLINK, JLINK, PYOCD, OPENOCD, STM32CUBE
multiplemonomials marked this conversation as resolved.
Show resolved Hide resolved
UPLOAD_METHOD: STM32CUBE
File renamed without changes.
12 changes: 12 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,12 @@
## Example of custom uploud method for L452RE_CUSTOM_CLOCK


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

# Config options for OPENOCD
# -------------------------------------------------------------
set(OPENOCD_UPLOAD_ENABLED TRUE)
set(OPENOCD_CHIP_CONFIG_COMMANDS
-f ${CMAKE_CURRENT_LIST_DIR}/openocd_cfgs/stm32l452re.cfg)
multiplemonomials marked this conversation as resolved.
Show resolved Hide resolved
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.