当前位置: 首页 > news >正文

综合电商网站建设需求文档深圳专业网站建设要求

综合电商网站建设需求文档,深圳专业网站建设要求,网站开发需要服务器吗,直播网站开发接入视频文章目录 GD - EmbeddedBuilder - 用DMA进行串口发送接收#xff0c;支持接收不定长包概述笔记硬件连接图形化配置485EN的配置串口的图形化配置 代码实现main.cgd32f3x0_hal_it.cgd32f3x0_hal_init.cgd32f3x0_hal_init.hgd32f3x0_hal_it.hgd32f3x0_libopt.h 备注END GD - Embe… 文章目录 GD - EmbeddedBuilder - 用DMA进行串口发送接收支持接收不定长包概述笔记硬件连接图形化配置485EN的配置串口的图形化配置 代码实现main.cgd32f3x0_hal_it.cgd32f3x0_hal_init.cgd32f3x0_hal_init.hgd32f3x0_hal_it.hgd32f3x0_libopt.h 备注END GD - EmbeddedBuilder - 用DMA进行串口发送接收支持接收不定长包 概述 看了EmbeddedBuilder_v1.4.1.23782自带的官方例子工程将串口的发送接收的DMA操作摘出来做了个实验细节都弄清楚了。 官方给的demo只演示一个知识点演示的比较简单如果自己不参照官方demo做个实验细节不清楚。 有些细节官方demo也没提到。(e.g. 如何正确判断串口DMA发送完成? 看官方demo, 只能看到进了DMA发送完成回调就算发送完成了。但是自己做了实验才能知道只有串口中断发生时进了DMA发送完成回调才算是发送完成接收方才能收到我们发给上位机的完整回包。如果是在DMA中断时进了发送完成回调算为发送完成就会导致接收方接受的最后一个字节内容错误)。 接收不定长包用到了接收空闲回调。如果本MCU的串口被其他人发了内容在进入接收空闲回调后只要收到的字节数 0, 就可以直接处理了此时收到的东西就是对方发来的整个buffer的内容。 比中断方式一个一个字节的匹配协议效率要高很多。 进了接收空闲回调对方发来的东西就都全了一起来判断协议要方便很多。 串口的收发用了DMA, 可以使一部分工作由DMA硬件自己做减轻MCU的负担, 提高固件运行的速度。 注意在接收空闲回调函数中时这时还是在中断中这时如果直接判断协议并发回包可能让接收方接收的最后一个字节错误. 原因是不方便判断是否DMA发送完成了因为根本等不到发送完成回调函数的执行。 这时可以在接收中断空闲回调中将收到的数据拷贝出来做个接收完成的标记在主循环中判断协议并发送回包。 笔记 硬件连接 MCU端采用GD的UART0的收发 一个GPIO控制485EN. 调试时将保护的那几个TVS拿掉了。485电路外围的电路和元件如下。 图形化配置 将SWD和串口配置上 时钟没改默认的是用内部晶振8MHZ的时钟。 485EN的配置 默认状态为推挽输出下拉。这样默认就是接收状态。 串口的图形化配置 设好通讯参数为115200, 其他默认。 产生UART0中断代码。 收发管脚都用DMA, 通道选挨着的2个通道。TX是从内存到设备RX是从设备到内存。 串口TX/RX的2个GPIO配置为上拉可以防止小信号干扰节省了外接在TX,RX上的2个外部上拉电阻。 代码实现 图形化配置完生成HAL库实现。 在EmbeddedBuilder生成的框架代码中添加自己的代码。自己所有的代码都写在begin x和end x之间防止图形化参数修改后重新生成框架代码时冲掉自己的手写代码。 main.c /*\file main.c*/ /*Copyright (c) 2024, GigaDevice Semiconductor Inc.All rights reserved.Redistribution and use in source and binary forms, with or without modification,are permitted provided that the following conditions are met:1. Redistributions of source code must retain the above copyright notice, thislist of conditions and the following disclaimer.2. Redistributions in binary form must reproduce the above copyright notice,this list of conditions and the following disclaimer in the documentationand/or other materials provided with the distribution.3. Neither the name of the copyright holder nor the names of its contributorsmay be used to endorse or promote products derived from this software withoutspecific prior written permission.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS ISAND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUTNOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, ORPROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITYOF SUCH DAMAGE.*/ #include gd32f3x0_hal.h #include gd32f3x0_hal_init.h /* user code [global 0] begin */#include assert.h // for assert #include stdbool.h // for bool#define ARRAYNUM(arr_nanme) (uint32_t)(sizeof(arr_nanme) / sizeof(*(arr_nanme))) #define TRANSMIT_SIZE (ARRAYNUM(transmitter_buffer) - 1)int g_is_from_DMA_Channel1_2_IRQHandler_1_or_0 0; int g_is_from_USART0_IRQHandler_1_or_0 0;uint8_t transmitter_buffer[256]; // DMA用的发送区char g_need_tx_buffer[0x100]; // 决定发送的内容 bool g_b_can_modify_g_need_tx_buffer true; uint8_t g_need_tx_cnt 0;uint8_t receiver_buffer[256]; __IO uint8_t rx_count 0;__IO FlagStatus tx_end RESET; __IO FlagStatus rx_end RESET;hal_uart_user_callback_struct user_tx_cb; hal_uart_user_callback_struct user_rx_cb;hal_uart_irq_struct irq_struct;void tx_test(int cnt);void rx_idle(void *ptr); void recv_proc(uint8_t *ptr, int cnt);void error_tx_cb(hal_uart_dev_struct *uart); void tx_complete(hal_uart_dev_struct *uart);void error_rx_cb(hal_uart_dev_struct *uart); void rx_complete(hal_uart_dev_struct *uart);/* user code [global 0] end *//*!\brief main function\param[in] none\param[out] none\retval none*/ int main(void) {/* user code [local 0] begin */int test_cnt 0;/* user code [local 0] end */msd_system_init();msd_clock_init();/* user code [local 1] begin *//* user code [local 1] end */msd_gpio_init();msd_dma_init();msd_usart0_init();/* user code [local 2] begin *//* wait IDLEF set and clear it */while (RESET hals_uart_flag_get(USART0, USART_FLAG_IDLE)) {}hals_uart_flag_clear(USART0, USART_FLAG_IDLE);/* enable idle line detected interrupt and callback function */hal_uart_struct_init(HAL_UART_IRQ_INIT_STRUCT, irq_struct);irq_struct.idle_line_detected_handle rx_idle;hal_uart_irq_handle_set(uart0_info, irq_struct);// test GPIO - 485 EN Vhal_gpio_bit_reset(EN_485_GPIO_PORT, EN_485_PIN); // 485接收使能/* receive data using DMA mode */hal_uart_struct_init(HAL_UART_USER_CALLBCAK_STRUCT, user_rx_cb);user_rx_cb.error_func error_rx_cb;user_rx_cb.complete_func rx_complete;hal_uart_receive_dma(uart0_info, receiver_buffer, 256, user_rx_cb);// 如果没开UART0 485接收使能上位机发来东西过?会也能进接收空闲但是没收到东西?hal_uart_struct_init(HAL_UART_USER_CALLBCAK_STRUCT, user_tx_cb);user_tx_cb.error_func error_tx_cb;user_tx_cb.complete_func tx_complete;// 不主动发东西一问一答/* user code [local 2] end */while (1) {/* user code [local 3] begin */hal_sys_basetick_delay_ms(1);// char g_need_tx_buffer[0x100]; // 决定发送的内容// bool g_b_can_modify_g_need_tx_buffer true;// uint8_t g_need_tx_cnt 0;// 串口回包优先if (!g_b_can_modify_g_need_tx_buffer) {// 串口中断已经收到了命令需要处理if (g_need_tx_cnt 0) {// 将第一个字节, 然后回包(假设回包逻辑就是这样的)g_need_tx_buffer[0];hal_gpio_bit_set(EN_485_GPIO_PORT, EN_485_PIN); // 485发送使能tx_end RESET;hal_uart_transmit_dma(uart0_info, g_need_tx_buffer,g_need_tx_cnt, user_tx_cb);// 需要等DMA发送完成。while (RESET tx_end) {};hal_gpio_bit_reset(EN_485_GPIO_PORT, EN_485_PIN); // 485接收使能}// 回包完成g_b_can_modify_g_need_tx_buffer true;g_need_tx_cnt 0;}/* user code [local 3] end */} } /* user code [global 1] begin */ void rx_idle(void *ptr) {hal_uart_dev_struct *temp_ptr (hal_uart_dev_struct*) ptr;/* number of data received */rx_count 256- (hals_dma_transfer_number_get(temp_ptr-p_dma_rx-channel));// hals_dma_transfer_number_config(temp_ptr-p_dma_rx-channel, DMA_CHCNT_RESET_VALUE);rx_end SET;if (rx_count 0) {// disable DMAhal_uart_receive_stop(temp_ptr); // 必须要先停止否则计数和内容还是累计的// 如果不先停止就会出现虚假内容(将上次收到的内容当作这次的收到的内容越来越多)// e.g. 第1次对方发来2个字节, aa bb// 自己也收到aa bb// 但是第2次对方发来3个字节, 11 22 33// 自己收到的却是 aa bb 11 22 33// proc recv data now// recv data ptr receiver_buffer// recv byte cnt rx_countrecv_proc(receiver_buffer, rx_count);}rx_end RESET;// DMA reconfigurehal_uart_receive_dma(uart0_info, receiver_buffer, 256, user_rx_cb); }void safe_copy(uint8_t *ptr, int cnt) {int cpy_len ((sizeof(g_need_tx_buffer) cnt) ? cnt : sizeof(g_need_tx_buffer));memcpy(g_need_tx_buffer, ptr, cpy_len);g_b_can_modify_g_need_tx_buffer false;g_need_tx_cnt cpy_len; }void recv_proc(uint8_t *ptr, int cnt) {// e.g. 回点东西/* transimt data using DMA mode */// sprintf((char*)transmitter_buffer, cnt%d\r\n, cnt);// tx_end RESET;// hal_gpio_bit_set(EN_485_GPIO_PORT, EN_485_PIN); // 485发送使能// hal_uart_transmit_dma(uart0_info, ptr, cnt, user_tx_cb);// 在这里直接等发送完成等不到估计是在中断中的原因// 不过发送已经完成了且上位机已经收到。// 已经实验过了确定不能在接收中断中等发送中断回调中赋值的数据。// 发送完成回调的时机比接收空闲的时机晚// 根本等不到发送完成回调中的变量赋值// while(RESET tx_end) {// }// 对于半双工通讯直接或间接在接收中断中发送内容是有风险的。// 假设就在这里发送那么发送完出了这个函数就切到接收状态了// 有可能导致发送的内容不对(接收方收的内容不对少东西或内容不对)// 接收处理只能将收到的东西存起来或者决定要发什么东西放到g_need_tx_buffer中// 真正发送要在主程序循环中做。if (!g_b_can_modify_g_need_tx_buffer || (g_need_tx_cnt 0)) {// 主程序没处理上一个要发送的内容这次收到的东西只能丢弃了} else {safe_copy(ptr, cnt); // 将接收到的内容给主程序循环处理} }void error_tx_cb(hal_uart_dev_struct *uart) {// 发送错误// printf(\n\rUSART error state: %u\n\r, uart-error_state);// printf(USART last error state: %u\n\r, uart-last_error);assert(false); }void tx_complete(hal_uart_dev_struct *uart) {// 发送完成// 如果不做处理一次发送操作会引起这里会进来2次// 一次是串口DMA中断(先进来)一次是串口普通中断(后进来)。// 从 uart 的内容看不出是DMA来的还是普通串口中断来的// 只能是在进入DMA中断时设置一个标记且这个标记不能是bool, 必须是内建的类型// 否则编译不过(将代码都写在begin x 和 end x之间的标准写法重新配置代码时不会清掉自己手写的代码)if (((hal_uart_dev_struct*) dma_usart0_tx_info.p_periph uart) (1 g_is_from_USART0_IRQHandler_1_or_0)) {// 在发生串口接收空闲中断时必须收到东西(rx bytes cnt 0)才响应(根据收到的命令发点回包给上位机)// 如果没收到东西(或有效内容)就不能给上位机回包。否则可能出现死循环.// 如果是DMA_usart0的完成回调设置发送完标记会导致接收方最后一个字节内容错误。// 所以必须等UART0的完成回调时才能设置发送完的标记。tx_end SET;} }void error_rx_cb(hal_uart_dev_struct *uart) {// 接收错误assert(false); }void rx_complete(hal_uart_dev_struct *uart) { // 接收完成rx_end SET; }/* user code [global 1] end */ gd32f3x0_hal_it.c /*\file gd32f3x0_hal_it.c*/ /*Copyright (c) 2024, GigaDevice Semiconductor Inc.All rights reserved.Redistribution and use in source and binary forms, with or without modification,are permitted provided that the following conditions are met:1. Redistributions of source code must retain the above copyright notice, thislist of conditions and the following disclaimer.2. Redistributions in binary form must reproduce the above copyright notice,this list of conditions and the following disclaimer in the documentationand/or other materials provided with the distribution.3. Neither the name of the copyright holder nor the names of its contributorsmay be used to endorse or promote products derived from this software withoutspecific prior written permission.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS ISAND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUTNOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, ORPROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITYOF SUCH DAMAGE.*/ #include gd32f3x0_hal_it.h #include gd32f3x0_hal.h #include gd32f3x0_hal_init.hvoid NMI_Handler(void) {/* user code [NonMaskableInt_IRQn local 0] begin *//* user code [NonMaskableInt_IRQn local 0] end *//* user code [NonMaskableInt_IRQn local 1] begin *//* user code [NonMaskableInt_IRQn local 1] end */ }void SVC_Handler(void) {/* user code [SVCall_IRQn local 0] begin *//* user code [SVCall_IRQn local 0] end *//* user code [SVCall_IRQn local 1] begin *//* user code [SVCall_IRQn local 1] end */ }void PendSV_Handler(void) {/* user code [PendSV_IRQn local 0] begin *//* user code [PendSV_IRQn local 0] end *//* user code [PendSV_IRQn local 1] begin *//* user code [PendSV_IRQn local 1] end */ }void SysTick_Handler(void) {/* user code [SysTick_IRQn local 0] begin *//* user code [SysTick_IRQn local 0] end */hal_sys_basetick_irq();/* user code [SysTick_IRQn local 1] begin *//* user code [SysTick_IRQn local 1] end */ }void DMA_Channel1_2_IRQHandler(void) {/* user code [DMA_Channel1_2_IRQn local 0] begin */g_is_from_DMA_Channel1_2_IRQHandler_1_or_0 1;/* user code [DMA_Channel1_2_IRQn local 0] end */hal_dma_irq(dma_usart0_tx_info);hal_dma_irq(dma_usart0_rx_info);/* user code [DMA_Channel1_2_IRQn local 1] begin */g_is_from_DMA_Channel1_2_IRQHandler_1_or_0 0;/* user code [DMA_Channel1_2_IRQn local 1] end */ }void USART0_IRQHandler(void) {/* user code [USART0_IRQn local 0] begin */g_is_from_USART0_IRQHandler_1_or_0 1;/* user code [USART0_IRQn local 0] end */hal_uart_irq(uart0_info);g_is_from_USART0_IRQHandler_1_or_0 0;/* user code [USART0_IRQn local 1] begin *//* user code [USART0_IRQn local 1] end */ } gd32f3x0_hal_init.c /*\file gd32f3x0_hal_init.c*/ /*Copyright (c) 2024, GigaDevice Semiconductor Inc.All rights reserved.Redistribution and use in source and binary forms, with or without modification,are permitted provided that the following conditions are met:1. Redistributions of source code must retain the above copyright notice, thislist of conditions and the following disclaimer.2. Redistributions in binary form must reproduce the above copyright notice,this list of conditions and the following disclaimer in the documentationand/or other materials provided with the distribution.3. Neither the name of the copyright holder nor the names of its contributorsmay be used to endorse or promote products derived from this software withoutspecific prior written permission.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS ISAND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUTNOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, ORPROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITYOF SUCH DAMAGE.*/ #include gd32f3x0_hal_init.h /* user code [global 0] begin *//* user code [global 0] end */ hal_uart_dev_struct uart0_info; hal_dma_dev_struct dma_usart0_tx_info; hal_dma_dev_struct dma_usart0_rx_info;void msd_system_init(void) {/* user code [system_init local 0] begin *//* user code [system_init local 0] end */hal_rcu_periph_clk_enable(RCU_CFGCMP);hal_nvic_irq_priority_group_set(NVIC_PRIGROUP_PRE4_SUB0);hal_sys_debug_init(SYS_DEBUG_SERIAL_WIRE);hal_sys_timesource_init(SYS_TIMEBASE_SOURCE_SYSTICK);hal_nvic_set_priority(NonMaskableInt_IRQn, 0, 0);hal_nvic_set_priority(SVCall_IRQn, 0, 0);hal_nvic_set_priority(PendSV_IRQn, 0, 0);hal_nvic_set_priority(SysTick_IRQn, 0, 0);/* user code [system_init local 1] begin *//* user code [system_init local 1] end */ }void msd_clock_init(void) {/* user code [clock_init local 0] begin *//* user code [clock_init local 0] end */hal_rcu_clk_struct rcu_clk_parameter;hal_rcu_osci_struct rcu_osci_parameter;hal_rcu_periphclk_struct rcu_periphclk_parameter;hal_rcu_struct_init(HAL_RCU_CLK_STRUCT, rcu_clk_parameter);hal_rcu_struct_init(HAL_RCU_OSCI_STRUCT, rcu_osci_parameter);hal_rcu_struct_init(HAL_RCU_PERIPHCLK_STRUCT, rcu_periphclk_parameter);rcu_osci_parameter.irc8m.need_configure ENABLE;rcu_osci_parameter.irc8m.state RCU_OSC_ON;rcu_osci_parameter.irc8m.adjust_value 0;/*If IRC48M is selected as USB clock source, please configure CTC calibration operation*/rcu_osci_parameter.irc48m.need_configure ENABLE;rcu_osci_parameter.irc48m.state RCU_OSC_ON;if (HAL_ERR_NONE ! hal_rcu_osci_config(rcu_osci_parameter)) {while (1);}rcu_clk_parameter.clock_type RCU_CLKTYPE_SYSCLK | RCU_CLKTYPE_AHBCLK| RCU_CLKTYPE_APB1CLK | RCU_CLKTYPE_APB2CLK | RCU_CLKTYPE_CK48MCLK;rcu_clk_parameter.sysclk_source RCU_SYSCLK_SRC_IRC8M;rcu_clk_parameter.ahbclk_divider RCU_SYSCLK_AHBDIV1;rcu_clk_parameter.apb1clk_divider RCU_AHBCLK_APB1DIV1;rcu_clk_parameter.apb2clk_divider RCU_AHBCLK_APB2DIV1;rcu_clk_parameter.ck48mclk_source RCU_USB_CK48MSRC_IRC48M;if (HAL_ERR_NONE ! hal_rcu_clock_config(rcu_clk_parameter)) {while (1);}rcu_periphclk_parameter.periph_clock_type RCU_PERIPH_CLKTYPE_USART0;rcu_periphclk_parameter.usart0_clock_source RCU_USART0_CLKSRC_APB2;if (HAL_ERR_NONE ! hal_rcu_periph_clock_config(rcu_periphclk_parameter)) {while (1);}/* user code [clock_init local 1] begin *//* user code [clock_init local 1] end */ }void msd_dma_init(void) {/* user code [dma_init local 0] begin *//* user code [dma_init local 0] end */hal_rcu_periph_clk_enable(RCU_DMA);hal_nvic_irq_enable(DMA_Channel1_2_IRQn, 0, 0);/* user code [dma_init local 1] begin *//* user code [dma_init local 1] end */ }void msd_dma_deinit(void) {/* user code [dma_deinit local 0] begin *//* user code [dma_deinit local 0] end */hal_rcu_periph_clk_disable(RCU_DMA);/* user code [dma_deinit local 1] begin *//* user code [dma_deinit local 1] end */ }void msd_gpio_init(void) {/* user code [gpio_init local 0] begin *//* user code [gpio_init local 0] end */hal_gpio_init_struct gpio_init_parameter;hal_rcu_periph_clk_enable(RCU_GPIOB);hal_rcu_periph_clk_enable(RCU_GPIOA);hal_gpio_struct_init(gpio_init_parameter);hal_gpio_bit_reset(EN_485_GPIO_PORT, EN_485_PIN);gpio_init_parameter.mode GPIO_MODE_OUTPUT_PP;gpio_init_parameter.pull GPIO_PULL_DOWN;gpio_init_parameter.ospeed GPIO_OSPEED_50MHZ;gpio_init_parameter.af GPIO_AF_0;hal_gpio_init(EN_485_GPIO_PORT, EN_485_PIN, gpio_init_parameter);/* user code [gpio_init local 1] begin *//* user code [gpio_init local 1] end */ }void msd_gpio_deinit(void) {/* user code [gpio_deinit local 0] begin *//* user code [gpio_deinit local 0] end */hal_rcu_periph_clk_disable(RCU_GPIOB);hal_rcu_periph_clk_disable(RCU_GPIOA);hal_gpio_deinit(EN_485_GPIO_PORT, EN_485_PIN);/* user code [gpio_deinit local 1] begin *//* user code [gpio_deinit local 1] end */ }void msd_usart0_init(void) {/* user code [usart0_init local 0] begin *//* user code [usart0_init local 0] end */hal_gpio_init_struct gpio_init_parameter;hal_dma_init_struct dma_usart0_tx_init_parameter;hal_dma_init_struct dma_usart0_rx_init_parameter;hal_uart_init_struct uart0_init_parameter;hal_rcu_periph_clk_enable(RCU_USART0);hal_gpio_struct_init(gpio_init_parameter);gpio_init_parameter.mode GPIO_MODE_AF_PP;gpio_init_parameter.pull GPIO_PULL_UP;gpio_init_parameter.ospeed GPIO_OSPEED_50MHZ;gpio_init_parameter.af GPIO_AF_0;hal_gpio_init(UART0_RX_485_GPIO_PORT, UART0_RX_485_PIN,gpio_init_parameter);gpio_init_parameter.mode GPIO_MODE_AF_PP;gpio_init_parameter.pull GPIO_PULL_UP;gpio_init_parameter.ospeed GPIO_OSPEED_50MHZ;gpio_init_parameter.af GPIO_AF_0;hal_gpio_init(UART0_TX_485_GPIO_PORT, UART0_TX_485_PIN,gpio_init_parameter);hal_uart_struct_init(HAL_UART_INIT_STRUCT, uart0_init_parameter);hal_uart_struct_init(HAL_UART_DEV_STRUCT, uart0_info);uart0_init_parameter.work_mode UART_WORK_MODE_ASYN;uart0_init_parameter.baudrate 115200;uart0_init_parameter.parity UART_PARITY_NONE;uart0_init_parameter.word_length UART_WORD_LENGTH_8BIT;uart0_init_parameter.stop_bit UART_STOP_BIT_1;uart0_init_parameter.direction UART_DIRECTION_RX_TX;uart0_init_parameter.over_sample UART_OVER_SAMPLE_16;uart0_init_parameter.sample_method UART_THREE_SAMPLE_BIT;uart0_init_parameter.hardware_flow UART_HARDWARE_FLOW_NONE;uart0_init_parameter.rx_fifo_en DISABLE;uart0_init_parameter.timeout_enable DISABLE;uart0_init_parameter.first_bit_msb DISABLE;uart0_init_parameter.tx_rx_swap DISABLE;uart0_init_parameter.rx_level_invert DISABLE;uart0_init_parameter.tx_level_invert DISABLE;uart0_init_parameter.data_bit_invert DISABLE;uart0_init_parameter.overrun_disable DISABLE;uart0_init_parameter.rx_error_dma_stop DISABLE;uart0_init_parameter.rs485_mode DISABLE;hal_uart_init(uart0_info, USART0, uart0_init_parameter);hal_dma_struct_init(HAL_DMA_INIT_STRUCT, dma_usart0_tx_init_parameter);hal_dma_struct_init(HAL_DMA_DEV_STRUCT, dma_usart0_tx_info);hal_dma_struct_init(HAL_DMA_INIT_STRUCT, dma_usart0_rx_init_parameter);hal_dma_struct_init(HAL_DMA_DEV_STRUCT, dma_usart0_rx_info);dma_usart0_tx_init_parameter.direction DMA_DIR_MEMORY_TO_PERIPH;dma_usart0_tx_init_parameter.periph_inc DISABLE;dma_usart0_tx_init_parameter.memory_inc ENABLE;dma_usart0_tx_init_parameter.periph_width DMA_PERIPH_SIZE_8BITS;dma_usart0_tx_init_parameter.memory_width DMA_MEMORY_SIZE_8BITS;dma_usart0_tx_init_parameter.mode DMA_NORMAL_MODE;dma_usart0_tx_init_parameter.priority DMA_PRIORITY_LEVEL_LOW;hal_dma_init(dma_usart0_tx_info, DMA_CH1, dma_usart0_tx_init_parameter);hal_periph_dma_info_bind(uart0_info, p_dma_tx, dma_usart0_tx_info);dma_usart0_rx_init_parameter.direction DMA_DIR_PERIPH_TO_MEMORY;dma_usart0_rx_init_parameter.periph_inc DISABLE;dma_usart0_rx_init_parameter.memory_inc ENABLE;dma_usart0_rx_init_parameter.periph_width DMA_PERIPH_SIZE_8BITS;dma_usart0_rx_init_parameter.memory_width DMA_MEMORY_SIZE_8BITS;dma_usart0_rx_init_parameter.mode DMA_NORMAL_MODE;dma_usart0_rx_init_parameter.priority DMA_PRIORITY_LEVEL_LOW;hal_dma_init(dma_usart0_rx_info, DMA_CH2, dma_usart0_rx_init_parameter);hal_periph_dma_info_bind(uart0_info, p_dma_rx, dma_usart0_rx_info);hal_nvic_irq_enable(USART0_IRQn, 0, 0);/* user code [usart0_init local 1] begin *//* user code [usart0_init local 1] end */ }void msd_usart0_deinit(void) {/* user code [usart0_deinit local 0] begin *//* user code [usart0_deinit local 0] end */hal_rcu_periph_clk_disable(RCU_USART0);hal_gpio_deinit(UART0_RX_485_GPIO_PORT, UART0_RX_485_PIN);hal_gpio_deinit(UART0_TX_485_GPIO_PORT, UART0_TX_485_PIN);hal_uart_deinit(uart0_info);hal_dma_deinit(dma_usart0_tx_info);hal_dma_deinit(dma_usart0_rx_info);/* user code [usart0_deinit local 1] begin *//* user code [usart0_deinit local 1] end */ }/* user code [global 1] begin *//* user code [global 1] end */ gd32f3x0_hal_init.h /*\file gd32f3x0_hal_init.h*/ /*Copyright (c) 2024, GigaDevice Semiconductor Inc.All rights reserved.Redistribution and use in source and binary forms, with or without modification,are permitted provided that the following conditions are met:1. Redistributions of source code must retain the above copyright notice, thislist of conditions and the following disclaimer.2. Redistributions in binary form must reproduce the above copyright notice,this list of conditions and the following disclaimer in the documentationand/or other materials provided with the distribution.3. Neither the name of the copyright holder nor the names of its contributorsmay be used to endorse or promote products derived from this software withoutspecific prior written permission.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS ISAND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUTNOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, ORPROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITYOF SUCH DAMAGE.*/ #ifndef GD32F3X0_HAL_INIT_H #define GD32F3X0_HAL_INIT_H #include gd32f3x0_hal.h #define UART0_RX_485_GPIO_PORT GPIOB #define EN_485_GPIO_PORT GPIOB #define UART0_RX_485_PIN GPIO_PIN_7 #define UART0_TX_485_GPIO_PORT GPIOB #define UART0_TX_485_PIN GPIO_PIN_6 #define EN_485_PIN GPIO_PIN_5 /* user code [global 0] begin *//* user code [global 0] end */ extern hal_uart_dev_struct uart0_info; extern hal_dma_dev_struct dma_usart0_tx_info; extern hal_dma_dev_struct dma_usart0_rx_info;void msd_system_init(void); void msd_clock_init(void); void msd_dma_init(void); void msd_dma_deinit(void); void msd_gpio_init(void); void msd_gpio_deinit(void); void msd_usart0_init(void); void msd_usart0_deinit(void);/* user code [global 1] begin *//* user code [global 1] end */ #endif gd32f3x0_hal_it.h /*\file gd32f3x0_hal_it.h*/ /*Copyright (c) 2024, GigaDevice Semiconductor Inc.All rights reserved.Redistribution and use in source and binary forms, with or without modification,are permitted provided that the following conditions are met:1. Redistributions of source code must retain the above copyright notice, thislist of conditions and the following disclaimer.2. Redistributions in binary form must reproduce the above copyright notice,this list of conditions and the following disclaimer in the documentationand/or other materials provided with the distribution.3. Neither the name of the copyright holder nor the names of its contributorsmay be used to endorse or promote products derived from this software withoutspecific prior written permission.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS ISAND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUTNOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, ORPROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITYOF SUCH DAMAGE.*/ #ifndef GD32F3X0_HAL_IT_H #define GD32F3X0_HAL_IT_H/* user code [global 0] begin */extern int g_is_from_DMA_Channel1_2_IRQHandler_1_or_0; extern int g_is_from_USART0_IRQHandler_1_or_0; /* user code [global 0] end */void NMI_Handler(void);void SVC_Handler(void);void PendSV_Handler(void);void SysTick_Handler(void);void DMA_Channel1_2_IRQHandler(void);void USART0_IRQHandler(void);/* user code [global 1] begin *//* user code [global 1] end */#endif/*GD32F3X0_HAL_IT_H*/ gd32f3x0_libopt.h /*!\file gd32f3x0_libopt.h\brief HAL library optional for gd32f3x0\version 2023-08-01, V1.0.0, HAL firmware for GD32F3x0*//*Copyright (c) 2023, GigaDevice Semiconductor Inc.Redistribution and use in source and binary forms, with or without modification,are permitted provided that the following conditions are met:1. Redistributions of source code must retain the above copyright notice, thislist of conditions and the following disclaimer.2. Redistributions in binary form must reproduce the above copyright notice,this list of conditions and the following disclaimer in the documentationand/or other materials provided with the distribution.3. Neither the name of the copyright holder nor the names of its contributorsmay be used to endorse or promote products derived from this software withoutspecific prior written permission.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS ISAND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUTNOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, ORPROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITYOF SUCH DAMAGE.*/#ifndef GD32F3X0_LIBOPT_H #define GD32F3X0_LIBOPT_H/* if set, flash operation (write and eraser) will reserve original data locatedin out of targeted scope */ #define FLASH_OPER_RESERVE_ORIGINAL_DATA 0 /* if set, the parameters check will be implemented in function */ #define HAL_PARAMETER_CHECK 0 /* if set, print debug message according to level of marco HAL_DEBUG_PRINTF_LEVELand halt code according to level of marco HAL_DEBUG_HALT_LEVEL */ #define HAL_DEBUG 0#if (1 HAL_DEBUG) #define HAL_DEBUG_PRINTF printf #define HAL_DEBUG_PRINTF_LEVEL HAL_DEBUG_LVL_ALL #define HAL_DEBUG_HALT_LEVEL HAL_DEBUG_LVL_NONE#define HAL_DEBUG_UART USART0 #define HAL_DEBUG_EXTRA_DO #endif /* 1 HAL_DEBUG *//* define value of high speed crystal oscillator (HXTAL) in Hz */ #define HAL_HXTAL_VALUE ((uint32_t)8000000) /*! HXTAL state change timeout (in ms) */ #define HAL_HXTAL_TIMEOUT ((uint32_t)100) /* define value of low speed crystal oscillator (LXTAL)in Hz */ #define HAL_LXTAL_VALUE ((uint32_t)32768) /*! LXTAL state change timeout (in ms) */ #define HAL_LXTAL_TIMEOUT ((uint32_t)5000)#include gd32f3x0_hal_dma.h #include gd32f3x0_hal_fmc.h #include gd32f3x0_hal_pmu.h #include gd32f3x0_hal_dac.h #include gd32f3x0_hal_gpio.h #include gd32f3x0_hal_rcu.h #include gd32f3x0_hal_exti.h #include gd32f3x0_hal_sys.h #include gd32f3x0_hal_syscfg.h #include gd32f3x0_hal_nvic.h #include gd32f3x0_hal_cmp.h #include gd32f3x0_hal_cec.h #include gd32f3x0_hal_crc.h #include gd32f3x0_hal_adc.h #include gd32f3x0_hal_ctc.h #include gd32f3x0_hal_fwdgt.h #include gd32f3x0_hal_tsi.h #include gd32f3x0_hal_wwdgt.h #include gd32f3x0_hal_spi_com.h #include gd32f3x0_hal_spi.h #include gd32f3x0_hal_i2s.h #include gd32f3x0_hal_usart_com.h #include gd32f3x0_hal_uart.h #include gd32f3x0_hal_usrt.h #include gd32f3x0_hal_irda.h #include gd32f3x0_hal_smartcard.h #include gd32f3x0_hal_rtc.h #include gd32f3x0_hal_i2c_com.h #include gd32f3x0_hal_i2c.h #include gd32f3x0_hal_smbus.h #include gd32f3x0_hal_timer.h #endif /* GD32F3X0_LIBOPT_H */ 备注 上位机的串口调试助手打开串口后要打开RTS/DTR选项(debug - 串口助手 - 如果不勾选RTS/DTR 不能正常收发)否则不能正确收包导致自己误会自己的固件工程实现或硬件焊接问题。 END
http://www.dnsts.com.cn/news/214328.html

相关文章:

  • 织梦做双语版网站网站建设中故障排除方法
  • 广电如何做视频网站网站怎样盈利
  • 建网站最低需要多少钱深圳优化公司公认安高粱seo
  • 教育网站解决方案网站建设小程序开发公司
  • 做设计的兼职网站深圳平台设计
  • ppt要怎么做网站wordpress 虾米页面
  • 江苏德丰建设集团网站wordpress wood3主题
  • 芜湖有哪些招聘网站做海报的素材哪个网站
  • 嘉兴网站建设电话平台网站建设 厦门
  • 安徽建站之星国内app开发公司
  • 顺德公益网站制作如何做英文网站的中文网
  • 网站界面设计说明天眼企查查网官网
  • 做链接哪个网站好广州市开发区建设局官方网站
  • 站长统计app官方网站去什么网站找做电影的素材
  • 免费网站安全软件下载电商平台网站多少钱
  • 如何提高网站seo排名wordpress ajax查询文章
  • 导航网站后台源码建设企业网站管理系统目的
  • 建设银行企业网站无法打印回单平潭综合实验区建设局网站
  • 网站制作套餐wordpress+防止采集
  • 域名被墙检测网站嘉鱼网站建设
  • 住房和城乡建设部网站 投诉哪个淘宝客网站最好
  • 网站验证码文件常州网站开发培训价格
  • 手机网站自动跳转做图表的网站知乎
  • 网站关键词优化到首页难度wordpress首页图片幻灯片播放
  • 做网站 花园路国贸下载网页图片
  • html5国外网站模板html源码下载微信会员卡管理系统怎么开通
  • 官方网站建设合作协议widgets wordpress怎么建
  • 网站推广公司经理职责代做网页设计平台
  • 湖州住房建设部网站没有网站做分类信息群发
  • vps服务器怎么创建多个网站wordpress加载图片慢