From 3eb7d6ede962521091e9869e2c54ed7fd2c86bb7 Mon Sep 17 00:00:00 2001 From: Mengsk Date: Wed, 13 Dec 2023 17:19:13 +0100 Subject: [PATCH 1/4] Enhance IAR CMake support. --- .../build_system/cmake/cpu/cortex-m4.cmake | 2 +- .../cmake/toolchain/arm_iar.cmake | 1 + hw/bsp/family_support.cmake | 20 ++++++++++++------- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/examples/build_system/cmake/cpu/cortex-m4.cmake b/examples/build_system/cmake/cpu/cortex-m4.cmake index 4e9bc242d7..db308aa83b 100644 --- a/examples/build_system/cmake/cpu/cortex-m4.cmake +++ b/examples/build_system/cmake/cpu/cortex-m4.cmake @@ -13,7 +13,7 @@ if (TOOLCHAIN STREQUAL "gcc") elseif (TOOLCHAIN STREQUAL "iar") set(TOOLCHAIN_COMMON_FLAGS --cpu cortex-m4 - --fpu VFPv4 + --fpu VFPv4_sp ) if (NOT DEFINED FREERTOS_PORT) diff --git a/examples/build_system/cmake/toolchain/arm_iar.cmake b/examples/build_system/cmake/toolchain/arm_iar.cmake index a487e5b9fe..1482624e55 100644 --- a/examples/build_system/cmake/toolchain/arm_iar.cmake +++ b/examples/build_system/cmake/toolchain/arm_iar.cmake @@ -26,6 +26,7 @@ list(APPEND TOOLCHAIN_COMMON_FLAGS ) list(APPEND TOOLCHAIN_EXE_LINKER_FLAGS + --diag_suppress=Li065 ) include(${CMAKE_CURRENT_LIST_DIR}/set_flags.cmake) diff --git a/hw/bsp/family_support.cmake b/hw/bsp/family_support.cmake index bd072e89d4..d6099eaa4a 100644 --- a/hw/bsp/family_support.cmake +++ b/hw/bsp/family_support.cmake @@ -72,7 +72,7 @@ set(WARNING_FLAGS_GNU -Wredundant-decls ) -set(WARNINGS_FLAGS_IAR "") +set(WARNING_FLAGS_IAR "") # Filter example based on only.txt and skip.txt @@ -191,10 +191,12 @@ function(family_configure_common TARGET RTOS) ) # run size after build - add_custom_command(TARGET ${TARGET} POST_BUILD - COMMAND ${CMAKE_SIZE} $ - ) - + find_program(SIZE_EXE ${CMAKE_SIZE}) + if(NOT ${SIZE_EXE} STREQUAL SIZE_EXE-NOTFOUND) + add_custom_command(TARGET ${TARGET} POST_BUILD + COMMAND ${SIZE_EXE} $ + ) + endif () # Add warnings flags target_compile_options(${TARGET} PUBLIC ${WARNING_FLAGS_${CMAKE_C_COMPILER_ID}}) @@ -205,6 +207,10 @@ function(family_configure_common TARGET RTOS) target_link_options(${TARGET} PUBLIC "LINKER:--no-warn-rwx-segments") endif () endif() + if (CMAKE_C_COMPILER_ID STREQUAL "IAR") + target_link_options(${TARGET} PUBLIC "LINKER:--map=$.map") + endif() + # ETM Trace option if (TRACE_ETM STREQUAL "1") @@ -367,7 +373,7 @@ function(family_flash_jlink TARGET) endif () file(GENERATE - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.jlink + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/$/${TARGET}.jlink CONTENT "halt loadfile $ r @@ -377,7 +383,7 @@ exit" add_custom_target(${TARGET}-jlink DEPENDS ${TARGET} - COMMAND ${JLINKEXE} -device ${JLINK_DEVICE} -if swd -JTAGConf -1,-1 -speed auto -CommandFile ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.jlink + COMMAND ${JLINKEXE} -device ${JLINK_DEVICE} -if swd -JTAGConf -1,-1 -speed auto -CommandFile ${CMAKE_CURRENT_BINARY_DIR}/$/${TARGET}.jlink ) endfunction() From 35615ecb6f9d884b11ac11751cdf50c3d618acbe Mon Sep 17 00:00:00 2001 From: Mengsk Date: Wed, 13 Dec 2023 17:41:54 +0100 Subject: [PATCH 2/4] Update doc. --- docs/reference/getting_started.rst | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/docs/reference/getting_started.rst b/docs/reference/getting_started.rst index f2a3e7e2a3..3db3fa2064 100644 --- a/docs/reference/getting_started.rst +++ b/docs/reference/getting_started.rst @@ -178,7 +178,10 @@ Some board use uf2 bootloader for drag & drop in to mass storage device, uf2 can $ make BOARD=feather_nrf52840_express all uf2 IAR Support -^^^^^^^^^^^ +----------- + +Use project connection +^^^^^^^^^^^^^^^^^^^^^^ IAR Project Connection files are provided to import TinyUSB stack into your project. @@ -191,19 +194,19 @@ IAR Project Connection files are provided to import TinyUSB stack into your proj - `STM32L0xx_HAL_Driver` is only needed to run examples, TinyUSB stack itself doesn't rely on MCU's SDKs. -* Open `Tools -> Configure Custom Argument Variables` (Switch to `Global` tab if you want to do it for all your projects) +* Open ``Tools -> Configure Custom Argument Variables`` (Switch to `Global` tab if you want to do it for all your projects) Click `New Group ...`, name it to `TUSB`, Click `Add Variable ...`, name it to `TUSB_DIR`, change it's value to the path of your TinyUSB stack, for example `C:\\tinyusb` Import stack only ~~~~~~~~~~~~~~~~~ -1. Open `Project -> Add project Connection ...`, click `OK`, choose `tinyusb\\tools\\iar_template.ipcf`. +1. Open ``Project -> Add project Connection ...``, click `OK`, choose `tinyusb\\tools\\iar_template.ipcf`. Run examples ~~~~~~~~~~~~ -1. (Python3 is needed) Run `iar_gen.py` to generate .ipcf files of examples: +1. (Python3 is needed) Run ``iar_gen.py`` to generate .ipcf files of examples: .. code-block:: @@ -212,3 +215,15 @@ Run examples 2. Open `Project -> Add project Connection ...`, click `OK`, choose `tinyusb\\examples\\(.ipcf of example)`. For example `C:\\tinyusb\\examples\\device\\cdc_msc\\iar_cdc_msc.ipcf` + +Native CMake support (9.50.1+) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +With 9.50.1 release, IAR added experimental native CMake support (strangely not mentioned in public release note). Now it's possible to import CMakeLists.txt then build and debug as a normal project. + +Following these steps: + +1. Add IAR compiler binary path to system ``PATH`` environment variable, such as ``C:\Program Files\IAR Systems\Embedded Workbench 9.2\arm\bin``. +2. Create new project in IAR, in Tool chain dropdown menu, choose CMake for Arm then Import ``CMakeLists.txt`` from chosen example directory. +3. Set up board option in ``Option - CMake/CMSIS-TOOLBOX - CMake``, for example :code:`-DBOARD=stm32f439nucleo -DTOOLCHAIN=iar`, **Uncheck 'Override tools in env'**. +4. (For debug only) Choose correct CPU model in ``Option - General Options - Target``, to profit register and memory view. From 2396fecee29d6a014647356d6609886cbabc5585 Mon Sep 17 00:00:00 2001 From: Mengsk Date: Thu, 14 Dec 2023 09:48:40 +0100 Subject: [PATCH 3/4] Move jlink script. --- hw/bsp/family_support.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/bsp/family_support.cmake b/hw/bsp/family_support.cmake index d6099eaa4a..50efab62b0 100644 --- a/hw/bsp/family_support.cmake +++ b/hw/bsp/family_support.cmake @@ -373,7 +373,7 @@ function(family_flash_jlink TARGET) endif () file(GENERATE - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/$/${TARGET}.jlink + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_$.jlink CONTENT "halt loadfile $ r From 6fda6e16f8a999a05d77c27f3bd4ee6aee7a6bb0 Mon Sep 17 00:00:00 2001 From: Mengsk Date: Thu, 14 Dec 2023 12:19:14 +0100 Subject: [PATCH 4/4] Update jlink script path. --- hw/bsp/family_support.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/bsp/family_support.cmake b/hw/bsp/family_support.cmake index 50efab62b0..539a776a64 100644 --- a/hw/bsp/family_support.cmake +++ b/hw/bsp/family_support.cmake @@ -373,7 +373,7 @@ function(family_flash_jlink TARGET) endif () file(GENERATE - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_$.jlink + OUTPUT $/${TARGET}.jlink CONTENT "halt loadfile $ r @@ -383,7 +383,7 @@ exit" add_custom_target(${TARGET}-jlink DEPENDS ${TARGET} - COMMAND ${JLINKEXE} -device ${JLINK_DEVICE} -if swd -JTAGConf -1,-1 -speed auto -CommandFile ${CMAKE_CURRENT_BINARY_DIR}/$/${TARGET}.jlink + COMMAND ${JLINKEXE} -device ${JLINK_DEVICE} -if swd -JTAGConf -1,-1 -speed auto -CommandFile $/${TARGET}.jlink ) endfunction()