mirror of
https://github.com/rene-dev/stmbl.git
synced 2026-02-05 18:01:21 +08:00
fix for config load error
This commit is contained in:
@@ -63,7 +63,6 @@ MEM(volatile float jog_timeout) = 0.0;
|
||||
MEM(volatile float jog_en) = 0.0;
|
||||
|
||||
INIT(
|
||||
hal_conf_init();
|
||||
if(hal_conf_load()){//flash load error
|
||||
hal.hal_state = CONFIG_LOAD_ERROR;
|
||||
}
|
||||
@@ -255,13 +254,25 @@ NRT(
|
||||
}else if(ret == -3){
|
||||
printf("flash read error\n");
|
||||
}else if(ret == -4){
|
||||
printf("hal running error\n");
|
||||
printf("cannot load while hal is running(run 'stop' command)\n");
|
||||
}else if(ret == -5){
|
||||
printf("CRC error\n");
|
||||
}else{
|
||||
printf("done\n");
|
||||
}
|
||||
}
|
||||
else if(!strcmp(s, "initflash")){//TODO: command to format param sectors, init sometimes fails...
|
||||
if(hal.rt_state != RT_STOP || hal.frt_state != FRT_STOP){
|
||||
printf("cannot init flash while hal is running(run 'stop' command)\n");
|
||||
}else{
|
||||
uint16_t ret = hal_conf_init();
|
||||
if(ret == FLASH_COMPLETE){
|
||||
printf("flash init OK. now do load or save\n");
|
||||
}else{
|
||||
printf("init error: %i\n",ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(!strcmp(s, "getconf")){
|
||||
hal_term_getconf();
|
||||
}
|
||||
|
||||
@@ -4,17 +4,18 @@
|
||||
#include "link.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void hal_conf_init(){
|
||||
uint16_t hal_conf_init(){
|
||||
FLASH_Unlock();
|
||||
EE_Init();
|
||||
uint16_t ret = EE_Init();
|
||||
FLASH_Lock();
|
||||
return ret;
|
||||
}
|
||||
|
||||
void hal_conf_save(){
|
||||
// if(ee_error != FLASH_COMPLETE){
|
||||
// printf("flash error:%i\n",ee_error);
|
||||
// return;
|
||||
// }
|
||||
if(hal.rt_state != RT_STOP || hal.frt_state != FRT_STOP){
|
||||
printf("cannot save while hal is running(run 'stop' command)\n");
|
||||
return(-1);
|
||||
}
|
||||
typedef union{
|
||||
float f;
|
||||
uint16_t byte[2];
|
||||
@@ -42,8 +43,9 @@ void hal_conf_save(){
|
||||
elo = EE_WriteVariable(address,param.byte[0]);
|
||||
ehi = EE_WriteVariable(address+1,param.byte[1]);
|
||||
if(elo != FLASH_COMPLETE || ehi != FLASH_COMPLETE){
|
||||
printf("error writing to %i: error%i,%i\n",address,elo,ehi);
|
||||
break;
|
||||
FLASH_Lock();
|
||||
printf("error writing to address %i: error: %i,%i\n",address,elo,ehi);
|
||||
return -1;
|
||||
}
|
||||
address+=2;
|
||||
}
|
||||
@@ -52,19 +54,19 @@ void hal_conf_save(){
|
||||
crc = crc16_finalize(crc);
|
||||
elo = EE_WriteVariable(address, crc);
|
||||
if(elo != FLASH_COMPLETE){
|
||||
printf("error writing crc to %i: error%i\n",address,elo);
|
||||
printf("error writing crc to address %i: error: %i\n",address,elo);
|
||||
FLASH_Lock();
|
||||
return -1;
|
||||
}
|
||||
FLASH_Lock();
|
||||
printf("done\n");
|
||||
printf("flash save OK\n");
|
||||
}
|
||||
|
||||
int hal_conf_load(){
|
||||
if(hal.rt_state != RT_STOP || hal.frt_state != FRT_STOP){
|
||||
return(-4);
|
||||
}
|
||||
// if(ee_error != FLASH_COMPLETE){
|
||||
// return -1;
|
||||
// }
|
||||
|
||||
typedef union{
|
||||
float f;
|
||||
uint16_t byte[2];
|
||||
@@ -93,6 +95,7 @@ int hal_conf_load(){
|
||||
param.byte[1] = hi;
|
||||
hal.hal_pins[i]->value = param.f;
|
||||
}else{
|
||||
printf("error reading address %i: %i,%i\n",address,elo,ehi);
|
||||
return -3;
|
||||
}
|
||||
address+=2;
|
||||
@@ -101,6 +104,7 @@ int hal_conf_load(){
|
||||
}
|
||||
elo = EE_ReadVariable(address,&lo);
|
||||
if(elo != 0){
|
||||
printf("error reading crc from address %i: %i\n",address,elo);
|
||||
return -3;
|
||||
}
|
||||
crc = crc16_finalize(crc);
|
||||
|
||||
@@ -6,4 +6,4 @@
|
||||
|
||||
void hal_conf_save();
|
||||
int hal_conf_load();
|
||||
void hal_conf_init();
|
||||
uint16_t hal_conf_init();
|
||||
|
||||
Reference in New Issue
Block a user