AnsweredAssumed Answered

simultanously 2 task not working freertos nucleoF103

Question asked by hobb.epy on Dec 27, 2015
Latest reply on Dec 27, 2015 by Clive One
Hi,
i am using nucleof103rb board, keil compiler. I have created 2 task in freeRTOS but only one task is getting executed.I tried but can't found the proper reason.
---------------          Edited after posted          ----------------------
I tried and i found it is problem with queueing. 
if i use queuesend and queuereceive then task get stuck at first task only.

I have attached the updated code.
#include "stm32f1xx_hal.h"
#include "cmsis_os.h"
 
UART_HandleTypeDef huart1;
xQueueHandle gbl_queue_handler=0;
 
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART1_UART_Init(void);
void StartDefaultTask(void const * argument);
void send_str1(void const * argument);
void send_str2(void const * argument);
void Sd_uart(void const * argument);
 
int main(void)
{
 
  HAL_Init();
 
  SystemClock_Config();
  MX_GPIO_Init();
  MX_USART1_UART_Init();
    HAL_UART_Transmit(&huart1,"Init",4,1000);
 
 
    gbl_queue_handler   = xQueueCreate(6,sizeof(uint8_t));
    xTaskCreate((TaskFunction_t)Sd_uart,"Suart",256,NULL,1,NULL);
    xTaskCreate((TaskFunction_t)send_str1,"string1",256,NULL,1,NULL);
 
vTaskStartScheduler();
   
 
while (1)
  {
 
  }
 
}
 
/** System Clock Configuration
*/
void SystemClock_Config(void)
{
 
  RCC_OscInitTypeDef RCC_OscInitStruct;
  RCC_ClkInitTypeDef RCC_ClkInitStruct;
 
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = 16;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2;
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL16;
  HAL_RCC_OscConfig(&RCC_OscInitStruct);
 
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
 
  HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
 
  HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
 
  /* SysTick_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
}
 
/* USART1 init function */
void MX_USART1_UART_Init(void)
{
 
      GPIO_InitTypeDef GPIO_InitStruct;
     
    __GPIOA_CLK_ENABLE();
    __USART1_CLK_ENABLE();
    //tx
  GPIO_InitStruct.Pin = GPIO_PIN_9;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
     
    //rx
  GPIO_InitStruct.Pin = GPIO_PIN_10;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_INPUT;
  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);  
     
  huart1.Instance = USART1;
  huart1.Init.BaudRate = 19200;
  huart1.Init.WordLength = UART_WORDLENGTH_8B;
  huart1.Init.StopBits = UART_STOPBITS_1;
  huart1.Init.Parity = UART_PARITY_NONE;
  huart1.Init.Mode = UART_MODE_TX_RX;
  huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart1.Init.OverSampling = UART_OVERSAMPLING_16;
  HAL_UART_Init(&huart1);
 
}
 
/** Configure pins as
        * Analog
        * Input
        * Output
        * EVENT_OUT
        * EXTI
     PA2   ------> USART2_TX
     PA3   ------> USART2_RX
*/
void MX_GPIO_Init(void)
{
 
  GPIO_InitTypeDef GPIO_InitStruct;
 
  /* GPIO Ports Clock Enable */
  __GPIOC_CLK_ENABLE();
  __GPIOD_CLK_ENABLE();
  __GPIOA_CLK_ENABLE();
  __GPIOB_CLK_ENABLE();
 
  /*Configure GPIO pin : PC13 */
  GPIO_InitStruct.Pin = GPIO_PIN_13;
  GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
 
  /*Configure GPIO pins : PA2 PA3 */
  GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 
  /*Configure GPIO pin : PA5 */
  GPIO_InitStruct.Pin = GPIO_PIN_5;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 
}
 
 
void StartDefaultTask(void const * argument)
{
 
 
  for(;;)
  {
    osDelay(1);
  }
}
 
void send_str1(void const * argument)
{
    uint8_t *dat="Sagar";
    for(;;)
    {
        xQueueSend(gbl_queue_handler,dat,0);
                GPIOA->ODR = 0x00000020;
        taskYIELD();
    }
}
 
 
void Sd_uart(void const * argument)
{
    uint8_t *data;
    xQueueReceive(gbl_queue_handler,data,100);
    for(;;)
    {
        HAL_UART_Transmit(&huart1,"UART Task",9,1000);
        if(xQueueReceive(gbl_queue_handler,data,100))
        {
            HAL_UART_Transmit(&huart1,data,5,1000);
        }
        else
        {
            HAL_UART_Transmit(&huart1,"No Data",7,1000);
        }
        taskYIELD();
    }
}
 
 
#ifdef USE_FULL_ASSERT
 
void assert_failed(uint8_t* file, uint32_t line)
{
 
}
 
#endif

Outcomes