Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for GCC9.3 on MSP430. Fixes #9. #10

Merged
merged 12 commits into from
Dec 29, 2024
1,021 changes: 1,021 additions & 0 deletions LICENSE.txt

Large diffs are not rendered by default.

74 changes: 74 additions & 0 deletions README-Migrating_from_GCC_4_to_9.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Migrating to the GCC9.3 Compiler for MSP430

A new platform core, "msp430gcc9", is now available for MSP430 LaunchPads. This new core uses GCC version 9.3, which was released in 2020. It is the latest MSP430 GCC compiler published by Texas Instruments.

The existing platform core, "msp430", includes GCC version 4.6, which was released in 2012.

While many sketches and libraries will compile and run the same without any changes, there are some cases where the code needs to be updated for proper compilation and operation.

A new platform name was used so that both can be installed by the Arduino boards manager at the same time. The new compiler can be used where the newer features are needed, but the old compiler can still be readily accessed when needed for compatibility reasons.

## Features in GCC 9.3 Compared to 4.6

For a full list of changes, see the GCC [release history][gcc-releases] and C++ Standards Support [summary][gcc-standards].

Probably the most impacting changes with the new compiler is support for C++11 and C++14 by default. C++17 is supported, but is not enabled by default.

[gcc-standards]: https://gcc.gnu.org/projects/cxx-status.html
[gcc-releases]: https://gcc.gnu.org/releases.html

## Issues With Using the New Compiler

I compiled all of my libraries and sketches with the new compiler. While most compiled without issue, I ran into a few problems as listed below.

### Program Size

In all the cases that I tested, sketches compiled with GCC 9.3 were larger, both in flash and RAM usage. The amount varied from sketch to sketch, and I did not notice any particular pattern in what caused the increases.

The default compiler options for the platform selects optimization level `-Os` which optimizes for space rather than speed. So there probably aren't any compiler configuration changes that would reduce the code size.

For the sketches that went over the available flash or RAM limit, I downgraded back to the GCC 4.6 compiler.

### Integer to Text Conversion Functions

The integer to text conversion functions `itoa()`, `ltoa()`, `utoa()`, and `ultoa()` are non-standard C++ functions, but included in the MSP platform cores. The function prototypes were previously included in the GCC 4.6 `stdlib.h` header, but are not included in the GCC 9.3 headers. If your sketch or library are using these functions, you will see an error similar to the following when compiling:

```text
/Users/user1/Documents/repos/file.cpp: In member function 'bool class1::f1(uint32_t)':
/Users/user1/Documents/repos/file.cpp:119:3: error: 'ultoa' was not declared in this scope; did you mean 'utoa'?
119 | ultoa(i, payload, 10);
| ^~~~~
| utoa
```

To fix this, you will need to explicitly include the header file declaring these functions in any file that uses them:

```cpp
#include "itoa.h"
```

This change is backwards compatible with GCC 4.6.

### Type Conversions

There may be cases where an implicit type conversion was used by GCC 4.6, but is now flagged with an error with GCC 9.3.

One example were I saw this was with the `Serial.println()` method when passing a value of type `size_t`:

```cpp
Serial.println(strlen(cstring1));
```

Which caused the following error with GCC 9.3:

```text
error: call of overloaded 'println(size_t)' is ambiguous
```

In this case, an explicit caste to type `unsigned int` was needed:

```cpp
Serial.println((unsigned int) strlen(cstring1));
```

This change is backwards compatible with GCC 4.6.
113 changes: 92 additions & 21 deletions README.md

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions actions/compile_arduino_sketch-MSP430F5529-GCC9.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# From: https://github.com/marketplace/actions/compile-arduino-sketches
# Uses: https://github.com/arduino/compile-sketches
name: Arduino Compile Sketches

on:
push:

jobs:
compile-sketches:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
- uses: arduino/compile-sketches@v1
with:
fqbn: 'energia:msp430gcc9:MSP-EXP430F5529LP'
platforms: |
- name: 'energia:msp430gcc9'
version: 1.1.0
source-url: 'https://raw.githubusercontent.com/Andy4495/TI_Platform_Cores_For_Aduino/main/json/package_energia_minimal_msp430_index.json'
sketch-paths: |
- .
verbose: true
enable-warnings-report: true
libraries: |
- source-path: ./
Binary file added boards/msp430-3.0.0.tar.bz2
Binary file not shown.
45 changes: 45 additions & 0 deletions json/package_energia_minimal_msp430_index.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,37 @@
"online": "http://energia.nu/reference"
},
"platforms": [
{
"name": "Energia MSP430 boards (GCCv9)",
"architecture": "msp430gcc9",
"version": "3.0.0",
"category": "Energia",
"url": "https://github.com/Andy4495/TI_Platform_Cores_For_Arduino/raw/main/boards/msp430-3.0.0.tar.bz2",
"archiveFileName": "msp430-3.0.0.tar.bz2",
"checksum": "SHA-256:5d0b72a45af738164af2e7b989eb058fd2529f6f3c0a5c3f7f22200b1c12bc86",
"size": "2206716",
"boards": [
{"name": "MSP-EXP430F5529"},
{"name": "MSP-EXP430FR2433"},
{"name": "MSP-EXP430FR4133"},
{"name": "MSP-EXP430FR5969"},
{"name": "MSP-EXP430FR6989"},
{"name": "MSP-EXP430FR5739"},
{"name": "MSP-EXP430FR2355"},
{"name": "MSP-EXP430FR2231"},
{"name": "MSP-EXP430G2"},
{"name": "MSP-EXP430G2ET"},
{"name": "MSP-EXP430FR5994"}
],
"toolsDependencies": [
{

"packager":"energia",
"name":"msp430-elf-gcc",
"version":"9.3.1.11"
}
]
},
{
"name": "Energia MSP430 boards",
"architecture": "msp430",
Expand Down Expand Up @@ -42,6 +73,19 @@
}
],
"tools": [
{
"name": "msp430-elf-gcc",
"version": "9.3.1.11",
"systems": [
{
"url": "https://github.com/Andy4495/TI_Platform_Cores_For_Arduino/releases/download/v1.3.0/msp430-elf-gcc-9.3.1.11_linux64.tar.bz2",
"checksum": "SHA-256:070d277bb0f5c07826f2fcf77204d442397dc98558ec7ce03a7bf35baaaaa65d",
"host": "x86_64-pc-linux-gnu",
"archiveFileName": "msp430-elf-gcc-9.3.1.11_linux64.tar.bz2",
"size": "77364170"
}
]
},
{
"name":"msp430-gcc",
"version":"4.6.6",
Expand All @@ -60,3 +104,4 @@
}
]
}

108 changes: 103 additions & 5 deletions json/package_energia_optimized_index.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,56 @@
"packages": [
{
"name": "energia",
"maintainer": "Energia",
"websiteURL": "http://www.energia.nu/",
"email": "[email protected]",
"maintainer": "Andy4495",
"websiteURL": "https://github.com/Andy4495/TI_Platform_Cores_For_Arduino",
"email": "Submit issue on GitHub",
"help": {
"online": "http://energia.nu/reference"
},
"platforms": [
{
"name": "Energia MSP430 boards (GCCv9)",
"architecture": "msp430gcc9",
"version": "3.0.0",
"category": "Energia",
"url": "https://github.com/Andy4495/TI_Platform_Cores_For_Arduino/raw/main/boards/msp430-3.0.0.tar.bz2",
"archiveFileName": "msp430-3.0.0.tar.bz2",
"checksum": "SHA-256:c919d1c33f2a7d672005bf4a12e215024ebd21590315b3585fd7fd1edd3a5740",
"size": "2205965",
"boards": [
{"name": "MSP-EXP430F5529"},
{"name": "MSP-EXP430FR2433"},
{"name": "MSP-EXP430FR4133"},
{"name": "MSP-EXP430FR5969"},
{"name": "MSP-EXP430FR6989"},
{"name": "MSP-EXP430FR5739"},
{"name": "MSP-EXP430FR2355"},
{"name": "MSP-EXP430FR2311"},
{"name": "MSP-EXP430G2"},
{"name": "MSP-EXP430G2ET"},
{"name": "MSP-EXP430FR5994"},
{"name": "MSP-EXP430FR2476"},
{"name": "MSP-EXP430FR5739"}
],
"toolsDependencies": [
{

"packager":"energia",
"name":"msp430-elf-gcc",
"version":"9.3.1.11"
},
{
"packager":"energia",
"name":"dslite",
"version":"12.8.0.3522"
},
{
"packager":"energia",
"name":"mspdebug",
"version":"0.25"
}
]
},
{
"name": "Energia MSP430 boards",
"architecture": "msp430",
Expand All @@ -26,7 +69,7 @@
{"name": "MSP-EXP430FR6989"},
{"name": "MSP-EXP430FR5739"},
{"name": "MSP-EXP430FR2355"},
{"name": "MSP-EXP430FR2231"},
{"name": "MSP-EXP430FR2311"},
{"name": "MSP-EXP430G2"},
{"name": "MSP-EXP430G2ET"},
{"name": "MSP-EXP430FR5994"}
Expand All @@ -46,7 +89,7 @@
{
"packager":"energia",
"name":"mspdebug",
"version":"0.24"
"version":"0.25"
}
]
},
Expand Down Expand Up @@ -397,6 +440,33 @@
}
],
"tools": [
{
"name": "msp430-elf-gcc",
"version": "9.3.1.11",
"systems": [
{
"url": "https://github.com/Andy4495/TI_Platform_Cores_For_Arduino/releases/download/v1.3.0/msp430-gcc-9.3.1.11_win64.zip",
"checksum": "SHA-256:1D087B7F19B9A69214E83C9671DCEB5B5D261287807C8E55CD523FFD57016F29",
"host": "i686-mingw32",
"archiveFileName": "msp430-elf-gcc-9.3.1.11_win32.tar.bz2",
"size": "114591102"
},
{
"url": "https://github.com/Andy4495/TI_Platform_Cores_For_Arduino/releases/download/v1.3.0/msp430-elf-gcc-9.3.1.11_macos.tar.bz2",
"checksum": "SHA-256:b87248f2a135b8b21a85f97b48befd8dbee86023226c8e05026c9832e6279926",
"host": "x86_64-apple-darwin",
"archiveFileName": "msp430-elf-gcc-9.3.1.11_macos.tar.bz2",
"size": "93455401"
},
{
"url": "https://github.com/Andy4495/TI_Platform_Cores_For_Arduino/releases/download/v1.3.0/msp430-elf-gcc-9.3.1.11_linux64.tar.bz2",
"checksum": "SHA-256:070d277bb0f5c07826f2fcf77204d442397dc98558ec7ce03a7bf35baaaaa65d",
"host": "x86_64-pc-linux-gnu",
"archiveFileName": "msp430-elf-gcc-9.3.1.11_linux64.tar.bz2",
"size": "77364170"
}
]
},
{
"name":"msp430-gcc",
"version":"4.6.6",
Expand Down Expand Up @@ -786,6 +856,34 @@
}
]
},
{
"name":"mspdebug",
"version":"0.25",
"systems":
[
{
"host":"i686-mingw32",
"url":"https://s3.amazonaws.com/energiaUS/tools/windows/mspdebug-0.24-i686-mingw32.tar.bz2",
"archiveFileName":"mspdebug-0.24-i686-mingw32.tar.bz2",
"checksum":"SHA-256:7b3dfb269b58f692d03080a641f543dfe01bcfcef43935c2bb31e2839e284e73",
"size":"1058435"
},
{
"host":"x86_64-apple-darwin",
"url":"https://github.com/Andy4495/TI_Platform_Cores_For_Arduino/releases/download/v1.3.0/mspdebug-0.25-x86_64-apple-darwin.tar.bz2",
"archiveFileName":"mspdebug-0.25-x86_64-apple-darwin.tar.bz2",
"checksum":"SHA-256:61b4a8faebe60b602794335fb614c80c1ad51ceefd306333188fd476ba8cd087",
"size":"161394"
},
{
"host":"x86_64-pc-linux-gnu",
"url":"https://s3.amazonaws.com/energiaUS/tools/linux64/mspdebug-0.24-i386-x86_64-pc-linux-gnu.tar.bz2",
"archiveFileName":"mspdebug-0.24-i386-x86_64-pc-linux-gnu.tar.bz2",
"checksum":"SHA-256:ec6131053a4ddd35b43d44591732313182e3487ffd77181df02ce23f0860a2e5",
"size":"147947"
}
]
},
{
"name":"cc3200prog",
"version":"1.1.4",
Expand Down
66 changes: 66 additions & 0 deletions tools/generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/zsh

# Tool to create processor core and tools archives for use by Arduino Board Manager
# Tars and compresses a directory tree, calculates SHA-256 checksum and file size

# 1. Get location of current archive (.tar.bz2 file) to use as starting point
# - Or skip this step if you want to archive an existing directory tree
# 2. Get name of directory to use as the top-level archive directory
# 3. Pause to let user to update directory tree as needed
# 4. Clean out unnecessary artifacts
# - MacOS ".DS_Store" or "._" files
# - Arduino "installed.json" file
# 5. Tar and compress (bz2) directory
# 6. Calculate and save filesize and sha-256 checksum in file "size-and-checksum.txt"

print "This script should be run from the directory where the archive will be created."
print "Do you want to uncompress an archive file or work on an existing directory [u/e]?"
read answer
if [[ $answer == "u" ]]
then
print "Enter path of archive to decompress: "
read archive_name
if [ ! -f $archive_name ]
then
echo "File not found: $archive_name"
exit 1
fi
tar xvf $archive_name
elif [[ $answer != "e" ]]
then
echo "Invalid reponse. Exiting."
exit 1
fi

print "Enter directory to archive: "
read directory_name
if [[ ! -d $directory_name ]]
then
echo "Directory not found: $directory_name"
exit 1
fi

print "Enter new archive name. It should end with .tar.bz2"
print "Example names are: msp430-3.0.0.tar.bz2, msp430-elf-gcc-8.3.0.16_macos.tar.bz2, msp430-elf-gcc-8.3.0.16_linux64.tar.bz2"
read new_archive_name

print "Update directory tree as needed and press Enter to continue:"
read wait_to_continue

print "Deleting MacOS Finder artifacts"
find $directory_name -name '.DS_Store' -type f -print -exec rm {} \;
find $directory_name -name '._*' -type f -print -exec rm {} \;
print "Deleting 'installed.json' Arduino artifact if necessary"
rm -f $directory_name/installed.json

print "Creating new archive"
tar cvjf $new_archive_name $directory_name

print "Calculate size and SHA-256 checksum and saving to file 'size_and_checksum.txt'"
ls -l $new_archive_name | awk '{print $5}' | read archive_size
shasum -a 256 $new_archive_name | awk '{print $1}' | read archive_shasum

print "$new_archive_name size (bytes): $archive_size" > size_and_checksum.txt
print "$new_archive_name checksum (SHA256): $archive_shasum" >> size_and_checksum.txt
cat size_and_checksum.txt

Loading