README.mediawiki 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 modules to find and configure CMSIS ans STM32HAL components.
  11. * CMake modules to find and configure ChibiOS components.
  12. * CMake project template.
  13. * Example projects
  14. ** stm32-blinky - blink LED using timers and PWM.
  15. ** stm32-newlib - show date using uart and libc functions from newlib
  16. ** stm32-chibios - blink led using ChibiOS/NIL
  17. == Building & Installing ==
  18. 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.
  19. Variables for toolchain:
  20. * TOOLCHAIN_PREFIX - where toolchain is located, '''default''': /usr
  21. * TARGET_TRIPLET - toolchain target triplet, '''default''': arm-none-eabi
  22. * STM32_FAMILY - STM32 family (F0, F1, F4, etc.) currently, F1 and F4 family are supported.
  23. '''Note:''' If STM32_CHIP variable is set, STM32_FAMILY is optional.
  24. * STM32Cube_DIR - path to STM32CubeMX directory '''default''': /opt/STM32Cube_FW_F1_V1.1.0 /opt/STM32Cube_FW_F4_V1.6.0
  25. == Usage ==
  26. For using scripts you'll need to copy contents of cmake folder into cmake's modules path, or use CMAKE_MODULE_PATH variable.
  27. Template project can be found in stm32-template folder.
  28. === Configure ===
  29. Common usage:
  30. cmake -DSTM32_CHIP=<chip> -DCMAKE_TOOLCHAIN_FILE=<path_to_gcc_stm32.cmake> -DCMAKE_BUILD_TYPE=Debug <path_to_source_dir>
  31. Where <nowiki><chip></nowiki> - stm32 chip name (e.g. STM32F100C8, STM32F407IG).
  32. This command will generate Makefile for project.
  33. Scripts will try to detected chip parameters (type, flash/ram size) from chip name.
  34. You can set this parameters directly using following cmake variables:
  35. * STM32_CHIP_TYPE - family-depended chip type. Global variable STM32_CHIP_TYPES contains list of valid types for current family
  36. * STM32_FLASH_SIZE - chip flash size (e.g. 64K)
  37. * STM32_RAM_SIZE - chip RAM size (e.g. 4K)
  38. For using with Eclipse CDT:
  39. 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>
  40. For release build:
  41. cmake -DSTM32_CHIP=<chip> -DCMAKE_TOOLCHAIN_FILE=<path_to_gcc_stm32.cmake> -DCMAKE_BUILD_TYPE=Release <path_to_source_dir>
  42. === Build ===
  43. make
  44. To build .hex:
  45. make <project name>.hex
  46. or .bin:
  47. make <project name>.bin
  48. === Linker script variables ===
  49. Next cmake variables are useful for linker tuning:
  50. * STM32_LINKER_SCRIPT - Path to custom linker script. You can use cmake variables (listed below) in itd.
  51. * STM32_FLASH_ORIGIN - Start address of flash (default: 0x08000000)
  52. * STM32_RAM_ORIGIN - Start address of RAM (default: 0x20000000)
  53. * STM32_CCRAM_ORIGIN - Start address of Core-Couped RAM (only for F4 family) (default: 0x10000000)
  54. * STM32_FLASH_SIZE - Flash size (default: from chip name)
  55. * STM32_RAM_SIZE - RAM size (default: from chip name)
  56. * STM32_CCRAM_SIZE - Core-Couped RAM size (only for F4 family) (default: 64 KiB)
  57. * STM32_MIN_STACK_SIZE - Minimum stack size for error detection at link-time (default: 512 bytes)
  58. * STM32_MIN_HEAP_SIZE - Minimum heap size for error detection at link-time (default: 0 bytes)
  59. === Useful cmake macros ===
  60. * STM32_GET_CHIP_TYPE(CHIP CHIP_TYPE) - gets chip type from chip name.
  61. * STM32_GET_CHIP_PARAMETERS(CHIP FLASH_SIZE RAM_SIZE) - gets chip ram/flash size from chip name.
  62. * STM32_SET_CHIP_DEFINITIONS(TARGET CHIP_TYPE) - sets chip family and type-specific compiler flags for target.
  63. * STM32_SET_FLASH_PARAMS(TARGET ...) - sets chip flash/ram parameters for targer.
  64. * STM32_SET_TARGET_PROPERTIES(TARGET) - sets all needed parameters and compiler flags for target.
  65. * 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.
  66. === ChibiOS Support ===
  67. This projects also supports ChibiOS v3.x.x (both nil and rt kernels).
  68. CMake modules for ChibiOS can find specified ChibiOS components using COMPONENTS directive.
  69. See project stm32-chibios for example usage.