Skip to main content
Explorer
July 26, 2024
Question

Problem with thread startup after power cycle on embedded application

  • July 26, 2024
  • 3 replies
  • 3487 views

Hello,

My application is loaded via flash memory. Four threads are created and they seem to be generated correctly because when the board is connected to the computer, all the threads run well. But if I disconnect the power and then turn it back on, the threads no longer run.

Systick is used for ThreadX and TIM6 is used for HAL-Tick.

But the scheduler does not start the threads. I do not understand why. I am new to threads.

Has anyone encountered a similar problem and have solutions to suggest? Please

I am attaching the file app_thread.c

    This topic has been closed for replies.

    3 replies

    Super User
    July 26, 2024

    Hi,

    i think, this has nothing to do with threads.

    Just make a simple test program, just flashing a LED (if you have one there on a pin). no RTOS/thread .

    Use same clock tree setting and flashing mode.

    Then check: is this program running after power cycle ?

    LadyMtAuthor
    Explorer
    July 26, 2024

    Thanks for your reply.

    Before calling MX_ThreadX_Init();

    void MX_ThreadX_Init(void)
    {
     /* USER CODE BEGIN Before_Kernel_Start */
    
     /* USER CODE END Before_Kernel_Start */
    
     tx_kernel_enter();
    
     /* USER CODE BEGIN Kernel_Start_Error */
    
     /* USER CODE END Kernel_Start_Error */
    }

    in the main.c file, I make the leds blink and on startup it does. But after MX_ThreadX_Init(), nothing happens

    Graduate II
    July 29, 2024

    That is to be expected as tx_kernel_enter() never returns if it starts correctly. Note the comments for user code after tx_kernel_enter(). It is only reached if there is an error starting the kernel.

    One thing to try in your threaded application is to blink a LED in the Kernel_Start_Error section to indicate an error starting the kernel.

    How is the board powered when it is disconnected from the computer?

    LadyMtAuthor
    Explorer
    August 1, 2024

    @AScha.3

    I am waiting for data from UART9 using HAL_UART_Receive_DMA(), and this data is processed within the threads. Now, I am starting to think that the interrupt system is not active after powering on.

    Would you like me to provide a potential troubleshooting approach or steps to diagnose and fix this issue?

     

     /* USER CODE BEGIN 2 */
    	HAL_UART_Receive_DMA(&huart9, rx_data, 1);
    	HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);
    	HAL_TIM_Base_Start(&htim2);
     /* USER CODE END 2 */
    
     MX_ThreadX_Init();
    Super User
    August 1, 2024

    >I did the two tests, and in both cases, it works really well when powered on.

     

    GOOD !

     

    +

    >that the interrupt system is not active after powering on

    If you dont stop it - it IS active .

    --- as you set it in Cube -> nvic settings (priority, active or not ---check this. )

    AScha3_0-1722512294443.png

    Just make the priority ranking with some sense - and the Azure sys timer is handeled by itself, you cannot change its settings. (TIM6 or whatever you give it...)

     

    LadyMtAuthor
    Explorer
    August 1, 2024

    To make it work, I replaced

    HAL_UART_Receive_DMA(&huart9, rx_data, 1);

    with

    HAL_UART_Receive_IT(&huart9, rx_data, 1);

    and now it works very well.

    I don't understand why using DMA on power-up causes the UART not to activate. Do you have any idea?

    Super User
    August 1, 2024

    No - but to receive 1 byte using the DMA is ... rather overshot the target .

    LadyMtAuthor
    Explorer
    August 1, 2024

    @AScha.3 wrote:

    No - but to receive 1 byte using the DMA is ... rather overshot the target .


    I don't quite understand what you mean by that, can you please explain?