STM32F411: get timer.c in, so far only with the system clock.
This test code in SysTickHandler() should give you a rather
accurate clock with only a few seconds deviation per hour:
#include "serial.h"
#include "sersendf.h"
void SysTick_Handler(void) {
static uint32_t count = 0;
static uint8_t minutes = 0, seconds = 0;
count++;
if ( ! (count % 500)) { // A full second.
seconds++;
if ( ! (seconds % 60)) {
seconds = 0;
minutes++;
}
sersendf_P(PSTR("%su:"), minutes);
if (seconds < 10)
serial_writechar('0');
sersendf_P(PSTR("%su\n"), seconds);
}
[...]
This commit is contained in:
parent
65dab6b180
commit
a798cfac34
|
|
@ -20,6 +20,8 @@
|
|||
|
||||
#include "cmsis-stm32f4xx.h"
|
||||
|
||||
#define F_CPU __SYSTEM_CLOCK
|
||||
|
||||
/** Pins for UART, the serial port.
|
||||
*/
|
||||
#define RXD_PORT PIOA_3_PORT
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define __SYSTEM_CLOCK 96000000
|
||||
/** @addtogroup STM32F4xx_System_Includes
|
||||
* @{
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -12,8 +12,43 @@
|
|||
|
||||
Initialise timer and enable system clock interrupt. Step interrupt is
|
||||
enabled later, when we start using it.
|
||||
|
||||
For the system clock, we use SysTickTimer. This timer is made for exactly
|
||||
such purposes.
|
||||
*/
|
||||
void timer_init() {
|
||||
|
||||
/**
|
||||
Initialise the system tick timer
|
||||
|
||||
We enable the system tick timer with interrupts. A similar function is
|
||||
SysTick_Config(uint32_t ticks) in cmsis-core_cm4.h
|
||||
|
||||
Register name mapping from STM32F4xx
|
||||
|
||||
*/
|
||||
NVIC_SetPriority(SysTick_IRQn, 0); // Highest priority.
|
||||
|
||||
// SysTick defined in cmsis-core_cm4.h.
|
||||
SysTick->LOAD = TICK_TIME - 1; // set reload register
|
||||
SysTick->VAL = 0; // Load the SysTick Counter Value
|
||||
|
||||
SysTick->CTRL = SysTick_CTRL_ENABLE_Msk // Enable the ticker.
|
||||
| SysTick_CTRL_TICKINT_Msk // Enable interrupt.
|
||||
| SysTick_CTRL_CLKSOURCE_Msk; // Run at full CPU clock.
|
||||
}
|
||||
|
||||
/** System clock interrupt.
|
||||
|
||||
Happens every TICK_TIME. Must have the same name as in
|
||||
cmsis-startup_lpc11xx.s
|
||||
*/
|
||||
void SysTick_Handler(void) {
|
||||
|
||||
#ifndef __ARMEL_NOTYET__
|
||||
clock_tick();
|
||||
dda_clock();
|
||||
#endif /* __ARMEL_NOTYET__ */
|
||||
}
|
||||
|
||||
/** Specify how long until the step timer should fire.
|
||||
|
|
@ -58,6 +93,7 @@ uint8_t timer_set(int32_t delay, uint8_t check_short) {
|
|||
This means to be an emergency stop.
|
||||
*/
|
||||
void timer_stop() {
|
||||
SysTick->CTRL = 0;
|
||||
}
|
||||
|
||||
#endif /* defined TEACUP_C_INCLUDE && defined __ARM_STM32F411__ */
|
||||
|
|
|
|||
Loading…
Reference in New Issue