mirror of
https://github.com/eddyem/stm32samples.git
synced 2026-03-21 17:21:04 +03:00
3steppers next stage
This commit is contained in:
@@ -26,20 +26,23 @@
|
||||
#include "flash.h"
|
||||
#include "strfunct.h"
|
||||
|
||||
extern const uint32_t __varsstart, _BLOCKSIZE;
|
||||
|
||||
static const uint32_t blocksize = (uint32_t)&_BLOCKSIZE;
|
||||
|
||||
// max amount of Config records stored (will be recalculate in flashstorage_init()
|
||||
static uint32_t maxCnum = FLASH_BLOCK_SIZE / sizeof(user_conf);
|
||||
static uint32_t maxCnum = 1024 / sizeof(user_conf); // can't use blocksize here
|
||||
|
||||
#define USERCONF_INITIALIZER { \
|
||||
.userconf_sz = sizeof(user_conf) \
|
||||
,.defflags.reverse = 0 \
|
||||
,.CANspeed = 100 \
|
||||
,.microsteps = 16 \
|
||||
,.accdecsteps = 25 \
|
||||
,.motspd = 1000 \
|
||||
,.maxsteps = 50000 \
|
||||
,.CANID = 0xaa \
|
||||
,.microsteps = {32, 32, 32} \
|
||||
,.accdecsteps = {25, 25, 25} \
|
||||
,.maxspd = {1000, 1000, 1000} \
|
||||
,.maxsteps = {50000, 50000, 50000} \
|
||||
,.motflags = {{0},{0},{0}} \
|
||||
}
|
||||
|
||||
static int erase_flash(const void*, const void*);
|
||||
static int write2flash(const void*, const void*, uint32_t);
|
||||
// don't write `static` here, or get error:
|
||||
@@ -83,7 +86,7 @@ static int binarySearch(int r, const uint8_t *start, int stor_size){
|
||||
*/
|
||||
void flashstorage_init(){
|
||||
if(FLASH_SIZE > 0 && FLASH_SIZE < 20000){
|
||||
uint32_t flsz = FLASH_SIZE * 1024; // size in bytes
|
||||
uint32_t flsz = FLASH_SIZE * blocksize; // size in bytes
|
||||
flsz -= (uint32_t)(&__varsstart) - FLASH_BASE;
|
||||
maxCnum = flsz / sizeof(user_conf);
|
||||
}
|
||||
@@ -147,13 +150,13 @@ static int erase_flash(const void *start, const void *end){
|
||||
uint32_t nblocks = 1, flsz = 0;
|
||||
if(!end){ // erase all remaining
|
||||
if(FLASH_SIZE > 0 && FLASH_SIZE < 20000){
|
||||
flsz = FLASH_SIZE * 1024; // size in bytes
|
||||
flsz = FLASH_SIZE * blocksize; // size in bytes
|
||||
flsz -= (uint32_t)start - FLASH_BASE;
|
||||
}
|
||||
}else{ // erase a part
|
||||
flsz = (uint32_t)end - (uint32_t)start;
|
||||
}
|
||||
nblocks = flsz / FLASH_BLOCK_SIZE;
|
||||
nblocks = flsz / blocksize;
|
||||
if(nblocks == 0 || nblocks >= FLASH_SIZE) return 1;
|
||||
for(uint32_t i = 0; i < nblocks; ++i){
|
||||
IWDG->KR = IWDG_REFRESH;
|
||||
@@ -177,7 +180,7 @@ static int erase_flash(const void *start, const void *end){
|
||||
/* (5) Clear EOP flag by software by writing EOP at 1 */
|
||||
/* (6) Reset the PER Bit to disable the page erase */
|
||||
FLASH->CR |= FLASH_CR_PER; /* (1) */
|
||||
FLASH->AR = (uint32_t)Flash_Data + i*FLASH_BLOCK_SIZE; /* (2) */
|
||||
FLASH->AR = (uint32_t)Flash_Data + i*blocksize; /* (2) */
|
||||
FLASH->CR |= FLASH_CR_STRT; /* (3) */
|
||||
while(!(FLASH->SR & FLASH_SR_EOP));
|
||||
FLASH->SR |= FLASH_SR_EOP; /* (5)*/
|
||||
@@ -191,16 +194,32 @@ static int erase_flash(const void *start, const void *end){
|
||||
return ret;
|
||||
}
|
||||
|
||||
void dump_userconf(){
|
||||
SEND("userconf_addr="); printuhex((uint32_t)Flash_Data);
|
||||
SEND("\nuserconf_sz="); printu(the_conf.userconf_sz);
|
||||
SEND("\nCANspeed="); printu(the_conf.CANspeed);
|
||||
SEND("\nmicrosteps="); printu(the_conf.microsteps);
|
||||
SEND("\naccdecsteps="); printu(the_conf.accdecsteps);
|
||||
SEND("\nmotspd="); printu(the_conf.motspd);
|
||||
SEND("\nmaxsteps="); printu(the_conf.maxsteps);
|
||||
//flags
|
||||
SEND("\nreverse="); bufputchar('0' + the_conf.defflags.reverse);
|
||||
void dump_userconf(_U_ char *txt){
|
||||
#ifdef EBUG
|
||||
SEND("flashsize="); printu(FLASH_SIZE); bufputchar('*');
|
||||
printu(blocksize); bufputchar('='); printu(FLASH_SIZE*blocksize);
|
||||
newline();
|
||||
sendbuf();
|
||||
#endif
|
||||
SEND("userconf_addr="); printuhex((uint32_t)Flash_Data);
|
||||
SEND("\nuserconf_idx="); printi(currentconfidx);
|
||||
SEND("\nuserconf_sz="); printu(the_conf.userconf_sz);
|
||||
SEND("\ncanspeed="); printu(the_conf.CANspeed);
|
||||
SEND("\ncanid="); printu(the_conf.CANID);
|
||||
// motors' data
|
||||
for(int i = 0; i < MOTORSNO; ++i){
|
||||
char cur = '0' + i;
|
||||
#define PROPNAME(nm) do{newline(); SEND(nm); bufputchar(cur); bufputchar('=');}while(0)
|
||||
PROPNAME("reverse");
|
||||
bufputchar('0' + the_conf.motflags[i].reverse);
|
||||
PROPNAME("microsteps");
|
||||
printu(the_conf.microsteps[i]);
|
||||
PROPNAME("accdecsteps");
|
||||
printu(the_conf.accdecsteps[i]);
|
||||
PROPNAME("maxspeed");
|
||||
printu(the_conf.maxspd[i]);
|
||||
PROPNAME("maxsteps");
|
||||
printu(the_conf.maxsteps[i]);
|
||||
#undef PROPNAME
|
||||
}
|
||||
NL();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user