CubeMX+FreeRTOS+USART1+LED+LetterShell
/**
* @brief 用户shell写
*
* @param data 数据
*/
void userShellWrite(char data)
{
// serialTransmit(&debugSerial, (uint8_t *)&data, 1, 0xFF);
HAL_UART_Transmit(&huart1, (uint8_t *)&data, 1, 0xFFFF);
}
/**
* @brief 用户shell读
*
* @param data 数据
* @return char 状态
*/
signed char userShellRead(char *data)
{
if(HAL_UART_Receive(&huart1, (uint8_t *)data, 1, 0xFFFF) == HAL_OK)
{
return 0;
}
else
{
return -1;
}
}
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART1_UART_Init();
/* USER CODE BEGIN 2 */
userShellInit(); //初始化配置LetterShell
/* USER CODE END 2 */
/* Init scheduler */
osKernelInitialize(); /* Call init function for freertos objects (in freertos.c) */
MX_FREERTOS_Init();
/* Start scheduler */
osKernelStart();
/* We should never get here as control is now taken by the scheduler */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
/* Create the thread(s) */
/* creation of defaultTask */
defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);
/* creation of shell_handler */
shell_handlerHandle = osThreadNew(ShellHandler, (Shell *)&shell, &shell_handler_attributes);
/* creation of LEDBlink */
LEDBlinkHandle = osThreadNew(LEDHandler, NULL, &LEDBlink_attributes);
/* USER CODE END Header_ShellHandler */
void ShellHandler(void *argument)
{
/* USER CODE BEGIN ShellHandler */
Shell *shell = (Shell *)argument;
char data;
/* Infinite loop */
for(;;)
{
//printf("ShellHandler\r\n");
if(shell->read && (shell->read(&data) == 0))
{
shellHandler(shell,data);
}
}
/* USER CODE END ShellHandler */
}
我的测试工程会提示输入密码:Please input password:
输入lux
即可
测试代码工程链接