Hi,
im trying to get arduino working on a STM32L431KCU6 custom board. After some fiddling around i got the servo sweep example working through the arduino ide with STM32duino.
Choosing “Generic L432KCUx” as board lets me upload and run this via my ST-Link V2.
The problems start with platformio. If i create a project selecting the ST Nucleo L432KC and upload the same sweep example, the board wont do anything.
.ini looks like this:
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:nucleo_l432kc]
platform = ststm32
board = nucleo_l432kc
framework = arduino
; debug_build_flags = -Os -ggdb2 -g2
Debugging does not work correctly, pausing reveals that the program ist stuck in the error handler:
/**
* @brief This function is executed in case of error occurrence.
* @param None
* @retval None
*/
WEAK void _Error_Handler(const char *msg, int val)
{
/* User can add his own implementation to report the HAL error return state */
core_debug("Error: %s (%i)\n", msg, val);
while (1) {
} // always holds here
}
After trying some different things i looked into the json file and compared it to similar ones.
The nucleo_l432kc.json was the only one that had this line missing:
"core": "stm32",
I created a new json (genericSTM32L431KC.json) for the L431KC with the only difference being this line:
{
"build": {
"core": "stm32", // added this line
"cpu": "cortex-m4",
"extra_flags": "-DSTM32L432xx",
"f_cpu": "80000000L",
"mcu": "stm32l432kcu6",
"product_line": "STM32L432xx",
"variant": "STM32L4xx/L432K(B-C)U_L442KCU"
},
"debug": {
"default_tools": [
"stlink"
],
"jlink_device": "STM32L432KC",
"onboard_tools": [
"stlink"
],
"openocd_target": "stm32l4x",
"svd_path": "STM32L4x2.svd"
},
"frameworks": [
"arduino",
"cmsis",
"mbed",
"stm32cube",
"libopencm3",
"zephyr"
],
"name": "ST Nucleo L432KC",
"upload": {
"maximum_ram_size": 65536,
"maximum_size": 262144,
"protocol": "stlink",
"protocols": [
"jlink",
"cmsis-dap",
"stlink",
"blackmagic",
"mbed"
]
},
"url": "https://developer.mbed.org/platforms/ST-Nucleo-L432KC/",
"vendor": "ST"
}
Now with the .ini looking like this:
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:nucleo_l432kc]
platform = ststm32
board = genericSTM32L431KC
framework = arduino
; debug_build_flags = -Os -ggdb2 -g2
The code runs just fine.
My question is: Why is the core for this particular board not specified?
To me it doesnt look like this has anything to with me using a slightly different MCU but i could be wrong.
PS: I also looked at this post and saw some similarities: Nucleo L432KC can't upload nor debug