Skip to main content
Jessy J
Associate III
May 14, 2018
Question

F

  • May 14, 2018
  • 41 replies
  • 4415 views

.

    This topic has been closed for replies.

    41 replies

    Kent Swan
    Associate III
    May 17, 2018
    Posted on May 17, 2018 at 12:05

    When using FreeRtos, you should normally be using osDelay().to apply a delay timing within a thread.  osDelay calls vTaskDelay which puts the thread on the delay queue to be reawakened some number of ms from now which permits the kernel to immediately allow another thread to execute. 

    This works very well in all cases with the sole exception that FreeRTOS incorrectly handles tick timing management in tickeless low power modes where threads are currently blocked by osDelay.  I've been working on an experimental mod to FreeRTOS which extends the normal tickless sleep method to accommodate threads on the delay queue..

    Jessy J
    Jessy JAuthor
    Associate III
    May 17, 2018
    Posted on May 17, 2018 at 12:12

    I did not understand what you are trying to say .. I am using osDelay as delay for threads but it blocks in HAL_delay function  

    in the while loop 

    __weak void HAL_Delay(uint32_t Delay)

    {

    uint32_t tickstart = HAL_GetTick();

    uint32_t wait = Delay;

    /* Add a freq to guarantee minimum wait */

    if (wait < HAL_MAX_DELAY)

    {

    wait += (uint32_t)(uwTickFreq);

    }

    while((HAL_GetTick() - tickstart) < wait)

    {

    }

    }
    Jessy J
    Jessy JAuthor
    Associate III
    May 17, 2018
    Posted on May 17, 2018 at 12:13

    when I put break point in the  HAL_TIM_IRQHandler(&htim6);. It does not go to the timer handler.. I checked the NVIC while debug .. all regiters are set to 0x0 .. I think its problem that tim6 does not launch but i am not sure 

    what do you think please ? 

    Karl Yamashita
    Principal
    May 17, 2018
    Posted on May 17, 2018 at 15:46

    I've had similar issue using a B-L475E-IOT01A eval board. I was stuck in the HAL-Delay(). It turns out that when i used CubeMX to generate code, that the Clock configuration was not set up correctly. So i would check to make sure your Clock configuration is correct and if you're using the external crystal check with an oscilloscope to see if it is clocking.

    If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source
    Jessy J
    Jessy JAuthor
    Associate III
    May 17, 2018
    Posted on May 17, 2018 at 15:56

    I AM using STM32479I EVAL BOARD and Here is the clock configuration generated by CubMX

    void SystemClock_Config(void)

    {

    RCC_OscInitTypeDef RCC_OscInitStruct;

    RCC_ClkInitTypeDef RCC_ClkInitStruct;

    RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;

    HAL_StatusTypeDef ret = HAL_OK;

    /**Configure the main internal regulator output voltage

    */

    __HAL_RCC_PWR_CLK_ENABLE();

    __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);

    /**Initializes the CPU, AHB and APB busses clocks

    */

    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;

    RCC_OscInitStruct.HSEState = RCC_HSE_ON;

    RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

    RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;

    RCC_OscInitStruct.PLL.PLLM = 15;

    RCC_OscInitStruct.PLL.PLLN = 144;

    RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;

    RCC_OscInitStruct.PLL.PLLQ = 5;

    RCC_OscInitStruct.PLL.PLLR = 2;

    ret = HAL_RCC_OscConfig(&RCC_OscInitStruct);

    if(ret != HAL_OK)

    {

    Error_Handler();

    }

    /**Initializes the CPU, AHB and APB busses clocks

    */

    RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK

    |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;

    RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;

    RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

    RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;

    RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;

    if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK)

    {

    _Error_Handler(__FILE__, __LINE__);

    }

    PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_SDIO|RCC_PERIPHCLK_CLK48;

    PeriphClkInitStruct.Clk48ClockSelection = RCC_CLK48CLKSOURCE_PLLQ;

    PeriphClkInitStruct.SdioClockSelection = RCC_SDIOCLKSOURCE_CLK48;

    if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)

    {

    _Error_Handler(__FILE__, __LINE__);

    }

    /**Configure the Systick interrupt time

    */

    HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

    /**Configure the Systick

    */

    HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

    /* SysTick_IRQn interrupt configuration */

    HAL_NVIC_SetPriority(SysTick_IRQn, 15, 0);

    }
    Tesla DeLorean
    Guru
    May 24, 2018
    Posted on May 24, 2018 at 03:39

    /* SysTick_IRQn interrupt configuration */

    HAL_NVIC_SetPriority(SysTick_IRQn, 15, 0); // Least priority, worst possible setting for a value you expect to tick under interrupt context everywhere else

      /* Set Systick interrupt in high priority for HAL_Delay() */

      HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); // Use this to ensure it fires

    The HAL_NVIC_SetPriorityGrouping() should create 16 levels of preemption

    /**

      * @brief This function configures the source of the time base:

      *        The time source is configured to have 1ms time base with a dedicated

      *        Tick interrupt priority.

      * @note This function is called  automatically at the beginning of program after

      *       reset by HAL_Init() or at any time when clock is reconfigured  by HAL_RCC_ClockConfig().

      * @note In the default implementation, SysTick timer is the source of time base.

      *       It is used to generate interrupts at regular time intervals.

      *       Care must be taken if HAL_Delay() is called from a peripheral ISR process,

      *       The SysTick interrupt must have higher priority (numerically lower)

      *       than the peripheral interrupt. Otherwise the caller ISR process will be blocked.

      *       The function is declared as __weak  to be overwritten  in case of other

      *       implementation  in user file.

      * @param TickPriority  Tick interrupt priority.

      * @retval HAL status

      */

    __weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)

    {

      /*Configure the SysTick to have interrupt in 1ms time basis*/

      HAL_SYSTICK_Config(SystemCoreClock/1000);

      /*Configure the SysTick IRQ priority */

      HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority ,0);

      /* Return function status */

      return HAL_OK;

    }
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..