[SOLVED] RTT and FreeRTOS

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • [SOLVED] RTT and FreeRTOS

    Hi folks,
    We are using JLink Plus with the SAMD21E16. Wondering if special configuration for RTT is necessary as it's causing some kind of deadlock or crash when used inside a Task.

    Consider this snippet of code

    Source Code

    1. void xBatteryManagementTask(void *p){
    2. uint16_t battery_voltage = 0;
    3. for(;;){
    4. bq_start_adc();
    5. battery_voltage = bq_get_adc_reg(ADC_VBAT);
    6. SEGGER_RTT_printf(0, "Battery voltage %umV", battery_voltage);
    7. if( battery_voltage < 12000){
    8. gpio_set_pin_level(RED_LED, false);
    9. }
    10. os_sleep(1000);
    11. }
    12. }
    Display All


    The battery voltage message is received in the RTT viewer the first time, but after that the application goes into deadlock or some type of error condition. Heartbeat LED no longer toggles. I tried debugging with Ozone but it's causing a hard fault on connection.
  • Hi,
    Thank you for your inquiry.

    The most common reason for such an issue is the following:
    FreeRTOS does not use a scheduler but interrupts to manage its tasks.
    If you have a task using RTT this can lead to problems as the following example explains.

    The main task calls SEGGER_RTT_printf(), which is locking RTT while writing the data to the buffer.
    At the same time, a different task is called via interrupt before SEGGER_RTT_printf() unlocks RTT again.
    The task then calls SEGGER_RTT_printf(), which is then waiting for SEGGER_RTT_printf() from the main task to unlock RTT.
    Unfortunately, the interrupt task can never return, since it is waiting for the RTT lock to open, resulting in a deadlock.

    To make sure that such a thin is not happening is the user's responsibility.

    Regarding the Ozone hard fault issue:
    Could you please open a separate Thread for that?

    Best regards,
    Fabian
    Please read the forum rules before posting: Forum Rules

    Keep in mind, this is not a support forum. Its main purpose is user to user interaction.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/


    Or you can contact us via e-mail.
  • Thanks for the response, Fabian.

    We will work on thread-safe usage of RTT. For now, it is working again. We discovered we were not using the RTOS compatible I2C driver provided by our vendor. That is what was causing the problems.

    As we add RTT_printfs() to other tasks we will make sure the code is thread-safe.

    Thanks again.
  • Hi,
    Good to hear that you are up and running again.

    We will consider this thread as closed now.

    Best regards,
    Fabian
    Please read the forum rules before posting: Forum Rules

    Keep in mind, this is not a support forum. Its main purpose is user to user interaction.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/


    Or you can contact us via e-mail.