add systick

This commit is contained in:
Kizarm 2024-01-16 20:05:11 +01:00
parent 56449d9dfb
commit 3e0f2aacf9
4 changed files with 27 additions and 7 deletions

View file

@ -21,7 +21,7 @@ VPATH = . ./$(TARGET)
# zdrojaky -> objekty
OBJS = STM32L4x2_startup.o system.o
MOBJS = main.o io.o
MOBJS = main.o io.o sys.o
BOBJS = $(addprefix $(BLD),$(OBJS))
@ -48,7 +48,7 @@ $(BLD)%.o: %.cpp
$(BLD):
mkdir $(BLD)
# MODULES #
main.o: main.cpp io.pcm
main.o: main.cpp io.pcm sys.pcm
%.o: %.cpp
-@echo [CXM $(TARGET)] $@
@$(CXX) $(VFLAGS) -c $(MFLAGS) $< -o $@

4
io.cpp
View file

@ -179,8 +179,4 @@ namespace io {
RCC.AHB2ENR.R |= cPortTab[port].clkMask;
setMode (type);
}
export void wait (const unsigned ms = 500000u) {
volatile unsigned n;
for (n=0u; n<ms; n+=1) asm volatile ("nop");
}
};

View file

@ -1,12 +1,14 @@
/* SIMPLE EXAMPLE: LED blinking */
import io; // use module !!!
import sys;
//////////////////////////////////////
static io::GpioClass led (GpioPortA, 10);
int main () {
sys::init ();
for (;;) {
~led; // change status - unary ~
io::wait ();
sys::delay ();
}
return 0;
}

22
sys.cpp Normal file
View file

@ -0,0 +1,22 @@
module;
#include "CortexM4.h"
#include "system.h"
export module sys;
static volatile unsigned count = 0u;
extern "C" void SysTick_Handler () {
if (count) count -= 1u;
}
namespace sys {
export void delay (const unsigned ms = 500) {
count = ms;
while (count) {
asm volatile ("wfi");
}
}
export void init () {
EnableDebugOnSleep();
SysTick.Config (SystemCoreClock / 1000u);
}
};