[AT32A403A] debug中的模拟串口打开的问题

[复制链接]
467|0
Hdj123 发表于 2025-9-28 10:12 | 显示全部楼层 |阅读模式
void USART1_2_Init(void)
{
    GPIO_InitType GPIO_InitStructure;
    USART_InitType USART_InitStructure;
    DMA_InitType DMA_InitStructure;
    NVIC_InitType NVIC_InitStructure;

    RCC_APB2PeriphClockCmd(RCC_APB2PERIPH_GPIOA | RCC_APB2PERIPH_USART1, ENABLE);
    RCC_APB1PeriphClockCmd(RCC_APB1PERIPH_USART2, ENABLE);
    RCC_AHBPeriphClockCmd(RCC_AHBPERIPH_DMA1, ENABLE);

    GPIO_InitStructure.GPIO_Pins = GPIO_Pins_2 | GPIO_Pins_9; // PA2 USART2 TX  LCD |  PA9 USART1  TX  mainboard
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_InitStructure.GPIO_MaxSpeed = GPIO_MaxSpeed_50MHz;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pins = GPIO_Pins_3 | GPIO_Pins_10; // PA2 USART2 RX  LCD |  PA9 USART1  RX  mainboard
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_InitStructure.GPIO_MaxSpeed = GPIO_MaxSpeed_50MHz;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
       
    USART_InitStructure.USART_BaudRate = 115200;
    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); // USART2 config
       
        USART_InitStructure.USART_BaudRate = 115200;
    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(USART1, &USART_InitStructure); // USART1 config

    DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&USART2->DT;
    DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)NULL;
    DMA_InitStructure.DMA_Direction = DMA_DIR_PERIPHERALDST;
    DMA_InitStructure.DMA_BufferSize = 0;
    DMA_InitStructure.DMA_PeripheralInc = DMA_PERIPHERALINC_DISABLE;
    DMA_InitStructure.DMA_MemoryInc = DMA_MEMORYINC_ENABLE;
    DMA_InitStructure.DMA_PeripheralDataWidth = DMA_PERIPHERALDATAWIDTH_BYTE;
    DMA_InitStructure.DMA_MemoryDataWidth = DMA_MEMORYDATAWIDTH_BYTE;
    DMA_InitStructure.DMA_Mode = DMA_MODE_NORMAL;
    DMA_InitStructure.DMA_Priority = DMA_PRIORITY_HIGH;
    DMA_InitStructure.DMA_MTOM = DMA_MEMTOMEM_DISABLE;
    DMA_Init(DMA1_Channel7, &DMA_InitStructure);
    USART_DMACmd(USART2, USART_DMAReq_Tx, ENABLE);
    DMA_ChannelEnable(DMA1_Channel7, ENABLE);

        USART_INTConfig(USART1, USART_FLAG_TDE, ENABLE);
    USART_INTConfig(USART2, USART_INT_RDNE, ENABLE);

        NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure);

    NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure);

        //USART_Cmd(USART1, ENABLE); // USART1 enable
        USART_Cmd(USART2, ENABLE); // USART2 enable
       
}

void USART2_IRQHandler(void)
{
    if(USART_GetITStatus(USART2, USART_INT_RDNE) != RESET)
    {
        uint8_t data = USART_ReceiveData(USART2);
        queue_push(data);
        USART_ClearITPendingBit(USART2, USART_INT_RDNE);
        //printf("%d\n", data);
    }
}



void usart2_send_dma(uint8_t *buf, uint16_t len)
{
    while(DMA_GetCurrDataCounter(DMA1_Channel7) != 0);
    DMA_ClearITPendingBit(DMA1_FLAG_TC7);
    DMA_ChannelEnable(DMA1_Channel7, DISABLE);
    DMA_SetCurrDataCounter(DMA1_Channel7, len);
    DMA1_Channel7->CMBA = (uint32_t)buf;
    DMA_ChannelEnable(DMA1_Channel7, ENABLE);
}使用的是串口2的dma发送,要发送到大彩的串口屏,现在想要知道debug中的模拟串口要怎么配置,有大佬知道吗
您需要登录后才可以回帖 登录 | 注册

本版积分规则

4

主题

6

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部