platform-ststm32: Code appears to upload but does not run on STM32 Nucleo L476RG
I recently updated VScode on my mac and since then any code upload onto my Nucleo L476RG appears to upload (the indicator light flashes red and green when uploading), but the code doesn’t run; anything I try to output to the serial port doesn’t show up, and a test code I created to blink the built-in LED doesn’t work either. I’ve tried changing the upload protocol, reverting back to the old version of VScode, even reverting back to an older version of the C++ extension on VScode, but nothing works. My friend can run everything exactly the same on a PC with no issues, which makes me think this is a mac problem; I’m just not sure what went wrong.
Test code:
// Start program
#include <Arduino.h>
#include <PrintStream.h>
void setup()
{
pinMode(LED_BUILTIN,OUTPUT);
digitalWrite(LED_BUILTIN,HIGH);
// Open serial port
Serial.begin(115200);
//Wait for connection to be set up
delay(1000);
// Intro Output
uint16_t class_num = 507;
Serial << endl << "Starting Program";
Serial << endl << "Class: ME " << class_num << endl;
pinMode(LED_BUILTIN,OUTPUT);
digitalWrite(LED_BUILTIN,HIGH);
}
void loop()
{
Serial.print(" - ");
digitalWrite(LED_BUILTIN,HIGH);
delay(1000);
digitalWrite(LED_BUILTIN,LOW);
delay(1000);
}
Platformio.ini:
; 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_l476rg]
platform = ststm32
board = nucleo_l476rg
framework = arduino
;bits per second from mC to computer to make sure they are the same frequency- otherwise file downloads will not work
monitor_speed = 115200
upload_protocol = stlink
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 23 (10 by maintainers)
@maxgerhardt I think “build_upload.maximum_ram_size” has a typo or something wrong. There’s an error message in the TERMINAL:
Ohh I possibly know why it all broke.
You see the LD script
https://github.com/stm32duino/Arduino_Core_STM32/blob/03052da8712de2e2f48b0460da079ff3c50e3fb0/variants/STM32L4xx/L475R(C-E-G)T_L476R(C-E-G)T_L486RGT/ldscript.ld#L37-L43
has two RAM regions. PlatformIO substitutes for
LD_MAX_DATA_SIZEthe value of the whole RAM,https://github.com/platformio/platform-ststm32/blob/62cae8a55ccb48ed06bc2edc87ca25f9350399c9/boards/nucleo_l476rg.json#L36-L36
and not just the length of the first RAM bank (which is 96KB and not 128KB).
Thus the stack pointer is intialized wrongly in a section of RAM that does not exist
https://github.com/stm32duino/Arduino_Core_STM32/blob/03052da8712de2e2f48b0460da079ff3c50e3fb0/variants/STM32L4xx/L475R(C-E-G)T_L476R(C-E-G)T_L486RGT/ldscript.ld#L32-L32
https://github.com/stm32duino/Arduino_Core_STM32/blob/03052da8712de2e2f48b0460da079ff3c50e3fb0/tools/platformio/platformio-build.py#L343-L344
and this instantly crashes on anything that needs stack, e.g. pushing registers to the stack.
Does it magically work if you add
at the end of the
platformio.iniwhen using the 14.0.0 platform?@valeros possible very critical bug due to a change in STM32Duino linker scripts, breaking all dual-RAM bank boards.
EDIT: Replaced wrong
build_..withboard_..in.ini.I have similar problem. And it’s my simple steps to reproduce and workaround below:
Versions: Windows 10 Pro ststm32: 14.0.0 PlatformIO IDE: 2.3.2 VSCode: 1.57.0 stm32duino: most current? I can’t find where I can see the version of this C/C++ VScode extension: 1.4.1