本帖最后由 tanzhuolin 于 2021-2-3 09:06 编辑
#1 点亮LED2
void LED_Init(void)
{
GPIO_InitType GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2PERIPH_GPIOD, ENABLE);
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pins = GPIO_Pins_13;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT_PP;
GPIO_InitStructure.GPIO_MaxSpeed = GPIO_MaxSpeed_50MHz;
GPIO_ResetBits(GPIOD, GPIO_Pins_13);
GPIO_Init(GPIOD, &GPIO_InitStructure);
}
#2网口测试:如果是直接使用官方的开发板,下载就能用了。我是使用自己做的主板焊接了AT32F407芯片来调试的,目前已经能够ping通了,参考的是官方的DP83848的demo,官方demo下载链接如下:
百度云链接:https://pan.baidu.com/s/1BQQz91QhJcyPF-mLMIsPJw 提取码: t3io
因为我的主板上的晶振不是8M的,因此参考了官方的文档对时钟进行了修改,文档链接:
http://www.arterytek.com/download/FAQ0093_How_to_modify_BSP_after_replacing_external_crystal_CH_V1.0.0.pdf
ping的测试效果如下:
#3串口打印测试:串口打印测试,我用的是串口2,而且需要IO重映射。ATK的库和ST的寄存器结构体的定义和很多标志的宏定义都是不一样的,因此有点不习惯,例如ST的状态寄存器是SR,ATK的是STA。ST的数据寄存器是DR,ATK的是DT。
void UART2_Init(uint32_t bound)
{
GPIO_InitType GPIO_InitStructure;
USART_InitType USART_InitStructure;
/*Enable the GPIO Clock*/
RCC_APB2PeriphClockCmd(RCC_APB2PERIPH_GPIOD | RCC_APB2PERIPH_AFIO, ENABLE);
/*Enable the UART Clock*/
RCC_APB1PeriphClockCmd(RCC_APB1PERIPH_USART2, ENABLE);
/* UART2 PinsRemap */
GPIO_PinsRemapConfig(GPIO_Remap_USART2, ENABLE);
/* Configure the UART2 TX pin */
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pins = GPIO_Pins_5;
GPIO_InitStructure.GPIO_MaxSpeed = GPIO_MaxSpeed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* Configure the UART2 RX pin */
GPIO_InitStructure.GPIO_Pins = GPIO_Pins_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/*Configure UART param*/
USART_StructInit(&USART_InitStructure);
USART_InitStructure.USART_BaudRate = bound;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART2, &USART_InitStructure);
//USART_INTConfig(AT32_PRINT_UART, USART_INT_RDNE, ENABLE);
USART_Cmd(USART2, ENABLE);
}
int fputc(int ch, FILE *f)
{
while((USART2->STS & USART_FLAG_TRAC) == 0){}
USART2->DT = ch;
return ch;
}
|