芯片有唯一的编号,看下文档时边有介绍读CORTEX型号的。就是看看是M0, M1,M4。
现在试一下:
首选选择USART的printf例程,读一下例程,我觉得重点是那个重定义的函数在哪里了。我找了老半天,终于找到在at32_board.c里:
#ifdef __GNUC__
/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
set to 'Yes') calls __io_putchar() */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
/**
* [url=home.php?mod=space&uid=159083]@brief[/url] Retargets the C library printf function to the USART.
* @param None
* @retval None
*/
PUTCHAR_PROTOTYPE
{
USART_SendData(AT32_PRINT_UART, ch);
while ( USART_GetFlagStatus(AT32_PRINT_UART, USART_FLAG_TRAC) == RESET );
return ch;
}
当然还得微库打勾:
以下是程序:直接读地址的内容.
int main(void)
{
/* USART1 configured as follow:
- BaudRate = 115200 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/
UART_Print_Init(115200);
/* Output a message on Hyperterminal using printf function */
printf("\n\rUSART Printf Example: retarget the C library printf function to the USART\n\r");
cortex_id = *(uint32_t *)0xE000ED00; //读取 cortex 型号
if((cortex_id == 0x410FC240) || (cortex_id == 0x410FC241))
{
printf("This chip is Cortex-M4.\r\n");
}
else
{
printf("This chip is Other Device.\r\n");
}
while (1)
{
}
}
以下是运得结果:
这也能读?都没有尝试过哈!