Other Parts Discussed in Thread: HALCOGEN
Tool/software:
The sys_selftest.c generated by HalCoGen contains this function:
boolean pbistIsTestCompleted(void)
{
    return ((systemREG1->MSTCGSTAT & 0x1U) != 0U);
}It violates MISRA-C 2004 12.2 "Volatile variable in complex expression", so I replace it by this equivalent function
boolean pbistIsTestCompleted(void)
{
  uint32 stat = systemREG1->MSTCGSTAT;
  return ((stat & 0x1U) != 0U);
}
After this modification, the system goes into prefetch abort exception. nError pin seems to go wild that a relay controlled by that pin switches back and forth.
The registers are CP15.IFSR=0x0d, CP15.IFAR=0xc3c3c3c2 (an invalid address), CP15.AIFSR=0x0.
If I undo this modification, the prefetch abort disappears. If I add it back, the prefetch happens again. If I run the code in debugger step by step, the prefetch disappears.
I think it isn't my code that causes this problem because it goes to prefetch exception before running main(), and the code runs before main() is generated by HalCoGen, except pbistIsTestCompleted.
Although the C code seems equivalent, the assembly is quite different. But I can't see why it has anything to do with prefetch abort. Compiler flags are -mv7R4 --code_state=32 --float_support=VFPv3D16 --include_path="C:/ti/ccs1260/ccs/tools/compiler/ti-cgt-arm_20.2.7.LTS/include" --include_path="C:/ti/Hercules/F021 Flash API/02.01.01/include" -g --symdebug:dwarf_version=3 --c99 --diag_warning=225 --diag_wrap=off --display_error_number --gen_func_subsections=on --gen_data_subsections=on --enum_type=packed --abi=eabi.
boolean pbistIsTestCompleted(void)
{
    return ((systemREG1->MSTCGSTAT & 0x1U) != 0U);
}
          pbistIsTestCompleted():
000176cc:   E3E0C097            mvn        r12, #0x97
000176d0:   E59C1000            ldr        r1, [r12]
000176d4:   E3A00000            mov        r0, #0
000176d8:   E3110001            tst        r1, #1
000176dc:   E3A0C000            mov        r12, #0
000176e0:   0A000000            beq        $C$L11
000176e4:   E3A0C001            mov        r12, #1
          $C$L11:
000176e8:   E35C0000            cmp        r12, #0
000176ec:   0A000000            beq        $C$L12
000176f0:   E3A00001            mov        r0, #1
 315      }
          $C$L12:
000176f4:   E12FFF1E            bx         lr
boolean pbistIsTestCompleted(void)
{
    uint32 stat = systemREG1->MSTCGSTAT;
    return ((stat & 0x1U) != 0U);
}
          pbistIsTestCompleted():
00016ea0:   E24DD008            sub        r13, r13, #8
 312          uint32 stat = systemREG1->MSTCGSTAT;
00016ea4:   E3E0C097            mvn        r12, #0x97
00016ea8:   E59CC000            ldr        r12, [r12]
00016eac:   E58DC000            str        r12, [r13]
 313          return ((stat & 0x1U) != 0U);
00016eb0:   E59D1000            ldr        r1, [r13]
00016eb4:   E3A00000            mov        r0, #0
00016eb8:   E3110001            tst        r1, #1
00016ebc:   E3A0C000            mov        r12, #0
00016ec0:   0A000000            beq        $C$L11
00016ec4:   E3A0C001            mov        r12, #1
          $C$L11:
00016ec8:   E35C0000            cmp        r12, #0
00016ecc:   0A000000            beq        $C$L12
00016ed0:   E3A00001            mov        r0, #1
 316      }
          $C$L12:
00016ed4:   E28DD008            add        r13, r13, #8
00016ed8:   E12FFF1E            bx         lr
Why does this happen? How can I locate the problem? Thanks very much!
 
				 
		 
					 
                           
				
