Merge pull request #2376 from HiFiPhile/iar_cmake

IAR CMake native support
This commit is contained in:
Ha Thach 2023-12-14 18:48:19 +07:00 committed by GitHub
commit 9474db8b0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 12 deletions

View File

@ -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 $ make BOARD=feather_nrf52840_express all uf2
IAR Support IAR Support
^^^^^^^^^^^ -----------
Use project connection
^^^^^^^^^^^^^^^^^^^^^^
IAR Project Connection files are provided to import TinyUSB stack into your project. 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. - `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, 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` for example `C:\\tinyusb`
Import stack only 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 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:: .. code-block::
@ -212,3 +215,15 @@ Run examples
2. Open `Project -> Add project Connection ...`, click `OK`, choose `tinyusb\\examples\\(.ipcf of example)`. 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` 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.

View File

@ -13,7 +13,7 @@ if (TOOLCHAIN STREQUAL "gcc")
elseif (TOOLCHAIN STREQUAL "iar") elseif (TOOLCHAIN STREQUAL "iar")
set(TOOLCHAIN_COMMON_FLAGS set(TOOLCHAIN_COMMON_FLAGS
--cpu cortex-m4 --cpu cortex-m4
--fpu VFPv4 --fpu VFPv4_sp
) )
if (NOT DEFINED FREERTOS_PORT) if (NOT DEFINED FREERTOS_PORT)

View File

@ -26,6 +26,7 @@ list(APPEND TOOLCHAIN_COMMON_FLAGS
) )
list(APPEND TOOLCHAIN_EXE_LINKER_FLAGS list(APPEND TOOLCHAIN_EXE_LINKER_FLAGS
--diag_suppress=Li065
) )
include(${CMAKE_CURRENT_LIST_DIR}/set_flags.cmake) include(${CMAKE_CURRENT_LIST_DIR}/set_flags.cmake)

View File

@ -72,7 +72,7 @@ set(WARNING_FLAGS_GNU
-Wredundant-decls -Wredundant-decls
) )
set(WARNINGS_FLAGS_IAR "") set(WARNING_FLAGS_IAR "")
# Filter example based on only.txt and skip.txt # Filter example based on only.txt and skip.txt
@ -191,10 +191,12 @@ function(family_configure_common TARGET RTOS)
) )
# run size after build # run size after build
add_custom_command(TARGET ${TARGET} POST_BUILD find_program(SIZE_EXE ${CMAKE_SIZE})
COMMAND ${CMAKE_SIZE} $<TARGET_FILE:${TARGET}> 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 # Add warnings flags
target_compile_options(${TARGET} PUBLIC ${WARNING_FLAGS_${CMAKE_C_COMPILER_ID}}) 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") target_link_options(${TARGET} PUBLIC "LINKER:--no-warn-rwx-segments")
endif () endif ()
endif() endif()
if (CMAKE_C_COMPILER_ID STREQUAL "IAR")
target_link_options(${TARGET} PUBLIC "LINKER:--map=$<TARGET_FILE:${TARGET}>.map")
endif()
# ETM Trace option # ETM Trace option
if (TRACE_ETM STREQUAL "1") if (TRACE_ETM STREQUAL "1")
@ -367,7 +373,7 @@ function(family_flash_jlink TARGET)
endif () endif ()
file(GENERATE file(GENERATE
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.jlink OUTPUT $<TARGET_FILE_DIR:${TARGET}>/${TARGET}.jlink
CONTENT "halt CONTENT "halt
loadfile $<TARGET_FILE:${TARGET}> loadfile $<TARGET_FILE:${TARGET}>
r r
@ -377,7 +383,7 @@ exit"
add_custom_target(${TARGET}-jlink add_custom_target(${TARGET}-jlink
DEPENDS ${TARGET} 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_FILE_DIR:${TARGET}>/${TARGET}.jlink
) )
endfunction() endfunction()