for (int i = 0; i < 20; i ++) {
printf("%d: Hello World From Nuclei RISC-V Processor!rn", i);
}
return 0;
}
很简介,几乎就只要printf函数,但是又不见串口的初始化,那这些外设的配置到哪了呢。
其实就在"system_gd32v103.c"里面,我们看一下:
/**
* brief early init function before main
* details
* This function is executed right before main function.
* For RISC-V gnu toolchain, _init function might not be called
* by __libc_init_array function, so we defined a new function
* to do initialization
*/
void _premain_init(void)
{
/* TODO: Add your own initialization code here, called before main */
SystemCoreClock = get_cpu_freq();
/* configure USART */
gd_com_init(SOC_DEBUG_UART);
/* Display banner after UART initialized */
SystemBannerPrint();
/* Initialize exception default handlers */
Exception_Init();
/* ECLIC initilization, mainly MTH and NLBIT */
ECLIC_Init();
}
这个函数已经完成了一些外设的初始化设置了。
函数名称和库函数的写法都和arm-m的很类似。熟练arm-m核的工程师应该可以很快上手。