PlatformIO Community

MSP430 compile for debug bad -O option

I just did a fresh install of PlatformIO and created a very simple project for MSP430.

First problem: using that simple “blink” sample, compilation in release mode works fine, including upload to board without any error message. But the board does not blink ! Any idea what could happen here?

Next I tried to debug. But here compilation fails, because msp430-g++ is executed with option “-Og”.
Error is: argument to ‘-O’ should be a non-negative integer
Compiler command line is shown by executing “pio run -v -t debug” in terminal.
I tried setting “build-flags = -O1”, but is not respected, while other options on build-flags are passed to the compiler.

Thanks for any hints.
Joerg

For which exact board are you compiling the project from the available targets? Which board do you have? When you follow the definitition of RED_LED from the main.cpp, what is it defined as?

You meant build_flags there?

can you upload the log of pio run -v -t debug? Because as seen here

Flags should be -O0 -g3 -ggdb -gdwarf-2, not containing -Og. Have you updated all your platforms using pio platform update?

Thanks for quick response.

The board is MSP-EXP430G2 Rev 1.4
The MCU is MSP430G2231

I selected the following board: TI LaunchPad MSP-EXP430G2 w/ MSP430G2231

platform.ini is

[env:lpmsp430g2231]
platform = timsp430
board = lpmsp430g2231
framework = arduino

build_flags = -O1

Ok. I ran the update again, but seems everything was up-to-date. And also attached output from debug compile:

PS C:\Work\msp430p1> pio platform update
Platform Espressif 32
--------
Updating espressif32                     @ 1.11.1         [Up-to-date]
Updating toolchain-xtensa32              @ 2.50200.80     [Up-to-date]
Updating tool-esptoolpy                  @ 1.20600.0      [Up-to-date]

Platform TI MSP430
--------
Updating timsp430                        @ 2.2.0          [Up-to-date]
Updating toolchain-timsp430              @ 1.40603.190926 [Up-to-date]
Updating framework-energiamsp430         @ 1.10807.190926 [Up-to-date]
Updating tool-mspdebug                   @ 1.2400.190926  [Up-to-date]
Updating tool-dslite                     @ 1.80200.1400   [Up-to-date]

PS C:\Work\msp430p1> pio run -v -t debug
Processing lpmsp430g2231 (platform: timsp430; board: lpmsp430g2231; framework: arduino; build_flags: -O1)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------CONFIGURATION: https://docs.platformio.org/page/boards/timsp430/lpmsp430g2231.html
PLATFORM: TI MSP430 2.2.0 > TI LaunchPad MSP-EXP430G2 w/ MSP430G2231
HARDWARE: MSP430G2231 1MHz, 256B RAM, 2KB Flash
DEBUG: Current (mspdebug) On-board (mspdebug)
PACKAGES: toolchain-timsp430 1.40603.190926 (4.6.3), framework-energiamsp430 1.10807.190926 (1.8.7)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 18 compatible libraries
Scanning dependencies...
No dependencies
Building in debug mode
msp430-g++ -o .pio\build\lpmsp430g2231\src\main.cpp.o -c -fno-exceptions -fno-threadsafe-statics -ffunction-sections -fdata-sections -mmcu=msp430g2231 -Og -g2 -ggdb2 -DF_CPU=1000000L -DPLATFORMIO=40100 -DENERGIA_ARCH_MSP430 -DENERGIA_MSP_EXP430G2231LP -DARDUINO=10807 -DENERGIA=10807 -D__PLATFORMIO_BUILD_DEBUG__ -Iinclude -Isrc -IC:\users\j***\.platformio\packages\framework-energiamsp430\cores\msp430 -IC:\users\j***\.platformio\packages\framework-energiamsp430\variants\MSP-EXP430G2231LP -IC:\users\j***\.platformio\packages\toolchain-timsp430\msp430\include src\main.cpp
cc1plus.exe: error: argument to '-O' should be a non-negative integer
msp430-g++ -o .pio\build\lpmsp430g2231\FrameworkEnergia\HardwareSerial.cpp.o -c -fno-exceptions -fno-threadsafe-statics -ffunction-sections -fdata-sections -mmcu=msp430g2231 -Og -g2 -ggdb2 -DF_CPU=1000000L -DPLATFORMIO=40100 -DENERGIA_ARCH_MSP430 -DENERGIA_MSP_EXP430G2231LP -DARDUINO=10807 -DENERGIA=10807 -D__PLATFORMIO_BUILD_DEBUG__*** [.pio\build\lpmsp430g2231\src\main.cpp.o] Error 1
 -Icc1plus.exe: error: argument to '-O' should be a non-negative integer
C:\users\j***\.platformio\cc1plus.exe: error: argument to '-O' should be a non-negative integer
pac*** [.pio\build\lpmsp430g2231\FrameworkEnergia\HardwareSerial.cpp.o] Error 1
kag*** [.pio\build\lpmsp430g2231\FrameworkEnergia\IPAddress.cpp.o] Error 1
es\framework-energiamsp430\cores\msp430 -IC:\users\j***\.placc1plus.exe: error: argument to '-O' should be a non-negative integer
tformio\packages\framework-energiamsp430\variants\MSP-EXP430G2231LP -IC:\users\j***\.platformio\packages\toolchain-timsp430\msp430\include C:\users\j*** [.pio\build\lpmsp430g2231\FrameworkEnergia\MACAddress.cpp.o] Error 1
***\.platformio\packages\framework-energiamsp430\cores\msp430\HardwareSerial.cpp
msp430-g++ -o .pio\build\lpmsp430g2231\FrameworkEnergia\IPAddress.cpp.o -c -fno-exceptions -fno-threadsafe-statics -ffunction-sections -fdata-sections -mmcu=msp430g2231 -Og -g2 -ggdb2 -DF_CPU=1000000L 
-DPLATFORMIO=40100 -DENERGIA_ARCH_MSP430 -DENERGIA_MSP_EXP430G2231LP -DARDUINO=10807 -DENERGIA=10807 -D__PLATFORMIO_BUILD_DEBUG__ -IC:\users\j***\.platformio\packages\framework-energiamsp430\cores\msp430 -IC:\users\j***\.platformio\packages\framework-energiamsp430\variants\MSP-EXP430G2231LP -IC:\users\j***\.platformio\packages\toolchain-timsp430\msp430\include C:\users\j***\.platformio\packages\framework-energiamsp430\cores\msp430\IPAddress.cpp
msp430-g++ -o .pio\build\lpmsp430g2231\FrameworkEnergia\MACAddress.cpp.o -c -fno-exceptions -fno-threadsafe-statics -ffunction-sections -fdata-sections -mmcu=msp430g2231 -Og -g2 -ggdb2 -DF_CPU=1000000L -DPLATFORMIO=40100 -DENERGIA_ARCH_MSP430 -DENERGIA_MSP_EXP430G2231LP -DARDUINO=10807 -DENERGIA=10807 -D__PLATFORMIO_BUILD_DEBUG__ -IC:\users\j***\.platformio\packages\framework-energiamsp430\cores\msp430 -IC:\users\j***\.platformio\packages\framework-energiamsp430\variants\MSP-EXP430G2231LP -IC:\users\j***\.platformio\packages\toolchain-timsp430\msp430\include C:\users\j***\.platformio\packages\framework-energiamsp430\cores\msp430\MACAddress.cpp
====================================================================================== [FAILED] Took 4.53 seconds ======================================================================================
PS C:\Work\msp430p1> 

C:\Users\j***.platformio\platforms\timsp430\builder\main.py is as you expected at line 37: PIODEBUGFLAGS=["-O0", “-g3”, “-ggdb”, “-gdwarf-2”],

When searching for “-Og” I found this in the following file line 324:
.platformio/penv/Lib/site-packages/platformio/builder/tools/piomisc.py
debug_flags = ["-Og", "-g2", "-ggdb2"]

Regarding RED_LED, here is what VSCode editor says:
from pins_energia.h and Energia.h:
static const uint8_t RED_LED = 2;
digital_pin_to_port[2] = P1
digital_pin_to_bit_mask[2] = BV(0)
P1 = 1
BV(0) = 1 << 0 = 1

According to the board imprint the red LED is in port 1.0. This seems to match the above definitions.
It had the original firmware just before I flashed the new sketch using PlatformIO. With this original firmware the two LEDs were indeed blinking.

So since these are the exact flags used in the complation command, it seems to be an error in PlatformI Othat it doesn’t use the PIODEBUGFLAGS correctly. When replacing these debug_flags with the corrent ones (["-O0", “-g3”, “-ggdb”, “-gdwarf-2”]), do you get further in the debugging process?

So this is actually looking good as you said. Just for completenes’ sake, can you show the exact code you’re running? Maybe change the pin number so that it mapts to a different GPIO and test it with a multimeter or LED?

I think either the microcontroller isn’t starting up correctly (clock source wrong or whatever) or it toggles the wrong pin.

We fixed this in the latest PIO Core 4.1.1. You can control debug_build_flags separately.

  1. Open VSCode terminal and type pio upgrade --dev
  2. See https://docs.platformio.org/en/latest/projectconf/section_env_debug.html#debug-build-flags

Hurray, release mode is working now.
At least big part of reason was, VSCode had a whole different file in the editor window, also named main.cpp, but which was not even member of the current workspace, ie I was never modifying the file that was being compiled. Sorry for the confusion. I only noticed that after running into the following problems which led me to setting up a new workspace from scratch first.

Regarding debug compilation I followed your suggestion and changed the piomisc.py file. Compilation uses these options. Debug starts up, however I run into next error:

Processing lpmsp430g2231 (platform: timsp430; board: lpmsp430g2231; framework: arduino)
--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/timsp430/lpmsp430g2231.html
PLATFORM: TI MSP430 2.2.0 > TI LaunchPad MSP-EXP430G2 w/ MSP430G2231
HARDWARE: MSP430G2231 1MHz, 256B RAM, 2KB Flash
DEBUG: Current (mspdebug) On-board (mspdebug)
PACKAGES: toolchain-timsp430 1.40603.190926 (4.6.3), framework-energiamsp430 1.10807.190926 (1.8.7)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 18 compatible libraries
Scanning dependencies...
No dependencies
Building in debug mode
Checking size .pio\build\lpmsp430g2231\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
DATA:    [=         ]   7.8% (used 20 bytes from 256 bytes)
PROGRAM: [=======   ]  67.3% (used 1378 bytes from 2048 bytes)
========================= [SUCCESS] Took 4.65 seconds =========================
MSPDebug version 0.24 - debugging tool for MSP430 MCUs
Copyright (C) 2009-2016 Daniel Beer <dlbeer@gmail.com>
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
----------------- NOTE ------------------
Modified version of mspdebug for Energia
            Do not use standalone
-----------------------------------------
Chip info database from MSP430.dll v3.3.1.4 Copyright (C) 2013 TI, Inc.

Using new (SLAC460L+) API
MSP430_GetNumberOfUsbIfs
MSP430_GetNameOfUsbIf
Found FET: HID0062:COM5
MSP430_Initialize: HID0062:COM5
Firmware version is 20409001
MSP430_VCC: 3000 mV
Reading symbols from c:\Work\msp430p2\.pio\build\lpmsp430g2231\firmware.elf...
done.
PlatformIO Unified Debugger -> http://bit.ly/pio-debug
PlatformIO: debug_tool = mspdebug
PlatformIO: Initializing remote target...
MSP430_OpenDevice
MSP430_GetFoundDevice
Device: F20x2_G2x2x_G2x3x (id = 0x0035)
2 breakpoints available
MSP430_EEM_Init
Chip ID data:
  ver_id:         01f2
  ver_sub_id:     0000
  revision:       30
  fab:            40
  self:           0000
  config:         02
Device: F20x2_G2x2x_G2x3x
Bound to port 2000. Now waiting for connection...
.pioinit:11: Error in sourced command file:
Remote register badly formatted: T0500:00f80000;01:74020000;02:00000000;03:00000000;04:ffcf0000;05:085a0000;06:fd1f0000;07:7dbf0000;08:4d020000;09:00000000;0a:780f0000;0b:484c0000;0c:09240000;0d:a6000000;0e:88020000;0f:00000000;
here: 0000;01:74020000;02:00000000;03:00000000;04:ffcf0000;05:085a0000;06:fd1f0000;07:7dbf0000;08:4d020000;09:00000000;0a:780f0000;0b:484c0000;0c:09240000;0d:a6000000;0e:88020000;0f:00000000;

I was also trying to get TimerSerial running, it somehow sets P1.2 into output mode but remains continuously low. I would expect to see some serial bit stream on the oscilloscope here.
Debugging this library is also not possible on the G2231 because the firmware would then not fit into the 2KB program memory.

Ok, I actually started this whole thing just an initial playground for the PlatformIO setup and got this old MSP430 board from my tool box. So I think, for myself would stop here and not follow this path any more. Hopefully I will be luckier with different kinds of controllers. Nevertheless, many thanks for your assistance.

Please file an issue here https://github.com/platformio/platform-timsp430/issues