This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Program sort of freezes or doesn't after a while when I change something completely unrelated (or so I think)

Hi everyone,

I have a problem I can't sort out. My program runs fine indefinitely if I set one variable in a function at one point but if I don't do that, the program, or at least the debugging stops after a while. The program sort of continues (I can send a few messages from my app to it) but after a while it just doesn't seem to respond.

So.

I added a debug print of "." in the main loop which has a 500ms delay in it. These are some startup messages I get when the program runs fine. The dots just keeps going.

app_timer: RTC: initialized!
 app: Erasing flash page
 app: --> Event received: erased 1 page from address 0x7F000.
 app: Converting a program to a buffer
 app: --> Event received: wrote 112 bytes at address 0x7F000.
 app: Converting a buffer to a program
 app: Accelerometers initialized. 25
 app: Accelerometers initialized. 24
 app: State --> NOT_CONNECTED
 app: end
..................................................................................................................

The dots just keeps going and going.

BUT! If I don't make that function call and set that variable the debugging (and parts of the program) stops after exactly the same amount of time every time:
 app_timer: RTC: initialized!
 app: Erasing flash page
 app: --> Event received: erased 1 page from address 0x7F000.
 app: Converting a program to a buffer
 app: --> Event received: wrote 112 bytes at address 0x7F000.
 app: Converting a buffer to a program
 app: Accelerometers initialized. 25
 app: Accelerometers initialized. 24
 app: State --> NOT_CONNECTED
 app: end
....................

Compare the number of dots in the two examples.

The weird thing now is that the difference is in the beginning of main.c. If I make a function call to a function located in an included file called:

set_potentiometer_resistance(&m_twi_1, DIGITAL_POT_I2C_ADDRESS_MAX5434, 25000);

In that function I only do this:

ret_code_t set_potentiometer_resistance(nrf_drv_twi_t const * p_instance, uint8_t address, int32_t resistance) {
    actual_potentiometer_resistance = resistance;
    ret_code_t err_code;
//    uint8_t payload[2];
//    payload[0] = DIGITAL_POT_MAX5434_COMMAND_VREG;
//    payload[1] = get_potentiometer_tap_position_from_resistance(resistance);
//    
//    err_code = nrf_drv_twi_tx(p_instance, address, &payload, sizeof(payload), false);
    return err_code;
}

The actual_potentiometer_resistance variable is placed in the header file of the potentiometer function.
static int32_t actual_potentiometer_resistance;
 

I can set it to zero, it works just as well. But if I try to set the value of that variable instead of calling the function, like this:

actual_potentiometer_resistance = 0;
instead of:
set_potentiometer_resistance(&m_twi_1, DIGITAL_POT_I2C_ADDRESS_MAX5434, 25000);
It doesn't work. It stops after the same amount of time.


I can't understund this behavior. It feels like I'm changing something totally unrelated. When I've had similar issues earlier, if the program stops after a while or the debugging stops after a while, all of those problems have been due to me not freeing a malloc:ed variable or so. But what could cause this?

Thanks in advance,
Samuel

Parents
  • Hi again,

    I know this is super hard to answer.

    Just wanted to add a few things. The program doesn't freeze actually, it's just the printing in the console window that stops.

    I've tried renaming the variable and it doesn't change the behavior. I've placed the variable in a different included file and then the debug freezes. I've tried to remove the variable and that won't work.

    So the program needs this specific variable (name can be changed) placed in this specific header (or source, tried that as well) file to not continue print debug messages. I can also change the name of the function with the same result. I just need to set this variable to some value for the debugging to work continuously...

    I've also tried another board as well as cleaned the project and so on. Same result.

Reply
  • Hi again,

    I know this is super hard to answer.

    Just wanted to add a few things. The program doesn't freeze actually, it's just the printing in the console window that stops.

    I've tried renaming the variable and it doesn't change the behavior. I've placed the variable in a different included file and then the debug freezes. I've tried to remove the variable and that won't work.

    So the program needs this specific variable (name can be changed) placed in this specific header (or source, tried that as well) file to not continue print debug messages. I can also change the name of the function with the same result. I just need to set this variable to some value for the debugging to work continuously...

    I've also tried another board as well as cleaned the project and so on. Same result.

Children
  • Hello again,

    samuel.zetterlund said:
    I know this is super hard to answer.

    Yes, but if you provide me with the information I requested in my other comment, then we may start attempting to resolve your issue.
    I am looking forward to hearing back from you on that!

    samuel.zetterlund said:
    Just wanted to add a few things. The program doesn't freeze actually, it's just the printing in the console window that stops.

    Thank you for the update - I am glad you were able to verify that the program does not crash.

    samuel.zetterlund said:
    I've tried renaming the variable and it doesn't change the behavior.

    I would not expect the variable name to matter here, but I think its declaration and the placement of the declaration might contribute to the unexpected behavior.

    Best regards,
    Karl

    P.S If you are worried about Intellectual property when sharing code, I may convert this ticket to a private ticket which is only viewable to you and the support staff here at Nordic Semiconductor. Please let me know if you would like me to do this.

Related