add systick
This commit is contained in:
parent
56449d9dfb
commit
3e0f2aacf9
4 changed files with 27 additions and 7 deletions
4
Makefile
4
Makefile
|
@ -21,7 +21,7 @@ VPATH = . ./$(TARGET)
|
||||||
|
|
||||||
# zdrojaky -> objekty
|
# zdrojaky -> objekty
|
||||||
OBJS = STM32L4x2_startup.o system.o
|
OBJS = STM32L4x2_startup.o system.o
|
||||||
MOBJS = main.o io.o
|
MOBJS = main.o io.o sys.o
|
||||||
|
|
||||||
BOBJS = $(addprefix $(BLD),$(OBJS))
|
BOBJS = $(addprefix $(BLD),$(OBJS))
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ $(BLD)%.o: %.cpp
|
||||||
$(BLD):
|
$(BLD):
|
||||||
mkdir $(BLD)
|
mkdir $(BLD)
|
||||||
# MODULES #
|
# MODULES #
|
||||||
main.o: main.cpp io.pcm
|
main.o: main.cpp io.pcm sys.pcm
|
||||||
%.o: %.cpp
|
%.o: %.cpp
|
||||||
-@echo [CXM $(TARGET)] $@
|
-@echo [CXM $(TARGET)] $@
|
||||||
@$(CXX) $(VFLAGS) -c $(MFLAGS) $< -o $@
|
@$(CXX) $(VFLAGS) -c $(MFLAGS) $< -o $@
|
||||||
|
|
4
io.cpp
4
io.cpp
|
@ -179,8 +179,4 @@ namespace io {
|
||||||
RCC.AHB2ENR.R |= cPortTab[port].clkMask;
|
RCC.AHB2ENR.R |= cPortTab[port].clkMask;
|
||||||
setMode (type);
|
setMode (type);
|
||||||
}
|
}
|
||||||
export void wait (const unsigned ms = 500000u) {
|
|
||||||
volatile unsigned n;
|
|
||||||
for (n=0u; n<ms; n+=1) asm volatile ("nop");
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
4
main.cpp
4
main.cpp
|
@ -1,12 +1,14 @@
|
||||||
/* SIMPLE EXAMPLE: LED blinking */
|
/* SIMPLE EXAMPLE: LED blinking */
|
||||||
import io; // use module !!!
|
import io; // use module !!!
|
||||||
|
import sys;
|
||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
static io::GpioClass led (GpioPortA, 10);
|
static io::GpioClass led (GpioPortA, 10);
|
||||||
|
|
||||||
int main () {
|
int main () {
|
||||||
|
sys::init ();
|
||||||
for (;;) {
|
for (;;) {
|
||||||
~led; // change status - unary ~
|
~led; // change status - unary ~
|
||||||
io::wait ();
|
sys::delay ();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
22
sys.cpp
Normal file
22
sys.cpp
Normal 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);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in a new issue