2739 views|1 replies

57

Posts

0

Resources
The OP
 

It is recommended that GD unify the macro names of enable and disable in the standard library [Copy link]

Today I tried GD's DMA+UART and encountered such a problem. On the one hand, it can be said that it was caused by my carelessness. On the other hand, I also hope that GD can unify some macro names of enable and disable, instead of doing each item separately. For example, the several enable and disable in the figure above, although the enabled and disabled items are different, these shifts can be processed in the function, and these macros can all be replaced by the same one. I wrote this piece of code today:
  1. usart_deinit(USART1); dma_deinit(DMA_CH3); usart_baudrate_set(USART1,115200); usart_parity_config(USART1, USART_PM_NONE); usart_word_length_set(USART1, USART_WL_8BIT); usart_stop_bit_set(USART1, USART_STB_1BIT); usart_hardware_flow_rts_config(USART1, USART_RTS_DISABLE); usart_hardware_flow_cts_config(USART1, USART_CTS_DISABLE); usart_receive_config(USART1, USART_RECEIVE_ENABLE); usart_transmit_config(USART1, USART_TRANSMIT_ENABLE); usart_enable(USART1); dma_parameter_struct dma_parameter; dma_parameter.direction = DMA_MEMORY_TO_PERIPHERAL; dma_parameter.memory_addr = (uint32_t)tx_buf; dma_parameter.memory_inc = DMA_MEMORY_INCREASE_ENABLE; dma_parameter.memory_width = DMA_MEMORY_WIDTH_8BIT; dma_parameter.periph_addr = USART1_TDATA_ADDRESS; dma_parameter.periph_inc = DMA_PERIPH_INCREASE_DISABLE; dma_parameter.periph_width = DMA_PERIPHERAL_WIDTH_8BIT; dma_parameter.priority = DMA_PRIORITY_ULTRA_HIGH; dma_init(DMA_CH3, dma_parameter); dma_circulation_disable(DMA_CH3); dma_memory_to_memory_disable(DMA_CH3); usart_dma_transmit_config(USART1, USART_DENR_ENABLE);
复制代码
is to use DMA to send the serial port. There is a problem in the above code, that is, I confused USART_DENR_ENABLE and USART_DENT_ENABLE and wrote it wrong. Then there was nothing in the serial port, because the initialization process only focused on the called API, and did not check whether the parameters were correct. After wondering for a few minutes and preparing to rewrite, I suddenly focused on USART_DENR_ENABLE, and changed it to USART_DENT_ENABLE and there was no problem. These two ENABLEs, when provided to users, mainly mean enable, why can't we use a unified macro, so that it is convenient to call. The difference between the two can be completely handled in the API.

This post is from GD32 MCU

Latest reply

  Details Published on 2018-9-18 11:57
 

935

Posts

1

Resources
2
 
This post is from GD32 MCU
 
Personal signature存储芯片/MCU/SRAM/PSRAM/DDR/FLASH/MRAM。web.www.sramsun.com  QQ3161422826 TEL:13751192923
 
 

Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list