From e795d98c8702cca2919e9aa4734d5db26fe4c570 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Fri, 7 May 2021 19:46:18 +0100 Subject: [PATCH] Add support to generate DAPLink files - Add new function to bin utils that generates DAPLink file. - Add SRecord util to ChibiOS ST platform. - Update ST_NUCLEO64_F091RC and ST_STM32F769I_DISCOVERY CMakelists to generate file. - Update Azure yaml to generate file on build for these targets. --- CMake/Modules/FindBuildUtils.cmake | 24 +++++++++++++++++++ azure-pipelines.yml | 5 +++- targets/ChibiOS/CMakeLists.txt | 15 ++++++++++++ .../ChibiOS/ST_NUCLEO64_F091RC/CMakeLists.txt | 24 +++++++++++++++++++ .../ST_NUCLEO64_F091RC/cmake-variants.json | 1 + .../nanoCLR/STM32F091xC_CLR-DEBUG.ld | 5 ++++ .../nanoCLR/STM32F091xC_CLR.ld | 5 ++++ .../ST_STM32F769I_DISCOVERY/CMakeLists.txt | 24 +++++++++++++++++++ .../cmake-variants.json | 1 + .../nanoCLR/STM32F76xx_CLR-DEBUG.ld | 1 + .../nanoCLR/STM32F76xx_CLR.ld | 1 + 11 files changed, 105 insertions(+), 1 deletion(-) diff --git a/CMake/Modules/FindBuildUtils.cmake b/CMake/Modules/FindBuildUtils.cmake index 317596066b..8160899e12 100644 --- a/CMake/Modules/FindBuildUtils.cmake +++ b/CMake/Modules/FindBuildUtils.cmake @@ -48,6 +48,30 @@ function(NF_GENERATE_HEX_PACKAGE FILE1 FILE2 OUTPUTFILENAME) endfunction() +# generates a binary file with nanoBooter + nanoCLR at the proper addresses +# ready to be drag & drop on targets that feature DAPLink +function(NF_GENERATE_BIN_PACKAGE FILE1 FILE2 OFFSET OUTPUTFILENAME) + + add_custom_command( + + TARGET ${NANOCLR_PROJECT_NAME}.elf POST_BUILD + + COMMAND ${TOOL_SRECORD_PREFIX}/srec_cat + + ${FILE1} -Binary + ${FILE2} -Binary -offset 0x${OFFSET} + -o ${OUTPUTFILENAME} -Binary + + WORKING_DIRECTORY ${TOOL_SRECORD_PREFIX} + + COMMENT "exporting hex files to one binary file" + ) + + # need to add a dependency of NANOCLR to NANOBOOTER because SRECORD util needs hex outputs of both targets + add_dependencies(${NANOCLR_PROJECT_NAME}.elf ${NANOBOOTER_PROJECT_NAME}.elf) + +endfunction() + function(NF_GENERATE_BUILD_OUTPUT_FILES TARGET) # need to remove the .elf suffix from target name diff --git a/azure-pipelines.yml b/azure-pipelines.yml index a9463d75f4..c2facd2558 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -284,11 +284,13 @@ jobs: BuildOptions: -DTARGET_SERIES=STM32F0xx -DRTOS=CHIBIOS -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DUSE_RNG=OFF -DNF_PLATFORM_NO_CLR_TRACE=ON -DNF_CLR_NO_IL_INLINE=ON -DAPI_Hardware.Stm32=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_System.Device.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_System.Device.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_System.Device.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_nanoFramework.System.Text=ON GccArm_Version: NeedsDFU: false + NeedsSRECORD: true ST_STM32F769I_DISCOVERY: TargetBoard: ST_STM32F769I_DISCOVERY BuildOptions: -DTARGET_SERIES=STM32F7xx -DRTOS=CHIBIOS -DSUPPORT_ANY_BASE_CONVERSION=ON -DNF_FEATURE_DEBUGGER=ON -DNF_FEATURE_RTC=ON -DNF_FEATURE_HAS_SDCARD=ON -DAPI_System.Math=ON -DAPI_Hardware.Stm32=ON -DNF_FEATURE_HAS_CONFIG_BLOCK=ON -DAPI_Windows.Devices.Gpio=ON -DAPI_System.Device.Gpio=ON -DAPI_Windows.Devices.Spi=ON -DAPI_System.Device.Spi=ON -DAPI_Windows.Devices.I2c=ON -DAPI_System.Device.I2c=ON -DAPI_Windows.Devices.Pwm=ON -DAPI_Windows.Devices.SerialCommunication=ON -DAPI_Windows.Devices.Adc=ON -DAPI_System.Device.Dac=ON -DAPI_System.Net=ON -DNF_SECURITY_MBEDTLS=ON -DAPI_nanoFramework.Devices.OneWire=ON -DAPI_nanoFramework.Devices.Can=ON -DAPI_System.IO.FileSystem=ON -DAPI_nanoFramework.ResourceManager=ON -DAPI_nanoFramework.System.Collections=ON -DAPI_nanoFramework.System.Text=ON -DAPI_nanoFramework.Graphics=ON -DGRAPHICS_MEMORY=Graphics_Memory.cpp -DGRAPHICS_DISPLAY=Otm8009a_DSI_Video_Mode.cpp -DGRAPHICS_DISPLAY_INTERFACE=DSI_To_Display_Video_Mode.cpp -DTOUCHPANEL_DEVICE=ft6x06_I2C.cpp -DTOUCHPANEL_INTERFACE=I2C_To_TouchPanel.cpp GccArm_Version: - NeedsDFU: false + NeedsDFU: false + NeedsSRECORD: true variables: # creates a counter and assigns it to the revision variable @@ -301,6 +303,7 @@ jobs: - template: azure-pipelines-templates/nb-gitversioning.yml - template: azure-pipelines-templates/download-install-arm-gcc-toolchain.yml - template: azure-pipelines-templates/download-install-ninja.yml + - template: azure-pipelines-templates/download-srecord.yml - template: azure-pipelines-templates/download-hexdfu.yml - template: azure-pipelines-templates/build-chibios-stm32.yml - template: azure-pipelines-templates/pack-publish-artifacts.yml diff --git a/targets/ChibiOS/CMakeLists.txt b/targets/ChibiOS/CMakeLists.txt index 25b2f4499e..62b8e9383e 100644 --- a/targets/ChibiOS/CMakeLists.txt +++ b/targets/ChibiOS/CMakeLists.txt @@ -27,6 +27,21 @@ if(DEFINED TOOL_HEX2DFU_PREFIX) endif() endif() +######################################################## +# check availability of SRecord tool, if specified +if(DEFINED TOOL_SRECORD_PREFIX) + if(NOT ((EXISTS ${TOOL_SRECORD_PREFIX}/srec_cat.exe) OR (EXISTS ${TOOL_SRECORD_PREFIX}/srec_cat))) + message(STATUS "") + message(STATUS "Couldn't find the srec_cat tool at the specified path: ${TOOL_SRECORD_PREFIX}/srec_cat.exe") + message(STATUS "Make sure that the CMake option TOOL_SRECORD_PREFIX has the correct path.") + message(STATUS "If you don't have this tool download it from https://sourceforge.net/projects/srecord/files/srecord-win32/") + message(STATUS "") + message(FATAL_ERROR "srec_cat tool not found") + else() + set(SRECORD_TOOL_AVAILABLE TRUE CACHE INTERNAL "srec_cat tool available") + endif() +endif() + # check if RTOS_SOURCE_FOLDER was specified or if it's empty (default is empty) set(NO_RTOS_SOURCE_FOLDER TRUE) if(RTOS_SOURCE_FOLDER) diff --git a/targets/ChibiOS/ST_NUCLEO64_F091RC/CMakeLists.txt b/targets/ChibiOS/ST_NUCLEO64_F091RC/CMakeLists.txt index 2162ef5580..2d30fda9fa 100644 --- a/targets/ChibiOS/ST_NUCLEO64_F091RC/CMakeLists.txt +++ b/targets/ChibiOS/ST_NUCLEO64_F091RC/CMakeLists.txt @@ -82,3 +82,27 @@ set_property(TARGET ${NANOCLR_PROJECT_NAME}.elf APPEND_STRING PROPERTY LINK_FLAG # generate output files nf_generate_build_output_files(${NANOBOOTER_PROJECT_NAME}.elf) nf_generate_build_output_files(${NANOCLR_PROJECT_NAME}.elf) + +# generate bin file for deployment +if(SRECORD_TOOL_AVAILABLE) + + ############################################################################################################ + ## when changing the linker file make sure to update the addresses below with the offset of the CLR image ## + ## DO NOT use the leading 0x notation, just the address in plain hexadecimal formating ## + ############################################################################################################ + + if(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES RelWithDebInfo) + NF_GENERATE_BIN_PACKAGE( + ${CMAKE_SOURCE_DIR}/build/${NANOBOOTER_PROJECT_NAME}.bin + ${CMAKE_SOURCE_DIR}/build/${NANOCLR_PROJECT_NAME}.bin + 5000 + ${CMAKE_SOURCE_DIR}/build/nanobooter-nanoclr.bin) + else() + NF_GENERATE_BIN_PACKAGE( + ${CMAKE_SOURCE_DIR}/build/${NANOBOOTER_PROJECT_NAME}.bin + ${CMAKE_SOURCE_DIR}/build/${NANOCLR_PROJECT_NAME}.bin + 2800 + ${CMAKE_SOURCE_DIR}/build/nanobooter-nanoclr.bin) + endif() + +endif() \ No newline at end of file diff --git a/targets/ChibiOS/ST_NUCLEO64_F091RC/cmake-variants.json b/targets/ChibiOS/ST_NUCLEO64_F091RC/cmake-variants.json index 5b27eb2637..3e504b5eab 100644 --- a/targets/ChibiOS/ST_NUCLEO64_F091RC/cmake-variants.json +++ b/targets/ChibiOS/ST_NUCLEO64_F091RC/cmake-variants.json @@ -30,6 +30,7 @@ "CMAKE_TOOLCHAIN_FILE": "CMake/toolchain.arm-none-eabi.cmake", "TOOLCHAIN_PREFIX": "", "TOOL_HEX2DFU_PREFIX": "", + "TOOL_SRECORD_PREFIX": "", "TARGET_SERIES": "STM32F0xx", "RTOS": "CHIBIOS", "RTOS_SOURCE_FOLDER": "", diff --git a/targets/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/STM32F091xC_CLR-DEBUG.ld b/targets/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/STM32F091xC_CLR-DEBUG.ld index de2a8667e8..cada5652cf 100644 --- a/targets/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/STM32F091xC_CLR-DEBUG.ld +++ b/targets/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/STM32F091xC_CLR-DEBUG.ld @@ -10,6 +10,11 @@ /* * STM32F091xC memory setup. */ + +/* +* When updating the flash0 address below make sure to update the address in NF_GENERATE_BIN_PACKAGE +*/ + MEMORY { flash0 (rx) : org = 0x08005000, len = 256k - 20k - 46k /* flash size less the space reserved for nanoBooter and application deployment*/ diff --git a/targets/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/STM32F091xC_CLR.ld b/targets/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/STM32F091xC_CLR.ld index f17e603438..241e3e9447 100644 --- a/targets/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/STM32F091xC_CLR.ld +++ b/targets/ChibiOS/ST_NUCLEO64_F091RC/nanoCLR/STM32F091xC_CLR.ld @@ -10,6 +10,11 @@ /* * STM32F091xC memory setup. */ + +/* +* When updating the flash0 address below make sure to update the address in NF_GENERATE_BIN_PACKAGE +*/ + MEMORY { flash0 (rx) : org = 0x08002800, len = 256k - 10k - 88k /* flash size less the space reserved for nanoBooter and application deployment*/ diff --git a/targets/ChibiOS/ST_STM32F769I_DISCOVERY/CMakeLists.txt b/targets/ChibiOS/ST_STM32F769I_DISCOVERY/CMakeLists.txt index bc92746c1b..955b24ce89 100644 --- a/targets/ChibiOS/ST_STM32F769I_DISCOVERY/CMakeLists.txt +++ b/targets/ChibiOS/ST_STM32F769I_DISCOVERY/CMakeLists.txt @@ -88,3 +88,27 @@ set_property(TARGET ${NANOCLR_PROJECT_NAME}.elf APPEND_STRING PROPERTY LINK_FLAG # generate output files nf_generate_build_output_files(${NANOBOOTER_PROJECT_NAME}.elf) nf_generate_build_output_files(${NANOCLR_PROJECT_NAME}.elf) + +# generate bin file for deployment +if(SRECORD_TOOL_AVAILABLE) + + ############################################################################################################ + ## when changing the linker file make sure to update the addresses below with the offset of the CLR image ## + ## DO NOT use the leading 0x notation, just the address in plain hexadecimal formating ## + ############################################################################################################ + + if(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES RelWithDebInfo) + NF_GENERATE_BIN_PACKAGE( + ${CMAKE_SOURCE_DIR}/build/${NANOBOOTER_PROJECT_NAME}.bin + ${CMAKE_SOURCE_DIR}/build/${NANOCLR_PROJECT_NAME}.bin + 10000 + ${CMAKE_SOURCE_DIR}/build/nanobooter-nanoclr.bin) + else() + NF_GENERATE_BIN_PACKAGE( + ${CMAKE_SOURCE_DIR}/build/${NANOBOOTER_PROJECT_NAME}.bin + ${CMAKE_SOURCE_DIR}/build/${NANOCLR_PROJECT_NAME}.bin + 10000 + ${CMAKE_SOURCE_DIR}/build/nanobooter-nanoclr.bin) + endif() + +endif() diff --git a/targets/ChibiOS/ST_STM32F769I_DISCOVERY/cmake-variants.json b/targets/ChibiOS/ST_STM32F769I_DISCOVERY/cmake-variants.json index 57549a0125..7b039c4d19 100644 --- a/targets/ChibiOS/ST_STM32F769I_DISCOVERY/cmake-variants.json +++ b/targets/ChibiOS/ST_STM32F769I_DISCOVERY/cmake-variants.json @@ -30,6 +30,7 @@ "CMAKE_TOOLCHAIN_FILE": "CMake/toolchain.arm-none-eabi.cmake", "TOOLCHAIN_PREFIX": "", "TOOL_HEX2DFU_PREFIX": "", + "TOOL_SRECORD_PREFIX": "", "RTOS": "CHIBIOS", "TARGET_SERIES": "STM32F7xx", "RTOS_SOURCE_FOLDER": "", diff --git a/targets/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/STM32F76xx_CLR-DEBUG.ld b/targets/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/STM32F76xx_CLR-DEBUG.ld index 9469524e37..2fc512b7c1 100644 --- a/targets/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/STM32F76xx_CLR-DEBUG.ld +++ b/targets/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/STM32F76xx_CLR-DEBUG.ld @@ -14,6 +14,7 @@ * * Notes: * BSS is placed in DTCM RAM in order to simplify DMA buffers management. + * When updating the flash0 address below make sure to update the address in NF_GENERATE_BIN_PACKAGE */ MEMORY { diff --git a/targets/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/STM32F76xx_CLR.ld b/targets/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/STM32F76xx_CLR.ld index 9469524e37..2fc512b7c1 100644 --- a/targets/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/STM32F76xx_CLR.ld +++ b/targets/ChibiOS/ST_STM32F769I_DISCOVERY/nanoCLR/STM32F76xx_CLR.ld @@ -14,6 +14,7 @@ * * Notes: * BSS is placed in DTCM RAM in order to simplify DMA buffers management. + * When updating the flash0 address below make sure to update the address in NF_GENERATE_BIN_PACKAGE */ MEMORY {