Fehlerbehandlung
This commit is contained in:
1 parent
6a9a634df0
commit
8ca3ce7f6a
4 files changed
+128
-42
No files matched your search
@@ -25,4 +25,4 @@ void StepLibraryDelay(unsigned int ms);
|
||||
|
||||
L6474_Handle_t init_stepper(void* pIO, void* pGPO, void* pPWM);
|
||||
|
||||
void reset_stepper();
|
||||
int reset_stepper();
|
||||
@@ -111,6 +111,10 @@ void Error_Handler(void);
|
||||
extern TIM_HandleTypeDef htim2;
|
||||
extern SPI_HandleTypeDef hspi1;
|
||||
|
||||
void green_led();
|
||||
void red_led();
|
||||
void blink_yellow_led();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -3,6 +3,16 @@
|
||||
#include "main.h"
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* States:
|
||||
* 0: need Reset
|
||||
* 1: need Reference
|
||||
* 2: all good
|
||||
*/
|
||||
|
||||
int state = 0;
|
||||
|
||||
static void* StepLibraryMalloc( unsigned int size ){
|
||||
return malloc(size);
|
||||
}
|
||||
@@ -80,7 +90,7 @@ L6474_Handle_t init_stepper(void* pIO, void* pGPO, void* pPWM){
|
||||
return s;
|
||||
}
|
||||
|
||||
void reset_stepper(L6474_Handle_t s){
|
||||
int reset_stepper(L6474_Handle_t s){
|
||||
|
||||
L6474_BaseParameter_t b;
|
||||
L6474_SetBaseParameter(&b);
|
||||
@@ -95,9 +105,11 @@ void reset_stepper(L6474_Handle_t s){
|
||||
result |= L6474_Initialize(s, &b);
|
||||
result |= L6474_SetPowerOutputs(s, 1);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
void stepper_reference(L6474_Handle_t s, int flag){
|
||||
int stepper_reference(L6474_Handle_t s, int flag){
|
||||
//flag: 0 keiner, 1 -t, 2 -e, 3 -s
|
||||
if(HAL_GPIO_ReadPin(REFERENCE_MARK_GPIO_Port, REFERENCE_MARK_Pin) == GPIO_PIN_RESET){
|
||||
|
||||
@@ -117,7 +129,9 @@ void stepper_reference(L6474_Handle_t s, int flag){
|
||||
}
|
||||
if(flag == 3){
|
||||
L6474_SetAbsolutePosition(s, 0);
|
||||
return;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
int button_pressed = 0;
|
||||
|
||||
@@ -130,27 +144,49 @@ void stepper_reference(L6474_Handle_t s, int flag){
|
||||
|
||||
}
|
||||
L6474_SetAbsolutePosition(s, 0);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
void stepper_softstart(L6474_Handle_t s, unsigned int duration){
|
||||
|
||||
}
|
||||
|
||||
void stepper_pos(L6474_Handle_t s){
|
||||
int stepper_pos(L6474_Handle_t s){
|
||||
int position = 0;
|
||||
L6474_GetAbsolutePosition(s, &position);
|
||||
printf("Stepper position: %d", position);
|
||||
|
||||
|
||||
L6474_Status_t status;
|
||||
|
||||
if(L6474_GetStatus(s, &status) != errcNONE){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void stepper_move(L6474_Handle_t s, int pos){
|
||||
int stepper_move(L6474_Handle_t s, int pos){
|
||||
xTaskCreate(blink_yellow_led, "blink_yellow_led", 1024, NULL, 1, NULL);
|
||||
|
||||
int position = 0;
|
||||
L6474_GetAbsolutePosition(s, &position);
|
||||
if(L6474_GetAbsolutePosition(s, &position) != errcNONE){
|
||||
return 1;
|
||||
}
|
||||
|
||||
int pos_diff = pos-position;
|
||||
int pos_diff = pos - position;
|
||||
|
||||
if(L6474_StepIncremental(s, pos_diff) != errcNONE){
|
||||
return 1;
|
||||
}
|
||||
|
||||
L6474_StepIncremental(s, pos_diff);
|
||||
L6474_Status_t status;
|
||||
if(L6474_GetStatus(s, &status) != errcNONE){
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -173,7 +209,10 @@ int StepperConsoleFunction( int argc, char** argv, void* ctx )
|
||||
}
|
||||
else if ( strcmp(argv[0], "step") == 0 )
|
||||
{
|
||||
|
||||
if(state != 2){
|
||||
printf("Please do reference\r\nFAIL");
|
||||
return -1;
|
||||
}
|
||||
if ( argc < 2 )
|
||||
{
|
||||
printf("missing step value for step command\r\nFAIL");
|
||||
@@ -187,25 +226,72 @@ int StepperConsoleFunction( int argc, char** argv, void* ctx )
|
||||
}
|
||||
else if ( strcmp(argv[0], "reset") == 0 )
|
||||
{
|
||||
reset_stepper(h);
|
||||
}
|
||||
else if ( strcmp(argv[0], "reference") == 0 )
|
||||
{
|
||||
stepper_reference(h, 0);
|
||||
}
|
||||
else if ( strcmp(argv[0], "pos") == 0 )
|
||||
{
|
||||
stepper_pos(h);
|
||||
}
|
||||
else if ( strcmp(argv[0], "move") == 0 )
|
||||
{
|
||||
if ( argc < 2 )
|
||||
{
|
||||
printf("missing step value for move command\r\nFAIL");
|
||||
if(reset_stepper(h)){
|
||||
state = 0;
|
||||
printf("\r\nFAIL");
|
||||
return -1;
|
||||
}
|
||||
|
||||
stepper_move(h, atoi(argv[1]));
|
||||
state = 1;
|
||||
printf("\r\nOK");
|
||||
return 0;
|
||||
}
|
||||
else if ( strcmp(argv[0], "reference") == 0 )
|
||||
{
|
||||
if(state < 1){
|
||||
printf("Please do reset\r\nFAIL");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(stepper_reference(h, 0)){
|
||||
state = 0;
|
||||
printf("\r\nFAIL");
|
||||
return -1;
|
||||
}
|
||||
|
||||
state = 2;
|
||||
printf("\r\nOK");
|
||||
return 0;
|
||||
}
|
||||
else if ( strcmp(argv[0], "position") == 0 )
|
||||
{
|
||||
if(state != 2){
|
||||
printf("Please do reference\r\nFAIL");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(stepper_pos(h)){
|
||||
state = 0;
|
||||
printf("\r\nFAIL");
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("\r\nOK");
|
||||
return 0;
|
||||
}
|
||||
else if ( strcmp(argv[0], "move") == 0 )
|
||||
{
|
||||
if(state != 2){
|
||||
printf("Please do reference\r\nFAIL");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ( argc < 2 )
|
||||
{
|
||||
printf("missing position value for move command\r\nFAIL");
|
||||
return -1;
|
||||
}
|
||||
if(atoi(argv[1]) < 0){
|
||||
printf("position value for move command cant be below 0\r\nFAIL");
|
||||
return -1;
|
||||
}
|
||||
if(stepper_move(h, atoi(argv[1]))==1){
|
||||
state = 0;
|
||||
printf("\r\nFAIL");
|
||||
return -1;
|
||||
}
|
||||
printf("\r\nOK");
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -213,8 +299,5 @@ int StepperConsoleFunction( int argc, char** argv, void* ctx )
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// now back to console
|
||||
return 0;
|
||||
}
|
||||
@@ -34,6 +34,8 @@
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PTD */
|
||||
|
||||
@@ -60,6 +62,8 @@ SPI_HandleTypeDef hspi1;
|
||||
TIM_HandleTypeDef htim2;
|
||||
|
||||
UART_HandleTypeDef huart3;
|
||||
|
||||
|
||||
/* USER CODE BEGIN PV */
|
||||
|
||||
/* USER CODE END PV */
|
||||
@@ -103,30 +107,28 @@ QueueHandle_t uartRxQueue;
|
||||
/* USER CODE BEGIN 0 */
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
void blink_green_led(){
|
||||
void green_led(){
|
||||
while(1){
|
||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET);
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET);
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_1, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_RESET);
|
||||
}
|
||||
}
|
||||
|
||||
void blink_yellow_led(){
|
||||
while(1){
|
||||
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_1, GPIO_PIN_SET);
|
||||
vTaskDelay(pdMS_TO_TICKS(100));
|
||||
vTaskDelay(pdMS_TO_TICKS(500));
|
||||
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_1, GPIO_PIN_RESET);
|
||||
vTaskDelay(pdMS_TO_TICKS(2000));
|
||||
vTaskDelay(pdMS_TO_TICKS(500));
|
||||
}
|
||||
}
|
||||
|
||||
void blink_red_led(){
|
||||
void red_led(){
|
||||
while(1){
|
||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET);
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_RESET);
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_1, GPIO_PIN_RESET);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -328,9 +330,6 @@ int main(void)
|
||||
|
||||
|
||||
// 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);
|
||||
|
||||
// mask a compiler warning by referencing the function but not using it (void cast)
|
||||
(void)CapabilityFunc;
|
||||
|
||||
Reference in new issue
Block a user