Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

startup.c broken with large BSS areas #1

Open
fenugrec opened this issue Nov 17, 2022 · 1 comment
Open

startup.c broken with large BSS areas #1

fenugrec opened this issue Nov 17, 2022 · 1 comment

Comments

@fenugrec
Copy link

candle-usb/candleLight_fw#135 (comment)

hardfault on a F042. Description copied from the comment linked above :

I think I have an idea of the issue causing the hardfault.

in startup.c :

typedef struct _zero_table_t
{
	uint32_t* dest;
	uint32_t wlen;
} zero_table_t;


void Reset_Handler(void)
{
....

	for (zero_table_t const* table = &__zero_table_start__; table < &__zero_table_end__; ++table)
	{
		for (size_t i=0; i<table->wlen; ++i)
		{
			table->dest[i] = 0u;
		}
	}

the for loop runs wlen times, but it writes a u32 every loop. Perfect, but the ldscripts calculate wlen with LONG (__data_end__ - __data_start__) , i.e. a value in bytes !

So the hardfault occurs on a build here with wlen=0x930 , at i=0x601 (thus trying to write at 0x2000 1804 - right outside an F042 's 6kB of RAM !)

@marckleinebudde
Copy link

The __copy_table code triggers the same problem. Once length in a copy or zero table entry reaches 1/4 of the total RAM size this code will hard fault the system. Before this it will only overwrite the memory....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants