I wanted to experiment a little with Zig lang. And I saw that it has a MSP430 backend. So I set out to try and run some Zig on an MSP430. This is the journey to a minimal blink example to get started.
The experiment:
- Starting with a known good blink example in C (
./blink-c
).- Well, what can I say, it blinks.
- Create minimal blink example in assembly (
./blink-asm
).- Understand what is really required
by reading a) the manual
and b) the generated assembly from
blink-c
. - To get
C
out of the loop completely.
- Understand what is really required
by reading a) the manual
and b) the generated assembly from
- Try to replicate it with Zig (
./blink-zig
).- See Learnings.
- MSP430G2xxx User's Guide (really good!)
- includes msp430 register and assembly reference (nice!)
- includes what is required to boot (thanks!)
- MSP430G2x53 Datasheet
- To follow along:
- TI MSP430 LaunchPad Development Tool (
MSP-EXP430G2
) MSP430G2553
(included in LaunchPad Kit)
- TI MSP430 LaunchPad Development Tool (
- Basically usable for every MSP430, just adapt the build and run procedure.
mspdebug
(Debian/Ubuntu:sudo apt install mspdebug
) - to flash and debug the code on the chipmsp430-elf-*
MSP430-GCC-OPENSOURCE toolchain from TI (link)- "Mitto Systems GCC 64-bit Linux - toolchain only" -> extract into
repo-dir/msp430-gcc-9.3.1.11_linux64
(or change path in.env
) - "Header and Support Files" -> extract into
repo-dir/msp430-gcc-support-files
(or change path in.env
)
- "Mitto Systems GCC 64-bit Linux - toolchain only" -> extract into
First set up your terminal environment:
source .env
(Must be executed in the repo directory, in subfolders use cd .. && source .env && cd -
.)
Enter the subdirectory of choice, then:
- Build:
./build.sh
- Inspect:
./inspect.sh
(the generated assembly) - Run:
./run.sh
(then enterprog blink.o
andrun
)