Reorganize repository to be used as a library
Project was organized as an application, wich makes it less practical to include in other projects. A template project may be added back to make up for the missing files
This commit is contained in:
parent
a2c41b51b4
commit
4a12fa7a3d
21
LICENSE
21
LICENSE
@ -1,21 +0,0 @@
|
|||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2020 Steins7
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
189
Makefile
189
Makefile
@ -1,189 +0,0 @@
|
|||||||
#-------------------------------------------------------------------------------
|
|
||||||
# this GNU-makefile relies on the GCC toolchain
|
|
||||||
|
|
||||||
# --- control global project settings
|
|
||||||
# RELEASE=1 -> enable optimisation, then disable debug
|
|
||||||
# RELEASE=0 -> disable optimisation, then enable debug
|
|
||||||
RELEASE=0
|
|
||||||
|
|
||||||
# --- project architecture
|
|
||||||
# program name
|
|
||||||
EXE_PREFIX=main
|
|
||||||
# project folders, This Makefile should be in the same folder as the SRC folder
|
|
||||||
SRC=src
|
|
||||||
BIN=bin
|
|
||||||
INC=include
|
|
||||||
LIB=lib
|
|
||||||
OBJ=${BIN}/obj
|
|
||||||
DEP=${BIN}/dep
|
|
||||||
# code folders, in the SRC folder
|
|
||||||
SUBFOLDERS=drivers target
|
|
||||||
# Define linker script file here
|
|
||||||
LDSCRIPT=${SRC}/target/STM32F103XB.ld
|
|
||||||
|
|
||||||
# --- advanced config
|
|
||||||
# List all user C define here
|
|
||||||
UDEFS=
|
|
||||||
# Define ASM defines here
|
|
||||||
UADEFS=
|
|
||||||
|
|
||||||
# --- toolchain configuration
|
|
||||||
TARGET=arm-none-eabi-
|
|
||||||
CC=${TARGET}gcc
|
|
||||||
CPP=${TARGET}g++
|
|
||||||
OBJCOPY=${TARGET}objcopy
|
|
||||||
AS=${TARGET}gcc -x assembler-with-cpp -c
|
|
||||||
SIZE=${TARGET}size
|
|
||||||
OBJDUMP=${TARGET}objdump
|
|
||||||
|
|
||||||
# --- hardware settings
|
|
||||||
ARCH=armv7-m
|
|
||||||
FLOAT-ABI=soft #no FPU on stm32f103
|
|
||||||
CPU=cortex-m3
|
|
||||||
CPUFLAGS=-mthumb
|
|
||||||
FPU=fpv4-sp-d16 #"FLOAT-ABI=soft" disable that
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
|
||||||
# --- makefile pre-incantation
|
|
||||||
|
|
||||||
# List all de:fault C defines here, like -D_DEBUG=1
|
|
||||||
DDEFS=-march=${ARCH} -mfloat-abi=${FLOAT-ABI} -mcpu=${CPU} -mfpu=${FPU} $\
|
|
||||||
${CPUFLAGS}
|
|
||||||
# List all default ASM defines here, like -D_DEBUG=1
|
|
||||||
DADEFS=-D__ASSEMBLY__
|
|
||||||
|
|
||||||
# --- deduce file names
|
|
||||||
MAIN_C_FILES=${wildcard ${SRC}/${strip ${EXE_PREFIX}}*.c}
|
|
||||||
MAIN_CPP_FILES=${wildcard ${SRC}/${strip ${EXE_PREFIX}}*.cpp}
|
|
||||||
|
|
||||||
COMMON_C_FILES=${filter-out ${MAIN_C_FILES},${wildcard ${SRC}/*.c}}
|
|
||||||
COMMON_C_FILES+=${foreach dir,${SUBFOLDERS},${wildcard ${SRC}/${dir}/*.c}}
|
|
||||||
|
|
||||||
COMMON_CPP_FILES=${filter-out ${MAIN_CPP_FILES},${wildcard ${SRC}/*.cpp}}
|
|
||||||
COMMON_CPP_FILES+=${foreach dir,${SUBFOLDERS},${wildcard ${SRC}/${dir}/*.cpp}}
|
|
||||||
|
|
||||||
COMMON_ASM_FILES=${foreach dir,${SUBFOLDERS},${wildcard ${SRC}/${dir}/*.s}}
|
|
||||||
|
|
||||||
MAIN_OBJECT_FILES=${sort ${patsubst ${src}/%.c,${obj}/%.o,${MAIN_C_FILES}} \
|
|
||||||
${patsubst ${src}/%.cpp,${obj}/%.o,${MAIN_CPP_FILES}}}
|
|
||||||
COMMON_OBJECT_FILES=${sort \
|
|
||||||
${patsubst ${SRC}/%.c,${OBJ}/%.o,${COMMON_C_FILES}} \
|
|
||||||
${patsubst ${SRC}/%.cpp,${OBJ}/%.o,${COMMON_CPP_FILES}} \
|
|
||||||
${patsubst ${SRC}/%s,${OBJ}/%o,${COMMON_ASM_FILES}}}
|
|
||||||
|
|
||||||
LIBRARIES=${foreach dir,${wildcard ${LIB}/*},${wildcard ${LIB}/${dir}/*.a}}
|
|
||||||
|
|
||||||
OBJECT_FILES=${MAIN_OBJECT_FILES} ${COMMON_OBJECT_FILES}
|
|
||||||
DEPEND_FILES=${OBJECT_FILES:%.o,%.d}
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
|
||||||
# --- makefile incantation
|
|
||||||
# down here is black magic, you probably don't want to modify anything
|
|
||||||
|
|
||||||
DEFS=${DDEFS} ${UDEFS}
|
|
||||||
ADEFS=${DADEFS} ${UADEFS}
|
|
||||||
|
|
||||||
# --- otpimisation
|
|
||||||
ifeq (${strip ${RELEASE}},0)
|
|
||||||
CFLAGS=-g3 -O0
|
|
||||||
else
|
|
||||||
CFLAGS=-O3
|
|
||||||
endif
|
|
||||||
|
|
||||||
# --- c/cpp
|
|
||||||
ifneq (${strip ${MAIN_CPP_FILES} ${COMMON_CPP_FILES}},)
|
|
||||||
CC:=${CPP}
|
|
||||||
CFLAGS+=-std=c++17
|
|
||||||
else
|
|
||||||
CFLAGS+=-std=c17
|
|
||||||
endif
|
|
||||||
|
|
||||||
ASFLAGS=${LIB} $(DEFS) -Wa,--gdwarf2 $(ADEFS)
|
|
||||||
CFLAGS+=-Wall ${DEFS} -Wextra -Warray-bounds -Wno-unused-parameter $\
|
|
||||||
-fomit-frame-pointer
|
|
||||||
LDFLAGS=-T ${LDSCRIPT} -lc -lgcc -lgcov -lm -Wl,-Map=$@.map,--gc-sections $\
|
|
||||||
--specs=nosys.specs
|
|
||||||
INCLUDE=-I ${INC}
|
|
||||||
|
|
||||||
# --- Generate dependency information
|
|
||||||
CFLAGS+=-MD -MP -MF ${patsubst %o,%d,$@}
|
|
||||||
ASFLAGS+=#-MD -MP -MF ${patsubst %o,%d,$@}
|
|
||||||
|
|
||||||
# --- folder tree
|
|
||||||
DIR_GUARD=@mkdir -p ${@D}
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
|
||||||
# --- make rules
|
|
||||||
all: ${BIN}/${EXE_PREFIX}.elf ${BIN}/${EXE_PREFIX}.hex ${BIN}/${EXE_PREFIX}.bin
|
|
||||||
|
|
||||||
rebuild : clean all
|
|
||||||
|
|
||||||
.SUFFIXES:
|
|
||||||
.SECONDARY:
|
|
||||||
.PHONY: all clean rebuild
|
|
||||||
|
|
||||||
# --- compiler command for elf file
|
|
||||||
${BIN}/%.elf : ${MAIN_OBJECT_FILES} ${COMMON_OBJECT_FILES}
|
|
||||||
@echo -e '\e[32;1m ==== linking $@ ====\e[0m'
|
|
||||||
@echo ${COMMON_OBJECT_FILES}
|
|
||||||
@echo
|
|
||||||
${DIR_GUARD}
|
|
||||||
${CC} ${INCLUDE} ${CFLAGS} -o $@ $^ ${LIBRARIES} ${LDFLAGS}
|
|
||||||
${OBJDUMP} -h $@
|
|
||||||
${SIZE} $@
|
|
||||||
@echo
|
|
||||||
|
|
||||||
# --- compiler commands for uploadable files
|
|
||||||
${BIN}/%.hex : ${BIN}/%.elf
|
|
||||||
@echo -e '\e[33;1m ==== translating $< ====\e[0m'
|
|
||||||
${OBJCOPY} -O ihex $< $@
|
|
||||||
@echo
|
|
||||||
|
|
||||||
${BIN}/%.bin : ${BIN}/%.elf
|
|
||||||
@echo -e '\e[33;1m ==== translating $< ====\e[0m'
|
|
||||||
${OBJCOPY} -O binary $< $@
|
|
||||||
@echo
|
|
||||||
|
|
||||||
# --- compiler commands for every source file
|
|
||||||
${OBJ}/%.o : ${SRC}/%.cpp
|
|
||||||
@echo -e '\e[36;1m ==== compiling $< ====\e[0m'
|
|
||||||
${DIR_GUARD}
|
|
||||||
${CPP} ${INCLUDE} -c ${CFLAGS} $< -o $@ ${LIBRARIES}
|
|
||||||
@echo
|
|
||||||
|
|
||||||
${BIN}/%.o : ${SRC}/%.cpp
|
|
||||||
@echo -e '\e[36;1m ==== compiling $< ====\e[0m'
|
|
||||||
${DIR_GUARD}
|
|
||||||
${CPP} ${INCLUDE} -c ${CFLAGS} $< -o $@ ${LIBRARIES}
|
|
||||||
@echo
|
|
||||||
|
|
||||||
${OBJ}/%.o : ${SRC}/%.c
|
|
||||||
@echo -e '\e[34;1m ==== compiling $< ====\e[0m'
|
|
||||||
${DIR_GUARD}
|
|
||||||
${CC} ${INCLUDE} -c ${CFLAGS} $< -o $@ ${LIBRARIES}
|
|
||||||
@echo
|
|
||||||
|
|
||||||
${BIN}/%.o : ${SRC}/%.c
|
|
||||||
@echo -e '\e[34;1m ==== compiling $< ====\e[0m'
|
|
||||||
${DIR_GUARD}
|
|
||||||
${CC} ${INCLUDE} -c ${CFLAGS} $< -o $@ ${LIBRARIES}
|
|
||||||
@echo
|
|
||||||
|
|
||||||
${OBJ}/%.o : ${SRC}/%.s
|
|
||||||
@echo -e '\e[35;1m ==== compiling $^ ====\e[0m'
|
|
||||||
${DIR_GUARD}
|
|
||||||
${AS} -o ${ASFLAGS} $< -o $@ ${LIBRARIES}
|
|
||||||
@echo
|
|
||||||
|
|
||||||
${BIN}/%.o : ${SRC}/%.s
|
|
||||||
@echo -e '\e[35;1m ==== compiling $^ ====\e[0m'
|
|
||||||
${DIR_GUARD}
|
|
||||||
${AS} -o ${ASFLAGS} $< -o $@ ${LIBRARIES}
|
|
||||||
@echo
|
|
||||||
|
|
||||||
# --- remove generated files
|
|
||||||
clean:
|
|
||||||
-rm -rf ${BIN}/*
|
|
||||||
|
|
||||||
-include ${DEPEND_FILES}
|
|
||||||
|
|
||||||
@ -1,2 +0,0 @@
|
|||||||
# stm32f1xx_HBL
|
|
||||||
simplified HAL for stm32f1 microcontrollers, designed to be easily customized
|
|
||||||
3
openocd
3
openocd
@ -1,3 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
openocd -f interface/stlink.cfg -f target/cs32f1x.cfg
|
|
||||||
|
|
||||||
20
src/drivers/rnd.c
Normal file
20
src/drivers/rnd.c
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#include "rnd.h"
|
||||||
|
|
||||||
|
uint32_t rnd_seed = 251;
|
||||||
|
|
||||||
|
void set_rnd_seed(uint32_t seed) {
|
||||||
|
rnd_seed = seed;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t rnd_byte() {
|
||||||
|
|
||||||
|
static uint32_t r = 251;
|
||||||
|
static uint32_t Y = 7;
|
||||||
|
|
||||||
|
if (r==0 || r==1 || r==0xFFFFFFFF) r=251;
|
||||||
|
r = (9973 * ~r) + ((Y) % 701);
|
||||||
|
Y = (r>>24) % 255;
|
||||||
|
|
||||||
|
return (uint8_t)Y;
|
||||||
|
}
|
||||||
|
|
||||||
11
src/drivers/rnd.h
Normal file
11
src/drivers/rnd.h
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#ifndef RND_H
|
||||||
|
#define RND_H
|
||||||
|
|
||||||
|
#include "stdint.h"
|
||||||
|
|
||||||
|
void set_rnd_seed(uint32_t seed);
|
||||||
|
|
||||||
|
uint8_t rnd_byte();
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
@ -33,8 +33,9 @@ int timer_config_cb(TIM_TypeDef* tmr, uint32_t* clk, OnTick cb) {
|
|||||||
IRQn_Type irqn;
|
IRQn_Type irqn;
|
||||||
uint32_t irq_priority;
|
uint32_t irq_priority;
|
||||||
|
|
||||||
|
switch((uint32_t)tmr) {
|
||||||
|
case (uint32_t)TIM1:
|
||||||
// get clocks config
|
// get clocks config
|
||||||
if (tmr == TIM1) {
|
|
||||||
*clk = sysclks.apb2_timer_freq;
|
*clk = sysclks.apb2_timer_freq;
|
||||||
|
|
||||||
// register callback function
|
// register callback function
|
||||||
@ -44,8 +45,10 @@ int timer_config_cb(TIM_TypeDef* tmr, uint32_t* clk, OnTick cb) {
|
|||||||
|
|
||||||
// enable timer clocking
|
// enable timer clocking
|
||||||
RCC->APB2ENR |= 1<<11;
|
RCC->APB2ENR |= 1<<11;
|
||||||
|
break;
|
||||||
|
|
||||||
} else if (tmr == TIM2) {
|
case (uint32_t)TIM2:
|
||||||
|
// get clocks config
|
||||||
*clk = sysclks.apb1_timer_freq;
|
*clk = sysclks.apb1_timer_freq;
|
||||||
|
|
||||||
// register callback function
|
// register callback function
|
||||||
@ -55,8 +58,10 @@ int timer_config_cb(TIM_TypeDef* tmr, uint32_t* clk, OnTick cb) {
|
|||||||
|
|
||||||
// enable timer clocking
|
// enable timer clocking
|
||||||
RCC->APB1ENR |= 1<<0;
|
RCC->APB1ENR |= 1<<0;
|
||||||
|
break;
|
||||||
|
|
||||||
} else if (tmr == TIM3) {
|
case (uint32_t)TIM3:
|
||||||
|
// get clocks config
|
||||||
*clk = sysclks.apb1_timer_freq;
|
*clk = sysclks.apb1_timer_freq;
|
||||||
|
|
||||||
// register callback function
|
// register callback function
|
||||||
@ -66,8 +71,10 @@ int timer_config_cb(TIM_TypeDef* tmr, uint32_t* clk, OnTick cb) {
|
|||||||
|
|
||||||
// enable timer clocking
|
// enable timer clocking
|
||||||
RCC->APB1ENR |= 1<<1;
|
RCC->APB1ENR |= 1<<1;
|
||||||
|
break;
|
||||||
|
|
||||||
} else if (tmr == TIM4) {
|
case (uint32_t)TIM4:
|
||||||
|
// get clocks config
|
||||||
*clk = sysclks.apb1_timer_freq;
|
*clk = sysclks.apb1_timer_freq;
|
||||||
|
|
||||||
// register callback function
|
// register callback function
|
||||||
@ -77,8 +84,11 @@ int timer_config_cb(TIM_TypeDef* tmr, uint32_t* clk, OnTick cb) {
|
|||||||
|
|
||||||
// enable timer clocking
|
// enable timer clocking
|
||||||
RCC->APB1ENR |= 1<<2;
|
RCC->APB1ENR |= 1<<2;
|
||||||
|
break;
|
||||||
|
|
||||||
} else return -1;
|
default:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// clear pending interrupts
|
// clear pending interrupts
|
||||||
tmr->SR &= !1;
|
tmr->SR &= !1;
|
||||||
@ -184,8 +194,9 @@ int timer_tick_init(TIM_TypeDef *tmr, uint16_t tick_ms, OnTick cb) {
|
|||||||
IRQn_Type irqn;
|
IRQn_Type irqn;
|
||||||
uint32_t irq_priority, clk;
|
uint32_t irq_priority, clk;
|
||||||
|
|
||||||
|
switch((uint32_t)tmr) {
|
||||||
|
case (uint32_t)TIM1:
|
||||||
// get back the clock frequency
|
// get back the clock frequency
|
||||||
if (tmr == TIM1) {
|
|
||||||
clk = sysclks.apb2_timer_freq;
|
clk = sysclks.apb2_timer_freq;
|
||||||
|
|
||||||
// register callback function
|
// register callback function
|
||||||
@ -195,8 +206,10 @@ int timer_tick_init(TIM_TypeDef *tmr, uint16_t tick_ms, OnTick cb) {
|
|||||||
|
|
||||||
// enable timer clocking
|
// enable timer clocking
|
||||||
RCC->APB2ENR |= 1<<11;
|
RCC->APB2ENR |= 1<<11;
|
||||||
|
break;
|
||||||
|
|
||||||
} else if (tmr == TIM2) {
|
case (uint32_t)TIM2:
|
||||||
|
// get back the clock frequency
|
||||||
clk = sysclks.apb1_timer_freq;
|
clk = sysclks.apb1_timer_freq;
|
||||||
|
|
||||||
// register callback function
|
// register callback function
|
||||||
@ -206,8 +219,10 @@ int timer_tick_init(TIM_TypeDef *tmr, uint16_t tick_ms, OnTick cb) {
|
|||||||
|
|
||||||
// enable timer clocking
|
// enable timer clocking
|
||||||
RCC->APB1ENR |= 1<<0;
|
RCC->APB1ENR |= 1<<0;
|
||||||
|
break;
|
||||||
|
|
||||||
} else if (tmr == TIM3) {
|
case (uint32_t)TIM3:
|
||||||
|
// get back the clock frequency
|
||||||
clk = sysclks.apb1_timer_freq;
|
clk = sysclks.apb1_timer_freq;
|
||||||
|
|
||||||
// register callback function
|
// register callback function
|
||||||
@ -217,8 +232,10 @@ int timer_tick_init(TIM_TypeDef *tmr, uint16_t tick_ms, OnTick cb) {
|
|||||||
|
|
||||||
// enable timer clocking
|
// enable timer clocking
|
||||||
RCC->APB1ENR |= 1<<1;
|
RCC->APB1ENR |= 1<<1;
|
||||||
|
break;
|
||||||
|
|
||||||
} else if (tmr == TIM4) {
|
case (uint32_t)TIM4:
|
||||||
|
// get back the clock frequency
|
||||||
clk = sysclks.apb1_timer_freq;
|
clk = sysclks.apb1_timer_freq;
|
||||||
|
|
||||||
// register callback function
|
// register callback function
|
||||||
@ -228,8 +245,11 @@ int timer_tick_init(TIM_TypeDef *tmr, uint16_t tick_ms, OnTick cb) {
|
|||||||
|
|
||||||
// enable timer clocking
|
// enable timer clocking
|
||||||
RCC->APB1ENR |= 1<<2;
|
RCC->APB1ENR |= 1<<2;
|
||||||
|
break;
|
||||||
|
|
||||||
} else return -1;
|
default:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// clear pending interrupts
|
// clear pending interrupts
|
||||||
tmr->SR &= !1;
|
tmr->SR &= !1;
|
||||||
@ -238,11 +258,11 @@ int timer_tick_init(TIM_TypeDef *tmr, uint16_t tick_ms, OnTick cb) {
|
|||||||
tmr->CR1 = (1<<7) | (1<<2); //buffering and update settings
|
tmr->CR1 = (1<<7) | (1<<2); //buffering and update settings
|
||||||
tmr->DIER = (1<<0); //Enable interrupts
|
tmr->DIER = (1<<0); //Enable interrupts
|
||||||
|
|
||||||
// set prescaler 1ms
|
// set prescaler 0.5ms
|
||||||
tmr->PSC = 8*(clk/1000)-1; //PSC = clk/f - 1 | don't know why 8 times...
|
tmr->PSC = 8*(clk/2000)-1; //PSC = clk/f - 1 | don't know why 8 times...
|
||||||
|
|
||||||
// set period
|
// set period
|
||||||
if(timer_set_period(tmr,tick_ms)) return -1;
|
if(timer_set_period(tmr, tick_ms)) return -1;
|
||||||
|
|
||||||
if (cb) {
|
if (cb) {
|
||||||
NVIC_SetPriority(irqn,irq_priority);
|
NVIC_SetPriority(irqn,irq_priority);
|
||||||
@ -254,7 +274,7 @@ int timer_tick_init(TIM_TypeDef *tmr, uint16_t tick_ms, OnTick cb) {
|
|||||||
|
|
||||||
int timer_set_period(TIM_TypeDef *tmr, uint16_t tick) {
|
int timer_set_period(TIM_TypeDef *tmr, uint16_t tick) {
|
||||||
// set period
|
// set period
|
||||||
tmr->ARR = tick-1; //tickms = (ARR+1)Tpsc
|
tmr->ARR = tick*2-1; //tickms = (ARR+1)Tpsc
|
||||||
|
|
||||||
// force update to reset counter and apply prescaler
|
// force update to reset counter and apply prescaler
|
||||||
tmr->EGR |= 1;
|
tmr->EGR |= 1;
|
||||||
@ -277,19 +297,26 @@ void timer_stop(TIM_TypeDef *tmr) {
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
int timer_enc_init(TIM_TypeDef* tmr) {
|
int timer_enc_init(TIM_TypeDef* tmr) {
|
||||||
// enable timer
|
// enable timer
|
||||||
if (tmr == TIM1) {
|
switch((uint32_t)tmr) {
|
||||||
|
case (uint32_t)TIM1:
|
||||||
RCC->APB2ENR |= 1<<11;
|
RCC->APB2ENR |= 1<<11;
|
||||||
|
break;
|
||||||
|
|
||||||
} else if (tmr == TIM2) {
|
case (uint32_t)TIM2:
|
||||||
RCC->APB1ENR |= 1<<0;
|
RCC->APB1ENR |= 1<<0;
|
||||||
|
break;
|
||||||
|
|
||||||
} else if (tmr == TIM3) {
|
case (uint32_t)TIM3:
|
||||||
RCC->APB1ENR |= 1<<1;
|
RCC->APB1ENR |= 1<<1;
|
||||||
|
break;
|
||||||
|
|
||||||
} else if (tmr == TIM4) {
|
case (uint32_t)TIM4:
|
||||||
RCC->APB1ENR |= 1<<2;
|
RCC->APB1ENR |= 1<<2;
|
||||||
|
break;
|
||||||
|
|
||||||
} else return -1; //no such timer
|
default:
|
||||||
|
return -1; //no such timer
|
||||||
|
}
|
||||||
|
|
||||||
//TODO set registers at reset value
|
//TODO set registers at reset value
|
||||||
|
|
||||||
|
|||||||
@ -19,6 +19,7 @@ int timer_wait_ms(TIM_TypeDef *tmr, uint16_t ms, OnTick cb);
|
|||||||
int timer_wait_us(TIM_TypeDef *tmr, uint16_t us, OnTick cb);
|
int timer_wait_us(TIM_TypeDef *tmr, uint16_t us, OnTick cb);
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
/** timer_tick_init
|
/** timer_tick_init
|
||||||
* setup timer to call cb function periodically, each tick_ms
|
* setup timer to call cb function periodically, each tick_ms
|
||||||
*/
|
*/
|
||||||
|
|||||||
52
src/main.c
52
src/main.c
@ -1,52 +0,0 @@
|
|||||||
// standard headers
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
// driver includes
|
|
||||||
#include "drivers/rcc.h"
|
|
||||||
#include "drivers/io.h"
|
|
||||||
|
|
||||||
Clock_t sysclks;
|
|
||||||
#include "drivers/timer.h"
|
|
||||||
|
|
||||||
extern uint32_t end;
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
/* static variables */;
|
|
||||||
int val = 0; //debug led
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
/* Timer IRQ */
|
|
||||||
static void timeout_cb(void) {
|
|
||||||
io_write(GPIOC, val, PIN_13);
|
|
||||||
val = !val;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
/* main function */
|
|
||||||
int main(void) {
|
|
||||||
|
|
||||||
// configure clocks (necessary before using timers)
|
|
||||||
rcc_config_clock(CLOCK_CONFIG_PERFORMANCE, &sysclks);
|
|
||||||
|
|
||||||
// configure GPIO for LED
|
|
||||||
if(io_configure(GPIOC, PIN_13, IO_MODE_OUTPUT | IO_OUT_PUSH_PULL, 0))
|
|
||||||
return -1;
|
|
||||||
io_write(GPIOC, 1, PIN_13);
|
|
||||||
|
|
||||||
// start timed interruption
|
|
||||||
timer_tick_init(TIM2, 1000, timeout_cb);
|
|
||||||
timer_start(TIM2);
|
|
||||||
|
|
||||||
uint32_t test = (uint32_t)(&end);
|
|
||||||
test++;
|
|
||||||
int* tab = (int*)malloc(10*sizeof(int));
|
|
||||||
for(int i=0; i<10; ++i) {
|
|
||||||
tab[i] = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
// main loop
|
|
||||||
for(;;);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user