開發板
接腳:
ST-Link V2 | STM8 |
---|---|
GND | GND |
3.3V | 3.3V |
RST | NRST |
SWIM | SWIM |
main.c
#define PB_ODR *(unsigned char*)0x5005 #define PB_IDR *(unsigned char*)0x5006 #define PB_DDR *(unsigned char*)0x5007 #define PB_CR1 *(unsigned char*)0x5008 #define PB_CR2 *(unsigned char*)0x5009 void main(void) { long cnt; PB_DDR = 0x20; PB_CR1 = 0x20; do { PB_ODR ^= 0x20; for (cnt = 0; cnt < 29000; cnt++); } while(1); }
Makefile
SDCC=sdcc SDLD=sdld OBJECTS=main.ihx .PHONY: all clean all: $(OBJECTS) clean: rm -f $(OBJECTS) %.ihx: %.c $(SDCC) -lstm8 -mstm8 --out-fmt-ihx $(CFLAGS) $(LDFLAGS) $<
編譯
$ make sdcc -lstm8 -mstm8 --out-fmt-ihx main.c
main.ihx
:048000008200800773 :1D800700AE00002707724F00005A26F9AE00002709D68023D700005A26F7CC800451 :03800400CC802409 :2080240052083520500735205008901A5005AE71484F0F051D00011F03A2006B027B05A24F :18804400006B017B016B051E037B02160326E5160127D720DF5B088112 :00000001FF
燒錄
$ tsudo stm8flash -c stlinkv2 -p stm8s103f3 -u $ tsudo stm8flash -c stlinkv2 -p stm8s103f3 -s flash -w main.ihx
完成