From 29c2c88c7148e0f34301d3e014bf9a133dae46f0 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth <wolfgang.hottgenroth@icloud.com> Date: Tue, 20 Feb 2024 12:50:23 +0100 Subject: [PATCH] initial --- Makefile | 41 ++++++++++++++++++++++++++++++ main.S | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 Makefile create mode 100644 main.S diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..549d950 --- /dev/null +++ b/Makefile @@ -0,0 +1,41 @@ +TOOLCHAIN_PREFIX=/opt/msp430-gcc +CC=$(TOOLCHAIN_PREFIX)/bin/msp430-elf-gcc + +# regular +MCU=msp430g2553 +COMMON=-Wall -mmcu=$(MCU) -std=gnu99 -I $(TOOLCHAIN_PREFIX)/include -Os -g0 +CFLAGS=$(COMMON) +ASFLAGS=$(COMMON) + +LDFLAGS=-L $(TOOLCHAIN_PREFIX)/include -Wl,-Map,firmware.map -nostdlib -nostartfiles -T $(MCU).ld + +firmware.elf: main.o + $(CC) -o $@ $(LDFLAGS) $^ + +.c.o: + $(CC) $(CFLAGS) -c $< + +.S.o: + $(CC) $(ASFLAGS) -c $< + + +.PHONY: all +all: firmware.elf + +.PHONY: clean +clean: + -rm -f *.o *.elf *.map + +.PHONY: upload +upload: firmware.elf + mspdebug rf2500 "prog firmware.elf" + +.PHONY: debug +debug: upload + mspdebug rf2500 gdb & + ddd --debugger "msp430-gdb -x firmware.gdb" + + + + +# /opt/msp430-gcc/bin/msp430-elf-gcc main.S -D_GNU_ASSEMBLER_ -Wall -Os -g -fdata-sections -ffunction-sections -mmcu=msp430g2553 -T /opt/msp430-gcc/include/msp430g2553.ld -I /opt/msp430-gcc/include/ -L /opt/msp430-gcc/include/ -nostdli diff --git a/main.S b/main.S new file mode 100644 index 0000000..50084f4 --- /dev/null +++ b/main.S @@ -0,0 +1,76 @@ + .file "main.S" + +#include <msp430g2553.h> + + +#define PC r0 +#define SP r1 +#define SR r2 + + + ;; .text is the name of the section, it is a hint for the linker to + ;; allocate the section + ;; ax: a means allocatable by linker, x means executable + ;; @progbits is a hint for the linker to allocate this section into + ;; program memory (flash) + .section ".text","ax",@progbits + +_start: + ;; disable watchdog + mov.w #WDTPW|WDTHOLD,&WDTCTL + + ;; configure clock system to the highest frequency + mov.b #DCO0|DCO1|DCO2,&DCOCTL + mov.b #XT2OFF|RSEL0|RSEL1|RSEL2|RSEL3,&BCSCTL1 + mov.b #0,&BCSCTL2 + mov.b #0,&BCSCTL3 + + ;; initialize stack pointer with value from linker + mov.w #__stack, SP + +init: + ;; configuration of GPIO Port1, use Bit6 as TA0.1 + mov.b #BIT6,&P1DIR + mov.b #BIT6,&P1SEL + + ;; timer configuration + ;; configure and stop timer + ;; cycle time is 56.25ns + mov.w #ID_0|MC_0|TACLR|TASSEL_2,&TACTL + ;; 2.0us + mov.w #45,&TACCR0 + ;; a bit less + mov.w #16,&TACCR1 + ;; configure output mode for TA0.1 +; mov.w #CCIE,&TACCTL0 +; mov.w #CCIE,&TACCTL1 + mov.w #OUTMOD_7,&TACCTL1 + ;; start timer in up mode + bis.w #MC0,&TACTL + + ;; enable interrupts + eint + +mainloop: + jmp mainloop + +; --- timer isr --- +;timer0_a0_isr: +; mov.b #BIT0,&P1OUT +; reti + +;timer0_a1_isr: +; mov.b #0,&P1OUT +; reti + +; --- interrupt vectors --- +; .section "__interrupt_vector_9","ax",@progbits +; .word timer0_a1_isr +; .section "__interrupt_vector_10","ax",@progbits +; .word timer0_a0_isr + + ;; .resetvec comes from linker + .section ".resetvec","ax",@progbits + .word _start + + .end