This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP-EXP430FR5994: push_back in vectorvariable does not work

Part Number: MSP-EXP430FR5994
Other Parts Discussed in Thread: MSP430WARE

Hello,

I have problem with a vector I declared in my code and the push_back that works with the vector.  The code is below

uti_timing::struct_timer_var timer_inst = {timer_id, timer::GetTimerValue(e_seconds), 0,0};
uti_timing::v_sec_timing_obj.push_back(timer_inst);

The uti_timing::v_sec_timing_obj.push_back(timer_inst) does not get the variables declared in the timer_inst.  I do not know why?

A snapshot of the debugger for the local variable is below

Snapshot of the vector variable value after the push_back

I chaged the timer::GetTimerValue(e_seconds) function to a 0 value but i still got the same problem.

I checked the entire code but did not find the source of the problem.  The code had worked well on a C2000 launchpad platform.

I am using CCS12 and the compiler version TI v21.6.0.LTS and  MSP430Ware 3.80.14.01.

Thanks

  • Hi there,

    Could you confirm that the issue is with push_back by stepping debug?

    Or maybe open the Memory Browser to check the value of the corresponding address.

    Thanks and Best Regards

    Yuhao Zhao

  • Thanks for your reply.  I did that and this are some snapshot I got.

    Memory snapshot before the push_back

    Memory snap shot after the puush_back

    Snapshot of local variables

    Snapshot of debug call stack

    Thanks.  

  • Hi Abayomi,

    Is this problem persistent? If you remove the other code and only use push_back in the main function, will the problem recur?

    By the way, maybe you can try setting the optimization level to 0.

    Thanks and Best Regards

    Yuhao Zhao

  • Thank you Zhao.  I tried a number of modifications on the code but did not get any progress.  Also I have to always put the values to push in the vector variable.

    1.  I tried the below code

                  uti_timing::struct_timer_var timer_inst = {uti_timing::e_device_up_tim,0,0,0}; 
                 uti_timing::v_sec_timing_obj.push_back(timer_inst);

           In debug view the values were the same as my previous post

    2.  The below code did not build 

         std::vector<uti_timing::struct_timer_var>  uti_timing::v_sec_timing_objb{ uti_timing::e_device_up_tim, 0, 0, 0 };

        I want to initialise the values at compile time then puss it to the vector at run time.  But I got the below error

                 Description Resource Path Location Type
                 #291 no instance of constructor "std::__2::vector<_Tp, _Allocator>::vector [with _Tp=uti_timing::struct_timer_var,                                                    _Allocator=std::__2::allocator<uti_timing::struct_timer_var>]" matches the argument list uti_timer.cpp /pro_cc/utility line 24 C/C++  Problem

    The above is strange.  I there another way to initialize a struct?

    3. I also tried the below code but the values of the push_back were the same as the post

                   uti_timing::struct_timer_var timer_inst;
                   uti_timing::v_sec_timing_obj.push_back(timer_inst);

    I look forward to a solution and suggestion to this.

    Thanks

  • Hi Abayomi,

    I will check the code and reply to you soon.

    Thanks and Best Regards

    Yuhao Zhao

  • Hello,

    I would like to know if you have been able to check the problem.

    Thanks

  • Hi Abayomi,

    Sorry to keep you waiting. Honestly, I didn't find the root cause in the Snapshot. 

    The way to use struct seems to be correct, so I have informed my colleagues about the issue.

    This may also be the include problem of the header file. 

    Thanks and Best Regards

    Yuhao Zhao

  • Hi Abayomi,

    Would you upload the code here if not confidential, so we can reproduce it for debug. Thanks a lot.

    Best Regards

    Sal

  • Hallo Sal Ye,

    Sorry for the late reply.  Sure I can.  Just to reference my first post.  The same code worked well on C2000 platform

    1. Defination of varaibles in the .h fine

    /**< timer ID it also serves as the event ID too */
    typedef enum
    {
    //e_device_off = 0,
    e_device_up_tim = 0, //timer ID for device up time
    e_total_charging_tim = 1, //timer ID for total charging time /**< timer ID for timing that is based on millie_seconds */
    e_bulk_charge_tim = 2, //timer id for bulk charging mode
    e_const_charge_tim = 3, //timer ID for constant charging mode
    e_float_charge_tim = 4, //timer ID for float charging time
    e_equal_charge_tim = 5, //timer equalize charging mode
    e_rate_of_chan_in_charging = 6, //timer ID for rate of change in charging
    e_charg_over_curr_monitor = 7, //timer ID for monitoring charge over current
    e_end_charg_op_delay = 8, //timer ID for delay to end charging operation
    e_charger_on_delay = 9, //delay to end float charging
    e_test_timer_max_charg_time = 10,

    e_max_no_of_sec_timers = 18,
    e_max_no_of_timers = 19,
    }enum_timer_id;

    /**< struct that hold the state of each timer instance */
    typedef struct
    {
    enum_timer_id timer_id_e; // links the timer struct to the timer parameters
    uint16_t start_time; //TODO might not be needed
    uint16_t timer_cycle_cou; //number of time the time period for a particular event has been achieved
    uint16_t elapsed_time; //set, when the time has elapsed and polled by timer instance owners
    }struct_timer_var;

    static std::vector<struct_timer_var> v_sec_timing_obj;

    2. Declaration of varaible in the .cpp file

    std::vector<uti_timing::struct_timer_var>  uti_timing::v_sec_timing_obj;

    3.  Create an instance of the timer vector object

    i. This function is called to create an instance of the timer vector object

    void uti_timing::UtimTimerInit(void)
    {
    uti_timing::EnableNewTimerInstance(e_device_up_tim);
    }

    ii. uti_timing::EnableNewTimerInstance function 

    void uti_timing::EnableNewTimerInstance(enum_timer_id timer_id)
    {
    uti_timing::s_timer_info[timer_id].timer_enabled_state = dev_config::e_enum_bool_1;

    if (timer_id <= e_max_no_of_sec_timers) // second timers
    {
    uti_timing::struct_timer_var timer_inst= {uti_timing::e_device_up_tim,0,0,0}; // = {timer_id, timer::GetTimerValue(e_seconds), 0,0};
    uti_timing::v_sec_timing_obj.push_back(timer_inst);
    }
    else
    {

    //error

    }
    }

    The above  function - uti_timing::EnableNewTimerInstance function does not work well as the push _back does not have the value is the timer_inst.

    If you need more information please let me know

    Thanks

  • Hi Abayomi,

    Thanks for your information, we are trying to figure out. Would you mind uploading whole project? It will be helpful for debugging.

    Thanks a lot!

    Best Regards

    Sal

  • timing test code.rar

    Thanks so miuch and sorry for the late reply.

    I have attached a stripped down version of the project for you.

    Thanks

  • Hi,

    Good morning.  I would like to ask if you have been able to run the  code to reproduce the problem.

    Thanks.

  • Hi Abayomi,

    Sorry for late reply, I have asked an expert to test your code, but now we are suffering COVID-19 and work from home, so we cannot get result without the MSP device right now.

    As soon as we come back to office, we will give the feedback to you.

    Thanks and Best Regards

    Sal

  • Hallo Ye,

    Is there any progress on the issue?

    Thanks

    Yomi

  • Hi Yomi,

    I tried the code. And I added the breakpoint and uti_timing::v_sec_timing_obj.size() to monitor the vector size.

    Here is the number before push_back. size = 0.

    Here is the number after push_back. size = 1.

    And when I tried to run the pushback again, it did not stop, which means uti_timing::EnableNewTimerInstance(enum_timer_id timer_id) was called only once. Maybe there is an issue with the call of this function.

    Thanks and Best Regards

    Yuhao Zhao

  • Hallo Zhao,

    Thank you for the reply.

    The problem with the code is not that the function is not called but that the variables of the vector are not correctly initialised and when they are increased, the values are wrong.

    The values of the vector should be initilised based on the below code

    uti_timing::struct_timer_var new_timer_inst = {timer_id, timer::GetTimerValue(e_seconds), 0,0};

    uti_timing::v_sec_timing_obj.push_back(new_timer_inst);

    The uti_timing::v_sec_timing_obj should have the value based on this code  - uti_timing::struct_timer_var new_timer_inst = {timer_id, timer::GetTimerValue(e_seconds), 0,0};

    But that does not happen but instead I have a very random value in the vector.

    Can you please check the value of the vector to see the problem I am talking about.

    This problem was explicitly stated in my first chat.

    Thanks

    Babatola Abayomi

  • Hallo Zhao,

    Good day.  I would like to know if you have been able to look at the issue?

    Thanks

  • Hallo,

    Have you been able to check.

    Thanks

**Attention** This is a public forum