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

IAR CMake native support #2376

merged 4 commits into from
Dec 14, 2023

Conversation

HiFiPhile
Copy link
Collaborator

Describe the PR

  • Resolve jlink script error
  • Make size.exe optional
  • Generate linker map
  • Fix typos
  • Update doc

@@ -367,7 +373,7 @@ function(family_flash_jlink TARGET)
endif ()

file(GENERATE
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}.jlink
OUTPUT ${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.

does IAR has 1 config per folder within the build dir. Normally clion has 1 build dir per config. If possible, change it to {TARGET}_$<CONFIG>.jlink would be better.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes each binary has it's own folder.

$ ls
audio_4_channel_mic_Debug.jlink           build.ninja          build-RelWithDebInfo.ninja  CMakeFiles/  RelWithDebInfo/
audio_4_channel_mic_Release.jlink         build-Debug.ninja    cmake_install.cmake         Debug/       tinyusb/
audio_4_channel_mic_RelWithDebInfo.jlink  build-Release.ninja  CMakeCache.txt              Release/

Copy link
Owner

@hathach hathach Dec 14, 2023

Choose a reason for hiding this comment

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

I see, for clion, I typically use one build dir per config.

$ ls
audio_test.elf  audio_test.elf.map  audio_test.jlink  CMakeFiles  cmake_install.cmake  tinyusb

I think maybe we can use $<TARGET_FILE_DIR:${TARGET}> instead of of ${CMAKE_CURRENT_BINARY_DIR} for the flash target as below, please try to see if that work for you. It should expand to parent folder of the exe file (within each config for IAR)

function(family_flash_jlink TARGET)
  if (NOT DEFINED JLINKEXE)
    set(JLINKEXE JLinkExe)
  endif ()

  file(GENERATE
    OUTPUT $<TARGET_FILE_DIR:${TARGET}>/${TARGET}.jlink
    CONTENT "halt
loadfile $<TARGET_FILE:${TARGET}>
r
go
exit"
    )

  add_custom_target(${TARGET}-jlink
    DEPENDS ${TARGET}
    COMMAND ${JLINKEXE} -device ${JLINK_DEVICE} -if swd -JTAGConf -1,-1 -speed auto -CommandFile $<TARGET_FILE_DIR:${TARGET}>/${TARGET}.jlink
    )
endfunction()

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It gives something like this:

.
├── build.ninja
├── build-Debug.ninja
├── build-Release.ninja
├── build-RelWithDebInfo.ninja
├── cmake_install.cmake
├── CMakeCache.txt
├── CMakeFiles
│   └──...
├── Debug
│   ├── audio_4_channel_mic.elf
│   ├── audio_4_channel_mic.elf.map
│   ├── audio_4_channel_mic.jlink
│   └── libboard_stm32f439nucleo.a
├── Release
│   ├── audio_4_channel_mic.elf
│   ├── audio_4_channel_mic.elf.map
│   ├── audio_4_channel_mic.jlink
│   └── libboard_stm32f439nucleo.a
├── RelWithDebInfo
│   ├── audio_4_channel_mic.elf
│   ├── audio_4_channel_mic.elf.map
│   ├── audio_4_channel_mic.jlink
│   └── libboard_stm32f439nucleo.a
└── tinyusb
    ├── cmake_install.cmake
    ├── CMakeFiles
    │   └──...
    ├── Debug
    │   └── libaudio_4_channel_mic-tinyusb.a
    ├── Release
    │   └── libaudio_4_channel_mic-tinyusb.a
    └── RelWithDebInfo
        └── libaudio_4_channel_mic-tinyusb.a

Copy link
Owner

@hathach hathach Dec 14, 2023

Choose a reason for hiding this comment

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

perfect, it is what we want the .jlink file in the same folder of the elf for both IAR Workbecnh and clion. Not sure if IAR can execute the -jlink target, if it does, it should be able to flash your board with correct elf.

Please push the update, it is all good now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

Currently CMake support is pretty primitive, it defaults to Ninja multi config generator and there is no option for pre/post build actions. And I had multiple crashes modifying CMake file.

I'm going to give them some feedbacks.

@@ -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}>

Copy link
Owner

@hathach hathach left a comment

Choose a reason for hiding this comment

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

perfect, thank you

@hathach hathach merged commit 9474db8 into hathach:master Dec 14, 2023
47 checks passed
@HiFiPhile HiFiPhile deleted the iar_cmake branch April 26, 2024 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants