/** ****************************************************************************** * @file STM32L152_Ex01_3TKeys_EVAL\src\main.c * @author MCD Application Team * @version V1.1.0 * @date 24-February-2014 * @brief Basic example of how to use the STMTouch Driver. ****************************************************************************** * @attention * *

© COPYRIGHT 2014 STMicroelectronics

* * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * You may not use this file except in compliance with the License. * You may obtain a copy of the License at: * * http://www.st.com/software_license_agreement_liberty_v2 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ****************************************************************************** */ /* Здесь необходимо создать большой комментарий о характеристиках железа МК. Или же лучше создать отдельный файл и сделать на него ссылку. Кстати, такой файл создает программа STM32CubeMX. И вообще, нужно создать глобальную папку проекта, где будет лежать все по полочкам ( схема, программа, текстовые файлы, документация и тд ) */ // Это программа для версии NixieClock_v2, которая является модифицированной версией предыдущей // NixieLUT /* Includes ------------------------------------------------------------------*/ #include "time.h" // FreeRTOS includes #include "FreeRTOS.h" #include "task.h" #include "queue.h" #include "semphr.h" #include "ltimers/ltimers.h" #include "head_task/head_task.h" #include "button/button_task.h" #include "button/button_handler.h" #include "nixie_driver/nixie_driver_task.h" #include "light_sensor/light_sensor_task.h" #ifdef LED_DRIVER #include "led_driver/led_driver_task.h" #endif #include "indicate/indicate_modes_task.h" #include "tsl_user.h" #include "time/time.h" #include "stm32f0xx_usart.h" /* Private typedefs ----------------------------------------------------------*/ /* Private defines -----------------------------------------------------------*/ /* Private macros ------------------------------------------------------------*/ // Задаем размеры кучи для каждой задачи отдельно // - как правильно определить необходимый минимум для кучи задачи? #define STACK_SIZE_HEAD ((unsigned short) 230) #define STACK_SIZE_NIXIE_DRIVER ((unsigned short) 80) #define STACK_SIZE_BUTTON ((unsigned short) 200) #define STACK_SIZE_LIGHT_SENSOR ((unsigned short) 70) #ifdef LED_DRIVER #define STACK_SIZE_LED_DRIVER ((unsigned short) 70) #endif #define STACK_SIZE_INDICATE_MODES ((unsigned short) 250) /* Private functions prototype ---------------------------------------------- */ static void USART1Init(void) { RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_1); GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1); GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_Init(GPIOA, &GPIO_InitStructure); USART_InitTypeDef usart_init = {0}; usart_init.USART_BaudRate = 115200; usart_init.USART_WordLength = USART_WordLength_8b; usart_init.USART_StopBits = USART_StopBits_1; usart_init.USART_Parity = USART_Parity_No; usart_init.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; usart_init.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_Init(USART1, &usart_init); USART_Cmd(USART1, ENABLE); } static void USART4Init(void) { RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART4, ENABLE); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); GPIO_PinAFConfig(GPIOA, GPIO_PinSource0, GPIO_AF_4); GPIO_PinAFConfig(GPIOA, GPIO_PinSource1, GPIO_AF_4); GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; GPIO_Init(GPIOA, &GPIO_InitStructure); USART_InitTypeDef usart_init = {0}; usart_init.USART_BaudRate = 9600; usart_init.USART_WordLength = USART_WordLength_8b; usart_init.USART_StopBits = USART_StopBits_1; usart_init.USART_Parity = USART_Parity_No; usart_init.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; usart_init.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_Init(USART4, &usart_init); USART_Cmd(USART4, ENABLE); } static void WIFI_IO_GPIOInit(void) { RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_SetBits(GPIOB, GPIO_Pin_0); // WIFI_EN GPIO_ResetBits(GPIOA, GPIO_Pin_15); // WIFI_IO0 } static void USART3Init(void) { RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); GPIO_PinAFConfig(GPIOB, GPIO_PinSource1, GPIO_AF_4); GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_4); GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_4); GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_4); GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; GPIO_Init(GPIOB, &GPIO_InitStructure); USART_InitTypeDef usart_init = {0}; usart_init.USART_BaudRate = 115200; usart_init.USART_WordLength = USART_WordLength_8b; usart_init.USART_StopBits = USART_StopBits_1; usart_init.USART_Parity = USART_Parity_No; usart_init.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; usart_init.USART_HardwareFlowControl = USART_HardwareFlowControl_RTS_CTS; USART_Init(USART3, &usart_init); USART_Cmd(USART3, ENABLE); } // ---------------------------------------------------------------------------- // Инициализация до создания задач // ---------------------------------------------------------------------------- void InitAll ( void ) { SystemInit(); WIFI_IO_GPIOInit(); USART1Init(); USART3Init(); USART4Init(); InitLTimers(); LightSensorInit(); NixieDriverInit(); HeadTaskInit(); IndicateModesInit(); #ifdef LED_DRIVER LED_DriverInit(); #endif TSL_user_Init(); TimeInit(); ButtonInit(); } static void TestUart(void *arg) { (void) arg; while (1) { if (USART3->ISR & USART_ISR_RXNE) { const uint16_t data = USART_ReceiveData(USART3); USART_SendData(USART1, data); } if (USART1->ISR & USART_ISR_RXNE) { const uint16_t data = USART_ReceiveData(USART1); USART_SendData(USART3, data); } } } BaseType_t TaskSuccess; // Главный цикл ------------------------------------------------------------- // int main () { InitAll (); // Создаем задачи FreeRTOS ----------------------------------------------- // // ВНИМАНИЕ !!! // Необходимо проверять кучу при создании задачи! ( и очереди ) // Если в программе используется подключаемая библиотека, которая использует // ОСРВ, то задача должна там и создаватья. То есть это нужно оформить в // в виде специальной функции TaskSuccess = xTaskCreate(Button_Task, "Button_Task", STACK_SIZE_BUTTON, NULL, tskIDLE_PRIORITY + 2, NULL); configASSERT(TaskSuccess); TaskSuccess = xTaskCreate(LightSensor_Task, "LightSensor_Task", STACK_SIZE_LIGHT_SENSOR, NULL, tskIDLE_PRIORITY + 2, NULL); configASSERT(TaskSuccess); TaskSuccess = xTaskCreate(Head_Task, "Head_Task", STACK_SIZE_HEAD, NULL, tskIDLE_PRIORITY + 2, NULL); configASSERT(TaskSuccess); TaskSuccess = xTaskCreate(IndicateModes_Task, "IndicateModes_Task", STACK_SIZE_INDICATE_MODES, NULL, tskIDLE_PRIORITY + 2, NULL); configASSERT(TaskSuccess); TaskSuccess = xTaskCreate(NixieDriver_Task, "NixieDriver_Task", STACK_SIZE_NIXIE_DRIVER, NULL, tskIDLE_PRIORITY + 2, NULL); configASSERT(TaskSuccess); #ifdef LED_DRIVER TaskSuccess = xTaskCreate(LED_Driver_Task, "LED_Driver_Task", STACK_SIZE_LED_DRIVER, NULL, tskIDLE_PRIORITY + 2, NULL); configASSERT(TaskSuccess); #endif TaskSuccess = xTaskCreate(TestUart, "TestUart", 200, NULL, tskIDLE_PRIORITY + 2, NULL); configASSERT(TaskSuccess); vTaskStartScheduler(); // И запускаем диспетчер задач ( он же планировщик ) } // end of main /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/