tested release compilation

This commit is contained in:
Edward Emelianov 2025-02-06 16:31:18 +03:00
parent 6eb0662f69
commit c06c89003a
9 changed files with 54 additions and 39 deletions

View File

@ -368,6 +368,7 @@ In case of absence of `ACK` you can get message `CAN bus is off, try to restart
### canspeed N ### canspeed N
CAN bus speed (in kbps, 50 <= N <= 1500) CAN bus speed (in kbps, 50 <= N <= 1500)
In case of setter, store new speed value in global parameters (and if you call `saveconf` later, it will be saved in flash memory). In case of setter, store new speed value in global parameters (and if you call `saveconf` later, it will be saved in flash memory).
As getter show string like `canspeed=250kbps`.
### canstat ### canstat
Get CAN bus status: values of registers `CAN->MSR`, `CAN->TSR`, `CAN->RF0R` and `CAN->RF1F`. Get CAN bus status: values of registers `CAN->MSR`, `CAN->TSR`, `CAN->RF0R` and `CAN->RF1F`.
### diagn[N] (37) G ### diagn[N] (37) G
@ -404,9 +405,10 @@ Dump motor flags' bits (for `motflagsN`) and reaction to limit switches (`eswrea
bit5 - 5: [reserved] bit5 - 5: [reserved]
bit6 - 6,7: drvtype - driver type (0 - only step/dir, 1 - UART, 2 - SPI, 3 - reserved) bit6 - 6,7: drvtype - driver type (0 - only step/dir, 1 - UART, 2 - SPI, 3 - reserved)
End-switches reaction: End-switches reaction:
0 - ignore end-switches 0 - ignore both end-switches
1 - stop @ esw in any moving direction 1 - ignore ESW1, ESW0 stops only when negative mowing
2 - stop only when moving in given direction (e.g. to minus @ESW0) 2 - stop @ esw in any moving direction
3 - stop only when moving in given direction (e.g. to minus @ESW0)
### dumpstates ### dumpstates
Dump motors' state codes (for getter `stateN`): Dump motors' state codes (for getter `stateN`):
@ -484,6 +486,7 @@ external multiplexer status (<0 - disable, 0..7 - enable and set address).
Motor number for next `pdn` commands (if you want to run custom commands by hands or in a batch). Motor number for next `pdn` commands (if you want to run custom commands by hands or in a batch).
### motreinit (25) ### motreinit (25)
Re-init motors after configuration changed. Some changes will run this automatically. Re-init motors after configuration changed. Some changes will run this automatically.
Answer - "OK" or error text.
### pdnN (43) GS ### pdnN (43) GS
Read/write TMC2209 (and other UART-based drivers) registers over uart @ motor number `motno`. Read/write TMC2209 (and other UART-based drivers) registers over uart @ motor number `motno`.
For `pdnN=X` `N` is register number, `X` is data to write into it. Due to protocol's particulars For `pdnN=X` `N` is register number, `X` is data to write into it. Due to protocol's particulars
@ -498,6 +501,7 @@ Like `relpos` but with constant slowest speed (you can change it with `minspeed`
Software reset. Software reset.
### saveconf (13) ### saveconf (13)
Save current configuration into MCU flash memory. Save current configuration into MCU flash memory.
Answer - "OK" or error text.
### screen* GS ### screen* GS
Enable (1) or disable (0) screen. Enable (1) or disable (0) screen.
### speedlimit (20) G ### speedlimit (20) G
@ -506,6 +510,7 @@ Get limiting speed for current microsteps setting.
Get Nth motor state (`dumpstates`: 0-relax, 1-accel, 2-move, 3-mvslow, 4-decel, 5-stall, 6-err). Get Nth motor state (`dumpstates`: 0-relax, 1-accel, 2-move, 3-mvslow, 4-decel, 5-stall, 6-err).
### stopN (30) ### stopN (30)
Stop Nth motor with deceleration (moving by ramp). Stop Nth motor with deceleration (moving by ramp).
Answer - "OK" or error text.
### time (10) G ### time (10) G
Get time from start (ms). Get time from start (ms).
### tmcbus * GS ### tmcbus * GS
@ -554,22 +559,20 @@ Command codes described in USB answer for `dumpcmd`:
26 - goto 26 - goto
27 - relpos 27 - relpos
28 - relslow 28 - relslow
29 - emstop N 29 - emstop
30 - stop 30 - stop
31 - emstop all
32 - gotoz 32 - gotoz
33 - state 33 - state
35 - abspos 35 - abspos
36 - motmul 36 - motmul
37 - diagn 37 - diagn
38 - eraseflash 38 - eraseflash
39 - udata
40 - usartstatus
41 - vdrive 41 - vdrive
42 - vfive 42 - vfive
43 - pdn 43 - pdn
44 - motno 44 - motno
45 - drvtype 45 - drvtype
46 - motcurrent
Error codes (`dumperr`): Error codes (`dumperr`):

View File

@ -22,9 +22,7 @@
#include "hardware.h" #include "hardware.h"
#include "strfunc.h" #include "strfunc.h"
#include "usb_dev.h" #include "usb_dev.h"
#ifdef EBUG
#include "proto.h" #include "proto.h"
#endif
// PD1 - Tx, PD0 - Rx !!! // PD1 - Tx, PD0 - Rx !!!
@ -304,17 +302,21 @@ CAN_status CAN_send(uint8_t *msg, uint8_t len, uint16_t target_id){
return CAN_OK; return CAN_OK;
} }
void CAN_flood(CAN_message *msg, int incr){ // return: 1 - flood is ON, 0 - flood is OFF
int CAN_flood(CAN_message *msg, int incr){
if(incr){ if(incr){
incrmessagectr = 0; incrmessagectr = 0;
incrflood = 1; incrflood = 1;
return; return 1;
}else incrflood = 0; }else incrflood = 0;
if(!msg) flood_msg = NULL; if(!msg){
else{ flood_msg = NULL;
return 0;
}else{
memcpy(&loc_flood_msg, msg, sizeof(CAN_message)); memcpy(&loc_flood_msg, msg, sizeof(CAN_message));
flood_msg = &loc_flood_msg; flood_msg = &loc_flood_msg;
} }
return 1;
} }
uint32_t CAN_speed(){ uint32_t CAN_speed(){

View File

@ -56,5 +56,5 @@ void CAN_printerr();
CAN_message *CAN_messagebuf_pop(); CAN_message *CAN_messagebuf_pop();
void CAN_flood(CAN_message *msg, int incr); int CAN_flood(CAN_message *msg, int incr);
uint32_t CAN_speed(); uint32_t CAN_speed();

View File

@ -275,7 +275,6 @@ 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);
USB_sendstr("===> val="); printi(*val); newline();
if(ISSETTER(par)){ if(ISSETTER(par)){
#if MICROSTEPSMAX > 512 #if MICROSTEPSMAX > 512
#error "Change the code anywhere!" #error "Change the code anywhere!"
@ -443,7 +442,7 @@ errcodes cu_usartstatus(uint8_t _U_ par, int32_t _U_ *val){
// V*10 // V*10
errcodes cu_vdrive(uint8_t par, int32_t _U_ *val){ errcodes cu_vdrive(uint8_t par, int32_t _U_ *val){
NOPARCHK(par); NOPARCHK(par);
*val = getADCvoltage(ADC_VDRIVE); *val = getADCvoltage(ADC_VDRIVE) * 11;
return ERR_OK; return ERR_OK;
} }

View File

@ -152,9 +152,9 @@ 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 //#ifdef EBUG
USB_sendstr("Erase block #"); printu(N); newline(); USB_sendstr("Erase block #"); printu(N); newline();
#endif //#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;
@ -185,13 +185,16 @@ int erase_storage(int npage){
FLASH->KEYR = FLASH_KEY1; FLASH->KEYR = FLASH_KEY1;
FLASH->KEYR = FLASH_KEY2; FLASH->KEYR = FLASH_KEY2;
} }
/*USB_sendstr("size/block size/nblocks/FLASH_SIZE: "); printu(flsz); //*
USB_sendstr("size/block size/nblocks/FLASH_SIZE: "); printu(flsz);
USB_putbyte('/'); printu(FLASH_blocksize); USB_putbyte('/'); USB_putbyte('/'); printu(FLASH_blocksize); USB_putbyte('/');
printu(nblocks); USB_putbyte('/'); printu(FLASH_SIZE); newline(); USB_sendall();*/ printu(flsz / FLASH_blocksize); USB_putbyte('/'); printu(FLASH_SIZE); newline();
//*/
while(FLASH->SR & FLASH_SR_BSY) IWDG->KR = IWDG_REFRESH; while(FLASH->SR & FLASH_SR_BSY) IWDG->KR = IWDG_REFRESH;
FLASH->SR = FLASH_SR_EOP | FLASH_SR_PGERR | FLASH_SR_WRPERR; FLASH->SR = FLASH_SR_EOP | FLASH_SR_PGERR | FLASH_SR_WRPERR;
FLASH->CR |= FLASH_CR_PER; FLASH->CR |= FLASH_CR_PER;
for(uint32_t i = start; i < end; ++i){ for(uint32_t i = start; i < end; ++i){
IWDG->KR = IWDG_REFRESH;
if(erase_pageN(i)){ if(erase_pageN(i)){
ret = 1; ret = 1;
break; break;

View File

@ -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 14.0.2, 2024-11-13T08:41:23. --> <!-- Written by QtCreator 15.0.1, 2025-02-06T16:30:11. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>
@ -33,6 +33,7 @@
<value type="bool" key="EditorConfiguration.ConstrainTooltips">false</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="bool" key="EditorConfiguration.KeyboardTooltips">false</value>
<value type="int" key="EditorConfiguration.LineEndingBehavior">0</value>
<value type="int" key="EditorConfiguration.MarginColumn">80</value> <value type="int" key="EditorConfiguration.MarginColumn">80</value>
<value type="bool" key="EditorConfiguration.MouseHiding">true</value> <value type="bool" key="EditorConfiguration.MouseHiding">true</value>
<value type="bool" key="EditorConfiguration.MouseNavigation">true</value> <value type="bool" key="EditorConfiguration.MouseNavigation">true</value>

View File

@ -40,6 +40,15 @@ uint8_t ShowMsgs = 1;
static uint16_t Ignore_IDs[IGN_SIZE]; static uint16_t Ignore_IDs[IGN_SIZE];
static uint8_t IgnSz = 0; static uint8_t IgnSz = 0;
static const char* errtxt[ERR_AMOUNT] = {
[ERR_OK] = "OK",
[ERR_BADPAR] = "BADPAR",
[ERR_BADVAL] = "BADVAL",
[ERR_WRONGLEN] = "WRONGLEN",
[ERR_BADCMD] = "BADCMD",
[ERR_CANTRUN] = "CANTRUN",
};
// parse `txt` to CAN_message // parse `txt` to CAN_message
static CAN_message *parseCANmsg(const char *txt){ static CAN_message *parseCANmsg(const char *txt){
static CAN_message canmsg; static CAN_message canmsg;
@ -134,7 +143,7 @@ int fn_canignore(uint32_t _U_ hash, char *args){
int fn_canreinit(uint32_t _U_ hash, char _U_ *args){ int fn_canreinit(uint32_t _U_ hash, char _U_ *args){
CAN_reinit(0); CAN_reinit(0);
USND("OK"); USND(errtxt[ERR_OK]);
return RET_GOOD; return RET_GOOD;
} }
@ -287,8 +296,10 @@ int fn_canfilter(uint32_t _U_ hash, char *args){
} }
int fn_canflood(uint32_t _U_ hash, char *args){ int fn_canflood(uint32_t _U_ hash, char *args){
CAN_flood(parseCANmsg(args), 0); if(CAN_flood(parseCANmsg(args), 0))
USB_sendstr("Simple flooding is ON (send with empty ID to stop)\n"); USB_sendstr("Simple flooding is ON (send with empty ID to stop)\n");
else
USB_sendstr("CAN flooding is OFF\n");
return RET_GOOD; return RET_GOOD;
} }
@ -343,8 +354,8 @@ int fn_canspeed(uint32_t _U_ hash, char _U_ *args){
uint32_t N; uint32_t N;
const char *n = getnum(args, &N); const char *n = getnum(args, &N);
if(args == n){ if(args == n){
USB_sendstr("No speed given"); USB_sendstr("canspeed=");
return RET_GOOD; goto rtn;
} }
if(N < 50){ if(N < 50){
USND("Lower speed is 50kbps"); USND("Lower speed is 50kbps");
@ -355,9 +366,10 @@ int fn_canspeed(uint32_t _U_ hash, char _U_ *args){
} }
CAN_reinit((uint16_t)N); CAN_reinit((uint16_t)N);
uint32_t regval = 4500 / N; uint32_t regval = 4500 / N;
the_conf.CANspeed = 4500 * regval; the_conf.CANspeed = 4500 / regval;
USB_sendstr("Reinit CAN bus with speed "); USB_sendstr("Reinit CAN bus with speed ");
printu(the_conf.CANspeed); USB_sendstr("kbps"); newline(); rtn:
printu(the_conf.CANspeed); USND("kbps");
return RET_GOOD; return RET_GOOD;
} }
@ -422,14 +434,6 @@ int fn_dumpmotflags(uint32_t _U_ hash, char _U_ *args){ // "dumpmotflags" (3615
return RET_GOOD; return RET_GOOD;
} }
static const char* errtxt[ERR_AMOUNT] = {
[ERR_OK] = "OK",
[ERR_BADPAR] = "BADPAR",
[ERR_BADVAL] = "BADVAL",
[ERR_WRONGLEN] = "WRONGLEN",
[ERR_BADCMD] = "BADCMD",
[ERR_CANTRUN] = "CANTRUN",
};
int fn_dumperr(uint32_t _U_ hash, char _U_ *args){ // "dumperr" (1223989764) int fn_dumperr(uint32_t _U_ hash, char _U_ *args){ // "dumperr" (1223989764)
USND("Error codes:"); USND("Error codes:");
for(int i = 0; i < ERR_AMOUNT; ++i){ for(int i = 0; i < ERR_AMOUNT; ++i){
@ -559,7 +563,7 @@ static int canusb_function(uint32_t hash, char *args){
break; break;
case CMD_EMSTOP: case CMD_EMSTOP:
e = cu_emstop(par, &val); e = cu_emstop(par, &val);
if(e == ERR_OK){ USND("OK"); return RET_GOOD;} if(e == ERR_OK){ USND(errtxt[ERR_OK]); return RET_GOOD;}
break; break;
case CMD_ESWREACT: case CMD_ESWREACT:
e = cu_eswreact(par, &val); e = cu_eswreact(par, &val);
@ -608,6 +612,7 @@ static int canusb_function(uint32_t hash, char *args){
break; break;
case CMD_MOTREINIT: case CMD_MOTREINIT:
e = cu_motreinit(par, &val); e = cu_motreinit(par, &val);
if(e == ERR_OK){ USND(errtxt[ERR_OK]); return RET_GOOD;}
break; break;
case CMD_PDN: case CMD_PDN:
e = cu_pdn(par, &val); e = cu_pdn(par, &val);
@ -623,6 +628,7 @@ static int canusb_function(uint32_t hash, char *args){
break; break;
case CMD_SAVECONF: case CMD_SAVECONF:
e = cu_saveconf(par, &val); e = cu_saveconf(par, &val);
if(e == ERR_OK){ USND(errtxt[ERR_OK]); return RET_GOOD;}
break; break;
case CMD_SCREEN: case CMD_SCREEN:
e = cu_screen(par, &val); e = cu_screen(par, &val);
@ -635,6 +641,7 @@ static int canusb_function(uint32_t hash, char *args){
break; break;
case CMD_STOP: case CMD_STOP:
e = cu_stop(par, &val); e = cu_stop(par, &val);
if(e == ERR_OK){ USND(errtxt[ERR_OK]); return RET_GOOD;}
break; break;
case CMD_TIME: case CMD_TIME:
e = cu_time(par, &val); e = cu_time(par, &val);

View File

@ -1,2 +1,2 @@
#define BUILD_NUMBER "192" #define BUILD_NUMBER "200"
#define BUILD_DATE "2025-02-05" #define BUILD_DATE "2025-02-06"