Putting data on with DATA tag corrupting memory

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

Putting data on with DATA tag corrupting memory

741 Views
yakoinfinity
Contributor II

Hello everyone! I've been working with my colleagues for a while with the new version of MCUXpresso IDE, founding that the compiler throw us an error asking to put all our non-zero initialized data with the __DATA tag, instead of _BSS, which is the one that we were using until then. 

Console_bss_data_error.PNG

Once we changed all previous _BSS located variables, the program compiled, but not runned into the board.

After a little debugging session, we found this:SSP_Init_bad_mutex.PNG

The declaration of this array is as follows:

os_mutex_t g_ssp_mutex[2] = {OS_MUTEX_NULL, OS_MUTEX_NULL};‍‍‍

being OS_MUTEX_NULL = 0xFF.

It's correct value, for both array members, would be 0xFF, as you can see in the next picture:

SSP_Init_good_mutex.PNG

The difference between both pictures is the pressence of DATA tag in the project (Yes, in the entire project), and the IDE version (v10.1.0 [build 589] vs. v10.0.2 [build 411], which worked for us). 

I supossed that RAM could be the problem, as it's zero-initialized on startup. So, I tried to move the array to another RAM bank (in this case, to bank ram2) with similar results:SSP_Init_bad_mutex_RAM2.PNG

We are using LPC1768 MCU, with MCUXpresso v10.1.0 & v10.0.2 running on Windows 10 Enterprise x64bits. The MCU RTOS is CoOs.

Any idea?

Regards,

Exequiel Beker.

Labels (1)
Tags (4)
0 Kudos
2 Replies

566 Views
lpcxpresso_supp
NXP Employee
NXP Employee

Fundamentally, bss variables are going to be zero initialised by the startup code in your project as your system comes out of reset (assuming you are using the "normal" IDE startup code and the IDE's managed linker script mechanism). And other, initialised data, variables are going to have their initial values defined in your code copied out of flash and into their runtime addresses.

When using the __BSS and __DATA macros from the "cr_section_macros.h" header file supplied in MCUXpresso IDE, you are not changing the nature of a particular variable. You can't change a bss variable to be an initialised one - you need to use the right macro for the type of the variable.

[Note: the "normal" IDE startup code will zero-init / initialise the BSS and DATA for all the RAM banks in your project.]

Thus you can write:

#include <cr_section_macros.h>
__DATA(RAM2) int data_buffer[2] = {1234,5678};
__BSS(RAM2) int bss_buffer[2];

but you can't then write:

__BSS(RAM2) int wrong_buffer[2] = {0x9ABC,0xDEF0};

One thing to note is that the version of the GCC compilation tools sitting underneath MCUXpresso IDE has changed between v10.0.x and v10.1.x - and behaviour can change slightly between versions. Thus it is possible that you might now see an error because of incorrect attributes being set by your macro usage that previously the linker failed to warn you about.

Whenever you are changing the "default" memory layout and placement of data, I would always suggest that you take the time to study the map file generated by the linker in order to understand what has actually happened in your generated image.

For more information, please read through chapter 14, "Memory Configuration and Linker Scripts" of the MCUXpresso IDE v10.1 User Guide.

Regards,

MCUXpresso IDE Support

0 Kudos

566 Views
Carlos_Mendoza
NXP Employee
NXP Employee

Hi Exequiel,

Could you send us a project so we can reproduce the issue on our side?

Thanks in advance!

Best Regards,
Carlos Mendoza
Technical Support Engineer

0 Kudos