HA! Success.
Should have read the freaking manual better.
What I’ve done:
- replace the ancient 4.6.3 toolchain from GCC toolchain for MSP430 download | SourceForge.net by the one that superseeds it, created by TI, at MSP430-GCC-OPENSOURCE IDE, configuration, compiler or debugger | TI.com, which is at version 9.3.1 – a gigantic leap forward
- fixup compiler tool names… the old toolchain had
msp430-gcc
, but the new toolchain names itmsp430-elf-gcc
… code here needs to be changed. - read the freaking manual to see that the user does not have to manually use another linker script or write the code differently to put things in low or highrom…
- add
-mlarge
to both thebuild_flags
(during compilation of c files to object files) and to the final linker command. Otherwise the linker will choose the small datamodel and saymain.o uses the large data model whereas [..]/msp430-elf/lib/crt0.o uses the small data mode
. Changing the linker flags has to be done in themain.py
builder script file though…
And when I again use the code
#include <string.h>
#include <stdio.h>
/* https://gcc.gnu.org/onlinedocs/gcc-3.2/gcc/Variable-Attributes.html */
#define HIROM_FUNC __attribute__ ((section (".upper.text")))
#define HIROM_CONST_DATA __attribute__ ((section (".upper.rodata")))
/* create test function in HIROM */
int HIROM_FUNC my_function_in_hirom(int a, int b) {
printf("Entry params: %d, %b\n", a, b);
return a + b;
}
/* place constant in HIROM */
/* volatile only to turn off compiler optimizations */
volatile const int constant_in_hirom HIROM_CONST_DATA = 123;
int main() {
my_function_in_hirom(1,2);
printf("Constant test: %d\n", constant_in_hirom);
return 0;
}
and compile it, the compilation log is
msp430-elf-g++ -o .pio\build\lpmsp430f5529\src\main.o -c -fno-exceptions -fno-threadsafe-statics -ffunction-sections -fdata-sections -mmcu=msp430f5529 -mlarge -DF_CPU=25000000L -DPLATFORMIO=50200 -DENERGIA_ARCH_MSP430 -DENERGIA_MSP_EXP430F5529LP -Iinclude -Isrc src\main.cpp
msp430-elf-gcc -o .pio\build\lpmsp430f5529\firmware.elf -mmcu=msp430f5529 -Wl,-gc-sections,-u,main -mlarge .pio\build\lpmsp430f5529\src\main.o -L.pio\build\lpmsp430f5529 -Wl,--start-group -lm -Wl,--end-group
MethodWrapper(["checkprogsize"], [".pio\build\lpmsp430f5529\firmware.elf"])
msp430-elf-objcopy -O ihex -R .eeprom .pio\build\lpmsp430f5529\firmware.elf .pio\build\lpmsp430f5529\firmware.hex
=========================== [SUCCESS] Took 2.19 seconds ===========================
So it can successfully use the large data model. I can also check that the functions and constants have been indeed placed in HIROM starting at 0x10000, by using nm
to see the address of the symbols.
> C:\Users\Max\.platformio\packages\toolchain-timsp430\bin\msp430-elf-nm .\.pio\build\lpmsp430f5529\firmware.elf
00010000 D constant_in_hirom
00010002 T _Z20my_function_in_hiromii
So the function and the constant really lives in HIROM now.
Of course I can also just leave the explicit placement out and let the compiler put stuff automatically in the required regions. They’ll be placed in low rom of course then since there’s still lots of space left.
Long story short: I’ll quickly publish the changes to the platform code, and then should just need to use a different
platform = <link to fixed platform repo>
and platform_packages
for the newer compiler in the platformio.ini
, and it should work.