README.mediawiki 5.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. == About ==
  2. This project is used to develop applications for stm32 - ST's ARM Cortex-M3(4) MCUs, using cmake, GCC, newlib (libc), STM32CubeMX package or ChibiOS.
  3. Requirements:
  4. * cmake >= 2.8
  5. * GCC toolchain with newlib (optionally).
  6. * STM32CubeMX package for STM32F1 or STM32F4 families.
  7. Project contains:
  8. * CMake common toolchain file, that configures cmake to use arm toolchain.
  9. * CMake family-specific toolchain file, that configures family-specific parameters.
  10. * CMake projects that installs CMSIS and STM32CubeMX (STM32HAL) sources into sysroot.
  11. * CMake modules to find and configure CMSIS ans STM32HAL components.
  12. * CMake modules to find and configure ChibiOS components.
  13. * CMake project template.
  14. * Example projects
  15. ** blinky - blink LED using timers and PWM.
  16. ** newlib - show date using uart and libc functions from newlib
  17. ** stm32-chibios - blink led using ChibiOS/NIL
  18. == Building & Installing ==
  19. First of all you need to configure toolchain and libraries, you can do this by editing gcc_stm32.cmake or (better way) pass it throught command line.
  20. Variables for toolchain:
  21. * TOOLCHAIN_PREFIX - where toolchain is located, '''default''': /usr
  22. * TARGET_TRIPLET - toolchain target triplet, '''default''': arm-none-eabi
  23. * STM32_FAMILY - STM32 family (F0, F1, F4, etc.) currently, F1 and F4 family are supported.
  24. '''Note:''' If STM32_CHIP variable is set, STM32_FAMILY is optional.
  25. Variables for CMSIS and STM32CubeMX:
  26. * STM32Cube_DIR - path to STM32CubeMX directory '''default''': /opt/STM32Cube_FW_F1_V1.1.0 /opt/STM32Cube_FW_F4_V1.6.0
  27. === Build CMSIS and Standard Peripherals Library ===
  28. In cmsis folder:
  29. cmake -DCMAKE_TOOLCHAIN_FILE=../gcc_stm32.cmake -DSTM32_FAMILY=F1 -DCMAKE_INSTALL_PREFIX=<path_to_toolchain>/arm-none-eabi/ -DCMAKE_BUILD_TYPE=Release
  30. make && make install
  31. In stdperiph folder
  32. cmake -DCMAKE_TOOLCHAIN_FILE=../gcc_stm32.cmake -DCMAKE_MODULE_PATH=<path_to_cmake_folder_of_this_project>/Modules -DSTM32_FAMILY=F1 -DCMAKE_INSTALL_PREFIX=<path_to_toolchain>/arm-none-eabi/ -DCMAKE_BUILD_TYPE=Release
  33. make && make install
  34. '''Note:''' For building for STM32F4 family, change -DSTM32_FAMILY=F1 to -DSTM32_FAMILY=F4
  35. '''Note:''' You can use different CMAKE_INSTALL_PREFIX, but than you'll have to configure cmake search paths when using cmake modules. You may specify an additional search path with -DEXTRA_FIND_PATH=<path-to-search>
  36. == Usage ==
  37. After building you need to copy cmake modules in cmake's modules path, or just set CMAKE_MODULE_PATH in project.
  38. Template project can be found in stm32-template folder.
  39. === Configure ===
  40. Common usage:
  41. cmake -DSTM32_CHIP=<chip> -DCMAKE_TOOLCHAIN_FILE=<path_to_gcc_stm32.cmake> -DCMAKE_BUILD_TYPE=Debug <path_to_source_dir>
  42. Where <nowiki><chip></nowiki> - stm32 chip name (e.g. STM32F100C8, STM32F407IG).
  43. This command will generate Makefile for project.
  44. Scripts will try to detected chip parameters (type, flash/ram size) from chip name.
  45. You can set this parameters directly using following cmake variables:
  46. * STM32_CHIP_TYPE - family-depended chip type. Global variable STM32_CHIP_TYPES contains list of valid types for current family
  47. * STM32_FLASH_SIZE - chip flash size (e.g. 64K)
  48. * STM32_RAM_SIZE - chip RAM size (e.g. 4K)
  49. For using with Eclipse CDT:
  50. cmake -DSTM32_CHIP=<chip> -DCMAKE_TOOLCHAIN_FILE=<path_to_gcc_stm32.cmake> -DCMAKE_BUILD_TYPE=Debug -G "Eclipse CDT4 - Unix Makefiles" <path_to_source_dir>
  51. For release build:
  52. cmake -DSTM32_CHIP=<chip> -DCMAKE_TOOLCHAIN_FILE=<path_to_gcc_stm32.cmake> -DCMAKE_BUILD_TYPE=Release <path_to_source_dir>
  53. === Build ===
  54. make
  55. To build .hex:
  56. make <project name>.hex
  57. or .bin:
  58. make <project name>.bin
  59. === Linker script variables ===
  60. Next cmake variables are useful for linker tuning:
  61. * STM32_FLASH_ORIGIN - Start address of flash (default: 0x08000000)
  62. * STM32_RAM_ORIGIN - Start address of RAM (default: 0x20000000)
  63. * STM32_STACK_ADDRESS - Address of stack bottom (default: RAM_ORIGIN + RAM_SIZE)
  64. * STM32_FLASH_SIZE - Flash size (default: from chip name)
  65. * STM32_RAM_SIZE - RAM size (default: from chip name)
  66. * STM32_MIN_STACK_SIZE - Minimum stack size for error detection at link-time (default: 512 bytes)
  67. * STM32_MIN_HEAP_SIZE - Minimum heap size for error detection at link-time (default: 0 bytes)
  68. === Useful cmake macros ===
  69. * STM32_GET_CHIP_TYPE(CHIP CHIP_TYPE) - gets chip type (HD, MD, etc.) from chip name.
  70. * STM32_GET_CHIP_PARAMETERS(CHIP FLASH_SIZE RAM_SIZE) - gets chip ram/flash size from chip name.
  71. * STM32_SET_CHIP_DEFINITIONS(TARGET CHIP_TYPE) - sets chip family and type-specific compiler flags for target.
  72. * STM32_SET_FLASH_PARAMS(TARGET ...) - sets chip flash/ram parameters for targer.
  73. * STM32_SET_TARGET_PROPERTIES(TARGET) - sets all needed parameters and compiler flags for target.
  74. * STM32_GENERATE_LIBRARIES(NAME SOURCES LIBRARIES) - generates libraries for all chip types in family. Resulting libraries stored in LIBRARIES and have names in ${NAME}_${FAMILY}_${CHIP_TYPE} format.
  75. * STM32_SET_HSE_VALUE - change HSE frequency definitions (in Hz).
  76. === ChibiOS Support ===
  77. This projects also supports ChibiOS v3.x.x (both nil and rt kernels).
  78. CMake modules for ChibiOS can find specified ChibiOS components using COMPONENTS directive.
  79. See project stm32-chibios for example usage.