Make a custom board needing a custom framework

Hi everyone,

I’m trying to create a custom board for my specific project.

My board is called orbita and I put an boards/orbita.json file in my project folder :

orbita.json :

{
  "build": {
    "core": "stm32",
    "cpu": "cortex-m4",
    "extra_flags": "-DSTM32G4xx -DSTM32G474x",
    "f_cpu": "170000000L",
    "mcu": "stm32g474ret6"
  },
  "connectivity": [
    "can"
  ],
  "debug": {
    "jlink_device": "STM32G474RE",
    "openocd_target": "stm32g4x",
    "svd_path": "STM32G474xx.svd"
  },
  "frameworks": [
    "stm32cube"
  ],
  "name": "Orbita",
  "upload": {
    "maximum_ram_size": 131072,
    "maximum_size": 524288,
    "protocol": "stlink",
    "protocols": [
      "jlink",
      "stlink",
      "dfu"
    ]
  }
}

and with freshly generated CubeMX code compilation fail :

Processing orbita (platform: ststm32; board: orbita; framework: stm32cube; build_flags: -I inc, -D USE_FULL_LL_DRIVER, -D HAL=STM32G474xx; lib_extra_dirs: modules/, /Users/nicolasrabault/Documents/luos; lib_deps: Luos; debug_tool: stlink; upload_protocol: dfu)
--------------------------------------------------------------------------------------------------
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/orbita.html
PLATFORM: ST STM32 6.0.0 > Orbita
HARDWARE: STM32G474RET6 170MHz, 128KB RAM, 512KB Flash
DEBUG: Current (stlink) External (jlink, stlink)
PACKAGES: 
 - framework-stm32cube 2.0.181130 
 - tool-dfuutil 1.9.200310 
 - toolchain-gccarmnoneeabi 1.70201.0 (7.2.1)
Warning! Cannot find a linker script for the required board! Firmware will be linked with a default linker script!
Error: Cannot find template file to configure framework!

It’s sounds like a framework error but I use the same framework on other project without trouble…
Do you have any ideas?

Refer to the code which generates this message

Since you have

    "mcu": "stm32g474ret6"

Does the file

C:\Users\<user>\.platformio\packages\framework-stm32cube\platformio\ldscripts\STM32G474RE_FLASH.ld

exist?

1 Like

Oh actually the way more critical error is that it doesn’t find the HAL files for the MCU_FAMILY, aka STM32G4 in your case. Have you put the appropriate files in the framework-stm32cube folder?

Refer to the code for the expected locations

1 Like

Thank for pointing me to this code I have a better understanding of how the linker script is selected now.
No it’s not. CubeMX create one for me so I add the generated script by adding

build_flags = 
    -Wl,-T$PROJECT_DIR/STM32G474RETX_FLASH.ld

I guess If I rename my linker script and put it manually into the framework files I will lose it at the next platformio update…
Also my project need to be used by multiple people and I need to have everything embedded on the project repo to avoid configuration troubles.

No I miss that! I just realized that all my other projects uses those files.
So I don’t need to keep my Driver folder locally for my working projects!

In my project generated Driver folder I don’t have any *xx_hal_conf.h or *xx_hal_conf_template.h.

What is the best way to make it work?

You can copy the current version of the framework-stm32cube package to like a github repository, add the needed support files for the STM32G4 series (linker files, the HAL for the G4 series) and then point PlatformIO to use this repository as the framework-stm32cube packages.

This can be done by using the platform_packages directive (docs). You can also develop locally in the framework folder and then at the end push it to a repo.

So what you’re basically doing here is not only adding a board but also the framework support files since they don’t exist in the PlatformIO stm32cube package as of now (refer).

1 Like

These should be in the stm32cube framework folder, not? There has to be a stm32g4xx_hal_conf.h somewhere.

The official firmware package for the G4 series is here: STM32CubeG4 - STM32Cube MCU Package for STM32G4 series (HAL, Low-Layer APIs and CMSIS, USB, File system, RTOS, Graphic - and examples running on ST boards) - STMicroelectronics

These files need to be added in the framework folder, along with the ldscript. Current folder structure is

framework-stm32cube$ tree -L 2
.
β”œβ”€β”€ f0
β”‚   β”œβ”€β”€ Drivers
β”‚   β”œβ”€β”€ package.xml
β”‚   β”œβ”€β”€ Release_Notes.html
β”‚   └── Utilities
β”œβ”€β”€ f1
β”‚   β”œβ”€β”€ Drivers
β”‚   β”œβ”€β”€ package.xml
β”‚   β”œβ”€β”€ Release_Notes.html
β”‚   └── Utilities
β”œβ”€β”€ f2
β”‚   β”œβ”€β”€ Drivers
β”‚   β”œβ”€β”€ package.xml
β”‚   β”œβ”€β”€ Release_Notes.html
β”‚   └── Utilities
β”œβ”€β”€ f3
β”‚   β”œβ”€β”€ Drivers
β”‚   β”œβ”€β”€ package.xml
β”‚   β”œβ”€β”€ Release_Notes.html
β”‚   └── Utilities
β”œβ”€β”€ f4
β”‚   β”œβ”€β”€ Drivers
β”‚   β”œβ”€β”€ Middlewares
β”‚   β”œβ”€β”€ package.xml
β”‚   β”œβ”€β”€ Release_Notes.html
β”‚   └── Utilities
β”œβ”€β”€ f7
β”‚   β”œβ”€β”€ Drivers
β”‚   β”œβ”€β”€ Middlewares
β”‚   β”œβ”€β”€ package.xml
β”‚   β”œβ”€β”€ Release_Notes.html
β”‚   └── Utilities
β”œβ”€β”€ h7
β”‚   β”œβ”€β”€ Drivers
β”‚   β”œβ”€β”€ package.xml
β”‚   β”œβ”€β”€ Release_Notes.html
β”‚   └── Utilities
β”œβ”€β”€ l0
β”‚   β”œβ”€β”€ Drivers
β”‚   β”œβ”€β”€ package.xml
β”‚   β”œβ”€β”€ Release_Notes.html
β”‚   └── Utilities
β”œβ”€β”€ l1
β”‚   β”œβ”€β”€ Drivers
β”‚   β”œβ”€β”€ package.xml
β”‚   β”œβ”€β”€ Release_Notes.html
β”‚   └── Utilities
β”œβ”€β”€ l4
β”‚   β”œβ”€β”€ Drivers
β”‚   β”œβ”€β”€ package.xml
β”‚   β”œβ”€β”€ Release_Notes.html
β”‚   └── Utilities
β”œβ”€β”€ package.json
└── platformio
    β”œβ”€β”€ ldscripts
    └── variants_remap.json
1 Like

Yes found it, but it is on the inc folder. I think cubemx put it into inc because it modify it accordingly to used functionalities. Basically I just have to enable all modules on this file and past it on the framework package with all the β€œDrivers” functions, linker gonna deal with it.

Yes I get it. I gonna give it a try.
Is there any way to contribute? If I make this framework work for me it could be interesting for other users…

You can add the board as PR into the GitHub - platformio/platform-ststm32: ST STM32: development platform for PlatformIO repository and also leave a link to the updated framework-stm32cube package, I’m sure they’ll update it.

@maxgerhardt, thanks to you I use the official firmware package and put it into my framework-stm32cube.
Now I pass the previous step but I got tons of error like :
unknown type name 'uint32_t'

I compare my files with other FRAMEWORK_CORE but I can’t see any difference regarding a #include <stdint.h> line…

I’m not so sure, this particular board is really custom, but I’m gonna think about it for my devs boards. Perhaps I could update the nucleo_g474re.json wich is using the same MCU to be able to use Arduino and STM32. But I will share my framework update for sure :wink:

This is thrown from framework files or project source code? Is your g4 folder structure in the framework-stm32cube the same as for other series? Can you share your current framework-stm32cube state for reprocdution?

Both I think but it’s difficult to say what is the first problem causing all this mess.

Yes I think. The only strange thing I noticed is the size of my linker script. All others are 4511bytes and mine is 5924bytes. This is the only file I get directly from my project, all others come from the official St firmware package of G4.

Here it is : GitHub - nicolas-rabault/framework-stm32cube_g4_: platformio framework-stm32cube with STM32G4 series management

Today I noticed something strange. Platformio seems to fail accessing my files. If I clic on error I get a popup like :
Capture d’écran 2020-04-16 aΜ€ 09.59.19
Indeed the path to access those files seems broken, VSC seems to search into an β€œers” folder (witch could be a part of the β€œDrivers” folder?). But this file is in framework, i check it…

For now I don’t get how it happening, but it seems to be only on the β€œproblem” view. If I use terminal VSC show me files as expected and find compilation missing symbols.
It sounds like a board/project configuration issue.

Is there somethig strange for you in my board.json file :

{
  "build": {
    "core": "stm32",
    "cpu": "cortex-m4",
    "extra_flags": [
      "-DSTM32G4xx",
      "-DSTM32G474x",
      "-DUSE_FULL_LL_DRIVER",
    ],
    "f_cpu": "170000000L",
    "mcu": "stm32g474ret6"
  },
  "connectivity": [
    "can"
  ],
  "debug": {
    "jlink_device": "STM32G474RE",
    "openocd_target": "stm32g4x",
    "svd_path": "STM32G474xx.svd"
  },
  "frameworks": [
    "stm32cube"
  ],
  "platform_packages": "framework-stm32cube@https://github.com/nicolas-rabault/framework-stm32cube_g4_.git",
  "name": "Orbita",
  "upload": {
    "maximum_ram_size": 131072,
    "maximum_size": 524288,
    "protocol": "dfu",
    "protocols": [
      "stlink",
      "dfu"
    ]
  },
  "url": "https://github.com/pollen-robotics/orbita",
  "vendor": "Pollen Robotics"
}

Or my platformio.ini :

[common]
default_envs = orbita

[env:orbita]
platform = ststm32
board = orbita
framework = stm32cube
build_flags = -I inc
debug_tool = stlink

Thanks a lot for your help.

I think that’s only valid in the platformio.ini, but for now it doesn’t affect anything.

Very weird. I’ll have a look at it today. But the HAL driver isn’t supposed to be in the firmware usually, but in the framework.

Yes indeed, I try it and it doesn’t work this way.

Watch out my project folder is called β€œfirmware”. You can find my entire project here : https://github.com/Luos-io/orbita

I think I got it!
The first issue is that the compiler doesn’t find stm32g474x.h and it’s because the file is named stm32g474xx.h on CMSIS framework package.

So I go back to my board.json and I noticed that I miss an β€˜x’ on a define so I add it :

"extra_flags": [
      "-DSTM32G4xx",
      "-DSTM32G474xx", ; <==== instead of  "-DSTM32G474x"
      "-DUSE_FULL_LL_DRIVER"

I think this modification fix my issue.

Now I have error on use of middleware (USB). Middlewares are in Framework but platformio doesn’t seems to use them.

To patch it I add Middlewares folder of Framework on my project folders and add :

build_flags = 
    -I inc
    -I Middlewares/ST/STM32_USB_Device_Library/Core/Inc
    -I Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc

into platformio.ini.

Is there any way to avoid copying files and link compiler to the framework one? Using a $FRAMEWORK_DIR or something?

My problem her was to create a New board on a really new MCU (stm32g4) not already supported by STM32 framework.

To make it work I had to create :

Thanks a lot to @maxgerhardt who solve all my problems and explain me a lot into platformio.