mirror of
https://github.com/eddyem/stm32samples.git
synced 2025-12-06 18:55:13 +03:00
Still don't work :(
This commit is contained in:
parent
8e4df528d9
commit
d23d2ab89d
@ -87,6 +87,17 @@ errcodes cu_diagn(uint8_t _U_ par, int32_t _U_ *val){
|
|||||||
return ERR_BADCMD;
|
return ERR_BADCMD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
errcodes cu_drvtype(uint8_t par, int32_t *val){
|
||||||
|
uint8_t n; CHECKN(n, par);
|
||||||
|
motflags_t *fl = &the_conf.motflags[n];
|
||||||
|
if(ISSETTER(par)){
|
||||||
|
if(*val >= DRVTYPE_AMOUNT) return ERR_BADVAL;
|
||||||
|
fl->drvtype = *val;
|
||||||
|
}
|
||||||
|
*val = fl->drvtype;
|
||||||
|
return ERR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
errcodes cu_emstop(uint8_t _U_ par, int32_t _U_ *val){
|
errcodes cu_emstop(uint8_t _U_ par, int32_t _U_ *val){
|
||||||
uint8_t n; CHECKN(n, par);
|
uint8_t n; CHECKN(n, par);
|
||||||
emstopmotor(n);
|
emstopmotor(n);
|
||||||
@ -235,6 +246,10 @@ errcodes cu_microsteps(uint8_t _U_ par, int32_t _U_ *val){
|
|||||||
if(m != 1<<MSB(m)) return ERR_BADVAL;
|
if(m != 1<<MSB(m)) return ERR_BADVAL;
|
||||||
if(the_conf.maxspd[n] * m > PCLK/(MOTORTIM_PSC+1)/(MOTORTIM_ARRMIN+1)) return ERR_BADVAL;
|
if(the_conf.maxspd[n] * m > PCLK/(MOTORTIM_PSC+1)/(MOTORTIM_ARRMIN+1)) return ERR_BADVAL;
|
||||||
the_conf.microsteps[n] = m;
|
the_conf.microsteps[n] = m;
|
||||||
|
motflags_t *f = the_conf.motflags;
|
||||||
|
if(f->drvtype == DRVTYPE_UART){
|
||||||
|
if(!pdnuart_microsteps(n, m)) return ERR_CANTRUN;
|
||||||
|
}
|
||||||
update_stepper(n);
|
update_stepper(n);
|
||||||
}
|
}
|
||||||
*val = the_conf.microsteps[n];
|
*val = the_conf.microsteps[n];
|
||||||
@ -244,7 +259,7 @@ errcodes cu_microsteps(uint8_t _U_ par, int32_t _U_ *val){
|
|||||||
errcodes cu_minspeed(uint8_t _U_ par, int32_t _U_ *val){
|
errcodes cu_minspeed(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(*val >= the_conf.maxspd[n]) return ERR_BADVAL;
|
if(*val >= the_conf.maxspd[n] || *val < 0) return ERR_BADVAL;
|
||||||
the_conf.minspd[n] = getSPD(n, *val);
|
the_conf.minspd[n] = getSPD(n, *val);
|
||||||
update_stepper(n);
|
update_stepper(n);
|
||||||
}
|
}
|
||||||
@ -252,6 +267,20 @@ errcodes cu_minspeed(uint8_t _U_ par, int32_t _U_ *val){
|
|||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
errcodes cu_motcurrent(uint8_t par, int32_t *val){
|
||||||
|
uint8_t n; CHECKN(n, par);
|
||||||
|
if(ISSETTER(par)){
|
||||||
|
if(*val < 1 || *val > 32) return ERR_BADVAL;
|
||||||
|
the_conf.motcurrent[n] = *val;
|
||||||
|
motflags_t *f = the_conf.motflags;
|
||||||
|
if(f->drvtype == DRVTYPE_UART){
|
||||||
|
if(!pdnuart_setcurrent(n, *val)) return ERR_CANTRUN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*val = the_conf.motcurrent[n];
|
||||||
|
return ERR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
errcodes cu_motflags(uint8_t _U_ par, int32_t _U_ *val){
|
errcodes cu_motflags(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)){
|
||||||
@ -262,6 +291,15 @@ errcodes cu_motflags(uint8_t _U_ par, int32_t _U_ *val){
|
|||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
errcodes cu_motno(uint8_t _U_ par, int32_t _U_ *val){
|
||||||
|
if(*val < 0 || *val >= MOTORSNO) return ERR_BADVAL;
|
||||||
|
if(ISSETTER(par)){
|
||||||
|
if(!pdnuart_setmotno(*val)) return ERR_CANTRUN;
|
||||||
|
}
|
||||||
|
*val = pdnuart_getmotno();
|
||||||
|
return ERR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
errcodes cu_motmul(uint8_t _U_ par, int32_t _U_ *val){
|
errcodes cu_motmul(uint8_t _U_ par, int32_t _U_ *val){
|
||||||
return ERR_BADCMD;
|
return ERR_BADCMD;
|
||||||
}
|
}
|
||||||
@ -275,9 +313,9 @@ errcodes cu_motreinit(uint8_t _U_ par, int32_t _U_ *val){
|
|||||||
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 = PARBASE(par);
|
||||||
if(ISSETTER(par)){
|
if(ISSETTER(par)){
|
||||||
if(!pdnuart_writereg(0, n, *val)) return ERR_CANTRUN;
|
if(!pdnuart_writereg(n, *val)) return ERR_CANTRUN;
|
||||||
}
|
}
|
||||||
if(!pdnuart_readreg(0, n, (uint32_t*)val)) return ERR_CANTRUN;
|
if(!pdnuart_readreg(n, (uint32_t*)val)) return ERR_CANTRUN;
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -449,5 +487,8 @@ const char* cancmds[CCMD_AMOUNT] = {
|
|||||||
[CCMD_USARTSTATUS] = "usartstatus",
|
[CCMD_USARTSTATUS] = "usartstatus",
|
||||||
[CCMD_VDRIVE] = "vdrive",
|
[CCMD_VDRIVE] = "vdrive",
|
||||||
[CCMD_VFIVE] = "vfive",
|
[CCMD_VFIVE] = "vfive",
|
||||||
[CCMD_PDN] = "pdn"
|
[CCMD_PDN] = "pdn",
|
||||||
|
[CCMD_MOTNO] = "motno",
|
||||||
|
[CCMD_DRVTYPE] = "drvtype",
|
||||||
|
[CCMD_MOTCURRENT] = "motcurrent",
|
||||||
};
|
};
|
||||||
|
|||||||
@ -86,14 +86,17 @@ enum{
|
|||||||
,CCMD_MOTORSTATE // motor state
|
,CCMD_MOTORSTATE // motor state
|
||||||
,CCMD_ENCPOS // position of encoder (independing on settings)
|
,CCMD_ENCPOS // position of encoder (independing on settings)
|
||||||
,CCMD_SETPOS // set motor position
|
,CCMD_SETPOS // set motor position
|
||||||
,CCMD_MOTMUL
|
,CCMD_MOTMUL // operations with motor multiplexer
|
||||||
,CCMD_DIAGN
|
,CCMD_DIAGN // DIAGN state for all motors
|
||||||
,CCMD_ERASEFLASH
|
,CCMD_ERASEFLASH // erase full storage
|
||||||
,CCMD_UDATA
|
,CCMD_UDATA // incoming data by USART1
|
||||||
,CCMD_USARTSTATUS
|
,CCMD_USARTSTATUS // current status of USART1
|
||||||
,CCMD_VDRIVE
|
,CCMD_VDRIVE // Vdrive voltage
|
||||||
,CCMD_VFIVE
|
,CCMD_VFIVE // 5V voltage
|
||||||
,CCMD_PDN
|
,CCMD_PDN // write/read TMC2209 registers over UART
|
||||||
|
,CCMD_MOTNO // motor number for next PDN command
|
||||||
|
,CCMD_DRVTYPE // driver type (0 - only step/dir, 1 - UART, 2 - SPI, 3 - reserved)
|
||||||
|
,CCMD_MOTCURRENT // motor current (1..32 for 1/32..32/32 of max current)
|
||||||
// should be the last:
|
// should be the last:
|
||||||
,CCMD_AMOUNT // amount of common commands
|
,CCMD_AMOUNT // amount of common commands
|
||||||
};
|
};
|
||||||
@ -108,6 +111,7 @@ errcodes cu_adc(uint8_t par, int32_t *val);
|
|||||||
errcodes cu_button(uint8_t par, int32_t *val);
|
errcodes cu_button(uint8_t par, int32_t *val);
|
||||||
errcodes cu_canid(uint8_t par, int32_t *val);
|
errcodes cu_canid(uint8_t par, int32_t *val);
|
||||||
errcodes cu_diagn(uint8_t par, int32_t *val);
|
errcodes cu_diagn(uint8_t par, int32_t *val);
|
||||||
|
errcodes cu_drvtype(uint8_t par, int32_t *val);
|
||||||
errcodes cu_emstop(uint8_t par, int32_t *val);
|
errcodes cu_emstop(uint8_t par, int32_t *val);
|
||||||
errcodes cu_eraseflash(uint8_t par, int32_t *val);
|
errcodes cu_eraseflash(uint8_t par, int32_t *val);
|
||||||
errcodes cu_esw(uint8_t par, int32_t *val);
|
errcodes cu_esw(uint8_t par, int32_t *val);
|
||||||
@ -122,7 +126,9 @@ errcodes cu_mcut(uint8_t par, int32_t *val);
|
|||||||
errcodes cu_mcuvdd(uint8_t par, int32_t *val);
|
errcodes cu_mcuvdd(uint8_t par, int32_t *val);
|
||||||
errcodes cu_microsteps(uint8_t par, int32_t *val);
|
errcodes cu_microsteps(uint8_t par, int32_t *val);
|
||||||
errcodes cu_minspeed(uint8_t par, int32_t *val);
|
errcodes cu_minspeed(uint8_t par, int32_t *val);
|
||||||
|
errcodes cu_motcurrent(uint8_t par, int32_t *val);
|
||||||
errcodes cu_motflags(uint8_t par, int32_t *val);
|
errcodes cu_motflags(uint8_t par, int32_t *val);
|
||||||
|
errcodes cu_motno(uint8_t par, int32_t *val);
|
||||||
errcodes cu_motmul(uint8_t par, int32_t *val);
|
errcodes cu_motmul(uint8_t par, int32_t *val);
|
||||||
errcodes cu_motreinit(uint8_t par, int32_t *val);
|
errcodes cu_motreinit(uint8_t par, int32_t *val);
|
||||||
errcodes cu_pdn(uint8_t par, int32_t *val);
|
errcodes cu_pdn(uint8_t par, int32_t *val);
|
||||||
|
|||||||
@ -32,7 +32,7 @@ static const uint32_t FLASH_blocksize = (uint32_t)&_BLOCKSIZE;
|
|||||||
// max amount of Config records stored (will be recalculate in flashstorage_init()
|
// max amount of Config records stored (will be recalculate in flashstorage_init()
|
||||||
static uint32_t maxCnum = 1024 / sizeof(user_conf); // can't use blocksize here
|
static uint32_t maxCnum = 1024 / sizeof(user_conf); // can't use blocksize here
|
||||||
|
|
||||||
#define DEFMF {.donthold = 1}
|
#define DEFMF {.donthold = 1, .drvtype = DRVTYPE_UART}
|
||||||
|
|
||||||
#define USERCONF_INITIALIZER { \
|
#define USERCONF_INITIALIZER { \
|
||||||
.userconf_sz = sizeof(user_conf) \
|
.userconf_sz = sizeof(user_conf) \
|
||||||
@ -226,6 +226,8 @@ int fn_dumpconf(uint32_t _U_ hash, char _U_ *args){ // "dumpconf" (3271513185)
|
|||||||
printu(the_conf.minspd[i]);
|
printu(the_conf.minspd[i]);
|
||||||
PROPNAME("maxsteps");
|
PROPNAME("maxsteps");
|
||||||
printu(the_conf.maxsteps[i]);
|
printu(the_conf.maxsteps[i]);
|
||||||
|
PROPNAME("motcurrent");
|
||||||
|
printu(the_conf.motcurrent[i]);
|
||||||
PROPNAME("motflags");
|
PROPNAME("motflags");
|
||||||
printuhex(*((uint8_t*)&the_conf.motflags[i]));
|
printuhex(*((uint8_t*)&the_conf.motflags[i]));
|
||||||
PROPNAME("eswreaction");
|
PROPNAME("eswreaction");
|
||||||
|
|||||||
@ -38,7 +38,16 @@
|
|||||||
|
|
||||||
#define FLASH_SIZE *((uint16_t*)FLASH_SIZE_REG)
|
#define FLASH_SIZE *((uint16_t*)FLASH_SIZE_REG)
|
||||||
|
|
||||||
#define MOTFLAGS_AMOUNT 6
|
#define MOTFLAGS_AMOUNT 7
|
||||||
|
|
||||||
|
enum{
|
||||||
|
DRVTYPE_SIMPLE,
|
||||||
|
DRVTYPE_UART,
|
||||||
|
DRVTYPE_SPI,
|
||||||
|
DRVTYPE_RESERVED,
|
||||||
|
DRVTYPE_AMOUNT
|
||||||
|
};
|
||||||
|
|
||||||
// motor flags
|
// motor flags
|
||||||
typedef struct{
|
typedef struct{
|
||||||
uint8_t reverse : 1; // bit0 - reversing motor rotation
|
uint8_t reverse : 1; // bit0 - reversing motor rotation
|
||||||
@ -47,6 +56,7 @@ typedef struct{
|
|||||||
uint8_t donthold : 1; // bit3 - clear power @ stop (don't hold motor when stopped)
|
uint8_t donthold : 1; // bit3 - clear power @ stop (don't hold motor when stopped)
|
||||||
uint8_t eswinv : 1; // bit4 - inverse end-switches
|
uint8_t eswinv : 1; // bit4 - inverse end-switches
|
||||||
uint8_t keeppos : 1; // bit5 - keep current position (as servo motor) - NOT USED HERE!!!
|
uint8_t keeppos : 1; // bit5 - keep current position (as servo motor) - NOT USED HERE!!!
|
||||||
|
uint8_t drvtype : 2; // bits 6,7 - driver type (0 - only step/dir, 1 - UART, 2 - SPI, 3 - reserved)
|
||||||
} motflags_t;
|
} motflags_t;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -63,6 +73,7 @@ typedef struct __attribute__((packed, aligned(4))){
|
|||||||
uint32_t maxsteps[MOTORSNO]; // maximal amount of steps
|
uint32_t maxsteps[MOTORSNO]; // maximal amount of steps
|
||||||
motflags_t motflags[MOTORSNO]; // motor's flags
|
motflags_t motflags[MOTORSNO]; // motor's flags
|
||||||
uint8_t ESW_reaction[MOTORSNO]; // end-switches reaction (esw_react)
|
uint8_t ESW_reaction[MOTORSNO]; // end-switches reaction (esw_react)
|
||||||
|
uint8_t motcurrent[MOTORSNO]; // IRUN as fraction of max current (1..32)
|
||||||
uint8_t isSPI; // ==1 if there's SPI drivers instead of UART
|
uint8_t isSPI; // ==1 if there's SPI drivers instead of UART
|
||||||
} user_conf;
|
} user_conf;
|
||||||
|
|
||||||
|
|||||||
@ -46,6 +46,8 @@ int fn_canstat(uint32_t _U_ hash, char _U_ *args) WAL; // "canstat" (237384179)
|
|||||||
|
|
||||||
int fn_diagn(uint32_t _U_ hash, char _U_ *args) WAL; // "diagn" (2334137736)
|
int fn_diagn(uint32_t _U_ hash, char _U_ *args) WAL; // "diagn" (2334137736)
|
||||||
|
|
||||||
|
int fn_drvtype(uint32_t _U_ hash, char _U_ *args) WAL; // "drvtype" (3930242451)
|
||||||
|
|
||||||
int fn_dumpcmd(uint32_t _U_ hash, char _U_ *args) WAL; // "dumpcmd" (1223955823)
|
int fn_dumpcmd(uint32_t _U_ hash, char _U_ *args) WAL; // "dumpcmd" (1223955823)
|
||||||
|
|
||||||
int fn_dumpconf(uint32_t _U_ hash, char _U_ *args) WAL; // "dumpconf" (3271513185)
|
int fn_dumpconf(uint32_t _U_ hash, char _U_ *args) WAL; // "dumpconf" (3271513185)
|
||||||
@ -84,10 +86,14 @@ int fn_microsteps(uint32_t _U_ hash, char _U_ *args) WAL; // "microsteps" (39743
|
|||||||
|
|
||||||
int fn_minspeed(uint32_t _U_ hash, char _U_ *args) WAL; // "minspeed" (3234848090)
|
int fn_minspeed(uint32_t _U_ hash, char _U_ *args) WAL; // "minspeed" (3234848090)
|
||||||
|
|
||||||
|
int fn_motcurrent(uint32_t _U_ hash, char _U_ *args) WAL; // "motcurrent" (1926997848)
|
||||||
|
|
||||||
int fn_motflags(uint32_t _U_ hash, char _U_ *args) WAL; // "motflags" (2153634658)
|
int fn_motflags(uint32_t _U_ hash, char _U_ *args) WAL; // "motflags" (2153634658)
|
||||||
|
|
||||||
int fn_motmul(uint32_t _U_ hash, char _U_ *args) WAL; // "motmul" (1543400099)
|
int fn_motmul(uint32_t _U_ hash, char _U_ *args) WAL; // "motmul" (1543400099)
|
||||||
|
|
||||||
|
int fn_motno(uint32_t _U_ hash, char _U_ *args) WAL; // "motno" (544673586)
|
||||||
|
|
||||||
int fn_motreinit(uint32_t _U_ hash, char _U_ *args) WAL; // "motreinit" (199682784)
|
int fn_motreinit(uint32_t _U_ hash, char _U_ *args) WAL; // "motreinit" (199682784)
|
||||||
|
|
||||||
int fn_pdn(uint32_t _U_ hash, char _U_ *args) WAL; // "pdn" (2963275719)
|
int fn_pdn(uint32_t _U_ hash, char _U_ *args) WAL; // "pdn" (2963275719)
|
||||||
@ -197,6 +203,9 @@ int parsecmd(const char *str){
|
|||||||
case CMD_DIAGN:
|
case CMD_DIAGN:
|
||||||
return fn_diagn(h, args);
|
return fn_diagn(h, args);
|
||||||
break;
|
break;
|
||||||
|
case CMD_DRVTYPE:
|
||||||
|
return fn_drvtype(h, args);
|
||||||
|
break;
|
||||||
case CMD_DUMPCMD:
|
case CMD_DUMPCMD:
|
||||||
return fn_dumpcmd(h, args);
|
return fn_dumpcmd(h, args);
|
||||||
break;
|
break;
|
||||||
@ -254,12 +263,18 @@ int parsecmd(const char *str){
|
|||||||
case CMD_MINSPEED:
|
case CMD_MINSPEED:
|
||||||
return fn_minspeed(h, args);
|
return fn_minspeed(h, args);
|
||||||
break;
|
break;
|
||||||
|
case CMD_MOTCURRENT:
|
||||||
|
return fn_motcurrent(h, args);
|
||||||
|
break;
|
||||||
case CMD_MOTFLAGS:
|
case CMD_MOTFLAGS:
|
||||||
return fn_motflags(h, args);
|
return fn_motflags(h, args);
|
||||||
break;
|
break;
|
||||||
case CMD_MOTMUL:
|
case CMD_MOTMUL:
|
||||||
return fn_motmul(h, args);
|
return fn_motmul(h, args);
|
||||||
break;
|
break;
|
||||||
|
case CMD_MOTNO:
|
||||||
|
return fn_motno(h, args);
|
||||||
|
break;
|
||||||
case CMD_MOTREINIT:
|
case CMD_MOTREINIT:
|
||||||
return fn_motreinit(h, args);
|
return fn_motreinit(h, args);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -31,6 +31,7 @@ int parsecmd(const char *cmdwargs);
|
|||||||
#define CMD_CANSPEED (549265992)
|
#define CMD_CANSPEED (549265992)
|
||||||
#define CMD_CANSTAT (237384179)
|
#define CMD_CANSTAT (237384179)
|
||||||
#define CMD_DIAGN (2334137736)
|
#define CMD_DIAGN (2334137736)
|
||||||
|
#define CMD_DRVTYPE (3930242451)
|
||||||
#define CMD_DUMPCMD (1223955823)
|
#define CMD_DUMPCMD (1223955823)
|
||||||
#define CMD_DUMPCONF (3271513185)
|
#define CMD_DUMPCONF (3271513185)
|
||||||
#define CMD_DUMPERR (1223989764)
|
#define CMD_DUMPERR (1223989764)
|
||||||
@ -50,8 +51,10 @@ int parsecmd(const char *cmdwargs);
|
|||||||
#define CMD_MCUVDD (2517587080)
|
#define CMD_MCUVDD (2517587080)
|
||||||
#define CMD_MICROSTEPS (3974395854)
|
#define CMD_MICROSTEPS (3974395854)
|
||||||
#define CMD_MINSPEED (3234848090)
|
#define CMD_MINSPEED (3234848090)
|
||||||
|
#define CMD_MOTCURRENT (1926997848)
|
||||||
#define CMD_MOTFLAGS (2153634658)
|
#define CMD_MOTFLAGS (2153634658)
|
||||||
#define CMD_MOTMUL (1543400099)
|
#define CMD_MOTMUL (1543400099)
|
||||||
|
#define CMD_MOTNO (544673586)
|
||||||
#define CMD_MOTREINIT (199682784)
|
#define CMD_MOTREINIT (199682784)
|
||||||
#define CMD_PDN (2963275719)
|
#define CMD_PDN (2963275719)
|
||||||
#define CMD_PING (10561715)
|
#define CMD_PING (10561715)
|
||||||
|
|||||||
@ -16,6 +16,7 @@
|
|||||||
"canspeed - GS CAN speed (reinit if setter)\n"
|
"canspeed - GS CAN speed (reinit if setter)\n"
|
||||||
"canstat - G CAN status\n"
|
"canstat - G CAN status\n"
|
||||||
"diagn[N]* - G DIAG state of motor N (or all)\n"
|
"diagn[N]* - G DIAG state of motor N (or all)\n"
|
||||||
|
"drvtypeN - GS driver type (0 - only step/dir, 1 - UART, 2 - SPI, 3 - reserved)\n"
|
||||||
"dumperr - dump error codes\n"
|
"dumperr - dump error codes\n"
|
||||||
"dumpcmd - dump command codes\n"
|
"dumpcmd - dump command codes\n"
|
||||||
"dumpconf - dump current configuration\n"
|
"dumpconf - dump current configuration\n"
|
||||||
@ -35,8 +36,10 @@
|
|||||||
"mcuvdd - G MCU Vdd\n"
|
"mcuvdd - G MCU Vdd\n"
|
||||||
"microstepsN - GS microsteps settings (2^0..2^9)\n"
|
"microstepsN - GS microsteps settings (2^0..2^9)\n"
|
||||||
"minspeedN - min speed (steps per sec)\n"
|
"minspeedN - min speed (steps per sec)\n"
|
||||||
|
"motcurrentN - GS motor current (1..32 for 1/32..32/32 of max current)\n"
|
||||||
"motflagsN - motorN flags\n"
|
"motflagsN - motorN flags\n"
|
||||||
"motmul* - GS external multiplexer status (<0 - disable, 0..7 - enable and set address)\n"
|
"motmul* - GS external multiplexer status (<0 - disable, 0..7 - enable and set address)\n"
|
||||||
|
"motno - GS motor number for next `pdn` commands\n"
|
||||||
"motreinit - re-init motors after configuration changed\n"
|
"motreinit - re-init motors after configuration changed\n"
|
||||||
"pdnN - GS read/write TMC2209 registers over uart @ motor0\n"
|
"pdnN - GS read/write TMC2209 registers over uart @ motor0\n"
|
||||||
"ping - echo given command back\n"
|
"ping - echo given command back\n"
|
||||||
|
|||||||
@ -16,6 +16,7 @@ cansend
|
|||||||
canspeed
|
canspeed
|
||||||
canstat
|
canstat
|
||||||
diagn
|
diagn
|
||||||
|
drvtype
|
||||||
dumperr
|
dumperr
|
||||||
dumpcmd
|
dumpcmd
|
||||||
dumpconf
|
dumpconf
|
||||||
@ -35,8 +36,10 @@ mcut
|
|||||||
mcuvdd
|
mcuvdd
|
||||||
microsteps
|
microsteps
|
||||||
minspeed
|
minspeed
|
||||||
|
motcurrent
|
||||||
motflags
|
motflags
|
||||||
motmul
|
motmul
|
||||||
|
motno
|
||||||
motreinit
|
motreinit
|
||||||
pdn
|
pdn
|
||||||
ping
|
ping
|
||||||
|
|||||||
@ -51,6 +51,10 @@ int main(void){
|
|||||||
adc_setup();
|
adc_setup();
|
||||||
pdnuart_setup();
|
pdnuart_setup();
|
||||||
USBPU_ON();
|
USBPU_ON();
|
||||||
|
for(int i = 0; i < MOTORSNO; ++i){
|
||||||
|
motflags_t flag = the_conf.motflags[i];
|
||||||
|
if(flag.drvtype == DRVTYPE_UART) pdnuart_init(i);
|
||||||
|
}
|
||||||
uint32_t ctr = 0;
|
uint32_t ctr = 0;
|
||||||
CAN_message *can_mesg;
|
CAN_message *can_mesg;
|
||||||
while(1){
|
while(1){
|
||||||
|
|||||||
Binary file not shown.
@ -18,10 +18,13 @@
|
|||||||
|
|
||||||
#include <stm32f3.h>
|
#include <stm32f3.h>
|
||||||
|
|
||||||
|
#include "flash.h"
|
||||||
#include "hardware.h"
|
#include "hardware.h"
|
||||||
#include "proto.h"
|
#include "proto.h"
|
||||||
|
#include "tmc2209.h"
|
||||||
|
|
||||||
extern volatile uint32_t Tms;
|
extern volatile uint32_t Tms;
|
||||||
|
static uint8_t motorno = 0;
|
||||||
|
|
||||||
#define MAXBUFLEN (8)
|
#define MAXBUFLEN (8)
|
||||||
// timeout, milliseconds
|
// timeout, milliseconds
|
||||||
@ -66,16 +69,18 @@ void pdnuart_setup(){
|
|||||||
setup_usart(1);
|
setup_usart(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int rwreg(uint8_t motorno, uint8_t reg, uint32_t data, int w){
|
static int rwreg(uint8_t reg, uint32_t data, int w){
|
||||||
if(motorno >= MOTORSNO || reg & 0x80) return FALSE;
|
if(motorno >= MOTORSNO || reg & 0x80) return FALSE;
|
||||||
|
uint32_t x = Tms;
|
||||||
|
while(Tms - x < 1);
|
||||||
int no = motorno >> 2;
|
int no = motorno >> 2;
|
||||||
uint8_t outbuf[MAXBUFLEN];
|
uint8_t outbuf[MAXBUFLEN];
|
||||||
outbuf[0] = 0xa0;
|
outbuf[0] = 0x05;
|
||||||
outbuf[1] = motorno - (no << 2);
|
outbuf[1] = motorno - (no << 2);
|
||||||
outbuf[2] = reg << 1;
|
outbuf[2] = reg;
|
||||||
int nbytes = 3;
|
int nbytes = 3;
|
||||||
if(w){
|
if(w){
|
||||||
outbuf[2] |= 1;
|
outbuf[2] |= 0x80;
|
||||||
for(int i = 6; i > 2; --i){
|
for(int i = 6; i > 2; --i){
|
||||||
outbuf[i] = data & 0xff;
|
outbuf[i] = data & 0xff;
|
||||||
data >>= 8;
|
data >>= 8;
|
||||||
@ -85,20 +90,25 @@ static int rwreg(uint8_t motorno, uint8_t reg, uint32_t data, int w){
|
|||||||
calcCRC(outbuf, nbytes);
|
calcCRC(outbuf, nbytes);
|
||||||
++nbytes;
|
++nbytes;
|
||||||
for(int i = 0; i < nbytes; ++i){
|
for(int i = 0; i < nbytes; ++i){
|
||||||
|
USB_sendstr("Send byte "); USB_putbyte('0'+i); USB_sendstr(": "); printuhex(outbuf[i]); newline();
|
||||||
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;
|
||||||
|
for(; l < 10000; ++l) if(USART[no]->ISR & USART_ISR_RXNE) break;
|
||||||
|
if(l == 10000) USND("Nothing received");
|
||||||
|
else {USB_sendstr("Rcv: "); printuhex(USART[no]->RDR); newline();}
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// return FALSE if failed
|
// return FALSE if failed
|
||||||
int pdnuart_writereg(uint8_t motorno, uint8_t reg, uint32_t data){
|
int pdnuart_writereg(uint8_t reg, uint32_t data){
|
||||||
return rwreg(motorno, reg, data, 1);
|
return rwreg(reg, data, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// return FALSE if failed
|
// return FALSE if failed
|
||||||
int pdnuart_readreg(uint8_t motorno, uint8_t reg, uint32_t *data){
|
int pdnuart_readreg(uint8_t reg, uint32_t *data){
|
||||||
if(!rwreg(motorno, reg, 0, 0)) return FALSE;
|
if(!rwreg(reg, 0, 0)) return FALSE;
|
||||||
uint32_t Tstart = Tms;
|
uint32_t Tstart = Tms;
|
||||||
uint8_t buf[8];
|
uint8_t buf[8];
|
||||||
int no = motorno >> 2;
|
int no = motorno >> 2;
|
||||||
@ -117,6 +127,60 @@ int pdnuart_readreg(uint8_t motorno, uint8_t reg, uint32_t *data){
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int readregister(uint8_t no, uint8_t reg, uint32_t *data){
|
||||||
|
int n = motorno; motorno = no;
|
||||||
|
int r = pdnuart_readreg(reg, data);
|
||||||
|
motorno = n;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int writeregister(uint8_t no, uint8_t reg, uint32_t data){
|
||||||
|
int n = motorno; motorno = no;
|
||||||
|
int r = pdnuart_writereg(reg, data);
|
||||||
|
motorno = n;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t pdnuart_getmotno(){
|
||||||
|
return motorno;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pdnuart_setmotno(uint8_t no){
|
||||||
|
if(no >= MOTORSNO) return FALSE;
|
||||||
|
motorno = no;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// write val into IHOLD_IRUN over UART to n'th motor
|
||||||
|
int pdnuart_setcurrent(uint8_t no, uint8_t val){
|
||||||
|
TMC2209_ihold_irun_reg_t regval;
|
||||||
|
if(!readregister(no, TMC2209Reg_IHOLD_IRUN, ®val.value)) return FALSE;
|
||||||
|
regval.irun = val;
|
||||||
|
return writeregister(no, TMC2209Reg_IHOLD_IRUN, regval.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// set microsteps over UART
|
||||||
|
int pdnuart_microsteps(uint8_t no, uint32_t val){
|
||||||
|
if(val > 256) return FALSE;
|
||||||
|
TMC2209_chopconf_reg_t regval;
|
||||||
|
if(!readregister(no, TMC2209Reg_CHOPCONF, ®val.value)) return FALSE;
|
||||||
|
if(val == 256) regval.mres = 0;
|
||||||
|
else regval.mres = MSB(val) + 1;
|
||||||
|
return writeregister(no, TMC2209Reg_CHOPCONF, regval.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// init driver number `no`
|
||||||
|
int pdnuart_init(uint8_t no){
|
||||||
|
TMC2209_gconf_reg_t gconf;
|
||||||
|
if(!readregister(no, TMC2209Reg_GCONF, &gconf.value)) return FALSE;
|
||||||
|
gconf.pdn_disable = 1; // PDN now is UART
|
||||||
|
gconf.mstep_reg_select = 1; // microsteps are by MSTEP
|
||||||
|
if(!writeregister(no, TMC2209Reg_GCONF, gconf.value)) return FALSE;
|
||||||
|
if(!pdnuart_microsteps(no, the_conf.microsteps[no])) return FALSE;
|
||||||
|
if(!pdnuart_setcurrent(no, the_conf.motcurrent[no])) return FALSE;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
static void parseRx(int no){
|
static void parseRx(int no){
|
||||||
USB_sendstr("Got from ");
|
USB_sendstr("Got from ");
|
||||||
|
|||||||
@ -21,5 +21,10 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
void pdnuart_setup();
|
void pdnuart_setup();
|
||||||
int pdnuart_writereg(uint8_t motorno, uint8_t reg, uint32_t data);
|
int pdnuart_writereg(uint8_t reg, uint32_t data);
|
||||||
int pdnuart_readreg(uint8_t motorno, uint8_t reg, uint32_t *data);
|
int pdnuart_readreg(uint8_t reg, uint32_t *data);
|
||||||
|
int pdnuart_setmotno(uint8_t no);
|
||||||
|
uint8_t pdnuart_getmotno();
|
||||||
|
int pdnuart_setcurrent(uint8_t no, uint8_t val);
|
||||||
|
int pdnuart_microsteps(uint8_t no, uint32_t val);
|
||||||
|
int pdnuart_init(uint8_t no);
|
||||||
|
|||||||
@ -405,12 +405,13 @@ int fn_time(uint32_t _U_ hash, char _U_ *args){ // "time" (19148340)
|
|||||||
|
|
||||||
|
|
||||||
static const char* motfl[MOTFLAGS_AMOUNT] = {
|
static const char* motfl[MOTFLAGS_AMOUNT] = {
|
||||||
"reverse - invert motor's rotation",
|
"0: reverse - invert motor's rotation",
|
||||||
"[reserved]",
|
"1: [reserved]",
|
||||||
"[reserved]",
|
"2: [reserved]",
|
||||||
"donthold - clear motor's power after stop",
|
"3: donthold - clear motor's power after stop",
|
||||||
"eswinv - inverse end-switches (1->0 instead of 0->1)",
|
"4: eswinv - inverse end-switches (1->0 instead of 0->1)",
|
||||||
"[reserved]"
|
"5: [reserved]",
|
||||||
|
"6,7: drvtype - driver type (0 - only step/dir, 1 - UART, 2 - SPI, 3 - reserved)"
|
||||||
};
|
};
|
||||||
static const char *eswfl[ESW_AMOUNT] = {
|
static const char *eswfl[ESW_AMOUNT] = {
|
||||||
[ESW_IGNORE] = "ignore end-switches",
|
[ESW_IGNORE] = "ignore end-switches",
|
||||||
@ -568,6 +569,9 @@ static int canusb_function(uint32_t hash, char *args){
|
|||||||
case CMD_DIAGN:
|
case CMD_DIAGN:
|
||||||
e = cu_diagn(par, &val);
|
e = cu_diagn(par, &val);
|
||||||
break;
|
break;
|
||||||
|
case CMD_DRVTYPE:
|
||||||
|
e = cu_drvtype(par, &val);
|
||||||
|
break;
|
||||||
case CMD_EMSTOP:
|
case CMD_EMSTOP:
|
||||||
e = cu_emstop(par, &val);
|
e = cu_emstop(par, &val);
|
||||||
break;
|
break;
|
||||||
@ -612,12 +616,18 @@ static int canusb_function(uint32_t hash, char *args){
|
|||||||
case CMD_MINSPEED:
|
case CMD_MINSPEED:
|
||||||
e = cu_minspeed(par, &val);
|
e = cu_minspeed(par, &val);
|
||||||
break;
|
break;
|
||||||
|
case CMD_MOTCURRENT:
|
||||||
|
e = cu_motcurrent(par, &val);
|
||||||
|
break;
|
||||||
case CMD_MOTFLAGS:
|
case CMD_MOTFLAGS:
|
||||||
e = cu_motflags(par, &val);
|
e = cu_motflags(par, &val);
|
||||||
break;
|
break;
|
||||||
case CMD_MOTMUL:
|
case CMD_MOTMUL:
|
||||||
e = cu_motmul(par, &val);
|
e = cu_motmul(par, &val);
|
||||||
break;
|
break;
|
||||||
|
case CMD_MOTNO:
|
||||||
|
e = cu_motno(par, &val);
|
||||||
|
break;
|
||||||
case CMD_MOTREINIT:
|
case CMD_MOTREINIT:
|
||||||
e = cu_motreinit(par, &val);
|
e = cu_motreinit(par, &val);
|
||||||
break;
|
break;
|
||||||
@ -674,7 +684,7 @@ static int canusb_function(uint32_t hash, char *args){
|
|||||||
USB_sendstr(errtxt[e]); newline();
|
USB_sendstr(errtxt[e]); newline();
|
||||||
}else{
|
}else{
|
||||||
USB_sendstr("OK par");
|
USB_sendstr("OK par");
|
||||||
if(par != CANMESG_NOPAR) printu(PARBASE(par));
|
if(PARBASE(par) != CANMESG_NOPAR) printu(PARBASE(par));
|
||||||
USB_putbyte('='); printi(val);
|
USB_putbyte('='); printi(val);
|
||||||
newline();
|
newline();
|
||||||
}
|
}
|
||||||
@ -689,6 +699,7 @@ int fn_accel(uint32_t _U_ hash, char _U_ *args) AL; //* "accel" (1490521981)
|
|||||||
int fn_adc(uint32_t _U_ hash, char _U_ *args) AL; // "adc" (2963026093)
|
int fn_adc(uint32_t _U_ hash, char _U_ *args) AL; // "adc" (2963026093)
|
||||||
int fn_button(uint32_t _U_ hash, char _U_ *args) AL; // "button" (1093508897)
|
int fn_button(uint32_t _U_ hash, char _U_ *args) AL; // "button" (1093508897)
|
||||||
int fn_diagn(uint32_t _U_ hash, char _U_ *args) AL; //* "diagn" (2334137736)
|
int fn_diagn(uint32_t _U_ hash, char _U_ *args) AL; //* "diagn" (2334137736)
|
||||||
|
int fn_drvtype(uint32_t _U_ hash, char _U_ *args) AL; // "drvtype" (3930242451)
|
||||||
int fn_emstop(uint32_t _U_ hash, char _U_ *args) AL; //* "emstop" (2965919005)
|
int fn_emstop(uint32_t _U_ hash, char _U_ *args) AL; //* "emstop" (2965919005)
|
||||||
int fn_eraseflash(uint32_t _U_ hash, char _U_ *args) AL; //* "eraseflash" (3177247267)
|
int fn_eraseflash(uint32_t _U_ hash, char _U_ *args) AL; //* "eraseflash" (3177247267)
|
||||||
int fn_esw(uint32_t _U_ hash, char _U_ *args) AL; // "esw" (2963094612)
|
int fn_esw(uint32_t _U_ hash, char _U_ *args) AL; // "esw" (2963094612)
|
||||||
@ -703,8 +714,10 @@ int fn_mcut(uint32_t _U_ hash, char _U_ *args) AL; // "mcut" (4022718)
|
|||||||
int fn_mcuvdd(uint32_t _U_ hash, char _U_ *args) AL; // "mcuvdd" (2517587080)
|
int fn_mcuvdd(uint32_t _U_ hash, char _U_ *args) AL; // "mcuvdd" (2517587080)
|
||||||
int fn_microsteps(uint32_t _U_ hash, char _U_ *args) AL; //* "microsteps" (3974395854)
|
int fn_microsteps(uint32_t _U_ hash, char _U_ *args) AL; //* "microsteps" (3974395854)
|
||||||
int fn_minspeed(uint32_t _U_ hash, char _U_ *args) AL; //* "minspeed" (3234848090)
|
int fn_minspeed(uint32_t _U_ hash, char _U_ *args) AL; //* "minspeed" (3234848090)
|
||||||
|
int fn_motcurrent(uint32_t _U_ hash, char _U_ *args) AL; // "motcurrent" (1926997848)
|
||||||
int fn_motflags(uint32_t _U_ hash, char _U_ *args) AL; //* "motflags" (2153634658)
|
int fn_motflags(uint32_t _U_ hash, char _U_ *args) AL; //* "motflags" (2153634658)
|
||||||
int fn_motmul(uint32_t _U_ hash, char _U_ *args) AL; //* "motmul" (1543400099)
|
int fn_motmul(uint32_t _U_ hash, char _U_ *args) AL; //* "motmul" (1543400099)
|
||||||
|
int fn_motno(uint32_t _U_ hash, char _U_ *args) AL; // "motno" (544673586)
|
||||||
int fn_motreinit(uint32_t _U_ hash, char _U_ *args) AL; //* "motreinit" (199682784)
|
int fn_motreinit(uint32_t _U_ hash, char _U_ *args) AL; //* "motreinit" (199682784)
|
||||||
int fn_pdn(uint32_t _U_ hash, char _U_ *args) AL; // "pdn" (2963275719)
|
int fn_pdn(uint32_t _U_ hash, char _U_ *args) AL; // "pdn" (2963275719)
|
||||||
int fn_ping(uint32_t _U_ hash, char _U_ *args) AL; // "ping" (10561715)
|
int fn_ping(uint32_t _U_ hash, char _U_ *args) AL; // "ping" (10561715)
|
||||||
|
|||||||
@ -707,7 +707,7 @@ typedef struct {
|
|||||||
|
|
||||||
TMC2209_status_t driver_status;
|
TMC2209_status_t driver_status;
|
||||||
|
|
||||||
trinamic_config_t config;
|
// trinamic_config_t config;
|
||||||
} TMC2209_t;
|
} TMC2209_t;
|
||||||
|
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
#define BUILD_NUMBER "84"
|
#define BUILD_NUMBER "95"
|
||||||
#define BUILD_DATE "2023-02-26"
|
#define BUILD_DATE "2023-03-01"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user