Professional Documents
Culture Documents
Main C
Main C
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "semphr.h"
#include <stdio.h>
#include <string.h>
#include <stdint.h>
typedef enum
{
Bit_RESET = 0,
Bit_SET
}BitAction;
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/*
* Realiza a alocação dinâmica da fila na memória RAM do STM32;
* Neste caso foi criado um fila com 5 elementos do tipo unsigned int 32
bits.
*/
if( (xQueue = xQueueCreate( 5, sizeof(char *)) ) == NULL )
{
//sprintf(UartSend,"nao foi possivel alocar xQueue");
//HAL_UART_Transmit(&huart2,(uint8_t*) UartSend, strlen(UartSend), 1);
/*
* Task_print e task_adc contém a função printf (ESP_LOGI). Portanto, foi
aumentado o stack
* para 2k;
*/
vTaskStartScheduler();
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/**
* @brief USART2 Initialization Function
* @param None
* @retval None
*/
static void MX_USART2_UART_Init(void)
{
/**
* @brief GPIO Initialization Function
* @param None
* @retval None
*/
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
taskENTER_CRITICAL();
USARTlib_Puts(UartSend_f);
taskEXIT_CRITICAL();
//xSemaphoreGive( xMutex );
}
void USARTlib_Putc(UART_HandleTypeDef* huart, char c)
{
//Envia caracter
HAL_UART_Transmit(huart, &c, 1, 10);
}
uint32_t status;
char Buffer_test[30];
char UartSend[100];
/*
* Esta task é responsável em receber o valor de count
* por meio da leitura da fila e imprimir na saída do console serial.
*/
void vTask_print( void * pvParameter )
{
uint32_t status;
char * recebe_string;
for(;;)
{
/* status_return = xQueueReceive( fila_name, variável_address, timeout)
*/
status = xQueueReceive(xQueue, &recebe_string, portMAX_DELAY);
if(status == pdPASS)
{
//Para entender a necessidade de alocação dinamica de memoria
//deixo o link abaixo, onde explica porque precisamos fazer um
malloc
//para alocar um buffer ao nosso ponteiro para uso na função
sprintf
//lembrando que iremos usar o pvPortMalloc que é safe thread para
o FreeRTOS
//https://stackoverflow.com/questions/19772667/c-sprintf-array-
char-pointers
vPrintString(UartSend);
/*
* Depois testar essa implementação
*/
/*
vPrintString("Foi recebido a string: ");
vPrintString(recebe_string);
vPrintString("\r\n\r\n");
*/
/*
* Task responsável em inverter o estado lógico do led building
* do kit;
*/
void vTask_blink( void *pvParameter )
{
for( ;; )
{
/* Liga Led */
HAL_GPIO_TogglePin(DOUT_LED1_GPIO_Port, DOUT_LED1_Pin);
vTaskDelay( 1000 / portTICK_PERIOD_MS );
/**
* @brief Period elapsed callback in non blocking mode
* @note This function is called when TIM4 interrupt took place, inside
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
* a global variable "uwTick" used as application time base.
* @param htim : TIM handle
* @retval None
*/
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
/* USER CODE BEGIN Callback 0 */
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */