Loading include/arch/lm4f120h5qr-stellaris/driver/gpio.h 0 → 100644 +63 −0 Original line number Diff line number Diff line /* * Copyright 2021 Daniel Friesel * * SPDX-License-Identifier: BSD-2-Clause */ #ifndef GPIO_H #define GPIO_H extern "C" { #include "lm4f_cpp_wrapper.h" } class GPIO { private: GPIO(const GPIO ©); public: GPIO () {} enum Pin : unsigned char { pa_0 = 0, pa_1, pa_2, pa_3, pa_4, pa_5, pa_6, pa_7, pb_0, pb_1, pb_2, pb_3, pb_4, pb_5, pb_6, pb_7, pc_0, pc_1, pc_2, pc_3, pc_4, pc_5, pc_6, pc_7, pd_0, pd_1, pd_2, pd_3, pd_4, pd_5, pd_6, pd_7, pe_0, pe_1, pe_2, pe_3, pe_4, pe_5, pe_6, pe_7, pf_0, pf_1, pf_2, pf_3, pf_4, PIN_INVALID }; inline void setup() { mp_gpio_setup(); } inline void led_on(unsigned char id) { mp_gpio_write(pf_1 + id, 1); } inline void led_off(unsigned char id) { mp_gpio_write(pf_1 + id, 0); } inline void led_toggle(unsigned char id) { mp_gpio_write(pf_1 + id, !mp_gpio_read(pf_1 + id)); } inline void input(unsigned char const pin) { mp_gpio_input(pin); } inline void input(unsigned char const pin, unsigned char const pull) { } inline void output(unsigned char const pin) { mp_gpio_output(pin); } /* inline void output(unsigned char const pin, unsigned char const value) { }*/ inline unsigned int read(unsigned char const pin) { return mp_gpio_read(pin); } inline void write(unsigned char const pin, unsigned char value) { mp_gpio_write(pin, value); } }; extern GPIO gpio; #endif include/arch/lm4f120h5qr-stellaris/driver/stdout.h 0 → 100644 +24 −0 Original line number Diff line number Diff line /* * Copyright 2021 Daniel Friesel * * SPDX-License-Identifier: BSD-2-Clause */ #ifndef STANDARDOUTPUT_H #define STANDARDOUTPUT_H #include "object/outputstream.h" class StandardOutput : public OutputStream { private: StandardOutput(const StandardOutput ©); public: StandardOutput () {} void setup(); virtual void put(char c) override; }; extern StandardOutput kout; #endif include/arch/lm4f120h5qr-stellaris/driver/uptime.h 0 → 100644 +32 −0 Original line number Diff line number Diff line /* * Copyright 2021 Daniel Friesel * * SPDX-License-Identifier: BSD-2-Clause */ #ifndef UPTIME_H #define UPTIME_H #include <stdint.h> class Uptime { private: Uptime(const Uptime ©); #ifdef TIMER_S uint32_t seconds; #endif public: #ifdef TIMER_S Uptime () : seconds(0) {} #else Uptime () {} #endif #ifdef TIMER_S inline uint32_t get_s() { return seconds; } inline void tick_s() { seconds++; } #endif }; extern Uptime uptime; #endif include/arch/lm4f120h5qr-stellaris/lm4f_cpp_wrapper.h 0 → 100644 +16 −0 Original line number Diff line number Diff line /* * Copyright 2021 Daniel Friesel * * SPDX-License-Identifier: BSD-2-Clause */ void arch_clock_init(); void arch_init_loop(); void mp_uart_setup(); void mp_uart_send_blocking(char c); void mp_gpio_setup(); void mp_gpio_input(unsigned char const pin); void mp_gpio_output(unsigned char const pin); unsigned int mp_gpio_read(unsigned char const pin); void mp_gpio_write(unsigned char const pin, unsigned char value); src/arch/lm4f120h5qr-stellaris/Makefile.inc 0 → 100644 +130 −0 Original line number Diff line number Diff line # vim:ft=make # # Copyright 2021 Daniel Friesel # # SPDX-License-Identifier: BSD-2-Clause SERIAL_PORT ?= ttyACM0 cpu_freq ?= 80000000 INCLUDES += -Iext/libopencm3/include COMMON_FLAGS += --static -nostartfiles -g3 -Os -fno-common COMMON_FLAGS += -ffunction-sections -fdata-sections COMMON_FLAGS += -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -DLM4F CC = arm-none-eabi-gcc CXX = arm-none-eabi-g++ OBJCOPY = arm-none-eabi-objcopy OBJDUMP = arm-none-eabi-objdump SIZE = arm-none-eabi-size C_TARGETS += src/arch/lm4f120h5qr-stellaris/lm4f_cpp_wrapper.c CXX_TARGETS += src/arch/lm4f120h5qr-stellaris/arch.cc ifdef CONFIG_aspectc CXX = ag++ -r build/repo.acp -v 0 --c_compiler arm-none-eabi-g++ -p . --Xcompiler endif ifneq ($(findstring adc,${arch_drivers}), ) CXX_TARGETS += src/arch/lm4f120h5qr-stellaris/driver/adc.cc endif CXX_TARGETS += src/arch/lm4f120h5qr-stellaris/driver/gpio.cc CXX_TARGETS += src/arch/lm4f120h5qr-stellaris/driver/stdout.cc # Commandline ifneq ($(findstring counter,${arch_drivers}), ) CONFIG_arch_lm4f120h5qr_stellaris_driver_counter = y endif #ifneq ($(findstring timer,${arch_drivers}), ) # CONFIG_arch_lm4f120h5qr_stellaris_driver_timer = y #endif ifeq (${timer_s}, 1) CONFIG_arch_lm4f120h5qr_stellaris_driver_uptime = y endif # Kconfig ifdef CONFIG_arch_lm4f120h5qr_stellaris_driver_counter CXX_TARGETS += src/arch/lm4f120h5qr-stellaris/driver/counter.cc endif #ifdef CONFIG_arch_lm4f120h5qr_stellaris_driver_timer # CXX_TARGETS += src/arch/lm4f120h5qr-stellaris/driver/timer.cc #endif ifdef CONFIG_arch_lm4f120h5qr_stellaris_driver_uptime COMMON_FLAGS += -DTIMER_S CXX_TARGETS += src/arch/lm4f120h5qr-stellaris/driver/uptime.cc endif ifneq (${cpu_freq}, ) COMMON_FLAGS += -DF_CPU=${cpu_freq}UL else COMMON_FLAGS += -DF_CPU=80000000UL endif OBJECTS = ${CXX_TARGETS:.cc=.o} ${C_TARGETS:.c=.o} ${ASM_TARGETS:.S=.o} .cc.o: ${QUIET}${CXX} ${INCLUDES} ${COMMON_FLAGS} ${CXXFLAGS} -c -o $@ ${@:.o=.cc} .c.o: ${QUIET}${CC} ${INCLUDES} ${COMMON_FLAGS} ${CFLAGS} -c -o $@ ${@:.o=.c} .S.o: ${QUIET}${CC} ${INCLUDES} ${COMMON_FLAGS} -c -o $@ ${@:.o=.S} .s.o: ${QUIET}${CC} ${INCLUDES} ${COMMON_FLAGS} -c -o $@ ${@:.o=.S} ext/libopencm3/Makefile: git submodule update --init ext/libopencm3/lib/libopencm3_lm4f.a: ext/libopencm3/Makefile ${MAKE} -C ext/libopencm3 build/system.elf: ${OBJECTS} ext/libopencm3/lib/libopencm3_stm32f4.a ${QUIET}mkdir -p build ${QUIET}${CXX} ${INCLUDES} ${COMMON_FLAGS} ${CXXFLAGS} \ -Lext/libopencm3/lib -Wl,--gc-sections \ -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group \ -T src/arch/lm4f120h5qr-stellaris/lm4f120h5qr.ld \ ${OBJECTS} -lopencm3_lm4f \ -o $@ ${QUIET}${SIZE} build/system.elf | tail -n1 | awk '{ print " ROM: " ($$1+$$2) " (" int(($$1+$$2)*100/49152) "%) RAM: " ($$2 + $$3) " (" int(($$2+$$3)*100/4096) "%)" }' program: build/system.elf ${OBJCOPY} -O binary build/system.elf build/system.bin lm4flash build/system.bin arch_clean: ${QUIET}rm -f ${OBJECTS} cat: ${QUIET}script/cat.py /dev/${SERIAL_PORT} 115200 ${cpu_freq} 65536 monitor: ${QUIET}screen /dev/${SERIAL_PORT} 115200 arch_help: @echo "lm4f120h5qr-stellaris specific flags:" arch_info: @echo "CPU Freq: ${cpu_freq} Hz" @echo "Timer Freq: ${timer_freq} Hz" @echo "I2C Freq: ${i2c_freq} Hz" @echo "Counter Overflow: 65536/255" @echo "Monitor: /dev/${SERIAL_PORT} 115200" attributes: build/system.elf ${QUIET}script/size.py ${SIZE} text,data data,bss .PHONY: arch_clean arch_help arch_info attributes cat monitor program Loading
include/arch/lm4f120h5qr-stellaris/driver/gpio.h 0 → 100644 +63 −0 Original line number Diff line number Diff line /* * Copyright 2021 Daniel Friesel * * SPDX-License-Identifier: BSD-2-Clause */ #ifndef GPIO_H #define GPIO_H extern "C" { #include "lm4f_cpp_wrapper.h" } class GPIO { private: GPIO(const GPIO ©); public: GPIO () {} enum Pin : unsigned char { pa_0 = 0, pa_1, pa_2, pa_3, pa_4, pa_5, pa_6, pa_7, pb_0, pb_1, pb_2, pb_3, pb_4, pb_5, pb_6, pb_7, pc_0, pc_1, pc_2, pc_3, pc_4, pc_5, pc_6, pc_7, pd_0, pd_1, pd_2, pd_3, pd_4, pd_5, pd_6, pd_7, pe_0, pe_1, pe_2, pe_3, pe_4, pe_5, pe_6, pe_7, pf_0, pf_1, pf_2, pf_3, pf_4, PIN_INVALID }; inline void setup() { mp_gpio_setup(); } inline void led_on(unsigned char id) { mp_gpio_write(pf_1 + id, 1); } inline void led_off(unsigned char id) { mp_gpio_write(pf_1 + id, 0); } inline void led_toggle(unsigned char id) { mp_gpio_write(pf_1 + id, !mp_gpio_read(pf_1 + id)); } inline void input(unsigned char const pin) { mp_gpio_input(pin); } inline void input(unsigned char const pin, unsigned char const pull) { } inline void output(unsigned char const pin) { mp_gpio_output(pin); } /* inline void output(unsigned char const pin, unsigned char const value) { }*/ inline unsigned int read(unsigned char const pin) { return mp_gpio_read(pin); } inline void write(unsigned char const pin, unsigned char value) { mp_gpio_write(pin, value); } }; extern GPIO gpio; #endif
include/arch/lm4f120h5qr-stellaris/driver/stdout.h 0 → 100644 +24 −0 Original line number Diff line number Diff line /* * Copyright 2021 Daniel Friesel * * SPDX-License-Identifier: BSD-2-Clause */ #ifndef STANDARDOUTPUT_H #define STANDARDOUTPUT_H #include "object/outputstream.h" class StandardOutput : public OutputStream { private: StandardOutput(const StandardOutput ©); public: StandardOutput () {} void setup(); virtual void put(char c) override; }; extern StandardOutput kout; #endif
include/arch/lm4f120h5qr-stellaris/driver/uptime.h 0 → 100644 +32 −0 Original line number Diff line number Diff line /* * Copyright 2021 Daniel Friesel * * SPDX-License-Identifier: BSD-2-Clause */ #ifndef UPTIME_H #define UPTIME_H #include <stdint.h> class Uptime { private: Uptime(const Uptime ©); #ifdef TIMER_S uint32_t seconds; #endif public: #ifdef TIMER_S Uptime () : seconds(0) {} #else Uptime () {} #endif #ifdef TIMER_S inline uint32_t get_s() { return seconds; } inline void tick_s() { seconds++; } #endif }; extern Uptime uptime; #endif
include/arch/lm4f120h5qr-stellaris/lm4f_cpp_wrapper.h 0 → 100644 +16 −0 Original line number Diff line number Diff line /* * Copyright 2021 Daniel Friesel * * SPDX-License-Identifier: BSD-2-Clause */ void arch_clock_init(); void arch_init_loop(); void mp_uart_setup(); void mp_uart_send_blocking(char c); void mp_gpio_setup(); void mp_gpio_input(unsigned char const pin); void mp_gpio_output(unsigned char const pin); unsigned int mp_gpio_read(unsigned char const pin); void mp_gpio_write(unsigned char const pin, unsigned char value);
src/arch/lm4f120h5qr-stellaris/Makefile.inc 0 → 100644 +130 −0 Original line number Diff line number Diff line # vim:ft=make # # Copyright 2021 Daniel Friesel # # SPDX-License-Identifier: BSD-2-Clause SERIAL_PORT ?= ttyACM0 cpu_freq ?= 80000000 INCLUDES += -Iext/libopencm3/include COMMON_FLAGS += --static -nostartfiles -g3 -Os -fno-common COMMON_FLAGS += -ffunction-sections -fdata-sections COMMON_FLAGS += -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -DLM4F CC = arm-none-eabi-gcc CXX = arm-none-eabi-g++ OBJCOPY = arm-none-eabi-objcopy OBJDUMP = arm-none-eabi-objdump SIZE = arm-none-eabi-size C_TARGETS += src/arch/lm4f120h5qr-stellaris/lm4f_cpp_wrapper.c CXX_TARGETS += src/arch/lm4f120h5qr-stellaris/arch.cc ifdef CONFIG_aspectc CXX = ag++ -r build/repo.acp -v 0 --c_compiler arm-none-eabi-g++ -p . --Xcompiler endif ifneq ($(findstring adc,${arch_drivers}), ) CXX_TARGETS += src/arch/lm4f120h5qr-stellaris/driver/adc.cc endif CXX_TARGETS += src/arch/lm4f120h5qr-stellaris/driver/gpio.cc CXX_TARGETS += src/arch/lm4f120h5qr-stellaris/driver/stdout.cc # Commandline ifneq ($(findstring counter,${arch_drivers}), ) CONFIG_arch_lm4f120h5qr_stellaris_driver_counter = y endif #ifneq ($(findstring timer,${arch_drivers}), ) # CONFIG_arch_lm4f120h5qr_stellaris_driver_timer = y #endif ifeq (${timer_s}, 1) CONFIG_arch_lm4f120h5qr_stellaris_driver_uptime = y endif # Kconfig ifdef CONFIG_arch_lm4f120h5qr_stellaris_driver_counter CXX_TARGETS += src/arch/lm4f120h5qr-stellaris/driver/counter.cc endif #ifdef CONFIG_arch_lm4f120h5qr_stellaris_driver_timer # CXX_TARGETS += src/arch/lm4f120h5qr-stellaris/driver/timer.cc #endif ifdef CONFIG_arch_lm4f120h5qr_stellaris_driver_uptime COMMON_FLAGS += -DTIMER_S CXX_TARGETS += src/arch/lm4f120h5qr-stellaris/driver/uptime.cc endif ifneq (${cpu_freq}, ) COMMON_FLAGS += -DF_CPU=${cpu_freq}UL else COMMON_FLAGS += -DF_CPU=80000000UL endif OBJECTS = ${CXX_TARGETS:.cc=.o} ${C_TARGETS:.c=.o} ${ASM_TARGETS:.S=.o} .cc.o: ${QUIET}${CXX} ${INCLUDES} ${COMMON_FLAGS} ${CXXFLAGS} -c -o $@ ${@:.o=.cc} .c.o: ${QUIET}${CC} ${INCLUDES} ${COMMON_FLAGS} ${CFLAGS} -c -o $@ ${@:.o=.c} .S.o: ${QUIET}${CC} ${INCLUDES} ${COMMON_FLAGS} -c -o $@ ${@:.o=.S} .s.o: ${QUIET}${CC} ${INCLUDES} ${COMMON_FLAGS} -c -o $@ ${@:.o=.S} ext/libopencm3/Makefile: git submodule update --init ext/libopencm3/lib/libopencm3_lm4f.a: ext/libopencm3/Makefile ${MAKE} -C ext/libopencm3 build/system.elf: ${OBJECTS} ext/libopencm3/lib/libopencm3_stm32f4.a ${QUIET}mkdir -p build ${QUIET}${CXX} ${INCLUDES} ${COMMON_FLAGS} ${CXXFLAGS} \ -Lext/libopencm3/lib -Wl,--gc-sections \ -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group \ -T src/arch/lm4f120h5qr-stellaris/lm4f120h5qr.ld \ ${OBJECTS} -lopencm3_lm4f \ -o $@ ${QUIET}${SIZE} build/system.elf | tail -n1 | awk '{ print " ROM: " ($$1+$$2) " (" int(($$1+$$2)*100/49152) "%) RAM: " ($$2 + $$3) " (" int(($$2+$$3)*100/4096) "%)" }' program: build/system.elf ${OBJCOPY} -O binary build/system.elf build/system.bin lm4flash build/system.bin arch_clean: ${QUIET}rm -f ${OBJECTS} cat: ${QUIET}script/cat.py /dev/${SERIAL_PORT} 115200 ${cpu_freq} 65536 monitor: ${QUIET}screen /dev/${SERIAL_PORT} 115200 arch_help: @echo "lm4f120h5qr-stellaris specific flags:" arch_info: @echo "CPU Freq: ${cpu_freq} Hz" @echo "Timer Freq: ${timer_freq} Hz" @echo "I2C Freq: ${i2c_freq} Hz" @echo "Counter Overflow: 65536/255" @echo "Monitor: /dev/${SERIAL_PORT} 115200" attributes: build/system.elf ${QUIET}script/size.py ${SIZE} text,data data,bss .PHONY: arch_clean arch_help arch_info attributes cat monitor program