Can not using function contain while loop in setup

Hi, I'm facing an weird problem when I use an function that is contain while loop

void GPS_init_usingWhile(char* configCommand, char *expectedResponse) {
    NRF_LOG_INFO("call GPS init using while");
    while(1){
        NRF_LOG_INFO("in while loop");
    }
}

int main(void){
 
  bool erase_bonds;
  log_init();
  NRF_LOG_INFO("Debug logging for UART over RTT started.");
  timers_init();
  timer_uarte_init();
  uarte_init();
  app_timer_start(m_app_timer_id, CONFIG_UART_INTERVAL, NULL);
  buttons_leds_init(&erase_bonds);
  power_management_init();
  ble_stack_init();
  gap_params_init();
  gatt_init();
  services_init();
  advertising_init();
  conn_params_init();
  advertising_start();

  ret_code_t err_code;
  app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(500, LED_2);
  pwm1_cfg.pin_polarity[1] = APP_PWM_POLARITY_ACTIVE_HIGH;
  err_code = app_pwm_init(&PWM1, &pwm1_cfg, pwm_ready_callback);
  APP_ERROR_CHECK(err_code);
  app_pwm_enable(&PWM1);
  firstInit = true;
  uarteInit_status = true;
  uarteUninit_status = false;
  firstUninit = false;
  timerTimeout_flag = false;
  //GPS_init_usingWhile(GPS_RMC,RMC_response);

  for (;;) {
    idle_state_handle();
    }
}

When I uncommented the 35th line => call GPS_init_usingWhile(GPS_RMC,RMC_response);  => here is my debug terminal

Here is when I commented the 35th => don't call GPS_init_usingWhile(GPS_RMC,RMC_response); => here is my debug terminal

=> so why I can not call the while loop GPS_init_usingWhile(GPS_RMC,RMC_response) ???

Parents
  • Hello,

    I think there is a misunderstanding here. If you uncomment GPS_init_using_While(...), you should see that you are actually inside that while loop. If you press the "pause" button when you are debugging, you should see that this is the case.

    The thing is that when you are in this while loop (that you never exit, because of the while (1), then the nRF52832 will never reach idle_state_handle(), which will actually process and print the log over the UART.

    So either you need to call it only a limited amount of times

    void GPS_init_usingWhile(char* configCommand, char *expectedResponse) {
        uint16_t counter=0;
        NRF_LOG_INFO("call GPS init using while");
        while(1){
            NRF_LOG_INFO("in while loop");
            counter++;
            if (counter > 5)
            {
                break;
            }
        }
    }

    Or you can disable deferred logging in sdk_config.h by setting NRF_LOG_DEFERRED to 0. This will cause the nRF to process the logging during runtime, and not in idle_state_handle().

    Best regards,

    Edvin

Reply
  • Hello,

    I think there is a misunderstanding here. If you uncomment GPS_init_using_While(...), you should see that you are actually inside that while loop. If you press the "pause" button when you are debugging, you should see that this is the case.

    The thing is that when you are in this while loop (that you never exit, because of the while (1), then the nRF52832 will never reach idle_state_handle(), which will actually process and print the log over the UART.

    So either you need to call it only a limited amount of times

    void GPS_init_usingWhile(char* configCommand, char *expectedResponse) {
        uint16_t counter=0;
        NRF_LOG_INFO("call GPS init using while");
        while(1){
            NRF_LOG_INFO("in while loop");
            counter++;
            if (counter > 5)
            {
                break;
            }
        }
    }

    Or you can disable deferred logging in sdk_config.h by setting NRF_LOG_DEFERRED to 0. This will cause the nRF to process the logging during runtime, and not in idle_state_handle().

    Best regards,

    Edvin

Children
Related