Add your board:

-

TODO explain all steps

1. Create a copy of the STM32/variants/TEMPLATE folder with a name of your choice.

-

TODO make TEMPLATE folder

+

TODO create TEMPLATE, for now just use an existing one

2. Edit the ldscript.ld file

+
    +
  1. Change the _estack to point to the end of RAM
  2. +
  3. FLASH LENGTH to be the size of RAM of the microcontroller
  4. +
  5. RAM LENGTH to be the size of RAM of the microcontroller
  6. +
+

TODO CCRAM? SDRAM?

3. Edit the variant.h file

+
    +
  1. Copy the enum {... from system/STM32XX/stm32_chip/stm32_STM32XXXXXX.h file.
  2. +
  3. If the board has pin name - pin number assigments (for example arduino headers), rearrange the enum accordingly.
  4. +
  5. Change LED_BUILTIN, MOSI, MISO... macros to point to the primary LED, primary SPI, primary I2C pins.
  6. +
  7. Add board specific macros if the board has extra leds, buttons, SPI CS select lines etc...
  8. +

4. Edit the variant.cpp file

+
    +
  1. Copy the const stm32_port_pin_type variant_pin_list[] = { from system/STM32XX/stm32_chip/stm32_STM32XXXXXX.h file.
  2. +
  3. Rearrange to be the same as enum { in variant.h
  4. +

5. Edit the systemclock_config.c file

+
    +
  1. Run STM32CubeMX, select the chip for your board
  2. +
  3. If the board has external crystal, set RCC HSE to crystal. In clock configuration, set PLL Source to HSE, set HSE to the frequency of the board crystal.
  4. +
  5. Set some peripherals (SPI, I2C, SDIO, USB, ...), so that the clock configuration will generate extra code needed for those peripherals, and bounds check the frequencies.
  6. +
  7. Go to clock configuration, set everything to maximum :), let CubeMX figure out the rest.
  8. +
  9. Click generate. Set toolchain/IDE to SW4STM32. Clik OK
  10. +
  11. From the generated src/main.c, copy void SystemClock_Config(void) { into your variant/.../systemclock_config.c
  12. +

6. Edit the boards.txt file

+

TODO create template. For now, copy an existing board

+
    +
  1. Rename the board
  2. +
  3. Change build.mcu= to your cortex-mX version
  4. +
  5. Change build.series= to STM32XX, where XX is the chip series
  6. +
  7. Change build.extra_flags=-DSTM32XXXXXX to be the exact chip version
  8. +
  9. Change upload.maximum_size= and upload.maximum_data_size= to the RAM/FLASH size of the chip
  10. +
  11. If the external crystal is not the board default in system/STM32XX/HAL_SRC/system_stm32XXxx.c, add -DHSE_VALUE=8000000 to xxx.build.extra_flags
  12. +
  13. TODO explain upload / usb / serial menu options
  14. +

7. Restart

+

Restart Arduino IDE

-

9. Run the tests on the board to check if it is working