49 static uint16_t Uart_cmd_flag = 0;
50 const CMD_T CmdTable[] = {
68 uint8_t aRxBuffer[8] = {
'0'};
69 uint8_t row0TxBuffer[] =
"\033[2J";
70 uint8_t row1TxBuffer[] =
"*******************************************************************************\n\r";
71 uint8_t row2TxBuffer[] =
"* X-NUCLEO-IHM11M1 - 6-Step Motor Control Expansion board *\n\r";
72 uint8_t row3TxBuffer[] =
"*******************************************************************************\n\r";
73 uint8_t row4TxBuffer[] =
" List of commands:\n\r\n\r";
74 uint8_t row5TxBuffer[] =
" <STARTM> -- Start Motor\n\r";
75 uint8_t row6TxBuffer[] =
" <STOPMT> -- Stop Motor\n\r";
76 uint8_t row7aTxBuffer[] =
" <DIRECT> -- Set the Motor direction CW or CCW \n\r";
77 uint8_t row7TxBuffer[] =
" <SETSPD> -- Set the Motor Speed\n\r";
78 uint8_t row7bTxBuffer[] =
" <GETSPD> -- Get the Motor Speed\n\r";
79 uint8_t row7cTxBuffer[] =
" <STATUS> -- Get the Status of system \n\r";
80 uint8_t row71TxBuffer[] =
" <POTENZ> -- Enable/Disable the potentiometer\n\r";
81 uint8_t row71bTxBuffer[] =
" <HELP> -- Show the help menu \n\r";
82 uint8_t rowVTxBuffer[] =
" >>> Insert the value: ";
83 uint8_t rowVTBxBuffer[] =
" >>> ENABLE <1> DISABLE <0>: ";
84 uint8_t rowV1TBxBuffer[] =
" >>> CW <0> CCW <1>: ";
85 uint8_t rowMxBuffer[] =
" >>> START MOTOR COMMAND RECEIVED ! <<< \n\r >";
86 uint8_t rowSxBuffer[] =
" >>> STOP MOTOR COMMAND RECEIVED ! <<< \n\r >";
87 uint8_t rowETxBuffer[] =
" >>> ERROR - PLEASE TYPE AGAIN ! <<< \n\r >";
88 uint8_t row8TxBuffer[] =
" ************* MAIN MOTOR PARAMETERS *************** \n\r";
89 uint8_t row9TxBuffer[] =
" <INIREF> -- Start-up current reference (0-4095) \n\r";
90 uint8_t row10TxBuffer[] =
" <ACCELE> -- Motor acceleration value during startup \n\r";
91 uint8_t row11TxBuffer[] =
" <POLESP> -- Set the Motor pole pairs \n\r";
92 uint8_t row14TxBuffer[] =
" ****** PI REGULATOR PARAMETERS - SPEED LOOP ******\n\r";
93 uint8_t row15TxBuffer[] =
" <KP-PRM> -- Set the PI proportional term \n\r";
94 uint8_t row16TxBuffer[] =
" <KI-PRM> -- Set the PI integral term \n\r\n\r >";
95 uint8_t rowLxBuffer[] =
" --- OK ---\n\r >";
97 extern uint8_t UART_FLAG_POTENZ;
118 if(HAL_UART_Receive_IT(&
huart2, (uint8_t *)aRxBuffer, 10) != HAL_OK)
119 {
huart2.State = HAL_UART_STATE_READY; }
132 HAL_UART_Transmit(&
huart2, (uint8_t *)row0TxBuffer, (
COUNTOF(row0TxBuffer) - 1),5000);
133 while (HAL_UART_GetState(&
huart2) != HAL_UART_STATE_READY)
136 HAL_UART_Transmit(&
huart2, (uint8_t *)row1TxBuffer, (
COUNTOF(row1TxBuffer) - 1),5000);
137 while (HAL_UART_GetState(&
huart2) != HAL_UART_STATE_READY)
140 HAL_UART_Transmit(&
huart2, (uint8_t *)row2TxBuffer, (
COUNTOF(row2TxBuffer) - 1),5000);
141 while (HAL_UART_GetState(&
huart2) != HAL_UART_STATE_READY)
144 HAL_UART_Transmit(&
huart2, (uint8_t *)row3TxBuffer, (
COUNTOF(row3TxBuffer) - 1),5000);
145 while (HAL_UART_GetState(&
huart2) != HAL_UART_STATE_READY)
148 HAL_UART_Transmit(&
huart2, (uint8_t *)row4TxBuffer, (
COUNTOF(row4TxBuffer) - 1),5000);
149 while (HAL_UART_GetState(&
huart2) != HAL_UART_STATE_READY)
152 HAL_UART_Transmit(&
huart2, (uint8_t *)row5TxBuffer, (
COUNTOF(row5TxBuffer) - 1),5000);
153 while (HAL_UART_GetState(&
huart2) != HAL_UART_STATE_READY)
156 HAL_UART_Transmit(&
huart2, (uint8_t *)row6TxBuffer, (
COUNTOF(row6TxBuffer) - 1),5000);
157 while (HAL_UART_GetState(&
huart2) != HAL_UART_STATE_READY)
160 HAL_UART_Transmit(&
huart2, (uint8_t *)row7aTxBuffer, (
COUNTOF(row7aTxBuffer) - 1),5000);
161 while (HAL_UART_GetState(&
huart2) != HAL_UART_STATE_READY)
164 HAL_UART_Transmit(&
huart2, (uint8_t *)row7TxBuffer, (
COUNTOF(row7TxBuffer) - 1),5000);
165 while (HAL_UART_GetState(&
huart2) != HAL_UART_STATE_READY)
168 HAL_UART_Transmit(&
huart2, (uint8_t *)row7bTxBuffer, (
COUNTOF(row7bTxBuffer) - 1),5000);
169 while (HAL_UART_GetState(&
huart2) != HAL_UART_STATE_READY)
172 HAL_UART_Transmit(&
huart2, (uint8_t *)row7cTxBuffer, (
COUNTOF(row7cTxBuffer) - 1),5000);
173 while (HAL_UART_GetState(&
huart2) != HAL_UART_STATE_READY)
176 HAL_UART_Transmit(&
huart2, (uint8_t *)row71TxBuffer, (
COUNTOF(row71TxBuffer) - 1),5000);
177 while (HAL_UART_GetState(&
huart2) != HAL_UART_STATE_READY)
180 HAL_UART_Transmit(&
huart2, (uint8_t *)row71bTxBuffer, (
COUNTOF(row71bTxBuffer) - 1),5000);
181 while (HAL_UART_GetState(&
huart2) != HAL_UART_STATE_READY)
184 HAL_UART_Transmit(&
huart2, (uint8_t *)row8TxBuffer, (
COUNTOF(row8TxBuffer) - 1),5000);
185 while (HAL_UART_GetState(&
huart2) != HAL_UART_STATE_READY)
188 HAL_UART_Transmit(&
huart2, (uint8_t *)row9TxBuffer, (
COUNTOF(row9TxBuffer) - 1),5000);
189 while (HAL_UART_GetState(&
huart2) != HAL_UART_STATE_READY)
192 HAL_UART_Transmit(&
huart2, (uint8_t *)row10TxBuffer, (
COUNTOF(row10TxBuffer) - 1),5000);
193 while (HAL_UART_GetState(&
huart2) != HAL_UART_STATE_READY)
196 HAL_UART_Transmit(&
huart2, (uint8_t *)row11TxBuffer, (
COUNTOF(row11TxBuffer) - 1),5000);
197 while (HAL_UART_GetState(&
huart2) != HAL_UART_STATE_READY)
200 HAL_UART_Transmit(&
huart2, (uint8_t *)row14TxBuffer, (
COUNTOF(row14TxBuffer) - 1),5000);
201 while (HAL_UART_GetState(&
huart2) != HAL_UART_STATE_READY)
204 HAL_UART_Transmit(&
huart2, (uint8_t *)row15TxBuffer, (
COUNTOF(row15TxBuffer) - 1),5000);
205 while (HAL_UART_GetState(&
huart2) != HAL_UART_STATE_READY)
208 HAL_UART_Transmit(&
huart2, (uint8_t *)row16TxBuffer, (
COUNTOF(row16TxBuffer) - 1),5000);
209 while (HAL_UART_GetState(&
huart2) != HAL_UART_STATE_READY)
224 uint32_t UART_num_decode()
228 for(uint8_t i=0;i<BUFF_RCV;i++)
230 Value_Buffer[i] = aRxBuffer[i];
232 return(atoi(Value_Buffer));
246 if(Uart_cmd_flag == 0)
261 HAL_UART_Transmit(&
huart2, (uint8_t *)rowLxBuffer, (
COUNTOF(rowLxBuffer) - 1),5000);
263 huart2.State = HAL_UART_STATE_READY;
270 huart2.State = HAL_UART_STATE_READY;
271 HAL_UART_Transmit(&
huart2, (uint8_t *)rowLxBuffer, (
COUNTOF(rowLxBuffer) - 1),5000);
278 huart2.State = HAL_UART_STATE_READY;
279 HAL_UART_Transmit(&
huart2, (uint8_t *)rowLxBuffer, (
COUNTOF(rowLxBuffer) - 1),5000);
286 huart2.State = HAL_UART_STATE_READY;
287 HAL_UART_Transmit(&
huart2, (uint8_t *)rowLxBuffer, (
COUNTOF(rowLxBuffer) - 1),5000);
295 huart2.State = HAL_UART_STATE_READY;
296 HAL_UART_Transmit(&
huart2, (uint8_t *)rowLxBuffer, (
COUNTOF(rowLxBuffer) - 1),5000);
303 huart2.State = HAL_UART_STATE_READY;
304 HAL_UART_Transmit(&
huart2, (uint8_t *)rowLxBuffer, (
COUNTOF(rowLxBuffer) - 1),5000);
311 huart2.State = HAL_UART_STATE_READY;
312 HAL_UART_Transmit(&
huart2, (uint8_t *)rowLxBuffer, (
COUNTOF(rowLxBuffer) - 1),5000);
318 huart2.State = HAL_UART_STATE_READY;
319 HAL_UART_Transmit(&
huart2, (uint8_t *)rowLxBuffer, (
COUNTOF(rowLxBuffer) - 1),5000);
338 HAL_UART_Transmit(&
huart2, (uint8_t *)rowVTxBuffer, (
COUNTOF(rowVTxBuffer) - 1),5000);
342 huart2.State = HAL_UART_STATE_READY;
354 huart2.State = HAL_UART_STATE_READY;
355 HAL_UART_Transmit(&
huart2, (uint8_t *)rowVTBxBuffer, (
COUNTOF(rowVTBxBuffer) - 1),5000);
368 void CMD_MSG_BOOL_DIRECT()
370 huart2.State = HAL_UART_STATE_READY;
371 HAL_UART_Transmit(&
huart2, (uint8_t *)rowV1TBxBuffer, (
COUNTOF(rowV1TBxBuffer) - 1),5000);
387 huart2.State = HAL_UART_STATE_READY;
388 HAL_UART_Transmit(&
huart2, (uint8_t *)rowMxBuffer, (
COUNTOF(rowMxBuffer) - 1),5000);
404 huart2.State = HAL_UART_STATE_READY;
405 HAL_UART_Transmit(&
huart2, (uint8_t *)rowSxBuffer, (
COUNTOF(rowSxBuffer) - 1),5000);
435 static char strLineMessage[40];
437 huart2.State = HAL_UART_STATE_READY;
438 sprintf(strLineMessage,
"-- The Motor Speed is: %d RPM -- \r\n >", SIXSTEP_parameters.
speed_fdbk_filtered);
439 HAL_UART_Transmit(&
huart2, (uint8_t*) strLineMessage,
sizeof(strLineMessage),5000);
467 huart2.State = HAL_UART_STATE_READY;
526 CMD_MSG_BOOL_DIRECT();
567 static char strLineMessage1[30];
568 static char strLineMessage2[30];
569 static char strLineMessage3[30];
570 static char strLineMessage4[30];
571 static char strLineMessage5[30];
572 static char strLineMessage6[30];
573 static char strLineMessage7[30];
574 static char strLineMessage8[30];
576 huart2.State = HAL_UART_STATE_READY;
577 switch (SIXSTEP_parameters.
STATUS)
580 sprintf(strLineMessage1,
" -- The status is: STARTUP --\r\n >");
581 HAL_UART_Transmit(&
huart2, (uint8_t*) strLineMessage1,
sizeof(strLineMessage1),5000);
584 sprintf(strLineMessage2,
" -- The status is: VALIDATION --\r\n >");
585 HAL_UART_Transmit(&
huart2, (uint8_t*) strLineMessage2,
sizeof(strLineMessage2),5000);
588 sprintf(strLineMessage3,
" -- The status is: START --\r\n >");
589 HAL_UART_Transmit(&
huart2, (uint8_t*) strLineMessage3,
sizeof(strLineMessage3),5000);
592 sprintf(strLineMessage4,
" -- The status is: STOP --\r\n >");
593 HAL_UART_Transmit(&
huart2, (uint8_t*) strLineMessage4,
sizeof(strLineMessage4),5000);
596 sprintf(strLineMessage5,
" -- The status is: RUN --\r\n >");
597 HAL_UART_Transmit(&
huart2, (uint8_t*) strLineMessage5,
sizeof(strLineMessage5),5000);
600 sprintf(strLineMessage6,
" -- The status is: ALIGNMENT --\r\n >");
601 HAL_UART_Transmit(&
huart2, (uint8_t*) strLineMessage6,
sizeof(strLineMessage6),5000);
604 sprintf(strLineMessage7,
" -- The status is: SPEEDFBKERROR --\r\n >");
605 HAL_UART_Transmit(&
huart2, (uint8_t*) strLineMessage7,
sizeof(strLineMessage7),5000);
608 sprintf(strLineMessage8,
" -- The status is: IDLE --\r\n >");
609 HAL_UART_Transmit(&
huart2, (uint8_t*) strLineMessage8,
sizeof(strLineMessage8),5000);
624 static uint8_t CmdListIndex;
628 strcpy(sCmd, pCommandString);
629 strtok (sCmd,
TOKEN);
630 strtok (sCmd, TOKEN2);
633 for(CmdListIndex=0;CmdTable[CmdListIndex].
pCmdFunc!=NULL; CmdListIndex++) {
634 if (strcmp(CmdTable[CmdListIndex].name, sCmd) == 0 )
642 if(CmdTable[CmdListIndex].pCmdFunc!=NULL) {
647 huart2.State = HAL_UART_STATE_READY;
648 HAL_UART_Transmit(&
huart2, (uint8_t *)rowETxBuffer, (
COUNTOF(rowETxBuffer) - 1),5000);
void UART_Set_Value(void)
uint8_t Enable_start_button
uint32_t Uart_value_to_set
SIXSTEP_PI_PARAM_InitTypeDef_t PI_parameters
#define COUNTOF(__BUFFER__)
void CMD_STARTM(void)
UART function.
uint8_t UART_FLAG_RECEIVE
UART_HandleTypeDef huart2
SIXSTEP_Base_SystStatus_t STATUS
uint32_t Get_UART_Data()
Get the UART value from DR register.
void CMD_Parser(char *pCommandString)
SIXSTEP_Base_InitTypeDef SIXSTEP_parameters
This file provides a set of functions needed to manage the UART com.
void UART_Communication_Task(void)
void MC_Set_PI_param(SIXSTEP_PI_PARAM_InitTypeDef_t *)
int16_t speed_fdbk_filtered
Six PI regulator parameters.