~joshrig/blink-c

5a0bdf2e3f588b2447201b9c026bd74b604b594b — Joshua Lynch 4 years ago ac01127 master
initial import
4 files changed, 189 insertions(+), 0 deletions(-)

A blink.c
A flash.ld
A gdbinit
A makefile
A blink.c => blink.c +65 -0
@@ 0,0 1,65 @@
#include <inttypes.h>


#define STACK_TOP 0x20010000

extern uint32_t _DATA_ROM_START;
extern uint32_t _DATA_RAM_START;
extern uint32_t _DATA_RAM_END;
extern uint32_t _BSS_START;
extern uint32_t _BSS_END;


void startup(void);
int main(void);


void *vector_table[] __attribute__((section("vectors"))) = {
    (void *)STACK_TOP,
    (void *)startup
};


void startup(void)
{
    uint32_t *ram_start = &_DATA_RAM_START;
    uint32_t *ram_end   = &_DATA_RAM_END;
    uint32_t *rom_start = &_DATA_ROM_START;
    uint32_t *bss_start = &_BSS_START;
    uint32_t *bss_end   = &_BSS_END;
    
    while (ram_start != ram_end)
        *ram_start++ = *rom_start++;

    while (bss_start != bss_end)
        *bss_start++ = 0x0;

    main();

    while(1);
}


#define PORTC_DIR *((uint32_t *)0x41008100)
#define PORTC_OUT *((uint32_t *)0x41008110)


int main(void)
{
    uint8_t state = 0;


    PORTC_DIR = 1 << 18;

    while (1)
    {
        PORTC_OUT = state << 18;

        state = state ? 0 : 1;

        for (uint32_t j = 0; j < 1000000; j++);
    }
    
    
    return 0;
}

A flash.ld => flash.ld +40 -0
@@ 0,0 1,40 @@
/*
 * ATSAME54P20A linker script
 */

MEMORY
{
        flash (rx)  : ORIGIN = 0x00000000, LENGTH = 1024K
        ram   (rwx) : ORIGIN = 0x20000000, LENGTH = 256K
}        


SECTIONS
{
        .text :
        {
                *(vectors)
                *(.text)
        } >flash

        .rodata :
        {
                *(.rodata)
        } >flash
        
        _DATA_ROM_START = .;
        .data :
        {
                _DATA_RAM_START = .;
                *(.data)
                _DATA_RAM_END = .;
        } >ram AT>flash

        .bss :
        {
                _BSS_START = .;
                *(.bss)
                _BSS_END = .;
        } >ram
}
        

A gdbinit => gdbinit +18 -0
@@ 0,0 1,18 @@
set print pretty on
set target-async on

file blink.elf

define reset
       target extended-remote localhost:3333

       monitor reset

       load

       monitor reg sp 0x20010000
       monitor reg pc 0x00000000

       monitor reg

end
\ No newline at end of file

A makefile => makefile +66 -0
@@ 0,0 1,66 @@
# -*- makefile -*-
CC          = arm-none-eabi-gcc
LD          = arm-none-eabi-ld
AS          = arm-none-eabi-as
OBJCOPY     = arm-none-eabi-objcopy
OBJDUMP     = arm-none-eabi-objdump
SIZE        = arm-none-eabi-size

TARGET_ARCH = -mcpu=cortex-m4 -mthumb
CPPFLAGS    =
CFLAGS      = -g -O0
LDFLAGS     = -Tflash.ld

SRCS       := $(wildcard *.c)
OBJS        = $(SRCS:%.c=%.o)
DEPS        = $(SRCS:%.c=%.d)

TARGET      = blink
OUT_ELF     = $(TARGET).elf
OUT_BIN     = $(TARGET).bin
OUT_INFO    = $(TARGET).lss



.PHONY: all
all: $(OUT_ELF) $(OUT_BIN) $(OUT_INFO)


$(OUT_ELF): $(OBJS)
	$(LD) $(LDFLAGS) -o $@ $^

$(OUT_BIN): $(OUT_ELF)
	$(OBJCOPY) -O binary $^ $@

$(OUT_INFO): $(OUT_ELF)
	$(OBJDUMP) -Sh $^ > $@
	$(SIZE) $^

.PHONY: clean
clean:
	-rm -f $(OBJS) $(DEPS) $(TARGET) $(OUT_ELF) $(OUT_BIN) $(OUT_INFO) nul *.d.*



.PHONY: check-syntax
check-syntax:
	$(CC) $(CPPFLAGS) $(CFLAGS) -o nul -S $(CHK_SOURCES)


# standard commands for making a .d file
#
%.d: %.c
	@echo making dependency for $<
	@set -e; \
	rm -f %@; \
	$(CC) -MM $(CFLAGS) $(CPPFLAGS) $< > $@.$$$$; \
	sed 's/\($*\)\.o[ :]*/\1.o $@ : /g' < $@.$$$$ > $@; \
	rm -f $@.$$$$

# only include the dependency files (and thus restart make)
# if we're not running the clean or check-syntax goal
#
ifeq (,$(filter clean,$(MAKECMDGOALS))$(filter check-syntax,$(MAKECMDGOALS)))
 -include $(DEPS)
endif