Add: initial (working) blinky light program

main
rkcf 2023-11-17 13:41:47 -06:00
commit bd8a3828d9
8 changed files with 126 additions and 0 deletions

6
.gitmodules vendored Normal file
View File

@ -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

38
Makefile Normal file
View File

@ -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 $@

1
README.org Normal file
View File

@ -0,0 +1 @@
#+Title: Oof Oww Ouch... My Blinky Arm

23
compile_commands.json Normal file
View File

@ -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"
}
]

1
lib/FreeRTOS Submodule

@ -0,0 +1 @@
Subproject commit 82b4c249aa52239e90462fff0ebd628e51d6046c

1
lib/libopencm3 Submodule

@ -0,0 +1 @@
Subproject commit 1f3abd43763fa39d23e737602b6d0011a45c70b2

32
nucleo-f411re.ld Normal file
View File

@ -0,0 +1,32 @@
/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
* Copyright (C) 2011 Stephen Caudle <scaudle@doceme.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
/* 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

24
src/blinky.c Normal file
View File

@ -0,0 +1,24 @@
#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/gpio.h>
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;
}