广州做网站的公网站优化排名首页
完整keil5工程自取 链接: https://pan.baidu.com/s/1pYB9YeNisxoEPikemtwDUg 提取码: ni7s
该项目主要是通过串口向STM32单片机传输并存储大文件至外部Flash,如字库、图片和MP3等。在115200波特率下,能够以接近100%的成功率完成接收和存储,但这一前提是必须在文件发送前预先擦除Flash的指定区域。若在接收过程中同时进行擦除和写入操作,会因耗时过长而增加丢包风险。尽管我们设置的4096字节接收缓冲区大小与Flash扇区大小相匹配,理论上能够实现最高效率,但在使用较小的缓冲区如1024或2048字节时,可能会意外触发串口空闲中断,这将导致跨扇区的Flash写入操作。若未预先擦除Flash,工作流程将变得繁琐:首先读取某个扇区的数据,然后擦除并写入该扇区,随后重复此过程至下一个扇区。整个过程耗时较长,影响传输效率。因此,为了优化性能,避免丢包,并减少因串口中断引起的跨扇区写入问题,预先擦除Flash成为了关键步骤。最后在串口空闲1s后判定文件发送完毕。(每写入一次都会判断接收数量跟写入数量是否一致,如果不一致了会提示接收错误,停止存入)
以下是主要的debug串口代码:
debug_usart.h:可以通过宏来更改串口,相应的dma配置,接收文件的话debug_usart_use_rxdma和debug_usart_use_rx_doublebuf一定要置1,表示使用dma接收,和使用双buf接收(这里的双buf接收不是dma配置的双buf,是自己手动切换的,因为尝试配过dma双buf但一直没成功)
#ifndef __DEBUG_USART_H_
#define __DEBUG_USART_H_#include "stm32f4xx.h"
#include "stm32f4xx_conf.h"
#include "stdio.h"
#include "string.h"
#include "user_uart.h"
#include "stdlib.h"
#include "24cxx.h"
#include "flash.h"#define debug_usart_use_rxdma 1 //是否使用dma接收,接收文件需要使用此选项
#define debug_usart_use_rx_doublebuf 1 //是否使用接收双buf,接收文件需要使用此选项
#define debug_usart_use_txdma 0 //是否使用dma发送,可选#define DEBUG_USART USART1
#define DEBUG_USART_TX_PIN_POART GPIOA
#define DEBUG_USART_TX_PIN GPIO_Pin_9
#define DEBUG_USART_RX_PIN_POART GPIOA
#define DEBUG_USART_RX_PIN GPIO_Pin_10#define DEBUG_USART_IRQHandler USART1_IRQHandler/* DMA接收的配置 */
#if debug_usart_use_rxdma
/* DMA2 Stream2 Channel4 */
#define DEBUG_USART_RXDMA_STREAM DMA2_Stream2
#define DEBUG_USART_RXDMA_CLEAR_BIT (DMA_FLAG_TCIF2 | DMA_FLAG_FEIF2 | DMA_FLAG_DMEIF2 | DMA_FLAG_TEIF2 | DMA_FLAG_HTIF2) //数字是stream
#define DEBUG_USART_RXDMA_IT DMA_IT_TCIF2 //数字是stream,传输完成中断
#define DEBUG_USART_RXDMA_IRQHandler DMA2_Stream2_IRQHandler
#if debug_usart_use_rx_doublebuf
#define DEBUG_USART_RXDMA_ARRAY __gp_debug_usart_dma_buf[0]//外设数组地址
#else
#define DEBUG_USART_RXDMA_ARRAY __gp_debug_usart_dma_buf//外设数组地址
#endif
#define DEBUG_USART_RXDMA_ARRAY_LEN DEBUG_USART_REC_LEN
#endif/* DMA发送的配置 */
#if debug_usart_use_txdma
/* DMA2 Stream7 Channel4 */
#define DEBUG_USART_TXDMA_RCC RCC_AHB1Periph_DMA2
#define DEBUG_USART_TXDMA_STREAM DMA2_Stream7
#define DEBUG_USART_TXDMA_CHANNEL DMA_Channel_4
#define DEBUG_USART_TXDMA_IRQN DMA2_Stream7_IRQn
#define DEBUG_USART_TXDMA_IRQHandler DMA2_Stream7_IRQHandler
#define DEBUG_USART_TXDMA_IT DMA_IT_TCIF7 //数字是stream,传输完成中断
#define DEBUG_USART_TXDMA_CLEAR_BIT (DMA_FLAG_TCIF7 | DMA_FLAG_FEIF7 | DMA_FLAG_DMEIF7 | DMA_FLAG_TEIF7 | DMA_FLAG_HTIF7)
#define DEBUG_USART_TXDMA_ARRAY __gp_debug_usart_txdma_buf
#define DEBUG_USART_TXDMA_ARRAY_LEN TX_BUF_LEN
#endif///#define DEBUG_USART_REC_LEN 4096 //定义最大接收字节数
extern uint8_t g_debug_usart_rec_buf[DEBUG_USART_REC_LEN + 1];
extern volatile uint8_t g_debug_usart_rec_flag;
extern uint16_t g_debug_usart_len;
extern uint8_t g_mc66x_usart_send_enable_flag;void Debug_Usart_Init(uint32_t baud);
void Debug_usart_rxd(void);
void debug_usart_dma_send(uint8_t *send_buffer , uint16_t nSendCount);/*=====用户配置(根据自己的分区进行配置)=====*/
#define BootLoader_Size 0x5000U ///< BootLoader的大小 20K
#define Application_Size 0x20000U ///< 应用程序的大小 128K#define Application_1_Addr 0x08020000U ///< 应用程序1的首地址
#define Application_2_Addr 0x08040000U ///< 应用程序2的首地址
/*==========================================*//* 启动的步骤 */
#define Startup_Normol 0xFFFFFFFF ///< 正常启动
#define Startup_Update 0xAAAAAAAA ///< 升级再启动
#define Startup_Reset 0x5555AAAA ///< ***恢复出厂 目前没使用***#define REVCIVE_FILE_IDLE 0
#define REVCIVE_FILE_ING 1
#define REVCIVE_FILE_END 2
#define REVCIVE_FILE_UNSTART 3#endif
debug_usart.c:其中User_usart_init(&debug_usart);是这篇文章里的http://t.csdnimg.cn/QtexL
或者可以直接下载开头的连接获取。按道理来说,只要修改一下flash写入函数就可以直接使用了。
#include "Debug_usart.h"uint8_t g_debug_usart_rec_buf[DEBUG_USART_REC_LEN + 1] = {0};
volatile uint8_t g_debug_usart_rec_flag = 0;
uint16_t g_debug_usart_len = 0;
uint8_t g_mc66x_usart_send_enable_flag = 0;//有些不用4G串口转发就置1
uint8_t g_revcive_file_flag = 0;//判断当前是否已经接收完了
uint8_t g_file_download_flag = 0;//用于判断当前是否处于下载状态
uint32_t g_download_sizecnt = 0;//记录接收数量
uint8_t g_updata_flag = 0;//记录是否可以升级
extern uint16_t g_timcnt_file_download_ms;#if debug_usart_use_rxdma
#if debug_usart_use_rx_doublebuf
static uint8_t __gp_debug_usart_dma_buf[2][DEBUG_USART_RXDMA_ARRAY_LEN];
uint8_t g_debug_usart_doublebuf_index = 0;
#else
static uint8_t __gp_debug_usart_dma_buf[DEBUG_USART_RXDMA_ARRAY_LEN];
#endif
#endif#if debug_usart_use_txdma
#define TX_BUF_LEN 4096
volatile uint8_t g_debug_usart_tx_flag = 0; //判断dma发送是否完成
static uint8_t __gp_debug_usart_txdma_buf[TX_BUF_LEN] = {0}; //dma发送缓冲区
static void debug_usart_tx_dma_init(void);
#endif//重定义fputc函数
int fputc(int ch, FILE * f)
{while((DEBUG_USART->SR & 0X40) == 0); //循环发送,直到发送完毕 DEBUG_USART->DR = (uint8_t) ch;return ch;
}void Debug_Usart_Init(uint32_t baud)
{user_usart_inittypedef debug_usart = {DEBUG_USART, DEBUG_USART_TX_PIN_POART, DEBUG_USART_TX_PIN, DEBUG_USART_RX_PIN_POART, DEBUG_USART_RX_PIN, baud, #if debug_usart_use_rxdma1,DEBUG_USART_RXDMA_ARRAY,DEBUG_USART_RXDMA_ARRAY_LEN,#else0,NULL,0,#endif"\r\ndebug usart"};User_usart_init(&debug_usart);/* DMA发送 */#if debug_usart_use_txdmadebug_usart_tx_dma_init();memset(__gp_debug_usart_txdma_buf, 0, sizeof(__gp_debug_usart_txdma_buf));#endifmemset(g_debug_usart_rec_buf, 0, sizeof(g_debug_usart_rec_buf));
}#if debug_usart_use_txdma
static void debug_usart_tx_dma_init(void)
{DMA_InitTypeDef DMA_InitStructure;USART_DMACmd(DEBUG_USART, USART_DMAReq_Tx, ENABLE); //使能串口的DMA发送RCC_AHB1PeriphClockCmd(DEBUG_USART_TXDMA_RCC, ENABLE); //DMA时钟使能DMA_Cmd(DEBUG_USART_TXDMA_STREAM, DISABLE); while (DMA_GetCmdStatus(DEBUG_USART_TXDMA_STREAM) != DISABLE); //等待DMA可配置DMA_InitStructure.DMA_Channel = DEBUG_USART_TXDMA_CHANNEL; //DMA通道配置DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&DEBUG_USART->DR; //DMA外设地址DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)DEBUG_USART_TXDMA_ARRAY; //发送缓存指针DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; //DMA传输方向:内存--->外设DMA_InitStructure.DMA_BufferSize = DEBUG_USART_TXDMA_ARRAY_LEN; //数据传输字节数量DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //外设非增量模式DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; //存储器增量模式DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; //外设数据长度:8位DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; //存储器数据长度:8位DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; //使用普通模式 DMA_InitStructure.DMA_Priority = DMA_Priority_Medium; //中等优先级 DMA_Priority_HighDMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable; //DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full; //DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; //存储器突发单次传输DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; //外设突发单次传输DMA_Init(DEBUG_USART_TXDMA_STREAM, &DMA_InitStructure); //初始化DMA StreamDMA_Cmd(DEBUG_USART_TXDMA_STREAM, DISABLE); /* DMA空闲(传输完成)中断 */DMA_ITConfig(DEBUG_USART_TXDMA_STREAM, DMA_IT_TC, ENABLE);NVIC_InitTypeDef NVIC_InitStructure;NVIC_InitStructure.NVIC_IRQChannel = DEBUG_USART_TXDMA_IRQN; //串口中断通道NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //抢占优先级0NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //子优先级0NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能NVIC_Init(&NVIC_InitStructure);
}
#endifvoid debug_usart_dma_send(uint8_t *p_send_buffer, uint16_t nSendCount)
{ #if debug_usart_use_txdmaif(nSendCount){uint16_t times = 0;while(nSendCount > DEBUG_USART_TXDMA_ARRAY_LEN){while(g_debug_usart_tx_flag); //等待上一次发送完成g_debug_usart_tx_flag = 1;memcpy(DEBUG_USART_TXDMA_ARRAY, p_send_buffer + times*DEBUG_USART_TXDMA_ARRAY_LEN, DEBUG_USART_TXDMA_ARRAY_LEN);DMA_Cmd(DEBUG_USART_TXDMA_STREAM, DISABLE); //关闭DMA传输while (DMA_GetCmdStatus(DEBUG_USART_TXDMA_STREAM) != DISABLE); //确保DMA可以被设置DMA_SetCurrDataCounter(DEBUG_USART_TXDMA_STREAM, DEBUG_USART_TXDMA_ARRAY_LEN); //数据传输量DMA_Cmd(DEBUG_USART_TXDMA_STREAM, ENABLE); //开启DMA传输times++;nSendCount -= DEBUG_USART_TXDMA_ARRAY_LEN;}while(g_debug_usart_tx_flag); //等待上一次发送完成g_debug_usart_tx_flag = 1;memcpy(DEBUG_USART_TXDMA_ARRAY, p_send_buffer + times*DEBUG_USART_TXDMA_ARRAY_LEN, nSendCount);DMA_Cmd(DEBUG_USART_TXDMA_STREAM, DISABLE); //关闭DMA传输while (DMA_GetCmdStatus(DEBUG_USART_TXDMA_STREAM) != DISABLE); //确保DMA可以被设置DMA_SetCurrDataCounter(DEBUG_USART_TXDMA_STREAM, nSendCount); //数据传输量DMA_Cmd(DEBUG_USART_TXDMA_STREAM, ENABLE);}#else/* 如果一开始使用了txdma,后边不用了,就调用printf */printf("%s", p_send_buffer);#endif
}void DEBUG_USART_IRQHandler(void)
{#if debug_usart_use_rxdmaif(USART_GetITStatus(DEBUG_USART,USART_IT_IDLE) != RESET){//printf("\r\n\r\n\r\n11\r\n\r\n");DMA_Cmd(DEBUG_USART_RXDMA_STREAM, DISABLE); //关闭接收DMA,防止处理其间有数据DEBUG_USART->SR;DEBUG_USART->DR; //清除IDLE标志 USART_ClearITPendingBit(DEBUG_USART, USART_IT_IDLE);//清除标志位 #if debug_usart_use_rx_doublebufif(!g_file_download_flag){g_debug_usart_rec_flag = 1;g_debug_usart_len = DEBUG_USART_RXDMA_ARRAY_LEN - DMA_GetCurrDataCounter(DEBUG_USART_RXDMA_STREAM);if(g_debug_usart_len){memcpy(g_debug_usart_rec_buf, __gp_debug_usart_dma_buf[g_debug_usart_doublebuf_index], g_debug_usart_len);g_debug_usart_rec_buf[g_debug_usart_len] = '\0';}}else{g_timcnt_file_download_ms = 0;g_debug_usart_len = DEBUG_USART_RXDMA_ARRAY_LEN - DMA_GetCurrDataCounter(DEBUG_USART_RXDMA_STREAM);g_download_sizecnt += g_debug_usart_len;g_revcive_file_flag = REVCIVE_FILE_ING;g_debug_usart_doublebuf_index ^= 1;DEBUG_USART_RXDMA_STREAM->M0AR = (uint32_t)__gp_debug_usart_dma_buf[g_debug_usart_doublebuf_index];}#elseg_debug_usart_rec_flag = 1;g_debug_usart_len=DEBUG_USART_RXDMA_ARRAY_LEN - DMA_GetCurrDataCounter(DEBUG_USART_RXDMA_STREAM);if(g_debug_usart_len){memcpy(g_debug_usart_rec_buf, DEBUG_USART_RXDMA_ARRAY, g_debug_usart_len);g_debug_usart_rec_buf[g_debug_usart_len] = '\0';}#endifDMA_SetCurrDataCounter(DEBUG_USART_RXDMA_STREAM, DEBUG_USART_RXDMA_ARRAY_LEN);DMA_ClearFlag(DEBUG_USART_RXDMA_STREAM, DEBUG_USART_RXDMA_CLEAR_BIT);//清除传输完成标志 DMA_Cmd(DEBUG_USART_RXDMA_STREAM, ENABLE);}#elseif (USART_GetITStatus(DEBUG_USART, USART_IT_RXNE) != RESET) {g_debug_usart_rec_buf[g_debug_usart_len++] = USART_ReceiveData(DEBUG_USART); //读取接收到的数据USART_ClearITPendingBit(DEBUG_USART, USART_IT_RXNE); //清除中断标志}if (USART_GetITStatus(DEBUG_USART, USART_IT_IDLE) != RESET) //接收中断(接收到的数据必须是0x0d 0x0a结尾){DEBUG_USART->SR;DEBUG_USART->DR; /* 清除IDLE标志 */g_debug_usart_rec_flag = 1;USART_ClearITPendingBit(DEBUG_USART, USART_IT_IDLE); //清除中断标志}#endif
}#if debug_usart_use_rxdma
void DEBUG_USART_RXDMA_IRQHandler(void)
{if(DMA_GetITStatus(DEBUG_USART_RXDMA_STREAM, DEBUG_USART_RXDMA_IT) != RESET) {DMA_Cmd(DEBUG_USART_RXDMA_STREAM, DISABLE);//关闭DMA DMA_ClearFlag(DEBUG_USART_RXDMA_STREAM, DEBUG_USART_RXDMA_CLEAR_BIT);#if debug_usart_use_rx_doublebufif(!g_file_download_flag){memcpy(g_debug_usart_rec_buf, __gp_debug_usart_dma_buf[g_debug_usart_doublebuf_index], DEBUG_USART_RXDMA_ARRAY_LEN);g_debug_usart_rec_buf[DEBUG_USART_RXDMA_ARRAY_LEN] = '\0';}else{g_timcnt_file_download_ms = 0;g_debug_usart_len = DEBUG_USART_RXDMA_ARRAY_LEN - DMA_GetCurrDataCounter(DEBUG_USART_RXDMA_STREAM);g_download_sizecnt += g_debug_usart_len;g_revcive_file_flag = REVCIVE_FILE_ING;}g_debug_usart_doublebuf_index ^= 1;DEBUG_USART_RXDMA_STREAM->M0AR = (uint32_t)__gp_debug_usart_dma_buf[g_debug_usart_doublebuf_index];#elseg_debug_usart_len = DEBUG_USART_RXDMA_ARRAY_LEN - DMA_GetCurrDataCounter(DEBUG_USART_RXDMA_STREAM);//g_debug_usart_rec_flag = 1;memcpy(g_debug_usart_rec_buf, DEBUG_USART_RXDMA_ARRAY, g_debug_usart_len);g_debug_usart_rec_buf[g_debug_usart_len] = '\0';#endifDMA_SetCurrDataCounter(DEBUG_USART_RXDMA_STREAM, DEBUG_USART_RXDMA_ARRAY_LEN);//设置传输数据长度DMA_Cmd(DEBUG_USART_RXDMA_STREAM, ENABLE);//打开DMA}
}
#endif#if debug_usart_use_txdma
void DEBUG_USART_TXDMA_IRQHandler(void)
{if(DMA_GetITStatus(DEBUG_USART_TXDMA_STREAM, DEBUG_USART_TXDMA_IT) != RESET) {memset(DEBUG_USART_TXDMA_ARRAY, 0, sizeof(DEBUG_USART_TXDMA_ARRAY));DMA_ClearFlag(DEBUG_USART_TXDMA_STREAM, DEBUG_USART_TXDMA_CLEAR_BIT);DMA_Cmd(DEBUG_USART_TXDMA_STREAM, DISABLE); g_debug_usart_tx_flag = 0;}
}
#endif#ifdef STM32F40_41xxx
void system_reset(void)
{INTX_DISABLE();SPI_DeInit(SPI1);RCC_DeInit(); // 复位时钟控制寄存器SYSCFG_DeInit();NVIC_SystemReset(); // 使用CMSIS提供的函数进行系统复位
}
#endif#define DOWNLOAD_UPDATE_FILE 0
#define DOWNLOAD_FONT_FILE 1
#define DOWNLOAD_JPEG_FILE 2#if debug_usart_use_rx_doublebuf
/**
* @brief 文件下载函数
* @param Select:DOWNLOAD_UPDATE_FILE 升级文件DOWNLOAD_FONT_FILE 字库文件DOWNLOAD_JPEG_FILE 图片文件
* @return 0 接收正常(不完全确定) 1 接收不正常
* @note
*/
uint8_t File_Down(uint8_t Select)
{uint8_t index = 0;uint16_t cnt = 0;uint32_t size = 0;uint32_t temp_addr = 0;uint16_t temp_len = 0;printf("erase the flash...\r\n");if(Select == DOWNLOAD_UPDATE_FILE){temp_addr = UPDATE_CODE_ADDR;uint32_t file_size = Application_Size;//大概的文件大小,用来擦除相应的区域printf("start addr:%d(%d sector) - end addr:%d(%d sector)\r\n", temp_addr, temp_addr / 4096, temp_addr + file_size, (temp_addr + file_size)/4096);/* 先擦除程序最大128k的flash */for(uint8_t i = 0; i < file_size/4096; i++){SPI_Flash_Erase_Sector(temp_addr / 4096 + i);}}else if(Select == DOWNLOAD_FONT_FILE){temp_addr = UnicodeGBKList_ADDR;uint32_t file_size = mUnicodeGBKListSize;//大概的文件大小,用来擦除相应的区域printf("start addr:%d(%d sector) - end addr:%d(%d sector)\r\n", temp_addr, temp_addr / 4096, temp_addr + file_size, (temp_addr + file_size)/4096);/* 先擦除88k的flash,字库86k */for(uint8_t i = 0; i < file_size/4096 + 1; i++){SPI_Flash_Erase_Sector(temp_addr / 4096 + i);}}else if(Select == DOWNLOAD_JPEG_FILE){temp_addr = 1000*4096;uint32_t file_size = 2400 * 1024;//大概的文件大小,用来擦除相应的区域printf("start addr:%d(%d sector) - end addr:%d(%d sector)\r\n", temp_addr, temp_addr / 4096, temp_addr + file_size, (temp_addr + file_size)/4096);/* 先擦除2.4M的flash,图片2.4M */for(uint16_t i = 0; i < file_size / 4096; i++){SPI_Flash_Erase_Sector(temp_addr / 4096 + i);}}/以下代码在没理顺之前不要修改///g_revcive_file_flag = REVCIVE_FILE_UNSTART;g_file_download_flag = 1;g_download_sizecnt = 0;g_timcnt_file_download_ms = 0;printf("\r\nwaiting for file ...\r\n");//接收到此消息后发送文件while(1){/* 串口接收空闲1s后判定为接收完成 */if(g_timcnt_file_download_ms > 1000){g_revcive_file_flag = REVCIVE_FILE_END;}switch(g_revcive_file_flag){case REVCIVE_FILE_IDLE:break;//空闲态case REVCIVE_FILE_ING: //传输态{g_revcive_file_flag = REVCIVE_FILE_IDLE;//状态切换 等待下一次进中断再切换成传输态index = g_debug_usart_doublebuf_index ^ 1;temp_len = g_debug_usart_len;/* 暂存下来,以防中途被中断修改 */if(temp_len){SPI_Flash_Write((u8 *)__gp_debug_usart_dma_buf[index], temp_addr, temp_len);size += temp_len;temp_addr += temp_len;}memset(__gp_debug_usart_dma_buf[index], 0, sizeof(__gp_debug_usart_dma_buf[index]));printf("cnt = %d | len = %d | total = %d\r\n", cnt++, temp_len, size);if(g_download_sizecnt != size)//判断进入接收中断次数跟存储次数是否一致{printf("\r\n\r\n---REVCIVE ERROR!!---\r\n\r\n");while(g_timcnt_file_download_ms < 1000) sDelay_ms(1);g_file_download_flag = 0;return 1;}}break;case REVCIVE_FILE_END: //传输完成态{g_file_download_flag = 0;printf("revcive size = %d byte\r\n", g_download_sizecnt);printf("save complete size = %d byte\r\n", size);return 0;}case REVCIVE_FILE_UNSTART: //未开始传输{g_timcnt_file_download_ms = 0;}break;}}
}
#endif#if 1void read_test(void)
{uint8_t testarray[1024];memset(testarray, 0, sizeof(testarray));SPI_Flash_Read(testarray, 1000*4096, sizeof(testarray));for(uint16_t i = 0; i < sizeof(testarray); i++){printf("%02x ", testarray[i]);}
// printf("\r\n");
// for(uint16_t i = 0; i < sizeof(testarray); i++)
// {
// printf("%c", testarray[i]);
// }
}#endifvoid Debug_usart_rxd(void)
{if(0);#if debug_usart_use_rx_doublebufelse if(strncmp((char*)g_debug_usart_rec_buf, "downloadfile", strlen("downloadfile")) == 0){File_Down(DOWNLOAD_JPEG_FILE);}else if(strncmp((char*)g_debug_usart_rec_buf, "read", strlen("read")) == 0){read_test();}#endif#ifdef STM32F40_41xxxelse if(strncmp((char*)g_debug_usart_rec_buf, "sysreset", strlen("sysreset")) == 0){system_reset();}#endif
}
用法:添加以下函数并在主循环里调用就可以了
void User_uart_handle(void)
{if (g_debug_usart_rec_flag) //打印debug串口接收到的数据{g_debug_usart_rec_flag = 0;debug_usart_dma_send("\r\ndebug_usart_rev=", strlen("\r\ndebug_usart_rev="));debug_usart_dma_send(g_debug_usart_rec_buf, g_debug_usart_len);Debug_usart_rxd();fflush(stdout);g_debug_usart_len = 0;memset(g_debug_usart_rec_buf, 0, sizeof(g_debug_usart_rec_buf));}
}