diff --git a/CMakeLists.txt b/CMakeLists.txt index 78dddff..da66435 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() \ No newline at end of file +### 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() diff --git a/README.md b/README.md index 99b9dca..04dead7 100644 --- a/README.md +++ b/README.md @@ -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). @@ -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. + diff --git a/cmake-variants.yaml b/cmake-variants.yaml new file mode 100644 index 0000000..4c9dc39 --- /dev/null +++ b/cmake-variants.yaml @@ -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 diff --git a/custom_targets.json b/custom_targets/custom_targets.json5 similarity index 100% rename from custom_targets.json rename to custom_targets/custom_targets.json5 diff --git a/custom_targets/upload_method_cfg/L452RE_CUSTOM_CLOCK.cmake b/custom_targets/upload_method_cfg/L452RE_CUSTOM_CLOCK.cmake new file mode 100644 index 0000000..821e4ec --- /dev/null +++ b/custom_targets/upload_method_cfg/L452RE_CUSTOM_CLOCK.cmake @@ -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) diff --git a/custom_targets/upload_method_cfg/L452RE_CUSTOM_PINMAP.cmake b/custom_targets/upload_method_cfg/L452RE_CUSTOM_PINMAP.cmake new file mode 100644 index 0000000..c05f101 --- /dev/null +++ b/custom_targets/upload_method_cfg/L452RE_CUSTOM_PINMAP.cmake @@ -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) \ No newline at end of file diff --git a/custom_targets/upload_method_cfg/L452RE_SIMPLE.cmake b/custom_targets/upload_method_cfg/L452RE_SIMPLE.cmake new file mode 100644 index 0000000..7ad6fb2 --- /dev/null +++ b/custom_targets/upload_method_cfg/L452RE_SIMPLE.cmake @@ -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) \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..1545687 --- /dev/null +++ b/main.cpp @@ -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); + } +} \ No newline at end of file diff --git a/mbed-os b/mbed-os index eda766e..e6a63d9 160000 --- a/mbed-os +++ b/mbed-os @@ -1 +1 @@ -Subproject commit eda766ec8f224ab93cfdb5fc96e0fead1931fedf +Subproject commit e6a63d96234ddae3916e3e8811144d070f9473f9 diff --git a/mbed_app.json b/mbed_app.json5 similarity index 100% rename from mbed_app.json rename to mbed_app.json5