commit bd8a3828d971d385ec812982b09033e31fda74a3 Author: rkcf Date: Fri Nov 17 13:41:47 2023 -0600 Add: initial (working) blinky light program diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..b9f738b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "lib/libopencm3"] + path = lib/libopencm3 + url = https://github.com/libopencm3/libopencm3 +[submodule "lib/FreeRTOS"] + path = lib/FreeRTOS + url = https://github.com/FreeRTOS/FreeRTOS diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3c8b768 --- /dev/null +++ b/Makefile @@ -0,0 +1,38 @@ +NAME=blinky + +PREFIX?=arm-none-eabi- +CC=$(PREFIX)gcc +AS=$(PREFIX)as +OBJCOPY=$(PREFIX)objcopy + +VPATH=src + +.SECONDARY: + +clean: + rm -f lib/libopencm3/lib/libopencm3_stm32f4.a + rm -f $(NAME).bin + rm -f $(NAME).elf + rm -f $(NAME).o + +clobber: + rm -f lib/libopencm3/lib/libopencm3_stm32f4.a + rm -f $(NAME).bin + $(MAKE) -C lib/libopencm3 clean + +libopencm3: + $(MAKE) -C lib/libopencm3 TARGETS=stm32/f4 + +flash: $(NAME).bin + st-flash write $(NAME).bin 0x8000000 + +all: libopencm3 $(NAME).bin + +%.o: %.c + $(CC) -Og -g -Wall -std=c99 -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -Ilib/libopencm3/include -DSTM32F4 -c $< -o $@ + +%.elf: %.o + $(CC) --static -nostartfiles -Tnucleo-f411re.ld -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -Llib/libopencm3/lib $< -lopencm3_stm32f4 -o $@ + +%.bin: %.elf + $(OBJCOPY) $< -O binary $@ diff --git a/README.org b/README.org new file mode 100644 index 0000000..5f87a8f --- /dev/null +++ b/README.org @@ -0,0 +1 @@ +#+Title: Oof Oww Ouch... My Blinky Arm diff --git a/compile_commands.json b/compile_commands.json new file mode 100644 index 0000000..77771ed --- /dev/null +++ b/compile_commands.json @@ -0,0 +1,23 @@ +[ + { + "arguments": [ + "/usr/bin/arm-none-eabi-gcc", + "-Og", + "-g", + "-Wall", + "-std=c99", + "-mthumb", + "-mcpu=cortex-m4", + "-mfloat-abi=hard", + "-Ilib/libopencm3/include", + "-DSTM32F4", + "-c", + "-o", + "blinky.o", + "src/blinky.c" + ], + "directory": "/home/fckr/progs/stm32/blinky-arm", + "file": "/home/fckr/progs/stm32/blinky-arm/src/blinky.c", + "output": "/home/fckr/progs/stm32/blinky-arm/blinky.o" + } +] diff --git a/lib/FreeRTOS b/lib/FreeRTOS new file mode 160000 index 0000000..82b4c24 --- /dev/null +++ b/lib/FreeRTOS @@ -0,0 +1 @@ +Subproject commit 82b4c249aa52239e90462fff0ebd628e51d6046c diff --git a/lib/libopencm3 b/lib/libopencm3 new file mode 160000 index 0000000..1f3abd4 --- /dev/null +++ b/lib/libopencm3 @@ -0,0 +1 @@ +Subproject commit 1f3abd43763fa39d23e737602b6d0011a45c70b2 diff --git a/nucleo-f411re.ld b/nucleo-f411re.ld new file mode 100644 index 0000000..9762ee2 --- /dev/null +++ b/nucleo-f411re.ld @@ -0,0 +1,32 @@ +/* + * This file is part of the libopencm3 project. + * + * Copyright (C) 2009 Uwe Hermann + * Copyright (C) 2011 Stephen Caudle + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ + +/* Linker script for Nucleo F411RE (STM32F411RE, 512K flash, 128K RAM). */ + +/* Define memory regions. */ +MEMORY +{ + rom (rx) : ORIGIN = 0x08000000, LENGTH = 512K + ram (rwx) : ORIGIN = 0x20000000, LENGTH = 128K +} + +/* Include the common ld script. */ +INCLUDE cortex-m-generic.ld + diff --git a/src/blinky.c b/src/blinky.c new file mode 100644 index 0000000..d14dbda --- /dev/null +++ b/src/blinky.c @@ -0,0 +1,24 @@ +#include +#include + +static void gpio_setup(void) { + /* Enable GPIOC clock */ + rcc_periph_clock_enable(RCC_GPIOA); + + /* Set GPIO to output push-pull */ + gpio_mode_setup(GPIOA, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO5); +} + +int main(void) { + int i; + + gpio_setup(); + + while (1) { + gpio_toggle(GPIOA, GPIO5); + for (i = 0; i < 1000000; i++) { + __asm__("nop"); + } + } + return 0; +}