platform-ststm32 icon indicating copy to clipboard operation
platform-ststm32 copied to clipboard

Support all boards that the STM32 Arduino core supports

Open maxgerhardt opened this issue 4 years ago • 1 comments

Per https://community.platformio.org/t/where-are-all-the-new-stm32-boards/23304.

Platform-STSTM32 should support all the boards which are selectible with that core in the Arduino IDE, too.

Examples:

  • Generic WL54CCUx (and lots of other WL series)
  • Generic H742IGKx (and lots of ther H7 series)
  • all generic STM32Lx series boards (L0, L1, L4, L5)
  • some 3d printer boards
  • etc. etc.

Maybe some automated sync script from board.txt -> board JSON file will come in handy. The variants in STM32Duino seem to be heavily auto-generated. For my GD32 I've written a script which generates board definitions from certain CSV files.

There are various issues open right now which only focus on one missing board, this issue is regarding the entirety of missing STM32 boards though and thus different.

maxgerhardt avatar Sep 04 '21 12:09 maxgerhardt

I recently had the need (or desire) to try something on the Nucleo G491RE, only to find there is no board for it!

Here's what I did which is working well so far (caveat: not done much testing yet):

  1. create a boards folder in the project, and add my custom json for the board
  2. after a bit of messing around, figured out the file has to be called "genericSTM32G491RE.json" or similar, but the "generic" is important
  3. I created the file as a copy of an existing definition, so I updated, name, MCU, RAM and FLASH sizes, etc... Importantly, don't forget to update the variant. The name of the variant folder you need can be found in the stm32 variants folder, which is somewhere like this: ~/.platformio/packages/[email protected]/variants/ It also complained about a missing openocd_chipname, so I added "openocd_chipname": "stm32g491re",
  4. Once your board description is complete, you can use it by typing "pio boards" in the PlatformIO CLI, and then reference it in your platformio.ini file in your project
  5. Open STM32CubeIDE and create a new project using your MCU. You don't have to configure anything, just save and choose "Generate Code" for the .ioc file. The resulting generated code will include a file like "STM32G491RETX_FLASH.ld".
  6. Copy this file to your platformio project (I made a folder "variant" and put it in there, calling it "ldscript.ld")
  7. Add to your platformio.ini: board_build.ldscript = ./variant/ldscript.ld
  8. Compile :-)

Since it is a previously unsupported board, you may have some compile problems. In my case (after a bit of research) I had to add a -DTIM7_DAC_IRQn=55 to the "extra_flags" as there is a small error in the HAL timers.h regarding this MCU.

Here's my resulting board definition file boards\genericSTM32G491RE.json:

{
    "build": {
        "core": "stm32",
        "cpu": "cortex-m4",
        "extra_flags": "-DSTM32G4xx -DSTM32G491xx -DTIM7_DAC_IRQn=55",
        "f_cpu": "170000000L",
        "mcu": "stm32g491ret6",
        "product_line": "STM32G491xx",
        "variant": "STM32G4xx/G491RC(I-T)_G491RE(I-T-Y)_G4A1RE(I-T-Y)"
    },
    "connectivity": [
        "can"
    ],
    "debug": {
        "default_tools": [
            "stlink"
        ],
        "jlink_device": "STM32G491RE",
        "onboard_tools": [
            "stlink"
        ],
        "openocd_chipname": "stm32g491re",
        "openocd_target": "stm32g4x",
        "svd_path": "STM32G491xx.svd"
    },
    "frameworks": [
        "arduino",
        "cmsis",
        "mbed",
        "libopencm3",
        "stm32cube",
        "zephyr"
    ],
    "name": "Nucleo G491RE",
    "upload": {
        "maximum_ram_size": 114688,
        "maximum_size": 524288,
        "protocol": "stlink",
        "protocols": [
            "stlink",
            "jlink",
            "cmsis-dap",
            "blackmagic",
            "mbed"
        ]
    },
    "url": "https://www.st.com/en/evaluation-tools/nucleo-g491re.html",
    "vendor": "ST"
}

and here the platformio.ini:

[env:nucleo_g491re]
platform = ststm32
board = genericSTM32G491RE
framework = arduino

lib_archive = false
upload_protocol = stlink
monitor_speed = 115200

board_build.ldscript = ./variant/ldscript.ld
build_flags =
  -D SERIAL_UART_INSTANCE=2

So far so good, I'll let you know if I find any problems with this.

This was supposed to be a kind of note to help the next person looking for a solution here.

On the topic of the actual issue, in the STM32 Core the variant folders all contain individual boards.txt files which have the partial configuration for that variant. So I think a script targeting those files which produces generic board json for all the variants in one fell swoop would be quite possible...

runger1101001 avatar Dec 22 '21 12:12 runger1101001