//****************************************************************************************** // STM32 Value line discovery (STM32F100RB) ARM Cortex M3 // Project : // Program Name : // Programer : // Create date : Version 1.0 H22.10.25 // Replace date : // History : // Laungage : FreeRTOS ( Atollic TrueSTUDIO ) //****************************************************************************************** // Description // //****************************************************************************************** /* Scheduler include files. */ #include "stm32f10x.h" #include "FreeRTOS.h" #include "semphr.h" #include "task.h" void User_Confugration( void ); void Put_PORT(unsigned int ); static void User_TASK_1( void *pvParameters ); static void User_TASK_2( void *pvParameters ); void Move_LED( unsigned int *); // xSemaphoreHandle Ind_Seph; portBASE_TYPE Ind_tmp; volatile unsigned int TASK1_LED = 0x0001; volatile unsigned int TASK2_LED = 0x0010; void main( void ) { // ***************** // 1.Initalized // ***************** User_Confugration( ); vSemaphoreCreateBinary(Ind_Seph); // Create Semaphore // ***************** // 2.Create Task // ***************** xTaskCreate( User_TASK_1, ( const char * const ) "User_Task_1", 100, NULL, 1, NULL ); xTaskCreate( User_TASK_2, ( const char * const ) "User_Task_2", 100, NULL, 1, NULL ); // ***************** // 3.Start Scheduler // ***************** vTaskStartScheduler(); } //****************************************************************************************** // Function Name : User_TASK_1 // Title : // Input : // Output : //****************************************************************************************** static void User_TASK_1( void *pvParameters ) { while(1){ Move_LED(&TASK1_LED); Put_PORT(TASK1_LED | TASK2_LED); if((TASK1_LED & 0x0001)==1) xSemaphoreGiveFromISR(Ind_Seph, &Ind_tmp); vTaskDelay(125 / portTICK_RATE_MS); } } //****************************************************************************************** // Function Name : User_TASK_2 // Title : // Input : // Output : //****************************************************************************************** static void User_TASK_2( void *pvParameters ) { while(1){ Move_LED(&TASK2_LED); Put_PORT(TASK1_LED | TASK2_LED); xSemaphoreTake(Ind_Seph, portMAX_DELAY); } } //****************************************************************************************** // Function Name : Move_LED // Title : // Input : // Output : //****************************************************************************************** void Move_LED( unsigned int *led_lst ) { if((*led_lst & 0b10000000) != 0 ){ *led_lst = ( *led_lst << 1 ) | 0b00000001; }else{ *led_lst = ( *led_lst << 1 ) & 0b11111110; } } //****************************************************************************************** // // Confugration // // //****************************************************************************************** void User_Confugration( void ) { // (1)Define APB2(peripheral clock enable register) RCC->APB2ENR = 0x000C; // APB2ENR[2-3]:IOPAEN,IOPBEN I/O port A,B clock enable // Set and cleared by software. 0: I/O portn clock disabled, 1:I/O portn clock enabled // (2)Define I/O Port A GPIOA->CRL = 0x11111111; // Port configuration register low (GPIOn[0-7]) GPIOA->CRH = 0x11111111; // Port configuration register high(GPIOn[8-15]) // CNF=00: General purpose output push-pull, MODE=01:Output mode, max speed 10 MHz // GPIOA->IDR // Port input data register (Read Only) IDR[31-16]:Reserved,@IDR[15-0]:Port output data GPIOA->ODR = 0x00000000; // Port output data register ODR[31-16]:Reserved,@ODR[15-0]:Port output data // GPIOA->BSRR // Port bit set/reset registe // GPIOA->BRR // Port bit reset register // GPIOA->LCKR // Port configuration lock register // (3)Define I/O Port B GPIOB->CRL = 0x11111111; // Port configuration register low (GPIOn[0-7]) GPIOB->CRH = 0x11111111; // Port configuration register high(GPIOn[8-15]) // CNF=00: General purpose output push-pull, MODE=01:Output mode, max speed 10 MHz // GPIOB->IDR // Port input data register (Read Only) IDR[31-16]:Reserved,@IDR[15-0]:Port output data GPIOB->ODR = 0x00000000; // Port output data register ODR[31-16]:Reserved,@ODR[15-0]:Port output data // GPIOB->BSRR // Port bit set/reset registe // GPIOB->BRR // Port bit reset register // GPIOB->LCKR // Port configuration lock register } void Put_PORT(unsigned int put_data ) { GPIOA->ODR = put_data | (put_data << 8); GPIOB->ODR = put_data | (put_data << 8); } //****************************************************************************************** // // Dummy Function // // //****************************************************************************************** void vApplicationMallocFailedHook(void){} void vApplicationIdleHook(void){} void taskFIRST_CHECK_FOR_STACK_OVERFLOW(void){} void taskSECOND_CHECK_FOR_STACK_OVERFLOW(void){} void vApplicationStackOverflowHook(void){}