本文整理汇总了C++中DMA_Cmd函数的典型用法代码示例。如果您正苦于以下问题:C++ DMA_Cmd函数的具体用法?C++ DMA_Cmd怎么用?C++ DMA_Cmd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DMA_Cmd函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
/*!< At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
file (startup_stm32l1xx_xx.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32l1xx.c file
*/
/* Preconfiguration before using DAC----------------------------------------*/
DAC_PreConfig();
/* TIM2 Configuration ------------------------------------------------------*/
/* TIM2 Periph clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
/* Time base configuration */
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
TIM_TimeBaseStructure.TIM_Period = 0xFF;
TIM_TimeBaseStructure.TIM_Prescaler = 0x0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
/* TIM2 TRGO selection */
TIM_SelectOutputTrigger(TIM2, TIM_TRGOSource_Update);
/* TIM2 enable counter */
TIM_Cmd(TIM2, ENABLE);
/* Configures Button GPIO and EXTI Line */
STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI);
while (1)
{
/* If the wave form is changed */
if (WaveChange == 1)
{
/* Switch the selected waves forms according the Button status */
if (SelectedWavesForm == 1)
{
/* The sine wave and the escalator wave has been selected */
/* Sine Wave generator ---------------------------------------------*/
DAC_DeInit();
/* DAC channel1 and channel2 Configuration */
DAC_InitStructure.DAC_Trigger = DAC_Trigger_T2_TRGO;
DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
DMA_DeInit(DMA1_Channel3);
DMA_InitStructure.DMA_PeripheralBaseAddr = DAC_DHR12R2_Address;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&Sine12bit;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
DMA_InitStructure.DMA_BufferSize = 32;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel3, &DMA_InitStructure);
/* Enable DMA1 Channel3 */
DMA_Cmd(DMA1_Channel3, ENABLE);
/* DAC Channel2 Init */
DAC_Init(DAC_Channel_2, &DAC_InitStructure);
/* Enable DAC Channel2 */
DAC_Cmd(DAC_Channel_2, ENABLE);
/* Enable DMA for DAC Channel2 */
DAC_DMACmd(DAC_Channel_2, ENABLE);
/* Escalator Wave generator ----------------------------------------*/
/* DAC channel1 Configuration */
DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
DAC_Init(DAC_Channel_1, &DAC_InitStructure);
/* DMA1 channel2 configuration */
DMA_DeInit(DMA1_Channel2);
DMA_InitStructure.DMA_PeripheralBaseAddr = DAC_DHR8R1_Address;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&Escalator8bit;
DMA_InitStructure.DMA_BufferSize = 6;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
DMA_Init(DMA1_Channel2, &DMA_InitStructure);
/* Enable DMA1 Channel2 */
DMA_Cmd(DMA1_Channel2, ENABLE);
/* Enable DAC Channel1: Once the DAC channel1 is enabled, PA.05 is
automatically connected to the DAC converter. */
//.........这里部分代码省略.........
示例2: LM75_ReadConfReg
/**
* @brief Read the configuration register from the LM75.
* @param None
* @retval LM75 configuration register value.
*/
uint8_t LM75_ReadConfReg(void)
{
uint8_t LM75_BufferRX[2] ={0,0};
/* Test on BUSY Flag */
LM75_Timeout = LM75_LONG_TIMEOUT;
while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BUSY))
{
if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
}
/* Configure DMA Peripheral */
LM75_DMA_Config(LM75_DMA_RX, (uint8_t*)LM75_BufferRX, 2);
/* Enable DMA NACK automatic generation */
I2C_DMALastTransferCmd(LM75_I2C, ENABLE);
/* Enable the I2C peripheral */
I2C_GenerateSTART(LM75_I2C, ENABLE);
/* Test on SB Flag */
LM75_Timeout = LM75_FLAG_TIMEOUT;
while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB))
{
if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
}
/* Send device address for write */
I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Transmitter);
/* Test on ADDR Flag */
LM75_Timeout = LM75_FLAG_TIMEOUT;
while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
{
if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
}
/* Send the device's internal address to write to */
I2C_SendData(LM75_I2C, LM75_REG_CONF);
/* Test on TXE FLag (data sent) */
LM75_Timeout = LM75_FLAG_TIMEOUT;
while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_TXE)) && (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF)))
{
if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
}
/* Send START condition a second time */
I2C_GenerateSTART(LM75_I2C, ENABLE);
/* Test on SB Flag */
LM75_Timeout = LM75_FLAG_TIMEOUT;
while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB))
{
if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
}
/* Send LM75 address for read */
I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Receiver);
/* Test on ADDR Flag */
LM75_Timeout = LM75_FLAG_TIMEOUT;
while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))
{
if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
}
/* Enable I2C DMA request */
I2C_DMACmd(LM75_I2C,ENABLE);
/* Enable DMA RX Channel */
DMA_Cmd(LM75_DMA_RX_CHANNEL, ENABLE);
/* Wait until DMA Transfer Complete */
LM75_Timeout = LM75_LONG_TIMEOUT;
while (!DMA_GetFlagStatus(LM75_DMA_RX_TCFLAG))
{
if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
}
/* Send STOP Condition */
I2C_GenerateSTOP(LM75_I2C, ENABLE);
/* Disable DMA RX Channel */
DMA_Cmd(LM75_DMA_RX_CHANNEL, DISABLE);
/* Disable I2C DMA request */
I2C_DMACmd(LM75_I2C,DISABLE);
/* Clear DMA RX Transfer Complete Flag */
DMA_ClearFlag(LM75_DMA_RX_TCFLAG);
/*!< Return Temperature value */
return (uint8_t)LM75_BufferRX[0];
}
示例3: LM75_ShutDown
/**
* @brief Enables or disables the LM75.
* @param NewState: specifies the LM75 new status. This parameter can be ENABLE
* or DISABLE.
* @retval None
*/
uint8_t LM75_ShutDown(FunctionalState NewState)
{
uint8_t LM75_BufferRX[2] ={0,0};
uint8_t LM75_BufferTX = 0;
__IO uint8_t RegValue = 0;
/* Test on BUSY Flag */
LM75_Timeout = LM75_LONG_TIMEOUT;
while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BUSY))
{
if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
}
/* Configure DMA Peripheral */
LM75_DMA_Config(LM75_DMA_RX, (uint8_t*)LM75_BufferRX, 2);
/* Enable DMA NACK automatic generation */
I2C_DMALastTransferCmd(LM75_I2C, ENABLE);
/* Enable the I2C peripheral */
I2C_GenerateSTART(LM75_I2C, ENABLE);
/* Test on SB Flag */
LM75_Timeout = LM75_FLAG_TIMEOUT;
while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB))
{
if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
}
/* Send device address for write */
I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Transmitter);
/* Test on ADDR Flag */
LM75_Timeout = LM75_FLAG_TIMEOUT;
while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
{
if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
}
/* Send the device's internal address to write to */
I2C_SendData(LM75_I2C, LM75_REG_CONF);
/* Test on TXE FLag (data sent) */
LM75_Timeout = LM75_FLAG_TIMEOUT;
while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_TXE)) && (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF)))
{
if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
}
/* Send START condition a second time */
I2C_GenerateSTART(LM75_I2C, ENABLE);
/* Test on SB Flag */
LM75_Timeout = LM75_FLAG_TIMEOUT;
while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB))
{
if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
}
/* Send LM75 address for read */
I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Receiver);
/* Test on ADDR Flag */
LM75_Timeout = LM75_FLAG_TIMEOUT;
while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))
{
if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
}
/* Enable I2C DMA request */
I2C_DMACmd(LM75_I2C,ENABLE);
/* Enable DMA RX Channel */
DMA_Cmd(LM75_DMA_RX_CHANNEL, ENABLE);
/* Wait until DMA Transfer Complete */
LM75_Timeout = LM75_LONG_TIMEOUT;
while (!DMA_GetFlagStatus(LM75_DMA_RX_TCFLAG))
{
if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
}
/* Send STOP Condition */
I2C_GenerateSTOP(LM75_I2C, ENABLE);
/* Disable DMA RX Channel */
DMA_Cmd(LM75_DMA_RX_CHANNEL, DISABLE);
/* Disable I2C DMA request */
I2C_DMACmd(LM75_I2C,DISABLE);
/* Clear DMA RX Transfer Complete Flag */
DMA_ClearFlag(LM75_DMA_RX_TCFLAG);
//.........这里部分代码省略.........
示例4: mpipe_txndef
/* returns the count of bytes still to be transmitted: blocking returns zero */
ot_int mpipe_txndef(ot_u8* data, ot_bool blocking, mpipe_priority data_priority) {
#ifndef RADIO_DEBUG
Twobytes crcval;
ot_int data_length = data[2];
int i;
data_length += 6;
data_two = data[2];
if (data_priority != MPIPE_Ack) {
if (mpipe.state != MPIPE_Idle) {
return -1;
}
mpipe.priority = data_priority;
mpipe.pktbuf = data;
mpipe.pktlen = data_length;
}
data[data_length++] = mpipe.sequence.ubyte[UPPER];
data[data_length++] = mpipe.sequence.ubyte[LOWER];
// no hardware crc16 on this cpu
crcval.ushort = crc_calc_block(data_length, data);
data[data_length++] = crcval.ubyte[UPPER];
data[data_length++] = crcval.ubyte[LOWER];
mpipe.state = MPIPE_Tx_Wait;
if (dma_running) {
for (;;)
asm("nop"); // starting to send when was already sending
}
DMA_DeInit(USART3_TX_DMA_CHANNEL);
UTX_DMA_Init.DMA_BufferSize = (uint16_t)data_length;
//UTX_DMA_Init.DMA_MemoryBaseAddr = (uint32_t)&data[0];
// ? is data on the stack or does it persist after return ? //
if (data_length >= sizeof(mpipe_tx_buf)) {
for (;;)
asm("nop");
}
for (i = 0; i < data_length; i++)
mpipe_tx_buf[i] = data[i];
UTX_DMA_Init.DMA_MemoryBaseAddr = (uint32_t)&mpipe_tx_buf[0];
/*UTX_DMA_Init.DMA_BufferSize = (uint16_t)(sizeof(const_data)-1);
UTX_DMA_Init.DMA_MemoryBaseAddr = (uint32_t)&const_data[0];*/
DMA_Init(USART3_TX_DMA_CHANNEL, &UTX_DMA_Init);
DMA_ClearFlag(DMA1_FLAG_TC2);
DMA_Cmd(USART3_TX_DMA_CHANNEL, ENABLE);
if (blocking == True) {
while (DMA_GetITStatus(DMA1_IT_TC2) == RESET)
asm("nop");
mpipe_txdone();
// always return 0 on success
return 0;
} else {
DMA_ITConfig(USART3_TX_DMA_CHANNEL, DMA_IT_TC, ENABLE);
// return number of bytes being transmitted
dma_running = 1;
return data_length;
}
#endif /* !RADIO_DEBUG */
}
示例5: DMA_I2C1MasterRead
void DMA_I2C1MasterRead(unsigned char device_id, unsigned short mem_byte_addr, unsigned short rx_count, unsigned char *rx_data )
{
unsigned char temp;
unsigned short i;
unsigned char *p;
DMA_InitTypeDef DMA_InitStructure;
p = rx_data;
//I2C_Cmd(I2C1, DISABLE);
I2C_Send7bitAddress(I2C1, 0xA8, I2C_Direction_Transmitter);
I2C_Cmd(I2C1, ENABLE);
//send byte mem addr
temp = ((mem_byte_addr) & 0xff);
I2CTXByte(I2C1,CMD_WRITE,temp); //tx memory addr
while(1)
{
if(I2C_GetITStatus(I2C1, I2C_FLAG_STOP_DET))
{
break;
}
}
//I2C_Cmd(I2C1, DISABLE);
I2C_Send7bitAddress(I2C1, 0xA8, I2C_Direction_Receiver);
I2C_Cmd(I2C1, ENABLE);
DMA_DeInit(DMA1_Channel2);
/*
DMA_InitStructure.DMA_PeripheralBaseAddr = (I2C1_BASE + 0x10);
DMA_InitStructure.DMA_MemoryBaseAddr = 0x20004000;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = rx_count;
DMA_InitStructure.DMA_PeripheralInc = DMA_SrcInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_DstInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
DMA_InitStructure.DMA_Mode = DMA_Mode_Hardware;
DMA_InitStructure.DMA_Priority = DMA_Priority_Low;
DMA_InitStructure.DMA_DST_PER = DST_PER_ACK0;
DMA_InitStructure.DMA_SRC_PER = SRC_PER_ACK7;
*/
DMA_InitStructure.DMA_PeripheralBaseAddr = (I2C1_BASE + 0x10);
DMA_InitStructure.DMA_MemoryBaseAddr =0x20004000;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = rx_count;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Enable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
DMA_InitStructure.DMA_Priority = DMA_Priority_Low;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel2, &DMA_InitStructure);
DMA_Cmd(DMA1_Channel2, ENABLE);
I2C_DMA_DIR = RDMAE_SET;
I2C_DMACmd(I2C1, ENABLE);
for(i=0;i<rx_count;i++)
{
I2C1->IC_DATA_CMD = 0x0100;
while(1)
{
if(I2C_GetITStatus(I2C1, I2C_IT_TX_EMPTY))
{
break;
}
}
}
DMAcheckStatus(DMA1_FLAG_TC2);
DMA_Cmd(DMA1_Channel2, DISABLE);
I2C_DMACmd(I2C1, DISABLE);
//I2C_Cmd(I2C1, DISABLE);
}
示例6: KWPInit
//.........这里部分代码省略.........
// KWP_TX2_EN_ON;
//UART2: Configure USART2 Tx (PA.2) as alternate function push-pull
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
//Configure USART2 Rx (PA.3) as input floating
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
//DMA Init for USART2_RX
// DMA_DeInit(DMA1_Channel6);
// DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)USART2+4;
// DMA_InitStructure.DMA_MemoryBaseAddr = (u32)USART2RxBuf;
// DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
// DMA_InitStructure.DMA_BufferSize = USART2_RX_BUF_SIZE;
// DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
// DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
// DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
// DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
// DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
// DMA_InitStructure.DMA_Priority = DMA_Priority_High;
// DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
// DMA_Init(DMA1_Channel6, &DMA_InitStructure);
//for(i=0;i<10;i++)
//{
// USART2RxBuf[3+i] = 0xae;
//}
//DMA Init for USART3_RX
DMA_DeInit(DMA1_Channel3);
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)USART3+4;
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)USART2RxBuf;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = USART2_RX_BUF_SIZE;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel3, &DMA_InitStructure); //通道3是usart3的接收
//Set USART2_RX to DMA mode
USART_DMACmd(USART3, USART_DMAReq_Rx, ENABLE);
//Start DMA Transfer
DMA_Cmd(DMA1_Channel3, ENABLE);
//Init USART1
USART_ClockInitStructure.USART_Clock = USART_Clock_Disable;
USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;
USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;
USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable;
//Configure the USART2 synchronous paramters
USART_ClockInit(USART3, &USART_ClockInitStructure);
//Configure USART1 basic and asynchronous paramters
USART_InitStructure.USART_BaudRate = KWPBaud;
USART_InitStructure.USART_WordLength = KWPBits;
USART_InitStructure.USART_StopBits = KWPStopBits;
USART_InitStructure.USART_Parity = KWPParity;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART3, &USART_InitStructure);
//Calc count the bit count for a word
bits=1; //Startup bit
if(USART_InitStructure.USART_WordLength==USART_WordLength_8b){
bits+=8;//data_bits + parity_bit
}else{
bits+=9;//data_bits + parity_bit
}
switch(USART_InitStructure.USART_StopBits){
case USART_StopBits_0_5:
bits+=0.5;
break;
case USART_StopBits_1:
bits+=1;
break;
case USART_StopBits_1_5:
bits+=1.5;
break;
case USART_StopBits_2:
bits+=2;
break;
}
KWPOneByteTakeUs=(u32)(
bits * 1000000.0 / (double)USART_InitStructure.USART_BaudRate
+0.5); //四舍五入
//Enable USART3
USART_Cmd(USART3, ENABLE);
}
示例7: usart3_init
void usart3_init(void)
{
/* RCC initialization */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);
/* GPIO initialization */
GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_USART3);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_USART3);
GPIO_InitTypeDef GPIO_InitStruct = {
.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11,
.GPIO_Mode = GPIO_Mode_AF,
.GPIO_Speed = GPIO_Speed_50MHz,
.GPIO_OType = GPIO_OType_PP,
.GPIO_PuPd = GPIO_PuPd_UP
};
GPIO_Init(GPIOC, &GPIO_InitStruct);
/* USART initialization */
USART_InitTypeDef USART_InitStruct = {
.USART_BaudRate = 9600,
.USART_Mode = USART_Mode_Rx | USART_Mode_Tx,
.USART_WordLength = USART_WordLength_8b,
.USART_StopBits = USART_StopBits_1,
.USART_Parity = USART_Parity_No
};
USART_Init(USART3, &USART_InitStruct);
USART_Cmd(USART3, ENABLE);
USART_ClearFlag(USART3, USART_FLAG_TC);
/* DMA initialization */
DMA_ClearFlag(DMA1_Stream4, DMA_FLAG_TCIF4);
}
char usart_getc(void)
{
while(USART_GetFlagStatus(USART3, USART_FLAG_RXNE) != SET);
return USART_ReceiveData(USART3);
}
void usart_puts(uint8_t *datas, int size)
{
DMA_ClearFlag(DMA1_Stream4, DMA_FLAG_TCIF4);
/* Setup the DMA */
DMA_InitTypeDef DMA_InitStructure = {
.DMA_BufferSize = (uint32_t)size,
.DMA_FIFOMode = DMA_FIFOMode_Disable,
.DMA_FIFOThreshold = DMA_FIFOThreshold_Full,
.DMA_MemoryBurst = DMA_MemoryBurst_Single,
.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte,
.DMA_MemoryInc = DMA_MemoryInc_Enable,
.DMA_Mode = DMA_Mode_Normal,
.DMA_PeripheralBaseAddr = (uint32_t)(&USART3->DR),
.DMA_PeripheralBurst = DMA_PeripheralBurst_Single,
.DMA_PeripheralInc = DMA_PeripheralInc_Disable,
.DMA_Priority = DMA_Priority_Medium,
.DMA_Channel = DMA_Channel_7,
.DMA_DIR = DMA_DIR_MemoryToPeripheral,
.DMA_Memory0BaseAddr = (uint32_t)datas
};
DMA_Init(DMA1_Stream4, &DMA_InitStructure);
/* Enable DMA to sent the data */
DMA_Cmd(DMA1_Stream4, ENABLE);
USART_DMACmd(USART3, USART_DMAReq_Tx, ENABLE);
while(DMA_GetFlagStatus(DMA1_Stream4, DMA_FLAG_TCIF4) == RESET);
}
int main()
{
usart3_init();
char *string = "STM32: Hello World!\n\r";
while(1) {
usart_puts(string, strlen(string) + 1);
}
return 0;
}
示例8: main
/**
* @brief Main program.
* @param None
* @retval None
*/
int main(void)
{
/* System Clocks Configuration */
RCC_Configuration();
/* Once the DAC channel is enabled, the corresponding GPIO pin is automatically
connected to the DAC converter. In order to avoid parasitic consumption,
the GPIO pin should be configured in analog */
GPIO_Configuration();
/* TIM2 Configuration */
/* Time base configuration */
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
TIM_TimeBaseStructure.TIM_Period = 0x19;
TIM_TimeBaseStructure.TIM_Prescaler = 0x0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
/* TIM2 TRGO selection */
TIM_SelectOutputTrigger(TIM2, TIM_TRGOSource_Update);
/* DAC channel1 Configuration */
DAC_InitStructure.DAC_Trigger = DAC_Trigger_T2_TRGO;
DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable;
DAC_Init(DAC_Channel_1, &DAC_InitStructure);
/* DAC channel2 Configuration */
DAC_Init(DAC_Channel_2, &DAC_InitStructure);
/* Fill Sine32bit table */
for (Idx = 0; Idx < 32; Idx++)
{
DualSine12bit[Idx] = (Sine12bit[Idx] << 16) + (Sine12bit[Idx]);
}
/* DMA2 channel4 configuration */
DMA_DeInit(DMA2_Channel4);
DMA_InitStructure.DMA_PeripheralBaseAddr = DAC_DHR12RD_Address;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&DualSine12bit;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
DMA_InitStructure.DMA_BufferSize = 32;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA2_Channel4, &DMA_InitStructure);
/* Enable DMA2 Channel4 */
DMA_Cmd(DMA2_Channel4, ENABLE);
/* Enable DAC Channel1: Once the DAC channel1 is enabled, PA.04 is
automatically connected to the DAC converter. */
DAC_Cmd(DAC_Channel_1, ENABLE);
/* Enable DAC Channel2: Once the DAC channel2 is enabled, PA.05 is
automatically connected to the DAC converter. */
DAC_Cmd(DAC_Channel_2, ENABLE);
/* Enable DMA for DAC Channel2 */
DAC_DMACmd(DAC_Channel_2, ENABLE);
/* TIM2 enable counter */
TIM_Cmd(TIM2, ENABLE);
while (1)
{
}
}
示例9: serialUSART1
serialPort_t *uartOpen(USART_TypeDef *USARTx, serialReceiveCallbackPtr callback, uint32_t baudRate, portMode_t mode, portOptions_t options)
{
uartPort_t *s = NULL;
if (USARTx == USART1) {
s = serialUSART1(baudRate, mode, options);
#ifdef USE_USART2
} else if (USARTx == USART2) {
s = serialUSART2(baudRate, mode, options);
#endif
#ifdef USE_USART3
} else if (USARTx == USART3) {
s = serialUSART3(baudRate, mode, options);
#endif
#ifdef USE_USART4
} else if (USARTx == UART4) {
s = serialUSART4(baudRate, mode, options);
#endif
#ifdef USE_USART5
} else if (USARTx == UART5) {
s = serialUSART5(baudRate, mode, options);
#endif
#ifdef USE_USART6
} else if (USARTx == USART6) {
s = serialUSART6(baudRate, mode, options);
#endif
} else {
return (serialPort_t *)s;
}
s->txDMAEmpty = true;
// common serial initialisation code should move to serialPort::init()
s->port.rxBufferHead = s->port.rxBufferTail = 0;
s->port.txBufferHead = s->port.txBufferTail = 0;
// callback works for IRQ-based RX ONLY
s->port.callback = callback;
s->port.mode = mode;
s->port.baudRate = baudRate;
s->port.options = options;
uartReconfigure(s);
// Receive DMA or IRQ
DMA_InitTypeDef DMA_InitStructure;
if (mode & MODE_RX) {
#ifdef STM32F40_41xxx
if (s->rxDMAStream) {
DMA_StructInit(&DMA_InitStructure);
DMA_InitStructure.DMA_PeripheralBaseAddr = s->rxDMAPeripheralBaseAddr;
DMA_InitStructure.DMA_Priority = DMA_Priority_Medium;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable ;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_1QuarterFull ;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single ;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
#else
if (s->rxDMAChannel) {
DMA_StructInit(&DMA_InitStructure);
DMA_InitStructure.DMA_PeripheralBaseAddr = s->rxDMAPeripheralBaseAddr;
DMA_InitStructure.DMA_Priority = DMA_Priority_Medium;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
#endif
DMA_InitStructure.DMA_BufferSize = s->port.rxBufferSize;
#ifdef STM32F40_41xxx
DMA_InitStructure.DMA_Channel = s->rxDMAChannel;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)s->port.rxBuffer;
DMA_DeInit(s->rxDMAStream);
DMA_Init(s->rxDMAStream, &DMA_InitStructure);
DMA_Cmd(s->rxDMAStream, ENABLE);
USART_DMACmd(s->USARTx, USART_DMAReq_Rx, ENABLE);
s->rxDMAPos = DMA_GetCurrDataCounter(s->rxDMAStream);
#else
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)s->port.rxBuffer;
DMA_DeInit(s->rxDMAChannel);
DMA_Init(s->rxDMAChannel, &DMA_InitStructure);
DMA_Cmd(s->rxDMAChannel, ENABLE);
USART_DMACmd(s->USARTx, USART_DMAReq_Rx, ENABLE);
s->rxDMAPos = DMA_GetCurrDataCounter(s->rxDMAChannel);
#endif
} else {
USART_ClearITPendingBit(s->USARTx, USART_IT_RXNE);
USART_ITConfig(s->USARTx, USART_IT_RXNE, ENABLE);
}
}
// Transmit DMA or IRQ
if (mode & MODE_TX) {
#ifdef STM32F40_41xxx
//.........这里部分代码省略.........
示例10: ADC_Config
void ADC_Config( void )
{
DMA_InitTypeDef DMA_InitStruct;
ADC_InitTypeDef ADC_InitStruct;
ADC_CommonInitTypeDef ADC_CommonInitStruct;
GPIO_InitTypeDef GPIO_InitStruct;
/* ADC Clk *******************************************************************/
RCC_ADCCLKConfig(RCC_ADC12PLLCLK_Div2);
ADCx_CLK_ENABLE();
ADCx_DMA_CLK_ENABLE();
/* ADC Pin *******************************************************************/
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStruct.GPIO_Pin = ADCxP_PIN;
GPIO_Init(ADCxP_GPIO_PORT, &GPIO_InitStruct);
GPIO_InitStruct.GPIO_Pin = ADCxN_PIN;
GPIO_Init(ADCxN_GPIO_PORT, &GPIO_InitStruct);
/* ADC DMA *******************************************************************/
DMA_DeInit(ADCx_DMA_CHANNEL);
DMA_InitStruct.DMA_PeripheralBaseAddr = ADCx_DR_ADDRESS;
DMA_InitStruct.DMA_MemoryBaseAddr = (uint32_t)ADC_DMA_ConvBuf;
DMA_InitStruct.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStruct.DMA_BufferSize = ADC_BUF_CHENNAL * ADC_BUF_SIZE;
DMA_InitStruct.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStruct.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStruct.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStruct.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStruct.DMA_Mode = DMA_Mode_Circular;
DMA_InitStruct.DMA_Priority = DMA_Priority_Medium;
DMA_InitStruct.DMA_M2M = DMA_M2M_Disable;
DMA_Init(ADCx_DMA_CHANNEL, &DMA_InitStruct);
DMA_Cmd(ADCx_DMA_CHANNEL, ENABLE);
/* ADC Calibration ***********************************************************/
ADC_VoltageRegulatorCmd(ADCx, ENABLE);
delay_ms(10);
ADC_SelectCalibrationMode(ADCx, ADC_CalibrationMode_Single);
ADC_StartCalibration(ADCx);
while(ADC_GetCalibrationStatus(ADCx) != RESET);
calibrationValue = ADC_GetCalibrationValue(ADCx);
/* ADC Common Init ***********************************************************/
ADC_CommonInitStruct.ADC_Mode = ADC_Mode_Interleave; // ADC_Mode_Independent
ADC_CommonInitStruct.ADC_Clock = ADC_Clock_AsynClkMode;
ADC_CommonInitStruct.ADC_DMAAccessMode = ADC_DMAAccessMode_1;
ADC_CommonInitStruct.ADC_DMAMode = ADC_DMAMode_Circular;
ADC_CommonInitStruct.ADC_TwoSamplingDelay = 0;
ADC_CommonInit(ADCx, &ADC_CommonInitStruct);
/* ADC Init *****************************************************************/
ADC_InitStruct.ADC_ContinuousConvMode = ADC_ContinuousConvMode_Enable;
ADC_InitStruct.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStruct.ADC_ExternalTrigConvEvent = ADC_ExternalTrigConvEvent_0;
ADC_InitStruct.ADC_ExternalTrigEventEdge = ADC_ExternalTrigEventEdge_None;
ADC_InitStruct.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStruct.ADC_OverrunMode = ADC_OverrunMode_Disable;
ADC_InitStruct.ADC_AutoInjMode = ADC_AutoInjec_Disable;
ADC_InitStruct.ADC_NbrOfRegChannel = ADC_BUF_SIZE;
ADC_Init(ADCx, &ADC_InitStruct);
/* ADC Regular Config *******************************************************/
ADC_RegularChannelConfig(ADCx, ADCxP_CHANNEL, 1, ADC_SampleTime_601Cycles5);
ADC_RegularChannelConfig(ADCx, ADCxN_CHANNEL, 2, ADC_SampleTime_601Cycles5);
/* Enable & Start ***********************************************************/
ADC_DMACmd(ADCx, ENABLE);
ADC_Cmd(ADCx, ENABLE);
while(!ADC_GetFlagStatus(ADCx, ADC_FLAG_RDY));
DMA_Cmd(ADCx_DMA_CHANNEL, ENABLE);
ADC_StartConversion(ADCx);
}
示例11: main
/**
* @brief Main program.
* @param None
* @retval None
*/
int main(void)
{
/*!< At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
file (startup_stm32f10x_xx.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f10x.c file
*/
/* System Clocks Configuration */
RCC_Configuration();
/* FSMC for SRAM and SRAM pins configuration */
SRAM_Init();
/* Write to FSMC -----------------------------------------------------------*/
/* DMA2 channel5 configuration */
DMA_DeInit(DMA2_Channel5);
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)SRC_Const_Buffer;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)Bank1_SRAM3_ADDR;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = 32;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Enable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Enable;
DMA_Init(DMA2_Channel5, &DMA_InitStructure);
/* Enable DMA2 channel5 */
DMA_Cmd(DMA2_Channel5, ENABLE);
/* Check if DMA2 channel5 transfer is finished */
while(!DMA_GetFlagStatus(DMA2_FLAG_TC5));
/* Clear DMA2 channel5 transfer complete flag bit */
DMA_ClearFlag(DMA2_FLAG_TC5);
/* Read from FSMC ----------------------------------------------------------*/
/* Destination buffer initialization */
for(Idx=0; Idx<128; Idx++) DST_Buffer[Idx]=0;
/* DMA1 channel3 configuration */
DMA_DeInit(DMA1_Channel3);
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)Bank1_SRAM3_ADDR;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)DST_Buffer;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = 128;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Enable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Enable;
DMA_Init(DMA1_Channel3, &DMA_InitStructure);
/* Enable DMA1 channel3 */
DMA_Cmd(DMA1_Channel3, ENABLE);
/* Check if DMA1 channel3 transfer is finished */
while(!DMA_GetFlagStatus(DMA1_FLAG_TC3));
/* Clear DMA1 channel3 transfer complete flag bit */
DMA_ClearFlag(DMA1_FLAG_TC3);
/* Check if the transmitted and received data are equal */
TransferStatus = Buffercmp(SRC_Const_Buffer, (uint32_t*)DST_Buffer, BufferSize);
/* TransferStatus = PASSED, if the transmitted and received data
are the same */
/* TransferStatus = FAILED, if the transmitted and received data
are different */
while (1)
{
}
}
示例12: DMA_Config
/**
* @brief Configure the DMA controller according to the Stream parameters
* defined in main.h file
* @param None
* @retval None
*/
static void DMA_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
DMA_InitTypeDef DMA_InitStructure;
__IO uint32_t Timeout = TIMEOUT_MAX;
/* Enable DMA clock */
RCC_AHB1PeriphClockCmd(DMA_STREAM_CLOCK, ENABLE);
/* Reset DMA Stream registers (for debug purpose) */
DMA_DeInit(DMA_STREAM);
/* Check if the DMA Stream is disabled before enabling it.
Note that this step is useful when the same Stream is used multiple times:
enabled, then disabled then re-enabled... In this case, the DMA Stream disable
will be effective only at the end of the ongoing data transfer and it will
not be possible to re-configure it before making sure that the Enable bit
has been cleared by hardware. If the Stream is used only once, this step might
be bypassed. */
while (DMA_GetCmdStatus(DMA_STREAM) != DISABLE)
{
}
/* Configure DMA Stream */
DMA_InitStructure.DMA_Channel = DMA_CHANNEL;
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)aSRC_Const_Buffer;
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)aDST_Buffer;
DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToMemory;
DMA_InitStructure.DMA_BufferSize = (uint32_t)BUFFER_SIZE;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Enable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_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(DMA_STREAM, &DMA_InitStructure);
/* Enable DMA Stream Transfer Complete interrupt */
DMA_ITConfig(DMA_STREAM, DMA_IT_TC, ENABLE);
/* DMA Stream enable */
DMA_Cmd(DMA_STREAM, ENABLE);
/* Check if the DMA Stream has been effectively enabled.
The DMA Stream Enable bit is cleared immediately by hardware if there is an
error in the configuration parameters and the transfer is no started (ie. when
wrong FIFO threshold is configured ...) */
Timeout = TIMEOUT_MAX;
while ((DMA_GetCmdStatus(DMA_STREAM) != ENABLE) && (Timeout-- > 0))
{
}
/* Check if a timeout condition occurred */
if (Timeout == 0)
{
/* Manage the error: to simplify the code enter an infinite loop */
while (1)
{
}
}
/* Enable the DMA Stream IRQ Channel */
NVIC_InitStructure.NVIC_IRQChannel = DMA_STREAM_IRQ;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
示例13: Wifi_CheckDMABuff_ForIPDData
IPD_Data Wifi_CheckDMABuff_ForIPDData()
{
currentIPD.Valid = 0;
//if((Millis() - lastDMABuffPoll) >= DMA_Rx_Buff_Poll_Int_ms)
// {
//Probably need to check for new client ({clientNum},CONNECT)
lastDMABuffPoll = Millis();
ESP_IPD_Data_Buffer_Pntr = memmem(USART3_RxBuffer,RxBuffSize,"+IPD",4);
if(ESP_IPD_Data_Buffer_Pntr)
{
//position = DMA_GetCurrDataCounter(DMA1_Channel3);
//position = strlen(USART3_RxBuffer);
//Copy IPD message and data to its own buffer so DMA can go about its business
strcpy(ESP_IPD_DataBuffer,ESP_IPD_Data_Buffer_Pntr);
DMA_Cmd(DMA1_Channel3,DISABLE);
//Wipes the received message from the DMA buffer (using the pointer to the data)
//This makes sure the data doesn't get mistaken for a new request, on the next buffer polling.
ClearArray_Size(ESP_IPD_Data_Buffer_Pntr,strlen(ESP_IPD_Data_Buffer_Pntr));
DMA_Initialize(USART3_RxBuffer, RxBuffSize);
//now we process since DMA isn't going to stomp on us.
currentIPD = ProcessIPD_Data(ESP_IPD_DataBuffer);
//TODO: Need to add a level of error detection/correction as data may be missing the
if(strstr(currentIPD.RequestType, "POST"))
{
//if URI contains dimming (the test for now)
if(strstr(currentIPD.URI, "dimming"))
{
if(strstr(currentIPD.URI, "?"))//If query String is found
{
URI = strtok(currentIPD.URI, "?");
if(strstr(URI,"="))//If URI was sent prepended with a '/' this will be true
{
queryString1 = strtok(URI, "=");
queryValue1 = strtok(NULL, "\0");
}
else
{
queryString1 = strtok(NULL, "=");
if(strstr(currentIPD.URI, "&"))
{
queryValue1 = strtok(NULL, "&");
}
else
{
queryValue1 = strtok(NULL, "\0");
}
}
currentIPD.Valid = 1;
}
dimmingValueToValidate = atoi(queryValue1);
if(dimmingValueToValidate <= 13000)
{
dimmingValue = dimmingValueToValidate;
RefreshCustomRESTResponseDimmer("172.20.112.136", "192.168.4.1", dimmingValue);
//SendRESTResponse(currentIPD.ConnectionNum, RESTResponse_Headers_Test_OK, customRESTResponse);
}
else {
RefreshCustomRESTResponse("172.20.112.136", "192.168.4.1", "dimmingValue", "InvalidValue");
}
currentIPD.Valid = 1;
}
}
//printf("Incoming webrequest\r\n");
}
//DMA_Rx_Buff_Index = strlen(USART3_RxBuffer);
//tstBuff = mempcpy(USART3_RxBuffer_Buffer, USART3_RxBuffer, RxBuffSize);
//DMA_Rx_Buff_Index = tstBuff - &USART3_RxBuffer_Buffer[0];
//tstBuff = memmem(USART3_RxBuffer,sizeof(USART3_RxBuffer),"OK\r\n",4);
//ClearArray_Size(USART3_RxBuffer, sizeof(USART3_RxBuffer));
// }
return currentIPD;
}
示例14: dac1_config
static void dac1_config(void)
{
DAC_InitTypeDef DAC_InitStructure;
DMA_InitTypeDef DMA_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/* DAC channel 1 Configuration */
/*
This line fixed a bug that cost me 5 days, bad wave amplitude
value, and some STM32F4 periph library bugs caused triangle wave
geneartion to be enable resulting in a low level tone on the
SM1000, that we thought was caused by analog issues like layour
or power supply biasing
*/
DAC_StructInit(&DAC_InitStructure);
DAC_InitStructure.DAC_Trigger = DAC_Trigger_T6_TRGO;
DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
DAC_Init(DAC_Channel_1, &DAC_InitStructure);
/* DMA1_Stream5 channel7 configuration **************************************/
/* Table 35 page 219 of the monster data sheet */
DMA_DeInit(DMA1_Stream5);
DMA_InitStructure.DMA_Channel = DMA_Channel_7;
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)DAC_DHR12R1_ADDRESS;
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)dac1_buf;
DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;
DMA_InitStructure.DMA_BufferSize = DAC_BUF_SZ;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(DMA1_Stream5, &DMA_InitStructure);
/* Enable DMA Half & Complete interrupts */
DMA_ITConfig(DMA1_Stream5, DMA_IT_TC | DMA_IT_HT, ENABLE);
/* Enable the DMA Stream IRQ Channel */
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Stream5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Enable DMA1_Stream5 */
DMA_Cmd(DMA1_Stream5, ENABLE);
/* Enable DAC Channel 1 */
DAC_Cmd(DAC_Channel_1, ENABLE);
/* Enable DMA for DAC Channel 1 */
DAC_DMACmd(DAC_Channel_1, ENABLE);
}
示例15: main
/**
* @brief Main program.
* @param None
* @retval None
*/
void main(void)
{
uint8_t arrayindex = 0;
uint8_t index1 = 0, index2 = 0;
ErrorStatus cryptostatus = ERROR;
/* Initialize LEDs mounted on STM8L1528-EVAL board */
STM_EVAL_LEDInit(LED1);
STM_EVAL_LEDInit(LED3);
/****************************************************************************/
/* Encryption phase */
/****************************************************************************/
/* Prepare the buffer to be transferred by DMA: Alternating key and plain text */
while (arrayindex < PLAINTEXT_SIZE * 2)
{
SrcBuffer[arrayindex] = EncryptionKey[index1];
arrayindex++;
SrcBuffer[arrayindex] = PlainText[index2];
arrayindex++;
index1++;
index2++;
if (index1 == 16) index1 = 0;
}
/* DMA configuration to transfer data to/from AES --------------------------*/
/* Enable DMA1 clock */
CLK_PeripheralClockConfig(CLK_Peripheral_DMA1, ENABLE);
/* DMA DeInit */
DMA_GlobalDeInit();
DMA_DeInit(DMA1_Channel0);
DMA_DeInit(DMA1_Channel3);
/* DMA1 channel 0 configuration
Input phase: data transfer from memory "SrcBuffer" to AES_DINR register */
DMA_Init(DMA1_Channel0, (uint16_t)SrcBuffer, AES_DINR_ADDRESS, PLAINTEXT_SIZE * 2,
DMA_DIR_MemoryToPeripheral, DMA_Mode_Normal, DMA_MemoryIncMode_Inc,
DMA_Priority_VeryHigh, DMA_MemoryDataSize_Byte);
/* DMA1 channel 3 configuration
Output phase: data transfer from AES_DOUTR register to memory "CypherText" */
DMA_Init(DMA1_Channel3, (uint16_t)CypherText, AES_DOUTR_ADDRESS, PLAINTEXT_SIZE,
DMA_DIR_PeripheralToMemory, DMA_Mode_Normal, DMA_MemoryIncMode_Inc,
DMA_Priority_VeryHigh, DMA_MemoryDataSize_Byte);
/* DMA1 Channel 0 and channel 3 enable */
DMA_Cmd(DMA1_Channel0, ENABLE);
DMA_Cmd(DMA1_Channel3, ENABLE);
/* DMA1 global enable */
DMA_GlobalCmd(ENABLE);
/* AES configuration to encrypt data using DMA transfer --------------------*/
/* Enable AES clock */
CLK_PeripheralClockConfig(CLK_Peripheral_AES, ENABLE);
/* Select the encryption mode */
AES_OperationModeConfig(AES_Operation_Encryp);
/* Enable using DMA for data transfer */
AES_DMAConfig(AES_DMATransfer_InOut, ENABLE);
/* Enable the AES peripheral: the AES initiates the DMA request */
AES_Cmd(ENABLE);
/* Wait for transfer from AES_DOUTR to memory to be completed */
while (DMA_GetFlagStatus(DMA1_FLAG_TC3) == RESET);
/****************************************************************************/
/* Decryption phase */
/****************************************************************************/
/* Prepare the buffer to be transferred by DMA: Alternating key and cypher text */
arrayindex = 0;
index1 = 0;
index2 = 0;
while (arrayindex < PLAINTEXT_SIZE * 2)
{
SrcBuffer[arrayindex] = EncryptionKey[index1];
arrayindex++;
SrcBuffer[arrayindex] = CypherText[index2];
arrayindex++;
index1++;
index2++;
if (index1 == 16) index1 = 0;
}
/* Disable the AES peripheral to change AES operation mode */
AES_Cmd(DISABLE);
/* DeInit DMA1 channel 3 */
DMA_DeInit(DMA1_Channel3);
/* DMA1 global disable */
DMA_GlobalCmd(DISABLE);
/* DMA1 channel 0 is already configured in Encryption phase
Input phase: data transfer from memory "SrcBuffer" to AES_DINR register */
/* Reconfigure channel 0 counter to start a new transfer */
//.........这里部分代码省略.........