GD32H7串口空闲中断+DMA传输+D-cache解读

软件–固件包下载

使用官网的开发板软件包:GD官网下载软件包GD32H7xx_Demo_Suites_V1.2.0,并解压
在这里插入图片描述
在这里插入图片描述
我使用H759_EVAL里面的工程,这里的比较全。其他几个demo suite也都可以。打开06_USART_DMA工程;
在这里插入图片描述

修改封装代码

将工程稍作修改,我这里是新建一个my_uart.c和my_uart.h;
引脚对应关系:

TX–>PB14–>DMA0 CH0
RX–>PB15–>DMA0 CH1


.c中内容

__attribute__((aligned(32))) uint8_t rxbuffer[128];
__attribute__((aligned(32))) uint8_t txbuffer[] = "hello world!";

这里注意,因为H7系列与其他系列不同,使用了D-CACHE和I-CACHE,为了保证cache line 边界对齐,必须使用字节对齐。还有工程使用了ac6编译器,与AC5相比,前面要加上__attribute__。AC5与AC6更多的语法区别,自行查找,如下只是一小部分。
在这里插入图片描述
在这里插入图片描述
添加retarget,使用printf功能;

int fputc(int ch, FILE *f)
{
   
    usart_data_transmit(DEBUG_UART, (uint8_t)ch);
    while (RESET == usart_flag_get(DEBUG_UART, USART_FLAG_TBE));
    return ch;
}


static void uart_config(uint32_t baudrate)
{
   
        /* enable COM GPIO clock */
    rcu_periph_clock_enable(DEBUG_UART_GPIO_CLK);
    /* enable USART clock */
    rcu_periph_clock_enable(DEBUG_UART_CLK);

        /* connect port to USARTx_Tx */
    gpio_af_set(DEBUG_UART_GPIO_PORT, DEBUG_UART_GPIO_AF, DEBUG_UART_TX_PIN);

    /* connect port to USARTx_Rx */
    gpio_af_set(DEBUG_UART_GPIO_PORT, DEBUG_UART_GPIO_AF, DEBUG_UART_RX_PIN);

    /* configure USART Tx as alternate function push-pull */
    gpio_mode_set(DEBUG_UART_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, DEBUG_UART_TX_PIN);
    gpio_output_options_set(DEBUG_UART_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_100_220MHZ, DEBUG_UART_TX_PIN);

    /* configure USART Rx as alternate function push-pull */
    gpio_mode_set(DEBUG_UART_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, DEBUG_UART_RX_PIN);
    gpio_output_options_set(DEBUG_UART_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_100_220MHZ, DEBUG_UART_RX_PIN);

    /* USART configure,数据位8,无奇偶,1停止,1起始 */
    usart_deinit(DEBUG_UART);
    usart_word_length_set(DEBUG_UART, USART_WL_8BIT);
    usart_stop_bit_set(DEBUG_UART, USART_STB_1BIT);
    
  • 14
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值