이번 시간에는 STM32 Discovery 보드에서 파란 버튼을 눌렀을때 간단한 UART 동작이 실행되는 것을 해볼 것 입니다.
파란 버튼을 누르면 "Hello EXTI(External Interrupt)" 가 Terminal에 출력 됩니다.
이를 FreeRTOS 환경에서 Interrupt Task를 만들어서 실행해봅니다.
교육영상
https://www.youtube.com/watch?v=0lX6OERAwsM
영상을 보기에 앞서 GPIO 설정과 Interrupt 설정을 해줘야 합니다.
https://www.plainy.co.kr/bbs/board.php?bo_table=stm32_lecture&wr_id=17 다음의 사이트를 참고하세요
STM32CubeMX가 꼭 필요합니다.
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
TaskHandle_t Led_GateKeeperHandle = NULL;
TaskHandle_t myTask2Handle = NULL;
TaskHandle_t myIntTaskHandle = NULL;
void Led_GateKeeper(void *pvParameters)
{
int count = (int*) pvParameters;
//TickType_t xDelay = 500 / portTICK_PERIOD_MS;
TickType_t xDelay = pdMS_TO_TICKS(1000);
TickType_t myLastUnblock;
myLastUnblock = xTaskGetTickCount();
char* text = "Hello STM32\r\n";
for(;;)
{
HAL_GPIO_WritePin(GPIOD, LD4_Pin|LD3_Pin|LD5_Pin|LD6_Pin, GPIO_PIN_RESET);
//vTaskDelay(xDelay); //ms가 아닌 number of ticks, (the number of CPU takes that the kernel runs on
vTaskDelayUntil( &myLastUnblock, xDelay );
HAL_GPIO_WritePin(GPIOD, LD4_Pin|LD3_Pin|LD5_Pin|LD6_Pin, GPIO_PIN_SET);
//vTaskDelay(xDelay);
vTaskDelayUntil( &myLastUnblock, xDelay );
}
}
void myIntTask(void *p){
while(1){
char* text = "Hello EXTI\r\n";
vTaskSuspend(NULL); // suspend itself
HAL_UART_Transmit(&huart2, (uint8_t *)text,strlen(text) , 10);
}
}
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
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_I2C1_Init();
MX_I2S3_Init();
MX_SPI1_Init();
MX_USART2_UART_Init();
/* USER CODE BEGIN 2 */
int pass = 8;
xTaskCreate(Led_GateKeeper, //Task Pointer
(const char* const)"led_gate", //Task Name
configMINIMAL_STACK_SIZE + 800, //Stack Depth
(void *)pass, //Parameters to pass to task
2, //Task Priority
&Led_GateKeeperHandle); //Pass Handle to created task
xTaskCreate(myIntTask, //Task Pointer
(const char* const)"IntTask", //Task Name
configMINIMAL_STACK_SIZE + 800, //Stack Depth
(void *)0, //Parameters to pass to task
2, //Task Priority
&myIntTaskHandle);
}
/* USER CODE BEGIN 4 */
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
BaseType_t checkIfYielRequired;
checkIfYielRequired = xTaskResumeFromISR(myIntTaskHandle);
portYIELD_FROM_ISR(checkIfYielRequired);
}
/* USER CODE END 4 */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
'FreeRTOS > FreeRTOS 기본 학습' 카테고리의 다른 글
08 FreeRTOS Tutorial: Task Utilities part2 (0) | 2019.06.21 |
---|---|
07 FreeRTOS Tutorial: Task Utilities part1 (0) | 2019.06.21 |
STM32F4 Discovery board - Keil 5 IDE with CubeMX: Tutorial 8 UART - Updated Dec 2017 (0) | 2019.06.10 |
FreeRTOS API (0) | 2019.06.10 |
Suspending and Resuming task (0) | 2019.06.07 |