config incapsulated to module
This commit is contained in:
@@ -30,6 +30,9 @@ all: main.bin
|
|||||||
OBJS+= main.o
|
OBJS+= main.o
|
||||||
OBJS+= syscall.o
|
OBJS+= syscall.o
|
||||||
OBJS+= usartu.o
|
OBJS+= usartu.o
|
||||||
|
OBJS+= config.o
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
main.elf: $(OBJS)
|
main.elf: $(OBJS)
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022 Oleg Borodin <borodin@unix7.org>
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <libopencm3/stm32/flash.h>
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
|
void config_init(config_t* c) {
|
||||||
|
c->gz = 0x00;
|
||||||
|
c->gy = 0x00;
|
||||||
|
};
|
||||||
|
|
||||||
|
config_t* config_getptr() {
|
||||||
|
return (config_t*)&_config;
|
||||||
|
}
|
||||||
|
|
||||||
|
void config_save(config_t* ptr) {
|
||||||
|
flash_unlock();
|
||||||
|
flash_erase_sector(SECTOR_NO, sizeof(config_t));
|
||||||
|
uint32_t caddr = (uint32_t)&_config;
|
||||||
|
flash_program(caddr, (uint8_t*)ptr, (uint32_t)sizeof(config_t));
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022 Oleg Borodin <borodin@unix7.org>
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef CONFIG_H_QWERTY
|
||||||
|
#define CONFIG_H_QWERTY
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define SECTOR_NO 1
|
||||||
|
extern uint8_t _config;
|
||||||
|
|
||||||
|
typedef struct __attribute__ ((packed)) {
|
||||||
|
int32_t gz;
|
||||||
|
int32_t gy;
|
||||||
|
} config_t;
|
||||||
|
|
||||||
|
void config_init(config_t* c);
|
||||||
|
void config_save(config_t* ptr);
|
||||||
|
config_t* config_getptr();
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
+8
-26
@@ -19,6 +19,7 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include <usartu.h>
|
#include <usartu.h>
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
static void clock_setup(void) {
|
static void clock_setup(void) {
|
||||||
rcc_clock_setup_pll(&rcc_hse_8mhz_3v3[RCC_CLOCK_3V3_168MHZ]);
|
rcc_clock_setup_pll(&rcc_hse_8mhz_3v3[RCC_CLOCK_3V3_168MHZ]);
|
||||||
@@ -48,41 +49,22 @@ static void usart_setup(uint32_t usart, uint32_t gpioport, uint32_t gpiopins, ui
|
|||||||
usart_enable(usart);
|
usart_enable(usart);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SECTOR_NO 1
|
|
||||||
extern uint8_t _config;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int32_t gz;
|
|
||||||
int32_t gy;
|
|
||||||
} config_t;
|
|
||||||
|
|
||||||
void config_init(config_t* c){
|
|
||||||
c->gz = 0x12;
|
|
||||||
c->gy = 0x17;
|
|
||||||
};
|
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
|
|
||||||
clock_setup();
|
clock_setup();
|
||||||
usart_setup(USART1, GPIOA, GPIO9 | GPIO10, 115200);
|
usart_setup(USART1, GPIOA, GPIO9 | GPIO10, 115200);
|
||||||
|
|
||||||
uint32_t caddr = 0xFFFFFFFF;
|
config_t rconfig;
|
||||||
caddr = (uint32_t)&_config;
|
config_init(&rconfig);
|
||||||
config_t* dconfig = (config_t*)caddr;
|
rconfig.gz = 0x15;
|
||||||
|
rconfig.gy = 0x19;
|
||||||
|
|
||||||
config_t tconfig;
|
config_save(&rconfig);
|
||||||
config_init(&tconfig);
|
|
||||||
|
|
||||||
flash_unlock();
|
config_t* sconfig = config_getptr();
|
||||||
flash_erase_sector(SECTOR_NO, sizeof(config_t));
|
|
||||||
|
|
||||||
printf("\r\n");
|
printf("gy = 0x%08lx \r\n", sconfig->gy);
|
||||||
printf("gy = 0x%08lx \r\n", dconfig->gy);
|
|
||||||
|
|
||||||
flash_program(caddr, (uint8_t*)&tconfig, (uint32_t)sizeof(config_t));
|
|
||||||
|
|
||||||
printf("gy = 0x%08lx \r\n", dconfig->gy);
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
||||||
|
|||||||
+1
-7
@@ -116,7 +116,7 @@ int _wait(int *status) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
void *xxx_sbrk(int incr) {
|
void *_sbrk(int incr) {
|
||||||
|
|
||||||
extern unsigned char *_end;
|
extern unsigned char *_end;
|
||||||
static unsigned char *heap = NULL;
|
static unsigned char *heap = NULL;
|
||||||
@@ -146,14 +146,8 @@ caddr_t __attribute__((weak)) _sbrk (int incr) {
|
|||||||
prev_heap_end = heap_end;
|
prev_heap_end = heap_end;
|
||||||
|
|
||||||
if (heap_end + incr > stack_ptr) {
|
if (heap_end + incr > stack_ptr) {
|
||||||
#if 0
|
|
||||||
extern void abort (void);
|
|
||||||
_write (1, "_sbrk: Heap and stack collision\n", 32);
|
|
||||||
abort ();
|
|
||||||
#else
|
|
||||||
errno = ENOMEM;
|
errno = ENOMEM;
|
||||||
return (caddr_t) -1;
|
return (caddr_t) -1;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
heap_end += incr;
|
heap_end += incr;
|
||||||
|
|||||||
Reference in New Issue
Block a user