mirror of
https://github.com/eddyem/stm32samples.git
synced 2025-12-06 18:55:13 +03:00
V 0.0.2
This commit is contained in:
parent
abdbac3e38
commit
7e9f81ca54
@ -8,10 +8,10 @@ MCU ?= F103x8
|
|||||||
# density (stm32f10x.h, lines 70-84)
|
# density (stm32f10x.h, lines 70-84)
|
||||||
DENSITY ?= MD
|
DENSITY ?= MD
|
||||||
# change this linking script depending on particular MCU model,
|
# change this linking script depending on particular MCU model,
|
||||||
LDSCRIPT ?= stm32f103x8.ld
|
LDSCRIPT ?= stm32f103xB.ld
|
||||||
DEFS = -DVERSION=\"0.0.1\"
|
DEFS = -DVERSION=\"0.0.1\"
|
||||||
# debug
|
# debug
|
||||||
DEFS += -DEBUG
|
#DEFS += -DEBUG
|
||||||
# proxy GPS output over USART1
|
# proxy GPS output over USART1
|
||||||
DEFS += -DUSART1PROXY
|
DEFS += -DUSART1PROXY
|
||||||
|
|
||||||
|
|||||||
@ -19,8 +19,15 @@ Chronometer for downhill competitions
|
|||||||
|
|
||||||
- PC13 - buzzer
|
- PC13 - buzzer
|
||||||
|
|
||||||
|
## LEDS
|
||||||
|
|
||||||
|
- LED0 - shining when there's no PPS signal, fades for 0.25s on PPS
|
||||||
|
- LED1 - don't shines if no GPS found, shines when time not valid, blinks when time valid
|
||||||
|
|
||||||
### Not implemented yet:
|
### Not implemented yet:
|
||||||
|
|
||||||
- PA5,6,7 (SCK, MISO, MOSI) - SPI
|
- PA5,6,7 (SCK, MISO, MOSI) - SPI
|
||||||
- PB0 - TRIG4 - ADC channel 8
|
- PB0 - TRIG4 - ADC channel 8
|
||||||
- PB6/7 (SCL, SDA) - I2C
|
- PB6/7 (SCL, SDA) - I2C
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@ -39,9 +39,7 @@
|
|||||||
#include "adc.h"
|
#include "adc.h"
|
||||||
#include "flash.h"
|
#include "flash.h"
|
||||||
#include "lidar.h"
|
#include "lidar.h"
|
||||||
#ifdef EBUG
|
#include "usart.h" // DBG
|
||||||
#include "usart.h"
|
|
||||||
#endif
|
|
||||||
#include <string.h> // memcpy
|
#include <string.h> // memcpy
|
||||||
|
|
||||||
extern uint32_t _edata, _etext, _sdata;
|
extern uint32_t _edata, _etext, _sdata;
|
||||||
@ -49,22 +47,22 @@ static int maxnum = FLASH_BLOCK_SIZE / sizeof(user_conf);
|
|||||||
|
|
||||||
|
|
||||||
typedef struct{
|
typedef struct{
|
||||||
const user_conf all_stored;
|
const user_conf all_stored;
|
||||||
} flash_storage;
|
} flash_storage;
|
||||||
|
|
||||||
#define USERCONF_INITIALIZER { \
|
#define USERCONF_INITIALIZER { \
|
||||||
.userconf_sz = sizeof(user_conf) \
|
.userconf_sz = sizeof(user_conf) \
|
||||||
,.dist_min = LIDAR_MIN_DIST \
|
,.dist_min = LIDAR_MIN_DIST \
|
||||||
,.dist_max = LIDAR_MAX_DIST \
|
,.dist_max = LIDAR_MAX_DIST \
|
||||||
,.trig_pullups = 0xff \
|
,.trig_pullups = 0xff \
|
||||||
,.trigstate = 0 \
|
,.trigstate = 0 \
|
||||||
,.trigpause = {400, 400, 400, 300, 300} \
|
,.trigpause = {400, 400, 400, 300, 300} \
|
||||||
,.ADC_min = ADC_MIN_VAL \
|
,.ADC_min = ADC_MIN_VAL \
|
||||||
,.ADC_max = ADC_MAX_VAL \
|
,.ADC_max = ADC_MAX_VAL \
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((section(".myvars"))) static const flash_storage Flash_Storage = {
|
__attribute__((section(".myvars"))) static const flash_storage Flash_Storage = {
|
||||||
.all_stored = USERCONF_INITIALIZER
|
.all_stored = USERCONF_INITIALIZER
|
||||||
};
|
};
|
||||||
|
|
||||||
static const user_conf *Flash_Data = &Flash_Storage.all_stored;
|
static const user_conf *Flash_Data = &Flash_Storage.all_stored;
|
||||||
|
|||||||
@ -46,9 +46,11 @@ extern uint8_t buzzer_on;
|
|||||||
|
|
||||||
// PPS and triggers state
|
// PPS and triggers state
|
||||||
// amount of triggers, should be less than 9; 5 - 0..2 - switches, 3 - LIDAR, 4 - ADC
|
// amount of triggers, should be less than 9; 5 - 0..2 - switches, 3 - LIDAR, 4 - ADC
|
||||||
#define TRIGGERS_AMOUNT (5)
|
#define TRIGGERS_AMOUNT (5)
|
||||||
|
// number of LIDAR trigger
|
||||||
|
#define LIDAR_TRIGGER (3)
|
||||||
// amount of digital triggers (on interrupts)
|
// amount of digital triggers (on interrupts)
|
||||||
#define DIGTRIG_AMOUNT (3)
|
#define DIGTRIG_AMOUNT (3)
|
||||||
|
|
||||||
uint8_t gettrig(uint8_t N);
|
uint8_t gettrig(uint8_t N);
|
||||||
void fillshotms(int i);
|
void fillshotms(int i);
|
||||||
|
|||||||
@ -50,7 +50,7 @@ void parse_lidar_data(char *txt){
|
|||||||
savetrigtime();
|
savetrigtime();
|
||||||
triggered = 1;
|
triggered = 1;
|
||||||
lidar_triggered_dist = last_lidar_dist;
|
lidar_triggered_dist = last_lidar_dist;
|
||||||
fillshotms(3);
|
fillshotms(LIDAR_TRIGGER);
|
||||||
#ifdef EBUG
|
#ifdef EBUG
|
||||||
SEND("Triggered! distance=");
|
SEND("Triggered! distance=");
|
||||||
printu(1, last_lidar_dist);
|
printu(1, last_lidar_dist);
|
||||||
|
|||||||
@ -240,7 +240,7 @@ int main(void){
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
RCC->CSR |= RCC_CSR_RMVF; // remove reset flags
|
RCC->CSR |= RCC_CSR_RMVF; // remove reset flags
|
||||||
//iwdg_setup();
|
iwdg_setup();
|
||||||
|
|
||||||
while (1){
|
while (1){
|
||||||
IWDG->KR = IWDG_REFRESH; // refresh watchdog
|
IWDG->KR = IWDG_REFRESH; // refresh watchdog
|
||||||
|
|||||||
@ -19,6 +19,7 @@
|
|||||||
#include "adc.h"
|
#include "adc.h"
|
||||||
#include "flash.h"
|
#include "flash.h"
|
||||||
#include "GPS.h"
|
#include "GPS.h"
|
||||||
|
#include "lidar.h"
|
||||||
#include "str.h"
|
#include "str.h"
|
||||||
#include "time.h"
|
#include "time.h"
|
||||||
#include "usart.h"
|
#include "usart.h"
|
||||||
@ -285,8 +286,14 @@ void show_trigger_shot(uint8_t tshot){
|
|||||||
if(tshot & X) tshot &= ~X;
|
if(tshot & X) tshot &= ~X;
|
||||||
else continue;
|
else continue;
|
||||||
if(trigger_shot & X) trigger_shot &= ~X;
|
if(trigger_shot & X) trigger_shot &= ~X;
|
||||||
USB_send("TRIG");
|
if(i == LIDAR_TRIGGER){
|
||||||
sendu(i);
|
USB_send("LIDAR, dist=");
|
||||||
|
sendu(lidar_triggered_dist);
|
||||||
|
USB_send(", TRIG=");
|
||||||
|
}else{
|
||||||
|
USB_send("TRIG");
|
||||||
|
sendu(i);
|
||||||
|
}
|
||||||
USB_send("=");
|
USB_send("=");
|
||||||
USB_send(get_time(&shottime[i].Time, shottime[i].millis));
|
USB_send(get_time(&shottime[i].Time, shottime[i].millis));
|
||||||
USB_send("\n");
|
USB_send("\n");
|
||||||
|
|||||||
@ -121,8 +121,9 @@ char *get_time(curtime *Tm, uint32_t T){
|
|||||||
|
|
||||||
|
|
||||||
#ifdef EBUG
|
#ifdef EBUG
|
||||||
int32_t ticksdiff=0, timecntr=0, timerval, Tms1;
|
int32_t timerval, Tms1;
|
||||||
#endif
|
#endif
|
||||||
|
int32_t timecntr=0, ticksdiff=0;
|
||||||
|
|
||||||
uint32_t last_corr_time = 0;
|
uint32_t last_corr_time = 0;
|
||||||
|
|
||||||
@ -145,8 +146,10 @@ void systick_correction(){
|
|||||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; // stop systick for a while
|
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk; // stop systick for a while
|
||||||
uint32_t systick_val = SysTick->VAL, L = SysTick->LOAD + 1;
|
uint32_t systick_val = SysTick->VAL, L = SysTick->LOAD + 1;
|
||||||
int32_t timer_val = Timer;
|
int32_t timer_val = Timer;
|
||||||
|
#ifdef EBUG
|
||||||
timerval = Timer;
|
timerval = Timer;
|
||||||
Tms1 = Tms;
|
Tms1 = Tms;
|
||||||
|
#endif
|
||||||
Timer = 0;
|
Timer = 0;
|
||||||
SysTick->VAL = SysTick->LOAD;
|
SysTick->VAL = SysTick->LOAD;
|
||||||
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk; // start it again
|
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk; // start it again
|
||||||
@ -155,7 +158,9 @@ void systick_correction(){
|
|||||||
if(last_corr_time){
|
if(last_corr_time){
|
||||||
if(Tms - last_corr_time < 1500){ // there was perevious PPS signal
|
if(Tms - last_corr_time < 1500){ // there was perevious PPS signal
|
||||||
int32_t D = L * (Tms - 1000 - last_corr_time) + (SysTick->LOAD - systick_val); // amount of spare ticks
|
int32_t D = L * (Tms - 1000 - last_corr_time) + (SysTick->LOAD - systick_val); // amount of spare ticks
|
||||||
|
#ifdef EBUG
|
||||||
++timecntr;
|
++timecntr;
|
||||||
|
#endif
|
||||||
ticksdiff += D;
|
ticksdiff += D;
|
||||||
uint32_t ticksabs = (ticksdiff < 0) ? -ticksdiff : ticksdiff;
|
uint32_t ticksabs = (ticksdiff < 0) ? -ticksdiff : ticksdiff;
|
||||||
// 10000 == 30 seconds * 1000 interrupts per second
|
// 10000 == 30 seconds * 1000 interrupts per second
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user