From e2729d6e1ef1450b2cf2ff439fde5cb641547bd0 Mon Sep 17 00:00:00 2001 From: FewiKay Date: Mon, 19 Oct 2026 00:40:30 +0200 Subject: [PATCH] added spindel.h and spindel.c --- .../stepper_h7/CM7/Core/Inc/Spindle/spindel.h | 12 ++++++ .../stepper_h7/CM7/Core/Src/Spindle/spindel.c | 42 +++++++++++++++++++ .../stepper_h7/CM7/Core/Src/main.c | 25 +---------- 3 files changed, 56 insertions(+), 23 deletions(-) create mode 100644 stm32-stepper-root/stepper_h7/CM7/Core/Inc/Spindle/spindel.h create mode 100644 stm32-stepper-root/stepper_h7/CM7/Core/Src/Spindle/spindel.c diff --git a/stm32-stepper-root/stepper_h7/CM7/Core/Inc/Spindle/spindel.h b/stm32-stepper-root/stepper_h7/CM7/Core/Inc/Spindle/spindel.h new file mode 100644 index 0000000..243ec5f --- /dev/null +++ b/stm32-stepper-root/stepper_h7/CM7/Core/Inc/Spindle/spindel.h @@ -0,0 +1,12 @@ +#include "Console.h" +#include "Spindle.h" +#include "main.h" +#include "FreeRTOS.h" +#include + +SpindleHandle_t init_spindle(ConsoleHandle_t c, float maxRPM, float minRPM, float absMinRPM); + + +static void SPINDLE_SetDutyCycle(SpindleHandle_t h, void* context, int backwards, float dutyCycle); + +static void SPINDLE_EnaPWM(SpindleHandle_t h, void* context, int ena); diff --git a/stm32-stepper-root/stepper_h7/CM7/Core/Src/Spindle/spindel.c b/stm32-stepper-root/stepper_h7/CM7/Core/Src/Spindle/spindel.c new file mode 100644 index 0000000..a246947 --- /dev/null +++ b/stm32-stepper-root/stepper_h7/CM7/Core/Src/Spindle/spindel.c @@ -0,0 +1,42 @@ +#include "Spindle/spindel.h" + + +SpindleHandle_t init_spindle(ConsoleHandle_t c, float maxRPM, float minRPM, float absMinRPM){ + // set parameters for the physical system + SpindlePhysicalParams_t s; + s.maxRPM = maxRPM; + s.minRPM = minRPM; + s.absMinRPM = absMinRPM; + s.setDutyCycle = SPINDLE_SetDutyCycle; + s.enaPWM = SPINDLE_EnaPWM; + s.context = NULL; + + return SPINDLE_CreateInstance( 4*configMINIMAL_STACK_SIZE, configMAX_PRIORITIES - 3, c, &s); +} + + +static void SPINDLE_SetDutyCycle(SpindleHandle_t h, void* context, int backwards, float dutyCycle){ + + //TODO: Herausfinden welcher Timer und diesen einstellen backwards beachten! + +} + +static void SPINDLE_EnaPWM(SpindleHandle_t h, void* context, int ena){ + //ena = 1 enable PWM / ena = 0 disable PWM + //TODO: + + if(ena == 1){ + + HAL_GPIO_WritePin(SPINDLE_ENA_L_GPIO_Port, SPINDLE_ENA_L_Pin, GPIO_PIN_SET); + HAL_GPIO_WritePin(SPINDLE_ENA_R_GPIO_Port, SPINDLE_ENA_R_Pin, GPIO_PIN_SET); + //TODO: PWM aktivieren + + }else if(ena == 0){ + + HAL_GPIO_WritePin(SPINDLE_ENA_L_GPIO_Port, SPINDLE_ENA_L_Pin, GPIO_PIN_RESET); + HAL_GPIO_WritePin(SPINDLE_ENA_R_GPIO_Port, SPINDLE_ENA_R_Pin, GPIO_PIN_RESET); + //TODO: PWM deaktivieren + + } + +} diff --git a/stm32-stepper-root/stepper_h7/CM7/Core/Src/main.c b/stm32-stepper-root/stepper_h7/CM7/Core/Src/main.c index c9afa49..5be4402 100644 --- a/stm32-stepper-root/stepper_h7/CM7/Core/Src/main.c +++ b/stm32-stepper-root/stepper_h7/CM7/Core/Src/main.c @@ -29,6 +29,7 @@ #include "assert.h" #include "Spindle.h" #include "Console.h" +#include "Spindle/spindel.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ @@ -100,18 +101,6 @@ QueueHandle_t uartRxQueue; /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ // -------------------------------------------------------------------------------------------------------------------- -static void playgroundTask(void* args) -// -------------------------------------------------------------------------------------------------------------------- -{ - (void)args; - - while(1) { - printf("test \n"); - vTaskDelay(pdMS_TO_TICKS(10)); - } - - vTaskDelete(xTaskGetCurrentTaskHandle()); -} void blink_green_led(){ while(1){ @@ -181,7 +170,6 @@ static int CapabilityFunc( int argc, char** argv, void* ctx ) return 0; } -SpindlePhysicalParams_t s; static int fabi(int argc, char** argv, void* ctx){ @@ -325,19 +313,10 @@ int main(void) CONSOLE_RegisterCommand(c, "fabi", "prints a hallo fabi", fabi, NULL); - //Spindel - s.maxRPM = 9000.0f; - s.minRPM = -9000.0f; - s.absMinRPM = 1600.0f; - s.setDirection = SPINDLE_SetDirection; - s.setDutyCycle = SPINDLE_SetDutyCycle; - s.enaPWM = SPINDLE_EnaPWM; - s.context = NULL; - SPINDLE_CreateInstance( 4*configMINIMAL_STACK_SIZE, configMAX_PRIORITIES - 3, c, &s); - // create a playground task at the very beginning + // tasks xTaskCreate(blink_green_led, "blink_green_led", 1024, NULL, 1, NULL); xTaskCreate(blink_yellow_led, "blink_yellow_led", 1024, NULL, 1, NULL); xTaskCreate(blink_red_led, "blink_red_led", 1024, NULL, 1, NULL);