Readme.md finished for current protocol

This commit is contained in:
Edward Emelianov 2024-08-20 17:25:26 +03:00
parent b10fb37c58
commit 3e86556206
5 changed files with 171 additions and 54 deletions

View File

@ -420,42 +420,157 @@ Dump motors' state codes (for getter `stateN`):
### emstop[N] (29 with `N` and 31 without) ### emstop[N] (29 with `N` and 31 without)
Emergency stop Nth motor or all (if `N` absent). Returns `OK` or error text. Emergency stop Nth motor or all (if `N` absent). Returns `OK` or error text.
### eraseflash [=N] (38)
Erase flash data storage (full or only N'th page of it). Use this option only if you have problems
when try to save current configuration.
### eswN (6) G
Get end-switches state. Return two bits (for limit switches 0 and 1): 1 means "active", 0 - "passive".
If you use SPI-based driver, only one switch available, so return will be 1-bit.
### eswreactN (24) GS
End-switches reaction: 0 - ignore, 1 - stop on any limit switch (both 0 and 1; moving will be available only backwards),
2 - stop only on switch 0. You can modify this values on-the-fly (but only when steppers aren't moving). This can be usefull,
for example, to rotate filter turret into given position using switch 1 to both as limit switch and position stopper.
But even in state 0 (ignore) active state of both switches estimates as error and you won't be able to move motor.
### gotoN (26) GS
Move motor to given absolute position.
### gotozN (32)
Find zero position & refresh counters. The motor would rotate in reverse direction until limit switch 0 acts or amount of
steps (parameter `maxsteps` of configuration) is exhausted.
### gpioconfN* GS
GPIO configuration (0 - PUin, 1 - PPout, 2 - ODout), N=0..2.
### gpio[N]* (12) GS
GPIO values, N=0..2. Without `N` run for all GPIOs (each byte is state: 0/1).
By default GPIOs are pulled up inputs.
### help
Show this help.
### maxspeedN (18) GS
Maximal motor speed (steps per sec). Depends on current microstep configuration. As speed depends on Nth motor's timer settings,
you can't give any value you want. Speed recalculated through ARR value:
"eraseflash [=N] (38) erase flash data storage (full or only N'th page of it)\n" ARR = 26MHz / microsteps / (speed - 1).
"esw[N] (6) G end-switches state\n"
"eswreactN (24) GS end-switches reaction (0 - ignore, 1 - stop@any, 2 - stop@zero)\n" Minimal value of ARR is 99 (260kHz), maximal is 0xffff (600Hz). And after that actual speed value calculated:
"gotoN (26) GS move motor to given absolute position\n"
"gotozN (32) find zero position & refresh counters\n" speed = 26MHz / microsteps / (ARR + 1).
"gpioconfN* - GS GPIO configuration (0 - PUin, 1 - PPout, 2 - ODout), N=0..2\n"
"gpioN* (12) GS GPIO values, N=0..2\n" And it can't be greater than 0xffff. So if your motor really can make, let's say, 32000 steps per second, you can run it only
help for microstepping not more than 2.
"maxspeedN (18) GS max speed (steps per sec)\n" ### maxstepsN (21) GS
"maxstepsN (21) GS max steps (from zero ESW)\n" Maximal steps amount (from zero ESW) for given motor. This is limiting positive position and amount of steps to make when
"mcut (7) G MCU T\n" searching of zero limit switch.
"mcuvdd (8) G MCU Vdd\n" ### mcut (7) G
"microstepsN (16) GS microsteps settings (2^0..2^9)\n" Temperature of MCU in thousandths of degC.
"minspeedN (19) min speed (steps per sec)\n" ### mcuvdd (8) G
"motcurrentN (46) GS motor current (1..32 for 1/32..32/32 of max current)\n" MCU Vdd value.
"motflagsN (23) motorN flags\n" ### microstepsN (16) GS
"motmul* (36) GS external multiplexer status (<0 - disable, 0..7 - enable and set address)\n" Microsteps settings (2^0..2^9). Read `maxspeed` about relationship of maximal speed and microsteppings.
"motno (44) GS motor number for next `pdn` commands\n" ### minspeedN (19) GS
"motreinit (25) re-init motors after configuration changed\n" Minimal motor speed (steps per sec), this is the starting speed of motor's ramp and default speed for `relslow` command,
"pdnN (43) GS read/write TMC2209 registers over uart @ motor0\n" so don't try to make it too large.
"ping (1)- echo given command back\n" ### motcurrentN (46) GS
"relposN (27) GS relative move (get remaining)\n" Maximal motor current (1..32 for 1/32..32/32 of max current) for TMC drivers. In case of simplest drivers like DRV8825
"relslowN (28) GS like 'relpos' but with slowest speed\n" you should set current using varistor on driver's board.
"reset (9) software reset\n" ### motflagsN (23) GS
"saveconf (13) save current configuration\n" Nth motor flags. To understand bit fields of these flags use `dumpmotflags`.
"screen* - GS screen enable (1) or disable (0)\n" ### motmul * (36) GS
"speedlimit (20) G limiting speed for current microsteps setting\n" external multiplexer status (<0 - disable, 0..7 - enable and set address).
"stateN (33) G motor state (0-relax, 1-accel, 2-move, 3-mvslow, 4-decel, 5-stall, 6-err)\n" ### motno (44) GS
"stopN (30) stop motor with deceleration\n" Motor number for next `pdn` commands (if you want to run custom commands by hands or in a batch).
"time (10) G time from start (ms)\n" ### motreinit (25)
"tmcbus* - GS TMC control bus (0 - USART, 1 - SPI)\n" Re-init motors after configuration changed. Some changes will run this automatically.
"udata* (39) GS data by usart in slave mode (text strings, '\\n'-terminated)\n" ### pdnN (43) GS
"usartstatus* (40) GS status of USART1 (0 - off, 1 - master, 2 - slave)\n" Read/write TMC2209 (and other UART-based drivers) registers over uart @ motor number `motno`.
"vdrive (41) G approx voltage on Vdrive\n" For `pdnN=X` `N` is register number, `X` is data to write into it. Due to protocol's particulars
"vfive (42) G approx voltage on 5V bus\n" you can't work with registers with address more than 126 (0x7e).
### ping (1)
Echo given command back. For CAN bus return original packet, for USB - given argumemt and parameter (but checking parameter).
### relposN (27) GS
Relative (with ramp) move for given amount of steps (get remaining steps for getter).
### relslowN (28) GS
Like `relpos` but with constant slowest speed (you can change it with `minspeed`).
### reset (9)
Software reset.
### saveconf (13)
Save current configuration into MCU flash memory.
### screen* GS
Enable (1) or disable (0) screen.
### speedlimit (20) G
Get limiting speed for current microsteps setting.
### stateN (33) G
Get Nth motor state (`dumpstates`: 0-relax, 1-accel, 2-move, 3-mvslow, 4-decel, 5-stall, 6-err).
### stopN (30)
Stop Nth motor with deceleration (moving by ramp).
### time (10) G
Get time from start (ms).
### tmcbus * GS
TMC control bus (0 - USART, 1 - SPI), unuseful command; use `motflags` instead.
### udata* (39) GS
Data by usart in slave mode (text strings, '\\n'-terminated).
### usartstatus* (40)
GS status of USART1 (0 - off, 1 - master, 2 - slave).
### vdrive (41) G
Approximate voltage on Vdrive input, millivolts.
### vfive (42) G
Approximate voltage on 5V bus, millivolts.
## CAN bus ## CAN bus
Default CAN ID is 1. Default CAN ID is 1.
Protocol use variable length incoming messages: from 2 bytes for simplest commands to all 8 bytes for common.
Bytes (in time order):
- **0**, **1** - little-endian command code.
- **2** - parameter number (0..126), 127 means "no parameter", elder bit (0x80) is a setter flag (without it
all rest part of message ignored).
- **3** - (only in packets from controller) error code.
- **4**...**8** - little-endian data.
Command codes described in USB answer for `dumpcmd`:
1 - ping
4 - adc
5 - button
6 - esw
7 - mcut
8 - mcuvdd
9 - reset
10 - time
12 - gpio
13 - saveconf
16 - microsteps
17 - accel
18 - maxspeed
19 - minspeed
20 - speedlimit
21 - maxsteps
23 - motflags
24 - eswreact
25 - motreinit
26 - goto
27 - relpos
28 - relslow
29 - emstop N
30 - stop
31 - emstop all
32 - gotoz
33 - state
35 - abspos
36 - motmul
37 - diagn
38 - eraseflash
39 - udata
40 - usartstatus
41 - vdrive
42 - vfive
43 - pdn
44 - motno
45 - drvtype
Error codes (`dumperr`):
0 - OK
1 - BADPAR
2 - BADVAL
3 - WRONGLEN
4 - BADCMD
5 - CANTRUN

View File

@ -194,7 +194,7 @@ TRUE_INLINE void iwdg_setup(){
static void setup_mpwm(int i){ static void setup_mpwm(int i){
volatile TIM_TypeDef *TIM = mottimers[i]; volatile TIM_TypeDef *TIM = mottimers[i];
TIM->CR1 = TIM_CR1_ARPE; // buffered ARR TIM->CR1 = TIM_CR1_ARPE; // buffered ARR
TIM->PSC = MOTORTIM_PSC; // 16MHz TIM->PSC = MOTORTIM_PSC; // 26MHz
// PWM mode 1 (active -> inactive) // PWM mode 1 (active -> inactive)
uint8_t n = mottchannels[i]; uint8_t n = mottchannels[i];
switch(n){ switch(n){

View File

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 13.0.2, 2024-08-15T16:49:30. --> <!-- Written by QtCreator 14.0.1, 2024-08-20T17:24:19. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>
<value type="QByteArray">{cf63021e-ef53-49b0-b03b-2f2570cdf3b6}</value> <value type="QByteArray">{7bd84e39-ca37-46d3-be9d-99ebea85bc0d}</value>
</data> </data>
<data> <data>
<variable>ProjectExplorer.Project.ActiveTarget</variable> <variable>ProjectExplorer.Project.ActiveTarget</variable>
@ -39,9 +39,9 @@
<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="int" key="EditorConfiguration.PreferAfterWhitespaceComments">0</value>
<value type="bool" key="EditorConfiguration.PreferSingleLineComments">false</value> <value type="bool" key="EditorConfiguration.PreferSingleLineComments">false</value>
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">false</value> <value type="bool" key="EditorConfiguration.ScrollWheelZooming">true</value>
<value type="bool" key="EditorConfiguration.ShowMargin">false</value> <value type="bool" key="EditorConfiguration.ShowMargin">false</value>
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">1</value> <value type="int" key="EditorConfiguration.SmartBackspaceBehavior">0</value>
<value type="bool" key="EditorConfiguration.SmartSelectionChanging">true</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.TabKeyBehavior">0</value>
@ -50,10 +50,10 @@
<value type="bool" key="EditorConfiguration.UseIndenter">false</value> <value type="bool" key="EditorConfiguration.UseIndenter">false</value>
<value type="int" key="EditorConfiguration.Utf8BomBehavior">1</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.cleanIndentation">false</value>
<value type="bool" key="EditorConfiguration.cleanWhitespace">true</value> <value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
<value type="QString" key="EditorConfiguration.ignoreFileTypes">*.md, *.MD, Makefile</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">false</value>
<value type="bool" key="EditorConfiguration.skipTrailingWhitespace">true</value> <value type="bool" key="EditorConfiguration.skipTrailingWhitespace">true</value>
<value type="bool" key="EditorConfiguration.tintMarginArea">true</value> <value type="bool" key="EditorConfiguration.tintMarginArea">true</value>
</valuemap> </valuemap>
@ -69,14 +69,16 @@
<value type="bool" key="AutoTest.Framework.QtQuickTest">true</value> <value type="bool" key="AutoTest.Framework.QtQuickTest">true</value>
<value type="bool" key="AutoTest.Framework.QtTest">true</value> <value type="bool" key="AutoTest.Framework.QtTest">true</value>
</valuemap> </valuemap>
<value type="bool" key="AutoTest.ApplyFilter">false</value>
<valuemap type="QVariantMap" key="AutoTest.CheckStates"/> <valuemap type="QVariantMap" key="AutoTest.CheckStates"/>
<valuelist type="QVariantList" key="AutoTest.PathFilters"/>
<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.AnalyzeOpenFiles">true</value>
<value type="bool" key="ClangTools.BuildBeforeAnalysis">true</value> <value type="bool" key="ClangTools.BuildBeforeAnalysis">true</value>
<value type="QString" key="ClangTools.DiagnosticConfig">Builtin.DefaultTidyAndClazy</value> <value type="QString" key="ClangTools.DiagnosticConfig">Builtin.DefaultTidyAndClazy</value>
<value type="int" key="ClangTools.ParallelJobs">4</value> <value type="int" key="ClangTools.ParallelJobs">8</value>
<value type="bool" key="ClangTools.PreferConfigFile">true</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"/>
@ -91,12 +93,12 @@
<value type="QString" key="DeviceType">Desktop</value> <value type="QString" key="DeviceType">Desktop</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</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.DisplayName">Desktop</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{91347f2c-5221-46a7-80b1-0a054ca02f79}</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{65a14f9e-e008-4c1b-89df-4eaa4774b6e3}</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value> <value type="qlonglong" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value> <value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value> <value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0"> <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/eddy/Docs/SAO/ELECTRONICS/STM32/F3-srcs/Multistepper</value> <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/Big/Data/00__Electronics/STM32/F303-nolib/Multistepper</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<valuelist type="QVariantList" key="GenericProjectManager.GenericMakeStep.BuildTargets"> <valuelist type="QVariantList" key="GenericProjectManager.GenericMakeStep.BuildTargets">
@ -106,8 +108,8 @@
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value>
</valuemap> </valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value> <value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Сборка</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Сборка</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap> </valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
@ -119,8 +121,8 @@
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericMakeStep</value>
</valuemap> </valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value> <value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Очистка</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Очистка</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap> </valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value> <value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
@ -128,15 +130,15 @@
<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"/> <valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">По умолчанию</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Default</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericBuildConfiguration</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">GenericProjectManager.GenericBuildConfiguration</value>
</valuemap> </valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.BuildConfigurationCount">1</value> <value type="qlonglong" key="ProjectExplorer.Target.BuildConfigurationCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0"> <valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">0</value> <value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Развёртывание</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Развёртывание</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Deploy</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
</valuemap> </valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value> <value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>

View File

@ -488,7 +488,7 @@ static int canusb_function(uint32_t hash, char *args){
const char *n = getnum(args, &N); const char *n = getnum(args, &N);
if(n != args){ // get parameter if(n != args){ // get parameter
if(N >= CANMESG_NOPAR){ if(N >= CANMESG_NOPAR){
USND("Wrong parameter value"); USB_sendstr(errtxt[ERR_BADPAR]); newline();
return RET_GOOD; return RET_GOOD;
} }
par = (uint8_t) N; par = (uint8_t) N;