diff --git a/F3:F303/Multistepper/Readme.md b/F3:F303/Multistepper/Readme.md index de880a4..282129a 100644 --- a/F3:F303/Multistepper/Readme.md +++ b/F3:F303/Multistepper/Readme.md @@ -398,11 +398,11 @@ Dump motor flags' bits (for `motflagsN`) and reaction to limit switches (`eswrea Motor flags: bit0 - 0: reverse - invert motor's rotation - bit1 - 1: [reserved] + bit1 - 1: nocheck - don't check driver for errors bit2 - 2: [reserved] bit3 - 3: donthold - clear motor's power after stop bit4 - 4: eswinv - inverse end-switches (1->0 instead of 0->1) - bit5 - 5: [reserved] + bit5 - 5: nodiag - don't check DIAG output bit6 - 6,7: drvtype - driver type (0 - only step/dir, 1 - UART, 2 - SPI, 3 - reserved) End-switches reaction: 0 - ignore both end-switches diff --git a/F3:F303/Multistepper/commonproto.c b/F3:F303/Multistepper/commonproto.c index 1ad292d..7674ab8 100644 --- a/F3:F303/Multistepper/commonproto.c +++ b/F3:F303/Multistepper/commonproto.c @@ -89,6 +89,7 @@ errcodes cu_button(uint8_t par, int32_t *val){ errcodes cu_diagn(uint8_t par, int32_t *val){ uint8_t n = PARBASE(par); + uint8_t oldstate = DIAGMULCUR(); #if MOTORSNO > 8 #error "Change this code!" #endif @@ -99,10 +100,12 @@ errcodes cu_diagn(uint8_t par, int32_t *val){ n |= motdiagn(i); } *val = n; + DIAGMUL(oldstate); return ERR_OK; } CHECKN(n, par); *val = motdiagn(n); + DIAGMUL(oldstate); return ERR_OK; } diff --git a/F3:F303/Multistepper/flash.c b/F3:F303/Multistepper/flash.c index f1a667a..22f2f5d 100644 --- a/F3:F303/Multistepper/flash.c +++ b/F3:F303/Multistepper/flash.c @@ -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() static uint32_t maxCnum = 1024 / sizeof(user_conf); // can't use blocksize here -#define DEFMF {.donthold = 1, .drvtype = DRVTYPE_UART} +#define DEFMF {.donthold = 1, .nodiag = 1, .drvtype = DRVTYPE_UART} #define USERCONF_INITIALIZER { \ .userconf_sz = sizeof(user_conf) \ diff --git a/F3:F303/Multistepper/flash.h b/F3:F303/Multistepper/flash.h index b60a7a7..6b87eee 100644 --- a/F3:F303/Multistepper/flash.h +++ b/F3:F303/Multistepper/flash.h @@ -51,11 +51,11 @@ enum{ // motor flags typedef struct{ uint8_t reverse : 1; // bit0 - reversing motor rotation - uint8_t encreverse : 1; // bit1 - reversing encoder rotation - NOT USED HERE!!! + uint8_t nocheck : 1; // bit1 - don't check drivers for error state uint8_t haveencoder : 1; // bit2 - have encoder - NOT USED HERE!!! uint8_t donthold : 1; // bit3 - clear power @ stop (don't hold motor when stopped) uint8_t eswinv : 1; // bit4 - inverse end-switches - uint8_t keeppos : 1; // bit5 - keep current position (as servo motor) - NOT USED HERE!!! + uint8_t nodiag : 1; // bit5 - don't check DIAG output uint8_t drvtype : 2; // bits 6,7 - driver type (0 - only step/dir, 1 - UART, 2 - SPI, 3 - reserved) } motflags_t; diff --git a/F3:F303/Multistepper/hardware.h b/F3:F303/Multistepper/hardware.h index c0456eb..aa81743 100644 --- a/F3:F303/Multistepper/hardware.h +++ b/F3:F303/Multistepper/hardware.h @@ -87,6 +87,7 @@ extern const uint32_t EXTpins[EXTNO]; // DIAG output of motors (PE2) & its multiplexer (PE3 - 0, PE4 - 1, PE5 - 2) #define DIAG() (GPIOE->IDR & (1<<2) ? 0 : 1) #define DIAGMUL(x) do{ register uint32_t v = x&7; GPIOE->BSRR = (v | (((~v)&7)<<16))<<3; }while(0) +#define DIAGMULCUR() ((GPIOE->ODR >> 3) & 7) extern volatile TIM_TypeDef *mottimers[MOTORSNO]; diff --git a/F3:F303/Multistepper/multistepper.bin b/F3:F303/Multistepper/multistepper.bin index 1d82208..3c06885 100755 Binary files a/F3:F303/Multistepper/multistepper.bin and b/F3:F303/Multistepper/multistepper.bin differ diff --git a/F3:F303/Multistepper/multistepper.creator.user b/F3:F303/Multistepper/multistepper.creator.user index 702d3dd..96a4cd7 100644 --- a/F3:F303/Multistepper/multistepper.creator.user +++ b/F3:F303/Multistepper/multistepper.creator.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -13,8 +13,8 @@ ProjectExplorer.Project.EditorSettings + true true - false true Cpp @@ -86,12 +86,14 @@ true + 0 ProjectExplorer.Project.Target.0 Desktop + true Desktop Desktop {91347f2c-5221-46a7-80b1-0a054ca02f79} @@ -109,8 +111,8 @@ GenericProjectManager.GenericMakeStep 1 - Сборка - Сборка + Build + Build ProjectExplorer.BuildSteps.Build @@ -122,8 +124,8 @@ GenericProjectManager.GenericMakeStep 1 - Очистка - Очистка + Clean + Clean ProjectExplorer.BuildSteps.Clean 2 @@ -133,13 +135,48 @@ По умолчанию GenericProjectManager.GenericBuildConfiguration + 0 + 0 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + 0 + true + + + 2 + + false + -e cpu-cycles --call-graph dwarf,4096 -F 250 + + ProjectExplorer.CustomExecutableRunConfiguration + + false + + true + true + + 1 1 0 - Развёртывание - Развёртывание + Deploy + Deploy ProjectExplorer.BuildSteps.Deploy 1 @@ -163,6 +200,7 @@ ProjectExplorer.CustomExecutableRunConfiguration false + true true @@ -173,10 +211,6 @@ ProjectExplorer.Project.TargetCount 1 - - ProjectExplorer.Project.Updater.FileVersion - 22 - Version 22 diff --git a/F3:F303/Multistepper/proto.c b/F3:F303/Multistepper/proto.c index 6035741..68385ed 100644 --- a/F3:F303/Multistepper/proto.c +++ b/F3:F303/Multistepper/proto.c @@ -407,11 +407,11 @@ int fn_reset(uint32_t _U_ hash, char _U_ *args){ // "reset" (1907803304) static const char* motfl[MOTFLAGS_AMOUNT] = { "0: reverse - invert motor's rotation", - "1: [reserved]", + "1: nocheck - don't check driver for errors", "2: [reserved]", "3: donthold - clear motor's power after stop", "4: eswinv - inverse end-switches (1->0 instead of 0->1)", - "5: [reserved]", + "5: nodiag - don't check DIAG output", "6,7: drvtype - driver type (0 - only step/dir, 1 - UART, 2 - SPI, 3 - reserved)" }; static const char *eswfl[ESW_AMOUNT] = { diff --git a/F3:F303/Multistepper/steppers.c b/F3:F303/Multistepper/steppers.c index fda2a9f..bbd530f 100644 --- a/F3:F303/Multistepper/steppers.c +++ b/F3:F303/Multistepper/steppers.c @@ -325,38 +325,48 @@ void addmicrostep(uint8_t i){ static void chkstepper(int i){ int32_t i32; static uint8_t stopctr[MOTORSNO] = {0}; // counters for encoders/position zeroing after stopping @ esw - // check DIAGN only for UART/SPI - if(the_conf.motflags[i].drvtype == DRVTYPE_UART || the_conf.motflags[i].drvtype == DRVTYPE_SPI){ - if(motdiagn(i) && state[i] != STP_ERR){ // error occured - DIAGN is low - //DBG("Oldstate: "); USB_putbyte('0' + state[i]); newline(); - /*char Nm = '0'+i; - USB_sendstr(STR_STATE); USB_putbyte(Nm); USB_sendstr("=6\n"); + char Nch = '0' + i; + // check driver status only for UART/SPI + if(!the_conf.motflags[i].nocheck){ + if(state[i] != STP_ERR && (the_conf.motflags[i].drvtype == DRVTYPE_UART || the_conf.motflags[i].drvtype == DRVTYPE_SPI)){ + if(the_conf.motflags[i].nodiag){ // check by pdn-uart + uint32_t u32; switch(the_conf.motflags[i].drvtype){ case DRVTYPE_UART: pdnuart_setmotno(i); if(pdnuart_readreg(TMC2209Reg_GSTAT, &u32)){ - USB_sendstr("GSTAT"); USB_putbyte(Nm); USB_putbyte('='); - USB_sendstr(u2str(u32)); newline(); - } - if(pdnuart_readreg(TMC2209Reg_DRV_STATUS, &u32)){ - USB_sendstr("DRV_STATUS"); USB_putbyte(Nm); USB_putbyte('='); - USB_sendstr(u2str(u32)); newline(); + TMC2209_gstat_reg_t s; + s.value = u32; + if(s.drv_err || s.uv_cp){ + if(pdnuart_readreg(TMC2209Reg_DRV_STATUS, &u32)){ + //TMC2209_drv_status_reg_t d; + //d.value = u32; + USB_sendstr("DRV_STATUS"); USB_putbyte(Nch); + USB_putbyte('='); USB_sendstr(u2str(u32)); + newline(); + } + USB_sendstr("state"); USB_putbyte(Nch); + USB_sendstr("=6\n"); + emstopmotor(i); + state[i] = STP_ERR; + } } break; default: break; - }*/ + } + }else if(DIAG()){ // error occured - DIAGN is low emstopmotor(i); state[i] = STP_ERR; return; } - } + }} #ifdef EBUG if(stp[i]){ stp[i] = 0; // motor state could be changed outside of interrupt, so return it to relax state[i] = STP_RELAX; - USB_sendstr("MOTOR"); USB_putbyte('0'+i); USB_sendstr(" stop @"); printi(stppos[i]); + USB_sendstr("MOTOR"); USB_putbyte(Nch); USB_sendstr(" stop @"); printi(stppos[i]); USB_sendstr(", V="); printu(curspeed[i]); USB_sendstr(", curstate="); printu(state[i]); newline(); } @@ -368,7 +378,7 @@ static void chkstepper(int i){ curspeed[i] = the_conf.maxspd[i]; state[i] = STP_MOVE; #ifdef EBUG - USB_sendstr("MOTOR"); USB_putbyte('0'+i); + USB_sendstr("MOTOR"); USB_putbyte(Nch); USB_sendstr(" -> MOVE@"); printi(stppos[i]); USB_sendstr(", V="); printu(curspeed[i]); newline(); #endif }else{ // increase speed @@ -407,7 +417,7 @@ static void chkstepper(int i){ curspeed[i] = the_conf.minspd[i]; state[i] = STP_MVSLOW; #ifdef EBUG - USB_sendstr("MOTOR"); USB_putbyte('0'+i); + USB_sendstr("MOTOR"); USB_putbyte(Nch); USB_sendstr(" -> MVSLOW@"); printi(stppos[i]); newline(); #endif } @@ -420,7 +430,7 @@ static void chkstepper(int i){ case M0FAST: if(state[i] == STP_RELAX || state[i] == STP_STALL){ // stopped -> move to + #ifdef EBUG - USB_putbyte('M'); USB_putbyte('0'+i); USB_sendstr("FAST: motor stopped\n"); + USB_putbyte('M'); USB_putbyte(Nch); USB_sendstr("FAST: motor stopped\n"); #endif if(ERR_OK != motor_relslow(i, 1000)){ #ifdef EBUG @@ -443,7 +453,7 @@ static void chkstepper(int i){ } if((state[i] == STP_RELAX || state[i] == STP_STALL) && ++stopctr[i] > 5){ // wait at least 50ms #ifdef EBUG - USB_putbyte('M'); USB_putbyte('0'+i); USND("SLOW: motor stopped"); + USB_putbyte('M'); USB_putbyte(Nch); USND("SLOW: motor stopped"); #endif ESW_reaction[i] = the_conf.ESW_reaction[i]; prevstppos[i] = targstppos[i] = stppos[i] = 0; @@ -489,15 +499,20 @@ void stopmotor(uint8_t i){ TODECEL(); } +// process only one stepper per run void process_steppers(){ static uint32_t Tlast = 0; - if(Tms - Tlast < MOTCHKINTERVAL) return; // hit every 10ms + if(Tms - Tlast < MOTCHKINTERVAL / MOTORSNO) return; // hit every ~10ms for full circle Tlast = Tms; static int firstrun = 1; - if(firstrun){ firstrun = 0; init_steppers(); return; } - for(int i = 0; i < MOTORSNO; ++i){ + if(firstrun){ firstrun = 0; init_steppers(); DIAGMUL(0); return; } + static int curmotno = 0; + chkstepper(curmotno++); + if(curmotno == MOTORSNO) curmotno = 0; + DIAGMUL(curmotno); + /*for(int i = 0; i < MOTORSNO; ++i){ chkstepper(i); - } + }*/ } uint8_t geteswreact(uint8_t i){ diff --git a/F3:F303/Multistepper/version.inc b/F3:F303/Multistepper/version.inc index 1ccd19b..592d71c 100644 --- a/F3:F303/Multistepper/version.inc +++ b/F3:F303/Multistepper/version.inc @@ -1,2 +1,2 @@ -#define BUILD_NUMBER "202" -#define BUILD_DATE "2025-04-16" +#define BUILD_NUMBER "205" +#define BUILD_DATE "2026-01-16"