S12 MCU global array is not initialized related problems

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

S12 MCU global array is not initialized related problems

839 Views
jack_huang1
Contributor III

Dear,

        When we use S9S12XHY128F0VLMR, we define an unsigned char global array with a size of 34 bytes, and make it stored in the paging random access memory by preprocessing instructions. (See Figure 1 for the code).

         The allocation in the.map file is shown in Figure 2.

          Since it is not initialized before use, and is assigned to another array through a for loop (the code is as follows:

           for(i=0;i<len3;i++)

                 {

                   Data[i]=TEL_DrvingInfo[i];

                 }

              

           We find that TEL_DrvingInfo[0] & 0x80 is a random value. There are other bit operations on TEL_DrvingInfo[0] via '&' and '|' in the code (as follows Figure 3),.But there is no operation to change the value of the highest bit of TEL_DrvingInfo[0].

            Under the above prerequisites, there are two questions I would like to consult:

            

          1. Suppose that TEL_DrvingInfo[0] & 0x80, which is the highest bit of array element 0, is 1 when the chip is reset, will it be 1 every time the chip is reset? (Is it 0 every time you reset it?) Does program running or chip reset change the value of this bit?

          2. Whether there are extreme conditions, such as strong magnetic, high temperature, will cause the value of this uninitialized bit to change, is there a way to clear the value of the 0 bit or clear the value of the 0 partition without brushing the program?

           

            Thank you!

             Best Regards.

0 Kudos
Reply
1 Reply

740 Views
giraffe508
Contributor IV

Hello,

Regarding your questions:

1. The value of an uninitialized variable, including an array like TEL_DrvingInfo[0], is undefined in C. This means that it can be any value at the time of reset, and it can change between resets. The value is not guaranteed to be the same every time the chip is reset. The value of this bit will not change during program execution unless your code changes it.

2. Extreme conditions like strong magnetic fields or high temperatures could potentially cause bit flips in memory, but this is generally unlikely. However, it's not impossible. If you want to ensure that the value of this bit is always clear at the start of your program, you should explicitly initialize it to 0. You can do this by adding a line of code like this at the start of your program:

 TEL_DrvingInfo[0] = 0; 

This will ensure that the value of TEL_DrvingInfo[0] is always 0 at the start of your program, regardless of any potential bit flips caused by extreme conditions.

As for clearing the value of the 0 partition without brushing the program, it's not clear what you mean by 'brushing the program'. If you mean reprogramming the chip, then yes, you can clear the value of the 0 partition by writing a 0 to it, just like you can with TEL_DrvingInfo[0].

I hope this helps! Let me know if you have any other questions.

0 Kudos
Reply