mirror of
https://github.com/eddyem/stm32samples.git
synced 2026-08-13 19:49:24 +03:00
some minor bugs fixed
This commit is contained in:
@@ -17,9 +17,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "adc.h"
|
#include "adc.h"
|
||||||
#ifdef EBUG
|
|
||||||
#include "proto.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ADCx_array - arrays for ADC channels with median filtering:
|
* @brief ADCx_array - arrays for ADC channels with median filtering:
|
||||||
@@ -126,39 +123,23 @@ uint16_t getADCval(int nch){
|
|||||||
PIX_SORT(p[4], p[2]) ;
|
PIX_SORT(p[4], p[2]) ;
|
||||||
#undef PIX_SORT
|
#undef PIX_SORT
|
||||||
#undef PIX_SWAP
|
#undef PIX_SWAP
|
||||||
/*
|
|
||||||
#ifdef EBUG
|
|
||||||
DBG("val: "); printu(p[4]); newline();
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
return p[4];
|
return p[4];
|
||||||
}
|
}
|
||||||
|
|
||||||
// get voltage @input nch (V) *1000V
|
// get voltage @input nch (V) *1000V
|
||||||
int32_t getADCvoltage(int nch){
|
int32_t getADCvoltage(int nch){
|
||||||
float v = getADCval(nch) * 3.3;
|
float v = getADCval(nch) * getVdd();
|
||||||
v /= 4.096f; // 12bit ADC
|
v /= 4096.f; // 12bit ADC
|
||||||
/*
|
|
||||||
#ifdef EBUG
|
|
||||||
DBG("v="); printf(v); newline();
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
return (uint32_t) v;
|
return (uint32_t) v;
|
||||||
}
|
}
|
||||||
|
|
||||||
// return MCU temperature (*1000 degrees of celsius)
|
// return MCU temperature (*1000 degrees of celsius)
|
||||||
int32_t getMCUtemp(){
|
int32_t getMCUtemp(){
|
||||||
// make correction on Vdd value
|
|
||||||
int32_t ADval = getADCval(ADC_TS);
|
int32_t ADval = getADCval(ADC_TS);
|
||||||
float temperature = (float) *TEMP30_CAL_ADDR - ADval;
|
float temperature = (float) *TEMP30_CAL_ADDR - ADval;
|
||||||
temperature *= (110.f - 30.f);
|
temperature *= (110.f - 30.f);
|
||||||
temperature /= (float)(*TEMP30_CAL_ADDR - *TEMP110_CAL_ADDR);
|
temperature /= (float)(*TEMP30_CAL_ADDR - *TEMP110_CAL_ADDR);
|
||||||
temperature += 30.f;
|
temperature += 30.f;
|
||||||
/*
|
|
||||||
#ifdef EBUG
|
|
||||||
DBG("t="); printf(temperature); newline();
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
return (uint32_t) (temperature*1000.f);
|
return (uint32_t) (temperature*1000.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,10 +147,5 @@ int32_t getMCUtemp(){
|
|||||||
int32_t getVdd(){
|
int32_t getVdd(){
|
||||||
float vdd = ((float) *VREFINT_CAL_ADDR) * 3.3f; // 3.3V
|
float vdd = ((float) *VREFINT_CAL_ADDR) * 3.3f; // 3.3V
|
||||||
vdd /= getADCval(ADC_VREF);
|
vdd /= getADCval(ADC_VREF);
|
||||||
/*
|
|
||||||
#ifdef EBUG
|
|
||||||
DBG("vdd="); printf(vdd); newline();
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
return (uint32_t) (vdd * 1000.f);
|
return (uint32_t) (vdd * 1000.f);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,9 +31,10 @@ uint32_t lastUnsleep = 0; // last keys activity time
|
|||||||
|
|
||||||
void process_keys(){
|
void process_keys(){
|
||||||
static uint32_t lastT = 0;
|
static uint32_t lastT = 0;
|
||||||
if(Tms == lastT) return;
|
uint32_t TmsNow = Tms; // make local copy to prevent variable changing
|
||||||
uint16_t d = (uint16_t)(Tms - lastT);
|
if(TmsNow == lastT) return;
|
||||||
lastT = Tms;
|
uint16_t d = (uint16_t)(TmsNow - lastT);
|
||||||
|
lastT = TmsNow;
|
||||||
for(int i = 0; i < BTNSNO; ++i){
|
for(int i = 0; i < BTNSNO; ++i){
|
||||||
keybase *k = &allkeys[i];
|
keybase *k = &allkeys[i];
|
||||||
keyevent e = k->event;
|
keyevent e = k->event;
|
||||||
@@ -62,8 +63,8 @@ void process_keys(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(e != k->event){
|
if(e != k->event){
|
||||||
k->lastTms = Tms;
|
k->lastTms = TmsNow;
|
||||||
lastUnsleep = Tms;
|
lastUnsleep = TmsNow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ uint32_t floodT = FLOOD_PERIOD_MS; // flood period in ms
|
|||||||
static uint8_t incrflood = 0; // ==1 for incremental flooding
|
static uint8_t incrflood = 0; // ==1 for incremental flooding
|
||||||
static uint32_t incrmessagectr = 0; // counter for incremental flooding
|
static uint32_t incrmessagectr = 0; // counter for incremental flooding
|
||||||
|
|
||||||
static uint32_t last_err_code = 0;
|
|
||||||
static CAN_status can_status = CAN_STOP;
|
static CAN_status can_status = CAN_STOP;
|
||||||
|
|
||||||
static void can_process_fifo(uint8_t fifo_num);
|
static void can_process_fifo(uint8_t fifo_num);
|
||||||
@@ -54,17 +53,8 @@ CAN_status CAN_get_status(){
|
|||||||
// push next message into buffer; return 1 if buffer overfull
|
// push next message into buffer; return 1 if buffer overfull
|
||||||
static int CAN_messagebuf_push(CAN_message *msg){
|
static int CAN_messagebuf_push(CAN_message *msg){
|
||||||
//MSG("Try to push\n");
|
//MSG("Try to push\n");
|
||||||
#ifdef EBUG
|
|
||||||
USB_sendstr("push: ");
|
|
||||||
for(int i = 0; i < msg->length; ++i){
|
|
||||||
printuhex(msg->data[i]); USB_putbyte(' ');
|
|
||||||
}
|
|
||||||
newline();
|
|
||||||
#endif
|
|
||||||
if(first_free_idx == first_nonfree_idx){
|
if(first_free_idx == first_nonfree_idx){
|
||||||
#ifdef EBUG
|
|
||||||
USB_sendstr("INBUF OVERFULL\n");
|
|
||||||
#endif
|
|
||||||
return 1; // no free space
|
return 1; // no free space
|
||||||
}
|
}
|
||||||
if(first_nonfree_idx < 0) first_nonfree_idx = 0; // first message in empty buffer
|
if(first_nonfree_idx < 0) first_nonfree_idx = 0; // first message in empty buffer
|
||||||
@@ -77,22 +67,12 @@ static int CAN_messagebuf_push(CAN_message *msg){
|
|||||||
// pop message from buffer
|
// pop message from buffer
|
||||||
CAN_message *CAN_messagebuf_pop(){
|
CAN_message *CAN_messagebuf_pop(){
|
||||||
if(first_nonfree_idx < 0) return NULL;
|
if(first_nonfree_idx < 0) return NULL;
|
||||||
#ifdef EBUG
|
|
||||||
//MSG("read from idx "); printu(first_nonfree_idx); NL();
|
|
||||||
#endif
|
|
||||||
CAN_message *msg = &messages[first_nonfree_idx++];
|
CAN_message *msg = &messages[first_nonfree_idx++];
|
||||||
if(first_nonfree_idx == CAN_INMESSAGE_SIZE) first_nonfree_idx = 0;
|
if(first_nonfree_idx == CAN_INMESSAGE_SIZE) first_nonfree_idx = 0;
|
||||||
if(first_nonfree_idx == first_free_idx){ // buffer is empty - refresh it
|
if(first_nonfree_idx == first_free_idx){ // buffer is empty - refresh it
|
||||||
first_nonfree_idx = -1;
|
first_nonfree_idx = -1;
|
||||||
first_free_idx = 0;
|
first_free_idx = 0;
|
||||||
}
|
}
|
||||||
#ifdef EBUG
|
|
||||||
USB_sendstr("pop: ");
|
|
||||||
for(int i = 0; i < msg->length; ++i){
|
|
||||||
printuhex(msg->data[i]); USB_putbyte(' ');
|
|
||||||
}
|
|
||||||
newline();
|
|
||||||
#endif
|
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,7 +130,7 @@ void CAN_setup(uint16_t speed){
|
|||||||
CAN->MCR |= CAN_MCR_INRQ; /* (1) */
|
CAN->MCR |= CAN_MCR_INRQ; /* (1) */
|
||||||
while((CAN->MSR & CAN_MSR_INAK) != CAN_MSR_INAK) /* (2) */
|
while((CAN->MSR & CAN_MSR_INAK) != CAN_MSR_INAK) /* (2) */
|
||||||
if(--tmout == 0) break;
|
if(--tmout == 0) break;
|
||||||
if(tmout==0){ DBG("timeout!\n");}
|
if(tmout==0){ DBG("Init mode entering timeout!\n");}
|
||||||
CAN->MCR &=~ CAN_MCR_SLEEP; /* (3) */
|
CAN->MCR &=~ CAN_MCR_SLEEP; /* (3) */
|
||||||
CAN->MCR |= CAN_MCR_ABOM; /* allow automatically bus-off */
|
CAN->MCR |= CAN_MCR_ABOM; /* allow automatically bus-off */
|
||||||
|
|
||||||
@@ -159,7 +139,7 @@ void CAN_setup(uint16_t speed){
|
|||||||
tmout = 10000;
|
tmout = 10000;
|
||||||
while(CAN->MSR & CAN_MSR_INAK) /* (6) */
|
while(CAN->MSR & CAN_MSR_INAK) /* (6) */
|
||||||
if(--tmout == 0) break;
|
if(--tmout == 0) break;
|
||||||
if(tmout==0){ DBG("timeout!\n");}
|
if(tmout==0){ DBG("Init mode exiting timeout!\n");}
|
||||||
// accept ALL
|
// accept ALL
|
||||||
CAN->FMR = CAN_FMR_FINIT; /* (7) */
|
CAN->FMR = CAN_FMR_FINIT; /* (7) */
|
||||||
CAN->FA1R = CAN_FA1R_FACT0 | CAN_FA1R_FACT1; /* (8) */
|
CAN->FA1R = CAN_FA1R_FACT0 | CAN_FA1R_FACT1; /* (8) */
|
||||||
@@ -182,7 +162,7 @@ void CAN_setup(uint16_t speed){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CAN_printerr(){
|
void CAN_printerr(){
|
||||||
if(!last_err_code) last_err_code = CAN->ESR;
|
uint32_t last_err_code = CAN->ESR;
|
||||||
if(!last_err_code){
|
if(!last_err_code){
|
||||||
USB_sendstr("No errors\n");
|
USB_sendstr("No errors\n");
|
||||||
return;
|
return;
|
||||||
@@ -207,19 +187,10 @@ void CAN_printerr(){
|
|||||||
if(last_err_code & CAN_ESR_BOFF) USB_sendstr("Bus off ");
|
if(last_err_code & CAN_ESR_BOFF) USB_sendstr("Bus off ");
|
||||||
if(last_err_code & CAN_ESR_EPVF) USB_sendstr("Passive error limit ");
|
if(last_err_code & CAN_ESR_EPVF) USB_sendstr("Passive error limit ");
|
||||||
if(last_err_code & CAN_ESR_EWGF) USB_sendstr("Error counter limit");
|
if(last_err_code & CAN_ESR_EWGF) USB_sendstr("Error counter limit");
|
||||||
last_err_code = 0;
|
|
||||||
USB_putbyte('\n');
|
USB_putbyte('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAN_proc(){
|
void CAN_proc(){
|
||||||
#ifdef EBUG
|
|
||||||
if(last_err_code){
|
|
||||||
USB_sendstr("Error, ESR=");
|
|
||||||
USB_sendstr(u2str(last_err_code));
|
|
||||||
USB_putbyte('\n');
|
|
||||||
last_err_code = 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
// check for messages in FIFO0 & FIFO1
|
// check for messages in FIFO0 & FIFO1
|
||||||
if(CAN->RF0R & CAN_RF0R_FMP0){
|
if(CAN->RF0R & CAN_RF0R_FMP0){
|
||||||
can_process_fifo(0);
|
can_process_fifo(0);
|
||||||
@@ -254,20 +225,9 @@ CAN_status CAN_send(uint8_t *msg, uint8_t len, uint16_t target_id){
|
|||||||
if(CAN->TSR & (CAN_TSR_TME)){
|
if(CAN->TSR & (CAN_TSR_TME)){
|
||||||
mailbox = (CAN->TSR & CAN_TSR_CODE) >> 24;
|
mailbox = (CAN->TSR & CAN_TSR_CODE) >> 24;
|
||||||
}else{ // no free mailboxes
|
}else{ // no free mailboxes
|
||||||
#ifdef EBUG
|
|
||||||
USB_sendstr("No free mailboxes\n");
|
|
||||||
#endif
|
|
||||||
return CAN_BUSY;
|
return CAN_BUSY;
|
||||||
}
|
}
|
||||||
#ifdef EBUG
|
|
||||||
USB_sendstr("Send data. Len="); USB_sendstr(u2str(len));
|
|
||||||
USB_sendstr(", tagid="); USB_sendstr(u2str(target_id));
|
|
||||||
USB_sendstr(", data=");
|
|
||||||
for(int i = 0; i < len; ++i){
|
|
||||||
USB_sendstr(" "); USB_sendstr(uhex2str(msg[i]));
|
|
||||||
}
|
|
||||||
USB_putbyte('\n');
|
|
||||||
#endif
|
|
||||||
CAN_TxMailBox_TypeDef *box = &CAN->sTxMailBox[mailbox];
|
CAN_TxMailBox_TypeDef *box = &CAN->sTxMailBox[mailbox];
|
||||||
uint32_t lb = 0, hb = 0;
|
uint32_t lb = 0, hb = 0;
|
||||||
switch(len){
|
switch(len){
|
||||||
@@ -339,19 +299,9 @@ TRUE_INLINE void formerr(CAN_message *msg, errcodes err){
|
|||||||
*/
|
*/
|
||||||
TRUE_INLINE void parseCANcommand(CAN_message *msg){
|
TRUE_INLINE void parseCANcommand(CAN_message *msg){
|
||||||
// we don't check msg here as it cannot be NULL
|
// we don't check msg here as it cannot be NULL
|
||||||
#ifdef EBUG
|
|
||||||
DBG("Get data: ");
|
|
||||||
for(int i = 0; i < msg->length; ++i){
|
|
||||||
USB_sendstr(uhex2str(msg->data[i])); USB_putbyte(' ');
|
|
||||||
}
|
|
||||||
for(int i = msg->length-1; i < 8; ++i) msg->data[i] = 0;
|
|
||||||
newline();
|
|
||||||
#endif
|
|
||||||
if(msg->length == 0) goto sendmessage; // PING
|
if(msg->length == 0) goto sendmessage; // PING
|
||||||
uint16_t Index = *(uint16_t*)msg->data;
|
uint16_t Index = *(uint16_t*)msg->data;
|
||||||
#ifdef EBUG
|
|
||||||
USB_sendstr("Index = "); USB_sendstr(u2str(Index)); newline();
|
|
||||||
#endif
|
|
||||||
if(Index >= CCMD_AMOUNT || !cancmdlist[Index]){
|
if(Index >= CCMD_AMOUNT || !cancmdlist[Index]){
|
||||||
formerr(msg, ERR_BADCMD);
|
formerr(msg, ERR_BADCMD);
|
||||||
goto sendmessage;
|
goto sendmessage;
|
||||||
@@ -369,9 +319,7 @@ TRUE_INLINE void parseCANcommand(CAN_message *msg){
|
|||||||
formerr(msg, ERR_WRONGLEN);
|
formerr(msg, ERR_WRONGLEN);
|
||||||
goto sendmessage;
|
goto sendmessage;
|
||||||
}
|
}
|
||||||
#ifdef EBUG
|
|
||||||
USB_sendstr("Run command\n");
|
|
||||||
#endif
|
|
||||||
errcodes ec = cancmdlist[Index](par, val);
|
errcodes ec = cancmdlist[Index](par, val);
|
||||||
if(ec != ERR_OK){
|
if(ec != ERR_OK){
|
||||||
formerr(msg, ec);
|
formerr(msg, ec);
|
||||||
@@ -387,10 +335,6 @@ static void can_process_fifo(uint8_t fifo_num){
|
|||||||
if(fifo_num > 1) return;
|
if(fifo_num > 1) return;
|
||||||
CAN_FIFOMailBox_TypeDef *box = &CAN->sFIFOMailBox[fifo_num];
|
CAN_FIFOMailBox_TypeDef *box = &CAN->sFIFOMailBox[fifo_num];
|
||||||
volatile uint32_t *RFxR = (fifo_num) ? &CAN->RF1R : &CAN->RF0R;
|
volatile uint32_t *RFxR = (fifo_num) ? &CAN->RF1R : &CAN->RF0R;
|
||||||
#ifdef EBUG
|
|
||||||
USB_sendstr(u2str(*RFxR & CAN_RF0R_FMP0)); USB_sendstr(" messages in FIFO #");
|
|
||||||
USB_sendstr(u2str(fifo_num)); newline();
|
|
||||||
#endif
|
|
||||||
// read all
|
// read all
|
||||||
while(*RFxR & CAN_RF0R_FMP0){ // amount of messages pending
|
while(*RFxR & CAN_RF0R_FMP0){ // amount of messages pending
|
||||||
// CAN_RDTxR: (16-31) - timestamp, (8-15) - filter match index, (0-3) - data length
|
// CAN_RDTxR: (16-31) - timestamp, (8-15) - filter match index, (0-3) - data length
|
||||||
@@ -456,9 +400,6 @@ void can1_rx1_isr(){ // Rx FIFO1 (overrun)
|
|||||||
|
|
||||||
void can1_sce_isr(){ // status changed
|
void can1_sce_isr(){ // status changed
|
||||||
if(CAN->MSR & CAN_MSR_ERRI){ // Error
|
if(CAN->MSR & CAN_MSR_ERRI){ // Error
|
||||||
#ifdef EBUG
|
|
||||||
last_err_code = CAN->ESR;
|
|
||||||
#endif
|
|
||||||
CAN->MSR = CAN_MSR_ERRI; // clear flag
|
CAN->MSR = CAN_MSR_ERRI; // clear flag
|
||||||
// request abort for problem mailbox
|
// request abort for problem mailbox
|
||||||
if(CAN->TSR & CAN_TSR_TERR0) CAN->TSR |= CAN_TSR_ABRQ0;
|
if(CAN->TSR & CAN_TSR_TERR0) CAN->TSR |= CAN_TSR_ABRQ0;
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ errcodes cu_accel(uint8_t _U_ par, int32_t _U_ *val){
|
|||||||
uint8_t n; CHECKN(n, par);
|
uint8_t n; CHECKN(n, par);
|
||||||
errcodes ret = ERR_OK;
|
errcodes ret = ERR_OK;
|
||||||
if(ISSETTER(par)){
|
if(ISSETTER(par)){
|
||||||
|
if(ismoving(n)) return ERR_CANTRUN;
|
||||||
if(*val/the_conf.microsteps[n] > ACCELMAXSTEPS || *val < 1) return ERR_BADVAL;
|
if(*val/the_conf.microsteps[n] > ACCELMAXSTEPS || *val < 1) return ERR_BADVAL;
|
||||||
uint16_t acc = the_conf.accel[n];
|
uint16_t acc = the_conf.accel[n];
|
||||||
the_conf.accel[n] = *val;
|
the_conf.accel[n] = *val;
|
||||||
@@ -113,7 +114,7 @@ errcodes cu_drvtype(uint8_t par, int32_t *val){
|
|||||||
uint8_t n; CHECKN(n, par);
|
uint8_t n; CHECKN(n, par);
|
||||||
motflags_t *fl = &the_conf.motflags[n];
|
motflags_t *fl = &the_conf.motflags[n];
|
||||||
if(ISSETTER(par)){
|
if(ISSETTER(par)){
|
||||||
if(*val >= DRVTYPE_AMOUNT) return ERR_BADVAL;
|
if(*val >= DRVTYPE_AMOUNT || *val < 0) return ERR_BADVAL;
|
||||||
fl->drvtype = *val;
|
fl->drvtype = *val;
|
||||||
}
|
}
|
||||||
*val = fl->drvtype;
|
*val = fl->drvtype;
|
||||||
@@ -134,6 +135,7 @@ errcodes cu_emstop(uint8_t par, int32_t _U_ *val){
|
|||||||
|
|
||||||
errcodes cu_eraseflash(uint8_t _U_ par, int32_t _U_ *val){
|
errcodes cu_eraseflash(uint8_t _U_ par, int32_t _U_ *val){
|
||||||
NOPARCHK(par);
|
NOPARCHK(par);
|
||||||
|
if(isanymoving()) return ERR_CANTRUN;
|
||||||
if(ISSETTER(par)){
|
if(ISSETTER(par)){
|
||||||
if(erase_storage(*val)) return ERR_BADVAL;
|
if(erase_storage(*val)) return ERR_BADVAL;
|
||||||
}else if(erase_storage(-1)) return ERR_CANTRUN;
|
}else if(erase_storage(-1)) return ERR_CANTRUN;
|
||||||
@@ -151,6 +153,7 @@ errcodes cu_eswreact(uint8_t _U_ par, int32_t _U_ *val){
|
|||||||
uint8_t n; CHECKN(n, par);
|
uint8_t n; CHECKN(n, par);
|
||||||
errcodes ret = ERR_OK;
|
errcodes ret = ERR_OK;
|
||||||
if(ISSETTER(par)){
|
if(ISSETTER(par)){
|
||||||
|
if(ismoving(n)) return ERR_CANTRUN;
|
||||||
if(*val < 0 || *val > ESW_AMOUNT-1) return ERR_BADVAL;
|
if(*val < 0 || *val > ESW_AMOUNT-1) return ERR_BADVAL;
|
||||||
uint8_t react = the_conf.ESW_reaction[n];
|
uint8_t react = the_conf.ESW_reaction[n];
|
||||||
the_conf.ESW_reaction[n] = *val;
|
the_conf.ESW_reaction[n] = *val;
|
||||||
@@ -192,14 +195,7 @@ errcodes cu_gpio(uint8_t par, int32_t *val){
|
|||||||
#error "change the code!!!"
|
#error "change the code!!!"
|
||||||
#endif
|
#endif
|
||||||
uint8_t n = PARBASE(par);
|
uint8_t n = PARBASE(par);
|
||||||
#ifdef EBUG
|
|
||||||
USND("par="); printu(par);
|
|
||||||
USND(", n="); USB_putbyte('0'+n); newline();
|
|
||||||
#endif
|
|
||||||
if(n == CANMESG_NOPAR){ // all
|
if(n == CANMESG_NOPAR){ // all
|
||||||
#ifdef EBUG
|
|
||||||
USND("ALL\n");
|
|
||||||
#endif
|
|
||||||
uint8_t g = (uint8_t)*val;
|
uint8_t g = (uint8_t)*val;
|
||||||
if(ISSETTER(par)){
|
if(ISSETTER(par)){
|
||||||
for(int i = 0; i < EXTNO; ++i){
|
for(int i = 0; i < EXTNO; ++i){
|
||||||
@@ -241,6 +237,7 @@ errcodes cu_maxspeed(uint8_t _U_ par, int32_t _U_ *val){
|
|||||||
uint8_t n; CHECKN(n, par);
|
uint8_t n; CHECKN(n, par);
|
||||||
errcodes ret = ERR_OK;
|
errcodes ret = ERR_OK;
|
||||||
if(ISSETTER(par)){
|
if(ISSETTER(par)){
|
||||||
|
if(ismoving(n)) return ERR_CANTRUN;
|
||||||
if(*val <= the_conf.minspd[n]) return ERR_BADVAL;
|
if(*val <= the_conf.minspd[n]) return ERR_BADVAL;
|
||||||
uint16_t maxspd = the_conf.maxspd[n];
|
uint16_t maxspd = the_conf.maxspd[n];
|
||||||
the_conf.maxspd[n] = getSPD(n, *val);
|
the_conf.maxspd[n] = getSPD(n, *val);
|
||||||
@@ -256,6 +253,7 @@ errcodes cu_maxspeed(uint8_t _U_ par, int32_t _U_ *val){
|
|||||||
errcodes cu_maxsteps(uint8_t _U_ par, int32_t _U_ *val){
|
errcodes cu_maxsteps(uint8_t _U_ par, int32_t _U_ *val){
|
||||||
uint8_t n; CHECKN(n, par);
|
uint8_t n; CHECKN(n, par);
|
||||||
if(ISSETTER(par)){
|
if(ISSETTER(par)){
|
||||||
|
if(ismoving(n)) return ERR_CANTRUN;
|
||||||
if(*val < 1) return ERR_BADVAL;
|
if(*val < 1) return ERR_BADVAL;
|
||||||
the_conf.maxsteps[n] = *val;
|
the_conf.maxsteps[n] = *val;
|
||||||
}
|
}
|
||||||
@@ -279,6 +277,7 @@ errcodes cu_mcuvdd(uint8_t par, int32_t *val){
|
|||||||
errcodes cu_microsteps(uint8_t _U_ par, int32_t _U_ *val){
|
errcodes cu_microsteps(uint8_t _U_ par, int32_t _U_ *val){
|
||||||
uint8_t n; CHECKN(n, par);
|
uint8_t n; CHECKN(n, par);
|
||||||
if(ISSETTER(par)){
|
if(ISSETTER(par)){
|
||||||
|
if(ismoving(n)) return ERR_CANTRUN;
|
||||||
#if MICROSTEPSMAX > 512
|
#if MICROSTEPSMAX > 512
|
||||||
#error "Change the code anywhere!"
|
#error "Change the code anywhere!"
|
||||||
#endif
|
#endif
|
||||||
@@ -305,6 +304,7 @@ errcodes cu_minspeed(uint8_t _U_ par, int32_t _U_ *val){
|
|||||||
uint8_t n; CHECKN(n, par);
|
uint8_t n; CHECKN(n, par);
|
||||||
errcodes ret = ERR_OK;
|
errcodes ret = ERR_OK;
|
||||||
if(ISSETTER(par)){
|
if(ISSETTER(par)){
|
||||||
|
if(ismoving(n)) return ERR_CANTRUN;
|
||||||
if(*val >= the_conf.maxspd[n] || *val < 0) return ERR_BADVAL;
|
if(*val >= the_conf.maxspd[n] || *val < 0) return ERR_BADVAL;
|
||||||
uint16_t minspd = the_conf.minspd[n];
|
uint16_t minspd = the_conf.minspd[n];
|
||||||
the_conf.minspd[n] = getSPD(n, *val);
|
the_conf.minspd[n] = getSPD(n, *val);
|
||||||
@@ -320,6 +320,7 @@ errcodes cu_minspeed(uint8_t _U_ par, int32_t _U_ *val){
|
|||||||
errcodes cu_motcurrent(uint8_t par, int32_t *val){
|
errcodes cu_motcurrent(uint8_t par, int32_t *val){
|
||||||
uint8_t n; CHECKN(n, par);
|
uint8_t n; CHECKN(n, par);
|
||||||
if(ISSETTER(par)){
|
if(ISSETTER(par)){
|
||||||
|
if(ismoving(n)) return ERR_CANTRUN;
|
||||||
if(*val < 0 || *val > 31) return ERR_BADVAL;
|
if(*val < 0 || *val > 31) return ERR_BADVAL;
|
||||||
the_conf.motcurrent[n] = *val;
|
the_conf.motcurrent[n] = *val;
|
||||||
motflags_t *f = the_conf.motflags;
|
motflags_t *f = the_conf.motflags;
|
||||||
@@ -335,6 +336,7 @@ errcodes cu_motflags(uint8_t _U_ par, int32_t _U_ *val){
|
|||||||
uint8_t n; CHECKN(n, par);
|
uint8_t n; CHECKN(n, par);
|
||||||
errcodes ret = ERR_OK;
|
errcodes ret = ERR_OK;
|
||||||
if(ISSETTER(par)){
|
if(ISSETTER(par)){
|
||||||
|
if(ismoving(n)) return ERR_CANTRUN;
|
||||||
motflags_t flags = the_conf.motflags[n];
|
motflags_t flags = the_conf.motflags[n];
|
||||||
the_conf.motflags[n] = *((motflags_t*)val);
|
the_conf.motflags[n] = *((motflags_t*)val);
|
||||||
if(!update_stepper(n)){
|
if(!update_stepper(n)){
|
||||||
@@ -347,9 +349,10 @@ errcodes cu_motflags(uint8_t _U_ par, int32_t _U_ *val){
|
|||||||
}
|
}
|
||||||
|
|
||||||
errcodes cu_motno(uint8_t _U_ par, int32_t _U_ *val){
|
errcodes cu_motno(uint8_t _U_ par, int32_t _U_ *val){
|
||||||
if(*val < 0 || *val >= MOTORSNO) return ERR_BADVAL;
|
uint8_t n; CHECKN(n, par);
|
||||||
if(ISSETTER(par)){
|
if(ISSETTER(par)){
|
||||||
if(!pdnuart_setmotno(*val)) return ERR_CANTRUN;
|
if(ismoving(n)) return ERR_CANTRUN;
|
||||||
|
if(!pdnuart_setmotno(n)) return ERR_CANTRUN;
|
||||||
}
|
}
|
||||||
*val = pdnuart_getmotno();
|
*val = pdnuart_getmotno();
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
@@ -362,16 +365,20 @@ errcodes cu_motmul(uint8_t _U_ par, int32_t _U_ *val){
|
|||||||
// witout parameter - reinit all steppers; with parameter - just update current
|
// witout parameter - reinit all steppers; with parameter - just update current
|
||||||
errcodes cu_motreinit(uint8_t _U_ par, int32_t _U_ *val){
|
errcodes cu_motreinit(uint8_t _U_ par, int32_t _U_ *val){
|
||||||
uint8_t n = PARBASE(par);
|
uint8_t n = PARBASE(par);
|
||||||
if(n == CANMESG_NOPAR) init_steppers();
|
if(n == CANMESG_NOPAR){
|
||||||
else{
|
// check that neither motor is moving
|
||||||
|
if(isanymoving()) return ERR_CANTRUN;
|
||||||
|
init_steppers();
|
||||||
|
}else{
|
||||||
if(n > MOTORSNO - 1) return ERR_BADPAR;
|
if(n > MOTORSNO - 1) return ERR_BADPAR;
|
||||||
if(!update_stepper(n)) return ERR_CANTRUN;
|
if(ismoving(n) || !update_stepper(n)) return ERR_CANTRUN;
|
||||||
}
|
}
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
errcodes cu_pdn(uint8_t par, int32_t *val){
|
errcodes cu_pdn(uint8_t par, int32_t *val){
|
||||||
uint8_t n = PARBASE(par);
|
uint8_t n; CHECKN(n, par);
|
||||||
|
if(ismoving(n)) return ERR_CANTRUN;
|
||||||
if(ISSETTER(par)){
|
if(ISSETTER(par)){
|
||||||
if(!pdnuart_writereg(n, *val)) return ERR_CANTRUN;
|
if(!pdnuart_writereg(n, *val)) return ERR_CANTRUN;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,11 +34,11 @@ motflags3=0x78
|
|||||||
eswreact3=0
|
eswreact3=0
|
||||||
microsteps4=32
|
microsteps4=32
|
||||||
accel4=2000
|
accel4=2000
|
||||||
maxspeed4=2000
|
maxspeed4=1000
|
||||||
minspeed4=20
|
minspeed4=20
|
||||||
maxsteps4=500000
|
maxsteps4=40000
|
||||||
motcurrent4=31
|
motcurrent4=31
|
||||||
motflags4=0x68
|
motflags4=0x78
|
||||||
eswreact4=0
|
eswreact4=0
|
||||||
microsteps5=32
|
microsteps5=32
|
||||||
accel5=500
|
accel5=500
|
||||||
|
|||||||
@@ -106,11 +106,13 @@ void flashstorage_init(){
|
|||||||
int store_userconf(){
|
int store_userconf(){
|
||||||
// maxnum - 3 means that there always should be at least one empty record after last data
|
// maxnum - 3 means that there always should be at least one empty record after last data
|
||||||
// for binarySearch() checking that there's nothing more after it!
|
// for binarySearch() checking that there's nothing more after it!
|
||||||
if(currentconfidx > (int)maxCnum - 3){ // there's no more place
|
int curidx = currentconfidx;
|
||||||
currentconfidx = 0;
|
if(curidx > (int)maxCnum - 3){ // there's no more place
|
||||||
|
curidx = 0;
|
||||||
if(erase_storage(-1)) return 1;
|
if(erase_storage(-1)) return 1;
|
||||||
}else ++currentconfidx; // take next data position (0 - within first run after firmware flashing)
|
}else ++curidx; // take next data position (0 - within first run after firmware flashing)
|
||||||
return write2flash((const void*)&Flash_Data[currentconfidx], &the_conf, sizeof(the_conf));
|
int r = write2flash((const void*)&Flash_Data[curidx], &the_conf, sizeof(the_conf));
|
||||||
|
if(0 == r) currentconfidx = curidx; // refresh counter only if succeed
|
||||||
}
|
}
|
||||||
|
|
||||||
static int write2flash(const void *start, const void *wrdata, uint32_t stor_size){
|
static int write2flash(const void *start, const void *wrdata, uint32_t stor_size){
|
||||||
@@ -135,9 +137,6 @@ static int write2flash(const void *start, const void *wrdata, uint32_t stor_size
|
|||||||
ret = 1;
|
ret = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#ifdef EBUG
|
|
||||||
else{ USB_sendstr("Written "); printuhex(data[i]); newline();}
|
|
||||||
#endif
|
|
||||||
if(FLASH->SR & FLASH_SR_PGERR){
|
if(FLASH->SR & FLASH_SR_PGERR){
|
||||||
USB_sendstr("Prog err\n");
|
USB_sendstr("Prog err\n");
|
||||||
ret = 1; // program error - meet not 0xffff
|
ret = 1; // program error - meet not 0xffff
|
||||||
@@ -152,9 +151,7 @@ static int write2flash(const void *start, const void *wrdata, uint32_t stor_size
|
|||||||
// erase Nth page of flash storage (flash should be prepared!)
|
// erase Nth page of flash storage (flash should be prepared!)
|
||||||
static int erase_pageN(int N){
|
static int erase_pageN(int N){
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
//#ifdef EBUG
|
|
||||||
USB_sendstr("Erase block #"); printu(N); newline();
|
USB_sendstr("Erase block #"); printu(N); newline();
|
||||||
//#endif
|
|
||||||
FLASH->AR = (uint32_t)Flash_Data + N*FLASH_blocksize;
|
FLASH->AR = (uint32_t)Flash_Data + N*FLASH_blocksize;
|
||||||
FLASH->CR |= FLASH_CR_STRT;
|
FLASH->CR |= FLASH_CR_STRT;
|
||||||
while(FLASH->SR & FLASH_SR_BSY) IWDG->KR = IWDG_REFRESH;
|
while(FLASH->SR & FLASH_SR_BSY) IWDG->KR = IWDG_REFRESH;
|
||||||
@@ -233,13 +230,11 @@ int fn_dumpmot(uint32_t _U_ hash, char _U_ *args){ // "dumpmot" (1224122507)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int fn_dumpconf(uint32_t _U_ hash, char _U_ *args){ // "dumpconf" (3271513185)
|
int fn_dumpconf(uint32_t _U_ hash, char _U_ *args){ // "dumpconf" (3271513185)
|
||||||
#ifdef EBUG
|
USB_sendstr("flashsize="); printu(FLASH_SIZE);
|
||||||
USB_sendstr("flashsize="); printu(FLASH_SIZE); USB_sendstr("kB\nblocksize=");
|
USB_sendstr("kB\nblocksize="); printu(FLASH_blocksize);
|
||||||
printu(FLASH_blocksize);
|
USB_sendstr("\nuserconf_addr="); printuhex((uint32_t)Flash_Data);
|
||||||
newline();
|
|
||||||
#endif
|
|
||||||
USB_sendstr("userconf_addr="); printuhex((uint32_t)Flash_Data);
|
|
||||||
USB_sendstr("\nuserconf_idx="); printi(currentconfidx);
|
USB_sendstr("\nuserconf_idx="); printi(currentconfidx);
|
||||||
|
USB_sendstr("\ncapacity="); printu(maxCnum-2);
|
||||||
USB_sendstr("\nuserconf_sz="); printu(the_conf.userconf_sz);
|
USB_sendstr("\nuserconf_sz="); printu(the_conf.userconf_sz);
|
||||||
USB_sendstr("\ncanspeed="); printu(the_conf.CANspeed);
|
USB_sendstr("\ncanspeed="); printu(the_conf.CANspeed);
|
||||||
USB_sendstr("\ncanid="); printu(the_conf.CANID);
|
USB_sendstr("\ncanid="); printu(the_conf.CANID);
|
||||||
|
|||||||
@@ -83,13 +83,6 @@ int main(void){
|
|||||||
int l = USB_receivestr(inbuff, MAXSTRLEN);
|
int l = USB_receivestr(inbuff, MAXSTRLEN);
|
||||||
if(l < 0) USB_sendstr("USB_BUF_OVERFLOW\n");
|
if(l < 0) USB_sendstr("USB_BUF_OVERFLOW\n");
|
||||||
else if(l){
|
else if(l){
|
||||||
/*
|
|
||||||
#ifdef EBUG
|
|
||||||
USB_sendstr("USB GOT:\n");
|
|
||||||
USB_sendstr(inbuff);
|
|
||||||
USB_sendstr("\n--------\n");
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
const char *ans = cmd_parser(inbuff);
|
const char *ans = cmd_parser(inbuff);
|
||||||
if(ans) USB_sendstr(ans);
|
if(ans) USB_sendstr(ans);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE QtCreatorProject>
|
<!DOCTYPE QtCreatorProject>
|
||||||
<!-- Written by QtCreator 18.0.1, 2026-01-20T16:33:49. -->
|
<!-- Written by QtCreator 20.0.0, 2026-07-13T16:54:37. -->
|
||||||
<qtcreator>
|
<qtcreator>
|
||||||
<data>
|
<data>
|
||||||
<variable>EnvironmentId</variable>
|
<variable>EnvironmentId</variable>
|
||||||
@@ -14,8 +14,6 @@
|
|||||||
<variable>ProjectExplorer.Project.EditorSettings</variable>
|
<variable>ProjectExplorer.Project.EditorSettings</variable>
|
||||||
<valuemap type="QVariantMap">
|
<valuemap type="QVariantMap">
|
||||||
<value type="bool" key="EditorConfiguration.AutoDetect">true</value>
|
<value type="bool" key="EditorConfiguration.AutoDetect">true</value>
|
||||||
<value type="bool" key="EditorConfiguration.AutoIndent">true</value>
|
|
||||||
<value type="bool" key="EditorConfiguration.CamelCaseNavigation">true</value>
|
|
||||||
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
|
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
|
||||||
<value type="QString" key="language">Cpp</value>
|
<value type="QString" key="language">Cpp</value>
|
||||||
<valuemap type="QVariantMap" key="value">
|
<valuemap type="QVariantMap" key="value">
|
||||||
@@ -30,33 +28,15 @@
|
|||||||
</valuemap>
|
</valuemap>
|
||||||
<value type="qlonglong" key="EditorConfiguration.CodeStyle.Count">2</value>
|
<value type="qlonglong" key="EditorConfiguration.CodeStyle.Count">2</value>
|
||||||
<value type="QByteArray" key="EditorConfiguration.Codec">KOI8-R</value>
|
<value type="QByteArray" key="EditorConfiguration.Codec">KOI8-R</value>
|
||||||
<value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value>
|
|
||||||
<value type="int" key="EditorConfiguration.IndentSize">4</value>
|
<value type="int" key="EditorConfiguration.IndentSize">4</value>
|
||||||
<value type="bool" key="EditorConfiguration.KeyboardTooltips">false</value>
|
|
||||||
<value type="int" key="EditorConfiguration.LineEndingBehavior">0</value>
|
|
||||||
<value type="int" key="EditorConfiguration.MarginColumn">80</value>
|
|
||||||
<value type="bool" key="EditorConfiguration.MouseHiding">true</value>
|
|
||||||
<value type="bool" key="EditorConfiguration.MouseNavigation">true</value>
|
|
||||||
<value type="int" key="EditorConfiguration.PaddingMode">1</value>
|
<value type="int" key="EditorConfiguration.PaddingMode">1</value>
|
||||||
<value type="int" key="EditorConfiguration.PreferAfterWhitespaceComments">0</value>
|
|
||||||
<value type="bool" key="EditorConfiguration.PreferSingleLineComments">false</value>
|
|
||||||
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">false</value>
|
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">false</value>
|
||||||
<value type="bool" key="EditorConfiguration.ShowMargin">false</value>
|
|
||||||
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">1</value>
|
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">1</value>
|
||||||
<value type="bool" key="EditorConfiguration.SmartSelectionChanging">true</value>
|
|
||||||
<value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
|
<value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
|
||||||
<value type="int" key="EditorConfiguration.TabKeyBehavior">0</value>
|
|
||||||
<value type="int" key="EditorConfiguration.TabSize">8</value>
|
<value type="int" key="EditorConfiguration.TabSize">8</value>
|
||||||
<value type="bool" key="EditorConfiguration.UseGlobal">true</value>
|
<value type="bool" key="EditorConfiguration.UseGlobal">true</value>
|
||||||
<value type="bool" key="EditorConfiguration.UseIndenter">false</value>
|
|
||||||
<value type="int" key="EditorConfiguration.Utf8BomBehavior">1</value>
|
|
||||||
<value type="bool" key="EditorConfiguration.addFinalNewLine">true</value>
|
<value type="bool" key="EditorConfiguration.addFinalNewLine">true</value>
|
||||||
<value type="bool" key="EditorConfiguration.cleanIndentation">true</value>
|
|
||||||
<value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
|
|
||||||
<value type="QString" key="EditorConfiguration.ignoreFileTypes">*.md, *.MD, Makefile</value>
|
|
||||||
<value type="bool" key="EditorConfiguration.inEntireDocument">true</value>
|
<value type="bool" key="EditorConfiguration.inEntireDocument">true</value>
|
||||||
<value type="bool" key="EditorConfiguration.skipTrailingWhitespace">true</value>
|
|
||||||
<value type="bool" key="EditorConfiguration.tintMarginArea">true</value>
|
|
||||||
</valuemap>
|
</valuemap>
|
||||||
</data>
|
</data>
|
||||||
<data>
|
<data>
|
||||||
@@ -76,11 +56,6 @@
|
|||||||
<value type="int" key="AutoTest.RunAfterBuild">0</value>
|
<value type="int" key="AutoTest.RunAfterBuild">0</value>
|
||||||
<value type="bool" key="AutoTest.UseGlobal">true</value>
|
<value type="bool" key="AutoTest.UseGlobal">true</value>
|
||||||
<valuemap type="QVariantMap" key="ClangTools">
|
<valuemap type="QVariantMap" key="ClangTools">
|
||||||
<value type="bool" key="ClangTools.AnalyzeOpenFiles">true</value>
|
|
||||||
<value type="bool" key="ClangTools.BuildBeforeAnalysis">true</value>
|
|
||||||
<value type="QString" key="ClangTools.DiagnosticConfig">Builtin.DefaultTidyAndClazy</value>
|
|
||||||
<value type="int" key="ClangTools.ParallelJobs">4</value>
|
|
||||||
<value type="bool" key="ClangTools.PreferConfigFile">true</value>
|
|
||||||
<valuelist type="QVariantList" key="ClangTools.SelectedDirs"/>
|
<valuelist type="QVariantList" key="ClangTools.SelectedDirs"/>
|
||||||
<valuelist type="QVariantList" key="ClangTools.SelectedFiles"/>
|
<valuelist type="QVariantList" key="ClangTools.SelectedFiles"/>
|
||||||
<valuelist type="QVariantList" key="ClangTools.SuppressedDiagnostics"/>
|
<valuelist type="QVariantList" key="ClangTools.SuppressedDiagnostics"/>
|
||||||
@@ -132,7 +107,7 @@
|
|||||||
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
|
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
|
||||||
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
|
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
|
||||||
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
|
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
|
||||||
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
|
<value type="UnknownType" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"></value>
|
||||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">По умолчанию</value>
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">По умолчанию</value>
|
||||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericBuildConfiguration</value>
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericBuildConfiguration</value>
|
||||||
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
|
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
|
||||||
@@ -155,10 +130,11 @@
|
|||||||
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
|
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
|
||||||
<value type="int" key="Analyzer.Valgrind.Callgrind.CostFormat">0</value>
|
<value type="int" key="Analyzer.Valgrind.Callgrind.CostFormat">0</value>
|
||||||
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
|
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
|
||||||
|
<valuelist type="QVariantList" key="Analyzer.Valgrind.SuppressionFiles"/>
|
||||||
<value type="QList<int>" key="Analyzer.Valgrind.VisibleErrorKinds"></value>
|
<value type="QList<int>" key="Analyzer.Valgrind.VisibleErrorKinds"></value>
|
||||||
<valuelist type="QVariantList" key="CustomOutputParsers"/>
|
<valuelist type="QVariantList" key="CustomOutputParsers"/>
|
||||||
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
|
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
|
||||||
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
|
<value type="UnknownType" key="PE.EnvironmentAspect.Changes"></value>
|
||||||
<value type="bool" key="PE.EnvironmentAspect.PrintOnRun">false</value>
|
<value type="bool" key="PE.EnvironmentAspect.PrintOnRun">false</value>
|
||||||
<value type="QString" key="PerfRecordArgsId">-e cpu-cycles --call-graph dwarf,4096 -F 250</value>
|
<value type="QString" key="PerfRecordArgsId">-e cpu-cycles --call-graph dwarf,4096 -F 250</value>
|
||||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
|
||||||
@@ -190,10 +166,11 @@
|
|||||||
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
|
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
|
||||||
<value type="int" key="Analyzer.Valgrind.Callgrind.CostFormat">0</value>
|
<value type="int" key="Analyzer.Valgrind.Callgrind.CostFormat">0</value>
|
||||||
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
|
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
|
||||||
|
<valuelist type="QVariantList" key="Analyzer.Valgrind.SuppressionFiles"/>
|
||||||
<value type="QList<int>" key="Analyzer.Valgrind.VisibleErrorKinds"></value>
|
<value type="QList<int>" key="Analyzer.Valgrind.VisibleErrorKinds"></value>
|
||||||
<valuelist type="QVariantList" key="CustomOutputParsers"/>
|
<valuelist type="QVariantList" key="CustomOutputParsers"/>
|
||||||
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
|
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
|
||||||
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
|
<value type="UnknownType" key="PE.EnvironmentAspect.Changes"></value>
|
||||||
<value type="bool" key="PE.EnvironmentAspect.PrintOnRun">false</value>
|
<value type="bool" key="PE.EnvironmentAspect.PrintOnRun">false</value>
|
||||||
<value type="QString" key="PerfRecordArgsId">-e cpu-cycles --call-graph dwarf,4096 -F 250</value>
|
<value type="QString" key="PerfRecordArgsId">-e cpu-cycles --call-graph dwarf,4096 -F 250</value>
|
||||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
|
||||||
|
|||||||
@@ -94,23 +94,12 @@ static int rwreg(uint8_t reg, uint32_t data, int w){
|
|||||||
++nbytes;
|
++nbytes;
|
||||||
for(int i = 0; i < nbytes; ++i){
|
for(int i = 0; i < nbytes; ++i){
|
||||||
IWDG->KR = IWDG_REFRESH;
|
IWDG->KR = IWDG_REFRESH;
|
||||||
/*
|
|
||||||
#ifdef EBUG
|
|
||||||
USB_sendstr("Send byte "); USB_putbyte('0'+i); USB_sendstr(": "); printuhex(outbuf[i]); newline();
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
USART[no]->TDR = outbuf[i]; // transmit
|
USART[no]->TDR = outbuf[i]; // transmit
|
||||||
while(!(USART[no]->ISR & USART_ISR_TXE));
|
while(!(USART[no]->ISR & USART_ISR_TXE));
|
||||||
int l = 0;
|
int l = 0;
|
||||||
for(; l < 10000; ++l) if(USART[no]->ISR & USART_ISR_RXNE) break;
|
for(; l < 10000; ++l) if(USART[no]->ISR & USART_ISR_RXNE) break;
|
||||||
// clear Rx
|
// clear Rx
|
||||||
(void) USART[no]->RDR;
|
(void) USART[no]->RDR;
|
||||||
/*
|
|
||||||
#ifdef EBUG
|
|
||||||
if(l == 10000) USND("Nothing received");
|
|
||||||
else {USB_sendstr("Rcv: "); printuhex(USART[no]->RDR); newline();}
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@@ -134,11 +123,6 @@ int pdnuart_readreg(uint8_t reg, uint32_t *data){
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
buf[i] = USART[no]->RDR;
|
buf[i] = USART[no]->RDR;
|
||||||
/*
|
|
||||||
#ifdef EBUG
|
|
||||||
USB_sendstr("Read byte: "); printuhex(buf[i]); newline();
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
uint32_t o = 0;
|
uint32_t o = 0;
|
||||||
for(int i = 3; i < 7; ++i){
|
for(int i = 3; i < 7; ++i){
|
||||||
@@ -228,13 +212,3 @@ int pdnuart_init(uint8_t no){
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
static void parseRx(int no){
|
|
||||||
USB_sendstr("Got from ");
|
|
||||||
USB_putbyte('#'); printu(curslaveaddr[no] + no*4); USB_sendstr(": ");
|
|
||||||
for(int i = 0; i < 8; ++i){
|
|
||||||
printuhex(inbuf[no][i]); USB_putbyte(' ');
|
|
||||||
}
|
|
||||||
newline();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|||||||
@@ -484,13 +484,6 @@ static int canusb_function(uint32_t hash, char *args){
|
|||||||
uint32_t N;
|
uint32_t N;
|
||||||
int32_t val = 0;
|
int32_t val = 0;
|
||||||
uint8_t par = CANMESG_NOPAR;
|
uint8_t par = CANMESG_NOPAR;
|
||||||
/*
|
|
||||||
DBG("CMD: hash=");
|
|
||||||
#ifdef EBUG
|
|
||||||
printu(hash); USB_sendstr(", args=");
|
|
||||||
USND(args);
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
if(*args){
|
if(*args){
|
||||||
const char *n = getnum(args, &N);
|
const char *n = getnum(args, &N);
|
||||||
if(n != args){ // get parameter
|
if(n != args){ // get parameter
|
||||||
@@ -509,12 +502,6 @@ static int canusb_function(uint32_t hash, char *args){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
#ifdef EBUG
|
|
||||||
USB_sendstr("par="); printuhex(par);
|
|
||||||
USB_sendstr(", val="); printi(val); newline();
|
|
||||||
#endif
|
|
||||||
*/
|
|
||||||
switch(hash){
|
switch(hash){
|
||||||
case CMD_ADC:
|
case CMD_ADC:
|
||||||
e = cu_adc(par, &val);
|
e = cu_adc(par, &val);
|
||||||
@@ -666,8 +653,6 @@ static int canusb_function(uint32_t hash, char *args){
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//if(e < ERR_OK || e >= ERR_AMOUNT) USND("Bad return code");
|
|
||||||
//else
|
|
||||||
if(ERR_OK != e){
|
if(ERR_OK != e){
|
||||||
USB_sendstr(errtxt[e]); newline();
|
USB_sendstr(errtxt[e]); newline();
|
||||||
}else{
|
}else{
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ static uint32_t Taccel[MOTORSNO] = {0};
|
|||||||
|
|
||||||
// recalculate ARR according to new speed
|
// recalculate ARR according to new speed
|
||||||
TRUE_INLINE void recalcARR(int i){
|
TRUE_INLINE void recalcARR(int i){
|
||||||
|
if(curspeed[i] < 1) curspeed[i] = 1;
|
||||||
uint32_t ARR = (((PCLK/(MOTORTIM_PSC+1)) / curspeed[i]) >> ustepsshift[i]) - 1;
|
uint32_t ARR = (((PCLK/(MOTORTIM_PSC+1)) / curspeed[i]) >> ustepsshift[i]) - 1;
|
||||||
if(ARR < MOTORTIM_ARRMIN) ARR = MOTORTIM_ARRMIN;
|
if(ARR < MOTORTIM_ARRMIN) ARR = MOTORTIM_ARRMIN;
|
||||||
else if(ARR > 0xffff) ARR = 0xffff;
|
else if(ARR > 0xffff) ARR = 0xffff;
|
||||||
@@ -144,15 +145,7 @@ errcodes getremainsteps(uint8_t i, int32_t *position){
|
|||||||
|
|
||||||
// calculate acceleration/deceleration parameters for motor i
|
// calculate acceleration/deceleration parameters for motor i
|
||||||
static void calcacceleration(uint8_t i){
|
static void calcacceleration(uint8_t i){
|
||||||
switch(state[i]){ // do nothing in case of error/stopping
|
if(!ismoving(i)) return; // do nothing in non-moving state
|
||||||
case STP_ERR:
|
|
||||||
case STP_RELAX:
|
|
||||||
case STP_STALL:
|
|
||||||
return;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
int32_t delta = targstppos[i] - stppos[i];
|
int32_t delta = targstppos[i] - stppos[i];
|
||||||
if(delta > 0){ // positive direction
|
if(delta > 0){ // positive direction
|
||||||
if(delta > 2*(int32_t)accdecsteps[i]){ // can move by trapezoid
|
if(delta > 2*(int32_t)accdecsteps[i]){ // can move by trapezoid
|
||||||
@@ -219,13 +212,7 @@ static int esw_block(uint8_t i){
|
|||||||
errcodes motor_absmove(uint8_t i, int32_t newpos){
|
errcodes motor_absmove(uint8_t i, int32_t newpos){
|
||||||
//if(i >= MOTORSNO) return ERR_BADPAR; // bad motor number
|
//if(i >= MOTORSNO) return ERR_BADPAR; // bad motor number
|
||||||
int8_t dir = (newpos > stppos[i]) ? 1 : -1;
|
int8_t dir = (newpos > stppos[i]) ? 1 : -1;
|
||||||
switch(state[i]){
|
if(ismoving(i)){
|
||||||
case STP_ERR:
|
|
||||||
case STP_RELAX:
|
|
||||||
break;
|
|
||||||
case STP_STALL:
|
|
||||||
break;
|
|
||||||
default: // moving state
|
|
||||||
DBG("Is moving");
|
DBG("Is moving");
|
||||||
return ERR_CANTRUN;
|
return ERR_CANTRUN;
|
||||||
}
|
}
|
||||||
@@ -251,6 +238,9 @@ errcodes motor_absmove(uint8_t i, int32_t newpos){
|
|||||||
USB_sendstr(", accdecsteps="); printu(accdecsteps[i]); newline();
|
USB_sendstr(", accdecsteps="); printu(accdecsteps[i]); newline();
|
||||||
#endif
|
#endif
|
||||||
MOTOR_EN(i);
|
MOTOR_EN(i);
|
||||||
|
// clear counter and generate update event to refresh ARR
|
||||||
|
mottimers[i]->CNT = 0;
|
||||||
|
mottimers[i]->EGR = TIM_EGR_UG;
|
||||||
mottimers[i]->CR1 |= TIM_CR1_CEN; // start timer
|
mottimers[i]->CR1 |= TIM_CR1_CEN; // start timer
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
@@ -282,13 +272,42 @@ void emstopmotor(uint8_t i){
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
// check that timer is works
|
||||||
|
if(mottimers[i]->CR1 & TIM_CR1_CEN){
|
||||||
stopflag[i] = 1;
|
stopflag[i] = 1;
|
||||||
|
}else{
|
||||||
|
state[i] = STP_RELAX;
|
||||||
|
stopflag[i] = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stp_state getmotstate(uint8_t i){
|
stp_state getmotstate(uint8_t i){
|
||||||
return state[i];
|
return state[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// return TRUE if motor is in moving state
|
||||||
|
uint8_t ismoving(uint8_t i){
|
||||||
|
switch(state[i]){
|
||||||
|
case STP_ACCEL:
|
||||||
|
case STP_MOVE:
|
||||||
|
case STP_MVSLOW:
|
||||||
|
case STP_DECEL:
|
||||||
|
return TRUE;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// return TRUE if any motor is in moving state
|
||||||
|
uint8_t isanymoving(){
|
||||||
|
for(int i = 0; i < MOTORSNO; ++i){
|
||||||
|
if(ismoving(i)) return TRUE;
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
// get DIAGN input
|
// get DIAGN input
|
||||||
uint8_t motdiagn(uint8_t i){
|
uint8_t motdiagn(uint8_t i){
|
||||||
if(i > MOTORSNO-1) return 0;
|
if(i > MOTORSNO-1) return 0;
|
||||||
@@ -445,6 +464,13 @@ static void chkstepper(int i){
|
|||||||
}
|
}
|
||||||
recalcARR(i);
|
recalcARR(i);
|
||||||
break;
|
break;
|
||||||
|
case STP_MVSLOW:
|
||||||
|
if(!(mottimers[i]->CR1 & TIM_CR1_CEN)){ // timer stopped but state wasn't changed
|
||||||
|
state[i] = STP_RELAX;
|
||||||
|
stopflag[i] = 0;
|
||||||
|
DBG("MVSLOW with timer stopped");
|
||||||
|
}
|
||||||
|
break;
|
||||||
default: // do nothing, check mvzerostate
|
default: // do nothing, check mvzerostate
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,5 +69,7 @@ uint8_t geteswreact(uint8_t i);
|
|||||||
void emstopmotor(uint8_t i);
|
void emstopmotor(uint8_t i);
|
||||||
void stopmotor(uint8_t i);
|
void stopmotor(uint8_t i);
|
||||||
stp_state getmotstate(uint8_t i);
|
stp_state getmotstate(uint8_t i);
|
||||||
|
uint8_t ismoving(uint8_t i);
|
||||||
|
uint8_t isanymoving();
|
||||||
uint8_t motdiagn(uint8_t i);
|
uint8_t motdiagn(uint8_t i);
|
||||||
void process_steppers();
|
void process_steppers();
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
#define BUILD_NUMBER "212"
|
#define BUILD_NUMBER "215"
|
||||||
#define BUILD_DATE "2026-01-20"
|
#define BUILD_DATE "2026-07-13"
|
||||||
|
|||||||
Reference in New Issue
Block a user