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.

MSP430FR2355: TI v21.6.1: strange for loop behavior

Part Number: MSP430FR2355

Good morning,

I encountered a strange behaviour during the debugging process of my firmware application on a MSP430FR2355 using Code Composer Studio 20.3.1.5.

That's the code (note that I placed those ASM comments just as a marker in order to find it easily in the assembly code):

__asm(";------------- BEGIN list_for_each_entry_safe"); // marker
list_for_each_entry_safe(event, tmp, &gpt_internal.used_events_queue, head) { // <=== I have the issue here
__asm(";------------- END list_for_each_entry_safe");  // marker
// rest of the code...
}


The list_for_each_entry_safe is the same as linux/list.h (v2.6.32). 

When debugging the list_for_each_entry_safe body with TI v21.6.1.LTS I saw an odd behaviour situation: 
the event variable, at the first iteration, contained invalid data, causing the firmware to crash (PC=0x0004).


Needles to say: all the structures were correctly initialized.

The same code, with TI v16.9.4.LTS, produced the expected results.


After some debugging I could have find out the source of the issue: the increment part of the for loop is being evaluated BEFORE each execution of the loop body and not after. That could explain the issue encountered.


If needed I can provide the generated ASM source files of that particular module (with TI16 and TI21 both).


Here are the compiler flags:
-vmspx --use_hw_mpy=F5 --include_path="${CCS_BASE_ROOT}/msp430/include" --
include_path="${CG_TOOL_ROOT}/include" <project include dirs> --advice:power=all --advice:hw_config=all -
-define=__MSP430FR2355__ --define=_FRWP_ENABLE --define=_INFO_FRWP_ENABLE -g --
printf_support=minimal --diag_warning=225 --diag_wrap=off --display_error_number --
silicon_errata=CPU21 --silicon_errata=CPU22 --silicon_errata=CPU40 --src_interlist --
gen_preprocessor_listing.


The optimization flags were the same for both compilations, I was only changing the compiler version in the project settings.


Did I miss something? Or did I do something wrong? 

Thank you in advance.
Regards,

**Attention** This is a public forum