Skip to content

Commit 9474db8

Browse files
authored
Merge pull request #2376 from HiFiPhile/iar_cmake
IAR CMake native support
2 parents 5a0c21a + 6fda6e1 commit 9474db8

File tree

4 files changed

+34
-12
lines changed

4 files changed

+34
-12
lines changed

docs/reference/getting_started.rst

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,10 @@ Some board use uf2 bootloader for drag & drop in to mass storage device, uf2 can
178178
$ make BOARD=feather_nrf52840_express all uf2
179179
180180
IAR Support
181-
^^^^^^^^^^^
181+
-----------
182+
183+
Use project connection
184+
^^^^^^^^^^^^^^^^^^^^^^
182185

183186
IAR Project Connection files are provided to import TinyUSB stack into your project.
184187

@@ -191,19 +194,19 @@ IAR Project Connection files are provided to import TinyUSB stack into your proj
191194

192195
- `STM32L0xx_HAL_Driver` is only needed to run examples, TinyUSB stack itself doesn't rely on MCU's SDKs.
193196

194-
* Open `Tools -> Configure Custom Argument Variables` (Switch to `Global` tab if you want to do it for all your projects)
197+
* Open ``Tools -> Configure Custom Argument Variables`` (Switch to `Global` tab if you want to do it for all your projects)
195198
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,
196199
for example `C:\\tinyusb`
197200

198201
Import stack only
199202
~~~~~~~~~~~~~~~~~
200203

201-
1. Open `Project -> Add project Connection ...`, click `OK`, choose `tinyusb\\tools\\iar_template.ipcf`.
204+
1. Open ``Project -> Add project Connection ...``, click `OK`, choose `tinyusb\\tools\\iar_template.ipcf`.
202205

203206
Run examples
204207
~~~~~~~~~~~~
205208

206-
1. (Python3 is needed) Run `iar_gen.py` to generate .ipcf files of examples:
209+
1. (Python3 is needed) Run ``iar_gen.py`` to generate .ipcf files of examples:
207210

208211
.. code-block::
209212
@@ -212,3 +215,15 @@ Run examples
212215
213216
2. Open `Project -> Add project Connection ...`, click `OK`, choose `tinyusb\\examples\\(.ipcf of example)`.
214217
For example `C:\\tinyusb\\examples\\device\\cdc_msc\\iar_cdc_msc.ipcf`
218+
219+
Native CMake support (9.50.1+)
220+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
221+
222+
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.
223+
224+
Following these steps:
225+
226+
1. Add IAR compiler binary path to system ``PATH`` environment variable, such as ``C:\Program Files\IAR Systems\Embedded Workbench 9.2\arm\bin``.
227+
2. Create new project in IAR, in Tool chain dropdown menu, choose CMake for Arm then Import ``CMakeLists.txt`` from chosen example directory.
228+
3. Set up board option in ``Option - CMake/CMSIS-TOOLBOX - CMake``, for example :code:`-DBOARD=stm32f439nucleo -DTOOLCHAIN=iar`, **Uncheck 'Override tools in env'**.
229+
4. (For debug only) Choose correct CPU model in ``Option - General Options - Target``, to profit register and memory view.

examples/build_system/cmake/cpu/cortex-m4.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ if (TOOLCHAIN STREQUAL "gcc")
1313
elseif (TOOLCHAIN STREQUAL "iar")
1414
set(TOOLCHAIN_COMMON_FLAGS
1515
--cpu cortex-m4
16-
--fpu VFPv4
16+
--fpu VFPv4_sp
1717
)
1818

1919
if (NOT DEFINED FREERTOS_PORT)

examples/build_system/cmake/toolchain/arm_iar.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ list(APPEND TOOLCHAIN_COMMON_FLAGS
2626
)
2727

2828
list(APPEND TOOLCHAIN_EXE_LINKER_FLAGS
29+
--diag_suppress=Li065
2930
)
3031

3132
include(${CMAKE_CURRENT_LIST_DIR}/set_flags.cmake)

hw/bsp/family_support.cmake

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ set(WARNING_FLAGS_GNU
7272
-Wredundant-decls
7373
)
7474

75-
set(WARNINGS_FLAGS_IAR "")
75+
set(WARNING_FLAGS_IAR "")
7676

7777

7878
# Filter example based on only.txt and skip.txt
@@ -191,10 +191,12 @@ function(family_configure_common TARGET RTOS)
191191
)
192192

193193
# run size after build
194-
add_custom_command(TARGET ${TARGET} POST_BUILD
195-
COMMAND ${CMAKE_SIZE} $<TARGET_FILE:${TARGET}>
196-
)
197-
194+
find_program(SIZE_EXE ${CMAKE_SIZE})
195+
if(NOT ${SIZE_EXE} STREQUAL SIZE_EXE-NOTFOUND)
196+
add_custom_command(TARGET ${TARGET} POST_BUILD
197+
COMMAND ${SIZE_EXE} $<TARGET_FILE:${TARGET}>
198+
)
199+
endif ()
198200
# Add warnings flags
199201
target_compile_options(${TARGET} PUBLIC ${WARNING_FLAGS_${CMAKE_C_COMPILER_ID}})
200202

@@ -205,6 +207,10 @@ function(family_configure_common TARGET RTOS)
205207
target_link_options(${TARGET} PUBLIC "LINKER:--no-warn-rwx-segments")
206208
endif ()
207209
endif()
210+
if (CMAKE_C_COMPILER_ID STREQUAL "IAR")
211+
target_link_options(${TARGET} PUBLIC "LINKER:--map=$<TARGET_FILE:${TARGET}>.map")
212+
endif()
213+
208214

209215
# ETM Trace option
210216
if (TRACE_ETM STREQUAL "1")
@@ -367,7 +373,7 @@ function(family_flash_jlink TARGET)
367373
endif ()
368374

369375
file(GENERATE
370-
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.jlink
376+
OUTPUT $<TARGET_FILE_DIR:${TARGET}>/${TARGET}.jlink
371377
CONTENT "halt
372378
loadfile $<TARGET_FILE:${TARGET}>
373379
r
@@ -377,7 +383,7 @@ exit"
377383

378384
add_custom_target(${TARGET}-jlink
379385
DEPENDS ${TARGET}
380-
COMMAND ${JLINKEXE} -device ${JLINK_DEVICE} -if swd -JTAGConf -1,-1 -speed auto -CommandFile ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.jlink
386+
COMMAND ${JLINKEXE} -device ${JLINK_DEVICE} -if swd -JTAGConf -1,-1 -speed auto -CommandFile $<TARGET_FILE_DIR:${TARGET}>/${TARGET}.jlink
381387
)
382388
endfunction()
383389

0 commit comments

Comments
 (0)