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

IAR CMake native support #2376

Merged
merged 4 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
23 changes: 19 additions & 4 deletions docs/reference/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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::

Expand All @@ -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.
2 changes: 1 addition & 1 deletion examples/build_system/cmake/cpu/cortex-m4.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions examples/build_system/cmake/toolchain/arm_iar.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
20 changes: 13 additions & 7 deletions hw/bsp/family_support.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -191,10 +191,12 @@ function(family_configure_common TARGET RTOS)
)

# run size after build
add_custom_command(TARGET ${TARGET} POST_BUILD
COMMAND ${CMAKE_SIZE} $<TARGET_FILE:${TARGET}>
)

find_program(SIZE_EXE ${CMAKE_SIZE})
if(NOT ${SIZE_EXE} STREQUAL SIZE_EXE-NOTFOUND)
add_custom_command(TARGET ${TARGET} POST_BUILD
COMMAND ${SIZE_EXE} $<TARGET_FILE:${TARGET}>
)
endif ()
# Add warnings flags
target_compile_options(${TARGET} PUBLIC ${WARNING_FLAGS_${CMAKE_C_COMPILER_ID}})

Expand All @@ -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=$<TARGET_FILE:${TARGET}>.map")
endif()


# ETM Trace option
if (TRACE_ETM STREQUAL "1")
Expand Down Expand Up @@ -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}_$<CONFIG>.jlink
CONTENT "halt
loadfile $<TARGET_FILE:${TARGET}>
r
Expand All @@ -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}/$<CONFIG>/${TARGET}.jlink
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to change as well, though please try the new $<TARGET_FILE_DIR:${TARGET}>

)
endfunction()

Expand Down