an introduction
by Sergey Lyubka
for Dublin C/C++ User Group
(*) from the book by Milan Verle
i8008
i8080
(*) from the book by Milan Verle
Motorola 6800
Zilog Z80
MOS 6502
(*) from the book by Milan Verle
(*) from the book by Milan Verle
Microcontrollers
Arduino nano
(few peripherals)
STM32F429I
(tons of peripherals)
is our friend
.cpu cortex-m0
.thumb
.thumb_func
.global _start
_start:
stacktop: .word 0x20001000
.word reset
.word hang
.word hang
.word hang
.word hang
.thumb_func
reset:
bl main
b hang
.thumb_func
.globl hang
hang: b .
.align
.end
#define LED 13 // Blue LED
#define PORT 6
#define RCC ((volatile unsigned *) 0x40023800)
enum { AHB1ENR = 12 };
#define GPIO(port) ((volatile unsigned *) (0x40020000 + (port) *0x400))
#define GPIOG GPIO(PORT)
enum { MODER = 0, TYPER = 1, SPEEDR = 2, BSRR = 6, AFRL = 8, AFRH = 9 };
int main(void) {
RCC[AHB1ENR] |= 1 << PORT; // Enable clock on GPIOG
GPIOG[MODER] |= 1 << (LED * 2); // GPIO mode
GPIOG[SPEEDR] |= 1 << (LED * 2); // Medium speed
GPIOG[TYPER] &= ~(1 << LED); // Output push-pull
for (;;) {
GPIOG[BSRR] |= 1 << LED;
for (volatile unsigned int i = 0; i < 1 << 18;) i++;
GPIOG[BSRR] |= 1 << (16 + LED);
for (volatile unsigned int i = 0; i < 1 << 18;) i++;
}
return 0;
}
TARGET = blink
ARCH = arm-none-eabi
CFLAGS = -W -Wall -O2 -g -nostdlib -nostartfiles -ffreestanding -mcpu=cortex-m0 -mthumb
AFLAGS = --warn --fatal-warnings -mcpu=cortex-m0
OBJS = obj/bootstrap.o obj/main.o
all : $(TARGET).bin
$(TARGET).bin: $(TARGET).elf
$(ARCH)-objcopy -O binary $< $@
$(TARGET).elf: $(OBJS)
$(ARCH)-ld $^ -T link.ld -o $@
# $(ARCH)-objdump -D $@ > $(TARGET).lst
obj/%.o: %.c
@mkdir -p $(dir $@)
$(ARCH)-gcc $(CFLAGS) -c $< -o $@
obj/%.o: %.s
@mkdir -p $(dir $@)
$(ARCH)-as $(AFLAGS) $< -o $@
flash: $(TARGET).bin
st-flash write $< 0x8000000
clean:
@rm -rf *.{bin,elf,map,lst} obj *.tgz