add nocheck flags

This commit is contained in:
Edward Emelianov 2026-01-16 15:04:03 +03:00
parent 9c0152d08f
commit 3697adba41
10 changed files with 97 additions and 44 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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) \

View File

@ -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;

View File

@ -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];

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 15.0.1, 2025-02-06T16:30:11. -->
<!-- Written by QtCreator 18.0.1, 2026-01-16T15:01:28. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
@ -13,8 +13,8 @@
<data>
<variable>ProjectExplorer.Project.EditorSettings</variable>
<valuemap type="QVariantMap">
<value type="bool" key="EditorConfiguration.AutoDetect">true</value>
<value type="bool" key="EditorConfiguration.AutoIndent">true</value>
<value type="bool" key="EditorConfiguration.AutoSpacesForTabs">false</value>
<value type="bool" key="EditorConfiguration.CamelCaseNavigation">true</value>
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
<value type="QString" key="language">Cpp</value>
@ -86,12 +86,14 @@
<valuelist type="QVariantList" key="ClangTools.SuppressedDiagnostics"/>
<value type="bool" key="ClangTools.UseGlobalSettings">true</value>
</valuemap>
<value type="int" key="RcSync">0</value>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.Target.0</variable>
<valuemap type="QVariantMap">
<value type="QString" key="DeviceType">Desktop</value>
<value type="bool" key="HasPerBcDcs">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{91347f2c-5221-46a7-80b1-0a054ca02f79}</value>
@ -109,8 +111,8 @@
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Сборка</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Сборка</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
@ -122,8 +124,8 @@
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Очистка</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Очистка</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
@ -133,13 +135,48 @@
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">По умолчанию</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.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Deploy</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.DeployConfiguration.CustomData"/>
<value type="bool" key="ProjectExplorer.DeployConfiguration.CustomDataEnabled">false</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
<value type="bool" key="Analyzer.Perf.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="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
<value type="QList&lt;int&gt;" key="Analyzer.Valgrind.VisibleErrorKinds"></value>
<valuelist type="QVariantList" key="CustomOutputParsers"/>
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<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="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
<value type="bool" key="ProjectExplorer.RunConfiguration.Customized">false</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.UniqueId"></value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.BuildConfigurationCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Развёртывание</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Развёртывание</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Deploy</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
@ -163,6 +200,7 @@
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
<value type="bool" key="ProjectExplorer.RunConfiguration.Customized">false</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.UniqueId"></value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
</valuemap>
@ -173,10 +211,6 @@
<variable>ProjectExplorer.Project.TargetCount</variable>
<value type="qlonglong">1</value>
</data>
<data>
<variable>ProjectExplorer.Project.Updater.FileVersion</variable>
<value type="int">22</value>
</data>
<data>
<variable>Version</variable>
<value type="int">22</value>

View File

@ -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] = {

View File

@ -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){

View File

@ -1,2 +1,2 @@
#define BUILD_NUMBER "202"
#define BUILD_DATE "2025-04-16"
#define BUILD_NUMBER "205"
#define BUILD_DATE "2026-01-16"