dkonigsberg

Import CubeMX code into project

Dec 4th, 2020
1,220
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2.  
  3. #
  4. # This script helps with importing framework source files from an STM32CubeMX
  5. # code generation dump. It does not prepare the complete project, and is
  6. # mainly intended for use in tracking framework code changes.
  7. #
  8. # Files copied by this script may overwrite local changes within the project,
  9. # so changed files should be carefully inspected before checking them in.
  10. #
  11. # This script can also be used as documentation on how the STM32CubeMX code
  12. # dump is translated into the project directory structure.
  13. #
  14.  
  15. #
  16. # Validate arguments to get input and output paths
  17. #
  18. if [[ -f "$1/.mxproject" ]]; then
  19.     CUBEDIR=$1
  20. else
  21.     echo "Need a valid CubeMX output path"
  22.     exit 1
  23. fi
  24.  
  25. if [[ -z "$2" ]]; then
  26.     if [[ -f ".project" ]]; then
  27.         PROJDIR="`readlink -f .`"
  28.     elif [[ -f "../.project" ]]; then
  29.         PROJDIR="`readlink -f ..`"
  30.     fi
  31. elif [[ -f "$2/.project" ]]; then
  32.     PROJDIR=`readlink -f $2`
  33. fi
  34.  
  35. if [[ ! -f "$PROJDIR/.project" ]]; then
  36.     echo "Need a valid project path"
  37.     exit 1
  38. fi
  39.  
  40. echo "CubeMX path: $CUBEDIR"
  41. echo "Project path: $PROJDIR"
  42.  
  43. #
  44. # Linker configuration files
  45. #
  46. cp "${CUBEDIR}/"*.ld "${PROJDIR}/"
  47.  
  48. #
  49. # Project core sources
  50. #
  51. mkdir -p "${PROJDIR}/src/system"
  52. cp "${CUBEDIR}/Core/Startup/"startup_stm32f411retx.s "${PROJDIR}/src/system/"
  53. cp "${CUBEDIR}/Core/Inc/"stm32f4xx*.h "${PROJDIR}/src/system/"
  54. cp "${CUBEDIR}/Core/Src/"stm32f4xx*.c "${PROJDIR}/src/system/"
  55. cp "${CUBEDIR}/Core/Src/"sys*.c "${PROJDIR}/src/system/"
  56.  
  57. #
  58. # External driver code
  59. #
  60. mkdir -p "${PROJDIR}/external/drivers/stm32f4xx/src"
  61. cp -r "${CUBEDIR}/Drivers/STM32F4xx_HAL_Driver/Src/"* "${PROJDIR}/external/drivers/stm32f4xx/src/"
  62.  
  63. mkdir -p "${PROJDIR}/external/drivers/stm32f4xx/include"
  64. cp -r "${CUBEDIR}/Drivers/STM32F4xx_HAL_Driver/Inc/"* "${PROJDIR}/external/drivers/stm32f4xx/include/"
  65.  
  66. mkdir -p "${PROJDIR}/external/drivers/cmsis/include"
  67. cp -r "${CUBEDIR}/Drivers/CMSIS/Device/ST/STM32F4xx/Include/"* "${PROJDIR}/external/drivers/cmsis/include/"
  68. cp -r "${CUBEDIR}/Drivers/CMSIS/Include/"* "${PROJDIR}/external/drivers/cmsis/include/"
  69.  
  70. #
  71. # External USB support code
  72. #
  73. mkdir -p "${PROJDIR}/external/usb/core/src"
  74. cp -r "${CUBEDIR}/Middlewares/ST/STM32_USB_Host_Library/Core/Src/"* "${PROJDIR}/external/usb/core/src/"
  75.  
  76. mkdir -p "${PROJDIR}/external/usb/core/include"
  77. cp -r "${CUBEDIR}/Middlewares/ST/STM32_USB_Host_Library/Core/Inc/"* "${PROJDIR}/external/usb/core/include/"
  78.  
  79. mkdir -p "${PROJDIR}/external/usb/class/src"
  80. cp -r "${CUBEDIR}/Middlewares/ST/STM32_USB_Host_Library/Class/CDC/Src/"* "${PROJDIR}/external/usb/class/src/"
  81. cp -r "${CUBEDIR}/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/"* "${PROJDIR}/external/usb/class/src/"
  82. cp -r "${CUBEDIR}/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Src/"* "${PROJDIR}/external/usb/class/src/"
  83.  
  84. mkdir -p "${PROJDIR}/external/usb/class/include"
  85. cp -r "${CUBEDIR}/Middlewares/ST/STM32_USB_Host_Library/Class/CDC/Inc/"* "${PROJDIR}/external/usb/class/include/"
  86. cp -r "${CUBEDIR}/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/"* "${PROJDIR}/external/usb/class/include/"
  87. cp -r "${CUBEDIR}/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Inc/"* "${PROJDIR}/external/usb/class/include/"
  88.  
  89. mkdir -p "${PROJDIR}/external/usb/target"
  90. cp -r "${CUBEDIR}/USB_HOST/Target/"* "${PROJDIR}/external/usb/target/"
  91.  
  92. #
  93. # External FATFS support code
  94. #
  95. mkdir -p "${PROJDIR}/external/fatfs/src"
  96. cp -r "${CUBEDIR}/Middlewares/Third_Party/FatFs/src/"* "${PROJDIR}/external/fatfs/src/"
  97.  
  98. mkdir -p "${PROJDIR}/external/fatfs/target"
  99. cp -r "${CUBEDIR}/FATFS/Target/"* "${PROJDIR}/external/fatfs/target/"
  100.  
  101. #
  102. # External FreeRTOS code
  103. #
  104. mkdir -p "${PROJDIR}/external/freertos"
  105. cp -r "${CUBEDIR}/Middlewares/Third_Party/FreeRTOS/Source/"* "${PROJDIR}/external/freertos/"
  106.  
RAW Paste Data