1、
程序代码:
myCountingSem01Handle = osSemaphoreNew(2, 2, &myCountingSem01_attributes);void StartDefaultTask(void *argument)
{/* USER CODE BEGIN StartDefaultTask *//* Infinite loop */for(;;){osSemaphoreAcquire(myCountingSem01Handle,osWaitForever);//计数型信号量,等待方式printf("生产了一辆三蹦子\r\n");osDelay(500);} /* USER CODE END StartDefaultTask */
}void StartTask02(void *argument)
{/* USER CODE BEGIN StartTask02 *//* Infinite loop */for(;;){osSemaphoreRelease(myCountingSem01Handle);//计数型信号量IDprintf("消费了一辆三蹦子\r\n");osDelay(500);}/* USER CODE END StartTask02 */
}//重新实现fputc函数功能
int fputc(int ch,FILE* f)
{HAL_UART_Transmit(&huart1,(uint8_t*)&ch,1,1000);return ch;
}
思维导图: