DMA中配置内存地址时,DMA_InitStructure.DMA_MemoryBaseAddr =(u32)RxBuff; ----其中的RxBuff为unsigned int类型。我希望使用malloc函数分配一个内存块,来存储从网络上下载的数据。将malloc返回的指针赋给内存地址,一直报错。
到底哪里出问题了啊,请指教
void USART2_DMA_Config(u32 *RxBuff)
{
// RxBuff=(u32 *)malloc(1024);
DMA_InitTypeDef DMA_InitStructure;
/*开启DMA时钟*/
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
/*设置DMA源:串口数据寄存器地址*/
DMA_InitStructure.DMA_PeripheralBaseAddr = ( u32 ) ( & ( USART2->DR ) );
/*内存地址(要传输的变量的指针)*/
// DMA_InitStructure.DMA_MemoryBaseAddr = (u32)SendBuff;
DMA_InitStructure.DMA_MemoryBaseAddr = RxBuff;
/*方向:从外设到内存*/
// DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
/*传输大小DMA_BufferSize=SENDBUFF_SIZE*/
// DMA_InitStructure.DMA_BufferSize = SENDBUFF_SIZE;
// DMA_InitStructure.DMA_BufferSize = RxBUFF_SIZE;
DMA_InitStructure.DMA_BufferSize = 1;
/*外设地址不增*/
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
/*内存地址自增*/
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
// DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;
/*外设数据单位*/
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
/*内存数据单位 8bit*/
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
/*DMA模式:不断循环*/
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal ;//正常缓存模式
// DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
/*优先级:中*/
DMA_InitStructure.DMA_Priority = DMA_Priority_Medium;
/*禁止内存到内存的传输 */
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
/*配置DMA1的4通道*/
// DMA_Init(DMA1_Channel4, &DMA_InitStructure);
DMA_Init(DMA1_Channel6, &DMA_InitStructure);
/*使能DMA*/
// DMA_Cmd (DMA1_Channel6,ENABLE);
// DMA_Cmd (DMA1_Channel6,ENABLE);
//DMA_ITConfig(DMA1_Channel4,DMA_IT_TC,ENABLE); //配置DMA发送完成后产生中断
}
void Web_To_ESP(void)
{
u32 *mem_address=NULL;
// bool state;
mem_address=(u32 *)malloc(1024);
USART2_DMA_Config(mem_address);
// do
// {
// strEsp8266_Fram_Record .InfBit .FramLength = 0; //从新开始接收新的数据包
// ESP8266_Usart ( "%s\r\n", "AT+CIPSTART=\"TCP\",\"eat.weixincore.com\",80" );
// Delay_ms ( 500); //延时
// strEsp8266_Fram_Record .Data_RX_BUF [ strEsp8266_Fram_Record .InfBit .FramLength ] = '\0';
// PC_Usart ( "%s", strEsp8266_Fram_Record .Data_RX_BUF );
// state= ( bool ) strstr ( strEsp8266_Fram_Record .Data_RX_BUF, "OK" )||( bool ) strstr ( strEsp8266_Fram_Record .Data_RX_BUF, "ALREAY CONNECT" )||
// (!( bool ) strstr ( strEsp8266_Fram_Record .Data_RX_BUF, "ERROR" ));
//
// }
// while(state==false);
ESP8266_Link_Server ( enumTCP, "eat.weixincore.com", "80", Single_ID ) ; //此处连接服务器3次,需要优化,但是如果用while,又卡死
ESP8266_Link_Server ( enumTCP, "eat.weixincore.com", "80", Single_ID );
ESP8266_Link_Server ( enumTCP, "eat.weixincore.com", "80", Single_ID );
ESP8266_Cmd ( "AT+CIPMODE=1", "OK", 0, 500 ); //0,非透传;1,透传
ESP8266_Cmd ( "AT+CIPSEND", "\r\n", ">", 500 );
ESP8266_SendString ( ENABLE, "GET /index.php?s=/Mobile/PrinterTest/index HTTP/1.1\r\n", NULL, Single_ID );
ESP8266_SendString ( ENABLE, "Host: eat.weixincore.com\r\n", NULL, Single_ID );
ESP8266_SendString ( ENABLE, "User-Agent: abc\r\n", NULL, Single_ID );
ESP8266_SendString ( ENABLE, "Connection: close\r\n", NULL, Single_ID );
ESP8266_SendString ( ENABLE, "\r\n", NULL, Single_ID );
USART_DMACmd(USART2, USART_DMAReq_Rx, ENABLE);
DMA_Cmd(DMA1_Channel6,ENABLE); /*使能DMA*/
while(1)
{
if(DMA_GetFlagStatus(DMA1_FLAG_TC6)!=RESET) //判断通道6传输完成
{
DMA_ClearFlag(DMA1_FLAG_TC6);//清除通道6传输完成标志
break;
}
}
PC_Usart ( "%s", mem_address );
free(mem_address);
}
在第二个函数中调用DMA配置,打印不出来 |
|