Commit 42668c44 authored by zapb's avatar zapb

Add example firmware

parent 46c9ead8
[submodule "firmware/libopencm3"]
path = firmware/libopencm3
url = https://github.com/libopencm3/libopencm3
branch = 78c23ba5
firmware.*
*.o
##
## Copyright (C) 2020 Marc Schink <dev@zabp.de>
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program 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 General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>.
##
PREFIX ?= arm-none-eabi-
CC = $(PREFIX)gcc
OBJCOPY = $(PREFIX)objcopy
OPENOCD ?= openocd
FP_FLAGS = -msoft-float
ARCH_FLAGS = -mcpu=cortex-m3 -mthumb $(FP_FLAGS)
LD_SCRIPT = libopencm3/lib/stm32/f1/stm32f100xb.ld
LDFLAGS = -L./libopencm3/lib
LDFLAGS += --static -nostartfiles
LDFLAGS += -T$(LD_SCRIPT)
CFLAGS = $(ARCH_FLAGS)
CFLAGS += -std=c11 -g3 -O0
CFLAGS += -I./libopencm3/include
CFLAGS += -fno-common -ffunction-sections -fdata-sections
CFLAGS += -DSTM32F1
LDLIBS = -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group
LDLIBS += -lopencm3_stm32f1
FIRMWARE_ELF = firmware.elf
FIRMWARE_BIN = firmware.bin
FIRMWARE_HEX = firmware.hex
all: $(FIRMWARE_ELF) $(FIRMWARE_BIN) $(FIRMWARE_HEX)
$(FIRMWARE_ELF): main.c libopencm3/lib/libopencm3_stm32f1.a
$(CC) $(CFLAGS) $(LDFLAGS) main.c $(LDLIBS) -o firmware.elf
libopencm3/Makefile:
git submodule update --init
libopencm3/lib/libopencm3_%.a: libopencm3/Makefile
$(MAKE) -C libopencm3 TARGETS=stm32/f1
$(FIRMWARE_BIN): $(FIRMWARE_ELF)
$(OBJCOPY) -O binary $< $@
$(FIRMWARE_HEX): $(FIRMWARE_ELF)
$(OBJCOPY) -O ihex $< $@
flash: $(FIRMWARE_ELF)
$(OPENOCD) -f interface/jlink.cfg -c "transport select swd" -f target/stm32f1x.cfg -c "program $(FIRMWARE_ELF) verify reset exit"
clean:
$(RM) $(FIRMWARE_ELF) $(FIRMWARE_BIN) $(FIRMWARE_HEX)
distclean: clean
$(MAKE) -C libopencm3 clean
.PHONY: all flash clean distclean
Subproject commit 78c23ba5a08fd5063c9d6daa66fc1ff58ee3a2aa
/*
* Copyright (C) 2020 Marc Schink <dev@zapb.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdbool.h>
#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/gpio.h>
#define LED2_GPIO GPIOA
#define LED2_PIN GPIO5
char *text = "This is some secret data stored in the flash memory together with the firmware. Exception(al) failure...!";
int main(void)
{
rcc_periph_clock_enable(RCC_GPIOA);
gpio_set_mode(LED2_GPIO, GPIO_MODE_OUTPUT_2_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL, LED2_PIN);
gpio_clear(LED2_GPIO, LED2_PIN);
while (true) {
for (uint32_t i = 0; i < (1 << 18); i++) {
__asm__("nop");
}
gpio_toggle(LED2_GPIO, LED2_PIN);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment