I am using https://github.com/ARM-software/CMSIS_5/blob/develop/Device/ARM/ARMCM33/Source/startup_ARMCM33.c file with following modifications:
_NO_RETURN void Reset_Handler(void)
{
__set_MSPLIM((uint32_t)(&__STACK_LIMIT));
SystemInit(); /* CMSIS System Initialization */
lpuart_init(&m33_uart, (void*)LPUART0_BASE, LPUART); // Initialize LPUART
__PROGRAM_START(); /* Enter PreMain (C library entry point) */
}
The __PROGRAM_START();
will jump to _start
which will do all the runtime configurations mentioned in the crt0.o
and then it will jump to main
(See https://embeddedartistry.com/blog/2019/04/08/a-general-overview-of-what-happens-before-main/ for more details).
In above snippet, I am doing LPUART initialization before _start
. After debugging the .elf, I got to know that this LPUART initialization gets lost when program reaches to main
.
Surprisingly, the same program works if I do LPUART initialization inside main
:
void main() {
lpuart_init(&m33_uart, (void*)LPUART0_BASE, LPUART);
/* some more code
...... */
}
It seems crt0.o
is doing something that will cause loss of the LPUART (or platform) configuration. I am not able to figure out the reason. Any help?
Edits:
void lpuart_init(lpuart_info_t* p_info, void* base_addr, uint32_t version)
{
p_info->base_addr = base_addr;
p_info->version = version;
}