diff --git a/stm32-stepper-root/stepper_h7/CM4/.settings/language.settings.xml b/stm32-stepper-root/stepper_h7/CM4/.settings/language.settings.xml
index 9dbd5cc..dd1a467 100644
--- a/stm32-stepper-root/stepper_h7/CM4/.settings/language.settings.xml
+++ b/stm32-stepper-root/stepper_h7/CM4/.settings/language.settings.xml
@@ -5,7 +5,7 @@
-
+
@@ -16,7 +16,7 @@
-
+
diff --git a/stm32-stepper-root/stepper_h7/CM7/.settings/language.settings.xml b/stm32-stepper-root/stepper_h7/CM7/.settings/language.settings.xml
index 905fd09..76bc169 100644
--- a/stm32-stepper-root/stepper_h7/CM7/.settings/language.settings.xml
+++ b/stm32-stepper-root/stepper_h7/CM7/.settings/language.settings.xml
@@ -5,7 +5,7 @@
-
+
@@ -16,7 +16,7 @@
-
+
diff --git a/stm32-stepper-root/stepper_h7/CM7/Core/Src/Stepper/stepper.c b/stm32-stepper-root/stepper_h7/CM7/Core/Src/Stepper/stepper.c
index 59355af..83fbcc3 100644
--- a/stm32-stepper-root/stepper_h7/CM7/Core/Src/Stepper/stepper.c
+++ b/stm32-stepper-root/stepper_h7/CM7/Core/Src/Stepper/stepper.c
@@ -4,8 +4,8 @@
#include "semphr.h"
// TIM4 (Pulse an PD15) laeuft mit 200 MHz / 128, TIM1 zaehlt die Pulse (16 Bit)
-#define STEP_TICK_HZ 1562500u
-#define STEP_CHUNK 60000u
+#define STEP_TICK_HZ 1562500u //TIM4 Takt
+#define STEP_CHUNK 60000u //TIM1 16 Bit:
#define STEP_HZ_MOVE 4000u // 300 mm/min bei 800 Schritten/mm
#define STEP_HZ_REFERENCE 500u // 37,5 mm/min bei 800 Schritten/mm
#define STEP_POLL_MS 50u // Treiberstatus-Abfrage waehrend der Fahrt
@@ -60,7 +60,6 @@ void StepLibraryDelay(unsigned int ms){
// 1 wenn der Treiber nicht fahrbereit ist. L6474_GetStatus selbst meldet nur SPI-Fehler,
// die Flags muessen hier ausgewertet werden. HIGHZ bleibt nach OCD/UVLO/TH_SD stehen.
-// Der Aufruf aus StepLibraryStep setzt LIBL6474_HAS_LOCKING 0 voraus.
static int StepperHasFault(L6474_Handle_t s){
L6474_Status_t status;
@@ -115,6 +114,48 @@ void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim){
portYIELD_FROM_ISR(woken);
}
+static int config_stepper(L6474_Handle_t s, int param, float value){
+ /*
+ * param 1: torque
+ * param 2: throvercurr
+ * param 3: powerena
+ * param 4: stepmode
+ * param 5: timeoff
+ * param 6: timeon
+ * param 7: timefast
+ * param 8: mmperturn
+ * param 9: posmax
+ * param 10: posmin
+ * param 11: posref
+ * param 12: stepsperturn
+ */
+
+ switch(param){
+ case 1:
+
+ case 2:
+ case 3:
+ if(value == 1){
+ HAL_GPIO_WritePin(STEP_RSTN_GPIO_Port, STEP_RSTN_Pin, GPIO_PIN_SET);
+ }else{
+ HAL_GPIO_WritePin(STEP_RSTN_GPIO_Port, STEP_RSTN_Pin, GPIO_PIN_RESET);
+ }
+ case 4:
+ case 5:
+ case 6:
+ case 7:
+ case 8:
+ case 9:
+ case 10:
+ case 11:
+ case 12:
+ default:
+ return 1;
+ }
+
+
+}
+
static int StepLibraryStep( void* pPWM, int dir, unsigned int numPulses ){
(void)pPWM;
@@ -145,7 +186,10 @@ static int StepLibraryStep( void* pPWM, int dir, unsigned int numPulses ){
}
-
+int cancel_stepper(){
+ TIM1->CR1 &= ~TIM_CR1_CEN;
+ return 0;
+}
L6474_Handle_t init_stepper(void* pIO, void* pGPO, void* pPWM){
@@ -204,7 +248,7 @@ int stepper_reference(L6474_Handle_t s, int flag){
}
yellow_led_start();
//flag: 0 keiner, 1 -t, 2 -e, 3 -s
- if(HAL_GPIO_ReadPin(REFERENCE_MARK_GPIO_Port, REFERENCE_MARK_Pin) == GPIO_PIN_RESET){
+ if(HAL_GPIO_ReadPin(USR_BUTTON_GPIO_Port, USR_BUTTON_Pin) == GPIO_PIN_SET){
if(L6474_StepIncremental(s, mm_to_step(5)) != errcNONE){
return 1;
@@ -216,7 +260,7 @@ int stepper_reference(L6474_Handle_t s, int flag){
if(L6474_StepIncremental(s, -1) != errcNONE){
return 1;
}
- if(HAL_GPIO_ReadPin(REFERENCE_MARK_GPIO_Port, REFERENCE_MARK_Pin) == GPIO_PIN_RESET){
+ if(HAL_GPIO_ReadPin(USR_BUTTON_GPIO_Port, USR_BUTTON_Pin) == GPIO_PIN_SET){
button_pressed=1;
}
@@ -235,7 +279,7 @@ int stepper_reference(L6474_Handle_t s, int flag){
if(L6474_StepIncremental(s, -1) != errcNONE){
return 1;
}
- if(HAL_GPIO_ReadPin(REFERENCE_MARK_GPIO_Port, REFERENCE_MARK_Pin) == GPIO_PIN_RESET){
+ if(HAL_GPIO_ReadPin(USR_BUTTON_GPIO_Port, USR_BUTTON_Pin) == GPIO_PIN_SET){
button_pressed=1;
}
@@ -256,7 +300,7 @@ int stepper_pos(L6474_Handle_t s){
if(L6474_GetAbsolutePosition(s, &position) != errcNONE){
return 1;
}
- printf("Stepper position: %d", position);
+ printf("%d", (position/800));
return StepperHasFault(s);
}
@@ -276,7 +320,6 @@ int stepper_move(L6474_Handle_t s, int pos){
int pos_diff = pos - position;
- // StepIncremental lehnt 0 Schritte als Fehler ab
if(pos_diff != 0 && L6474_StepIncremental(s, pos_diff) != errcNONE){
return 1;
}
@@ -284,19 +327,24 @@ int stepper_move(L6474_Handle_t s, int pos){
return StepperHasFault(s);
}
+static void print_binary_8bit(unsigned int val) {
+ for (int i = 7; i >= 0; i--) {
+ int bit = (val >> i) & 1;
+ printf("%d", bit);
+ if (i == 4) printf(" ");
+ }
+ printf("\r\n");
+}
int StepperConsoleFunction( int argc, char** argv, void* ctx )
-// --------------------------------------------------------------------------------------------------------------------
{
- //possible commands are
- //(stepper) step 100
+
(void)argc;
(void)argv;
(void)ctx;
L6474_Handle_t h = (L6474_Handle_t)ctx;
- // first decode the subcommand and all arguments
if ( argc == 0 )
{
printf("invalid number of arguments\r\n");
@@ -423,6 +471,110 @@ int StepperConsoleFunction( int argc, char** argv, void* ctx )
printf("OK\r\n");
return 0;
}
+ else if (strcmp(argv[0], "status") == 0)
+ {
+ L6474x_State_t currentState;
+ L6474_Status_t stepperStatus;
+ int moving = 0;
+
+ // 1. get state of state machine
+ if (L6474_GetState(h, ¤tState) != errcNONE)
+ {
+ printf("failed to get state\r\nFAIL");
+ return -1;
+ }
+
+ // 2.get driver-state
+ if (L6474_GetStatus(h, &stepperStatus) != errcNONE)
+ {
+ printf("failed to get status\r\nFAIL");
+ return -1;
+ }
+
+ unsigned int errorBits = ((stepperStatus.WRONG_CMD & 0x01) << 8) |
+ ((stepperStatus.UVLO & 0x01) << 7) |
+ ((stepperStatus.TH_WARN & 0x01) << 6) |
+ ((stepperStatus.TH_SD & 0x01) << 5) |
+ ((stepperStatus.ONGOING & 0x01) << 4) |
+ ((stepperStatus.OCD & 0x01) << 3) |
+ ((stepperStatus.NOTPERF_CMD & 0x01) << 2) |
+ ((stepperStatus.HIGHZ & 0x01) << 1) |
+ ((stepperStatus.DIR & 0x01) << 0);
+
+
+
+ // 3. check for moving motor aka async pending operation (should be always 0 with no async mode)
+ L6474_IsMoving(h, &moving);
+
+
+ printf("0x%X\r\n", (unsigned int)currentState); //print state in first line
+ printf("0x%X\r\n", errorBits); //print error flags in second line
+ printf("internal error bits in binary: ");
+ print_binary_8bit(errorBits);
+ printf("%d\r\n", moving); //print async pending op in third line
+ printf("OK");
+
+ return 0;
+ }
+ else if (strcmp(argv[0], "config") == 0)
+ {
+ float value = atof(argv[2]);
+
+ switch(atoi(argv[1])){
+ case 1:
+ config_stepper(h, 1, value);
+ printf("OK\r\n");
+ return 0;
+ case 2:
+ config_stepper(h, 2, value);
+ printf("OK\r\n");
+ return 0;
+ case 3:
+ config_stepper(h, 3, value);
+ printf("OK\r\n");
+ return 0;
+ case 4:
+ config_stepper(h, 4, value);
+ printf("OK\r\n");
+ return 0;
+ case 5:
+ config_stepper(h, 5, value);
+ printf("OK\r\n");
+ return 0;
+ case 6:
+ config_stepper(h, 6, value);
+ printf("OK\r\n");
+ return 0;
+ case 7:
+ config_stepper(h, 7, value);
+ printf("OK\r\n");
+ return 0;
+ case 8:
+ config_stepper(h, 8, value);
+ printf("OK\r\n");
+ return 0;
+ case 9:
+ config_stepper(h, 9, value);
+ printf("OK\r\n");
+ return 0;
+ case 10:
+ config_stepper(h, 10, value);
+ printf("OK\r\n");
+ return 0;
+ case 11:
+ config_stepper(h, 11, value);
+ printf("OK\r\n");
+ return 0;
+ case 12:
+ config_stepper(h, 12, value);
+ printf("OK\r\n");
+ return 0;
+ default:
+ printf("FAIL\r\n");
+ return 1;
+ }
+ }
+
else
{
printf("passed invalid sub command\r\n");