void usart_setup(const usart_dev *dev, uint32_t baudRate, uint16_t wordLength, uint16_t stopBits, uint16_t parity, uint16_t mode, uint16_t hardwareFlowControl) { /* Check the parameters */ assert_param(IS_USART_ALL_PERIPH(dev->USARTx)); assert_param(IS_USART_BAUDRATE(baud)); assert_param(IS_USART_STOPBITS(stopbits)); assert_param(IS_USART_PARITY(parity)); assert_param(IS_USART_WORD_LENGTH(wordLength)); assert_param(IS_USART_MODE(mode)); assert_param(IS_USART_HARDWARE_FLOW_CONTROL(hardwareFlowControl)); memset(dev->state, 0, sizeof(*dev->state)); dev->state->txbusy = 0; dev->state->callback = 0; /* Disable USARTx */ usart_disable(dev); rb_init(dev->txrb, USART_TX_BUF_SIZE, dev->state->tx_buf); rb_init(dev->rxrb, USART_RX_BUF_SIZE, dev->state->rx_buf); /* Enables the USART's 8x oversampling mode. */ USART_OverSampling8Cmd(dev->USARTx, ENABLE); USART_ClockInitTypeDef USART_InitClock; USART_ClockStructInit(&USART_InitClock); USART_ClockInit(dev->USARTx, &USART_InitClock); USART_InitTypeDef USART_config; USART_StructInit(&USART_config); USART_config.USART_BaudRate = baudRate; USART_config.USART_WordLength = wordLength; USART_config.USART_StopBits = stopBits; USART_config.USART_Parity = parity; USART_config.USART_Mode = mode; USART_config.USART_HardwareFlowControl = hardwareFlowControl; USART_Init(dev->USARTx, &USART_config); dev->USARTx->CR1 &= ~(USART_MASK_IDLEIE | USART_MASK_RXNEIE | USART_MASK_TCEIE | USART_MASK_TXEIE | USART_MASK_PEIE); dev->USARTx->CR2 &= ~(USART_MASK2_LBDIE); dev->USARTx->CR3 &= ~(USART_MASK3_CTSIE | USART_MASK3_EIE); if(mode & USART_Mode_Rx) { /* Enable Rx request */ USART_ClearFlag(dev->USARTx, USART_FLAG_RXNE); dev->USARTx->CR1 |= USART_MASK_RXNEIE; } if(mode & USART_Mode_Tx) { USART_ClearFlag(dev->USARTx, USART_FLAG_TC); } enable_nvic_irq(dev->irq, UART_INT_PRIORITY); }
void usart2_Configuration(u32 baudrate) { GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; USART_ClockInitTypeDef USART_ClockInitstructure; /* Enable GPIOA clock */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); /* Enable USART clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);//usart1 is on APB2 at 84Mhz max, usart2,3,6 are on APB1 at 42Mhz max /* Connect PXx to USARTx_Tx*/ GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_USART2); /* Connect PXx to USARTx_Rx*/ GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_USART2); /* Configure USART as alternate function */ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; // Tx Rx GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); USART_OverSampling8Cmd(USART2, ENABLE); USART_InitStructure.USART_BaudRate = baudrate; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; /* USART Clock Initialization */ USART_ClockInitstructure.USART_Clock = USART_Clock_Disable ; USART_ClockInitstructure.USART_CPOL = USART_CPOL_High ; USART_ClockInitstructure.USART_LastBit = USART_LastBit_Disable; USART_ClockInitstructure.USART_CPHA = USART_CPHA_1Edge; /* USART configuration */ USART_Init(USART2, &USART_InitStructure); USART_ClockInit(USART2, &USART_ClockInitstructure); /* Enable USART */ USART_Cmd(USART2, ENABLE); }
void serialOpenUART(serialPort_t *s) { USART_InitTypeDef USART_InitStructure; // reduce oversampling to allow for higher baud rates USART_OverSampling8Cmd(s->USARTx, ENABLE); USART_StructInit(&USART_InitStructure); USART_InitStructure.USART_BaudRate = s->baudRate; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = s->stopBits; USART_InitStructure.USART_Parity = s->parity; USART_InitStructure.USART_HardwareFlowControl = s->flowControl; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_Init(s->USARTx, &USART_InitStructure); USART_Cmd(s->USARTx, ENABLE); }
void usart_setup(usart_dev *dev, uint32_t baudRate, uint16_t wordLength, uint16_t stopBits, uint16_t parity, uint16_t mode, uint16_t hardwareFlowControl, uint32_t tx_timeout) { /* Check the parameters */ assert_param(IS_USART_ALL_PERIPH(dev->USARTx)); assert_param(IS_USART_BAUDRATE(baud)); assert_param(IS_USART_STOPBITS(stopbits)); assert_param(IS_USART_PARITY(parity)); assert_param(IS_USART_WORD_LENGTH(wordLength)); assert_param(IS_USART_MODE(mode)); assert_param(IS_USART_HARDWARE_FLOW_CONTROL(hardwareFlowControl)); dev->tx_timeout = tx_timeout; dev->txbusy = 0; dev->usetxrb = 1; dev->use_timeout = 0; /* Disable USARTx */ USART_Cmd(dev->USARTx, DISABLE); /* Enables the USART's 8x oversampling mode. */ USART_OverSampling8Cmd(dev->USARTx, ENABLE); USART_ClockInitTypeDef USART_InitClock; USART_ClockStructInit(&USART_InitClock); USART_ClockInit(dev->USARTx, &USART_InitClock); USART_InitTypeDef USART_config; USART_StructInit(&USART_config); USART_config.USART_BaudRate = baudRate; USART_config.USART_WordLength = wordLength; USART_config.USART_StopBits = stopBits; USART_config.USART_Parity = parity; USART_config.USART_Mode = mode; USART_config.USART_HardwareFlowControl = hardwareFlowControl; USART_Init(dev->USARTx, &USART_config); NVIC_InitTypeDef NVIC_InitStructure; /* Configure the NVIC Preemption Priority Bits */ //NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); /* Enable the USART Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = dev->irq; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); USART_ITConfig(dev->USARTx, USART_IT_PE, DISABLE); USART_ITConfig(dev->USARTx, USART_IT_IDLE, DISABLE); USART_ITConfig(dev->USARTx, USART_IT_LBD, DISABLE); if (IS_USART_1236_PERIPH(dev->USARTx)) USART_ITConfig(dev->USARTx, USART_IT_CTS, DISABLE); USART_ITConfig(dev->USARTx, USART_IT_ERR, DISABLE); /* Enable USART2 Rx request */ USART_ITConfig(dev->USARTx, USART_IT_RXNE, ENABLE); USART_ClearFlag(dev->USARTx, USART_FLAG_RXNE); USART_ITConfig(dev->USARTx, USART_IT_TC, DISABLE); USART_ITConfig(dev->USARTx, USART_IT_TXE, ENABLE); USART_ClearFlag(dev->USARTx, USART_FLAG_TC); /* USART_ITConfig(dev->USARTx, USART_IT_RXNE, ENABLE); USART_ITConfig(dev->USARTx, USART_IT_PE, ENABLE); USART_ITConfig(dev->USARTx, USART_IT_ERR, ENABLE); */ }
/** * @brief Configures the USART Peripheral. * @param None * @retval None */ static void USART_Config(void) { USART_InitTypeDef USART_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; /* Peripheral Clock Enable -------------------------------------------------*/ /* Enable GPIO clock */ RCC_AHB1PeriphClockCmd(USARTx_TX_GPIO_CLK | USARTx_RX_GPIO_CLK, ENABLE); /* Enable USART clock */ USARTx_CLK_INIT(USARTx_CLK, ENABLE); /* Enable the DMA clock */ RCC_AHB1PeriphClockCmd(USARTx_DMAx_CLK, ENABLE); /* USARTx GPIO configuration -----------------------------------------------*/ /* Connect USART pins to AF7 */ GPIO_PinAFConfig(USARTx_TX_GPIO_PORT, USARTx_TX_SOURCE, USARTx_TX_AF); GPIO_PinAFConfig(USARTx_RX_GPIO_PORT, USARTx_RX_SOURCE, USARTx_RX_AF); /* Configure USART Tx and Rx as alternate function push-pull */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Pin = USARTx_TX_PIN; GPIO_Init(USARTx_TX_GPIO_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = USARTx_RX_PIN; GPIO_Init(USARTx_RX_GPIO_PORT, &GPIO_InitStructure); /* USARTx configuration ----------------------------------------------------*/ /* Enable the USART OverSampling by 8 */ USART_OverSampling8Cmd(USARTx, ENABLE); /* USARTx configured as follow: - BaudRate = 5250000 baud - Maximum BaudRate that can be achieved when using the Oversampling by 8 is: (USART APB Clock / 8) Example: - (USART3 APB1 Clock / 8) = (42 MHz / 8) = 5250000 baud - (USART1 APB2 Clock / 8) = (84 MHz / 8) = 10500000 baud - Maximum BaudRate that can be achieved when using the Oversampling by 16 is: (USART APB Clock / 16) Example: (USART3 APB1 Clock / 16) = (42 MHz / 16) = 2625000 baud Example: (USART1 APB2 Clock / 16) = (84 MHz / 16) = 5250000 baud - Word Length = 8 Bits - one Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 5250000; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; /* When using Parity the word length must be configured to 9 bits */ USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_Init(USARTx, &USART_InitStructure); /* Configure DMA controller to manage USART TX and RX DMA request ----------*/ /* Configure DMA Initialization Structure */ DMA_InitStructure.DMA_BufferSize = BUFFERSIZE ; DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable ; DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_1QuarterFull ; DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single ; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; DMA_InitStructure.DMA_PeripheralBaseAddr =(uint32_t) (&(USARTx->DR)) ; DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_Priority = DMA_Priority_High; /* Configure TX DMA */ DMA_InitStructure.DMA_Channel = USARTx_TX_DMA_CHANNEL ; DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral ; DMA_InitStructure.DMA_Memory0BaseAddr =(uint32_t)aTxBuffer ; DMA_Init(USARTx_TX_DMA_STREAM,&DMA_InitStructure); /* Configure RX DMA */ DMA_InitStructure.DMA_Channel = USARTx_RX_DMA_CHANNEL ; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory ; DMA_InitStructure.DMA_Memory0BaseAddr =(uint32_t)aRxBuffer ; DMA_Init(USARTx_RX_DMA_STREAM,&DMA_InitStructure); /* Enable USART */ USART_Cmd(USARTx, ENABLE); }
/** * @brief Configures the USART Peripheral. * @param None * @retval None */ static void USART_Config(void) { USART_InitTypeDef USART_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; /* Peripheral Clock Enable -------------------------------------------------*/ /* Enable GPIO clock */ RCC_AHB1PeriphClockCmd(USARTx_TX_GPIO_CLK | USARTx_RX_GPIO_CLK, ENABLE); /* Enable USART clock */ USARTx_CLK_INIT(USARTx_CLK, ENABLE); /* Enable the DMA clock */ RCC_AHB1PeriphClockCmd(USARTx_DMAx_CLK, ENABLE); /* USARTx GPIO configuration -----------------------------------------------*/ /* Connect USART pins to AF7 */ GPIO_PinAFConfig(USARTx_TX_GPIO_PORT, USARTx_TX_SOURCE, USARTx_TX_AF); GPIO_PinAFConfig(USARTx_RX_GPIO_PORT, USARTx_RX_SOURCE, USARTx_RX_AF); /* Configure USART Tx and Rx as alternate function push-pull */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Pin = USARTx_TX_PIN; GPIO_Init(USARTx_TX_GPIO_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = USARTx_RX_PIN; GPIO_Init(USARTx_RX_GPIO_PORT, &GPIO_InitStructure); /* USARTx configuration ----------------------------------------------------*/ /* Enable the USART OverSampling by 8 */ USART_OverSampling8Cmd(USARTx, ENABLE); /* USARTx configured as follow: - BaudRate = 5250000 baud - Maximum BaudRate that can be achieved when using the Oversampling by 8 is: (USART APB Clock / 8) Example: - (USART3 APB1 Clock / 8) = (42 MHz / 8) = 5250000 baud - (USART1 APB2 Clock / 8) = (84 MHz / 8) = 10500000 baud - Maximum BaudRate that can be achieved when using the Oversampling by 16 is: (USART APB Clock / 16) Example: (USART3 APB1 Clock / 16) = (42 MHz / 16) = 2625000 baud Example: (USART1 APB2 Clock / 16) = (84 MHz / 16) = 5250000 baud - Word Length = 8 Bits - one Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 5250000; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; /* When using Parity the word length must be configured to 9 bits */ USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_Init(USARTx, &USART_InitStructure); /* Configure DMA controller to manage USART TX and RX DMA request ----------*/ DMA_InitStructure.DMA_PeripheralBaseAddr = USARTx_DR_ADDRESS; 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_Normal; DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh; DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable; DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full; DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; /* Here only the unchanged parameters of the DMA initialization structure are configured. During the program operation, the DMA will be configured with different parameters according to the operation phase */ /* Enable USART */ USART_Cmd(USARTx, ENABLE); }
void COMInit(COM_TypeDef COM) { DMA_InitTypeDef DMA_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; USART_InitTypeDef USART_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; /* Enable GPIO clock */ RCC_AHB1PeriphClockCmd(COM_TX_PORT_CLK[COM] | COM_RX_PORT_CLK[COM] | RCC_AHB1Periph_GPIOD, ENABLE); if (COM == USART_COM1) { /* Enable UART clock */ RCC_APB2PeriphClockCmd(COM_USART_CLK[COM], ENABLE); } /* Connect PXx to USARTx_Tx*/ GPIO_PinAFConfig(COM_TX_PORT[COM], COM_TX_PIN_SOURCE[COM], COM_TX_AF[COM]); /* Connect PXx to USARTx_Rx*/ GPIO_PinAFConfig(COM_RX_PORT[COM], COM_RX_PIN_SOURCE[COM], COM_RX_AF[COM]); /* Configure USART Tx as alternate function */ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Pin = COM_TX_PIN[COM]; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(COM_TX_PORT[COM], &GPIO_InitStructure); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Pin = COM_RX_PIN[COM]; GPIO_Init(COM_RX_PORT[COM], &GPIO_InitStructure); /*USART Init code*/ USART_OverSampling8Cmd(COM_USART[COM], ENABLE); USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_Init(COM_USART[COM], &USART_InitStructure); /*USART Interrupt code*/ /*USART TX interrupt*/ NVIC_InitStructure.NVIC_IRQChannel = COM_DMA_TX_IRQn[COM]; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = COM_TX_DMA_PREPRIO[COM]; NVIC_InitStructure.NVIC_IRQChannelSubPriority = COM_TX_DMA_SUBPRIO[COM]; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /*USART RX interrupt*/ NVIC_InitStructure.NVIC_IRQChannel = COM_DMA_RX_IRQn[COM]; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = COM_RX_DMA_PREPRIO[COM]; NVIC_InitStructure.NVIC_IRQChannelSubPriority = COM_RX_DMA_SUBPRIO[COM]; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); RCC_AHB1PeriphClockCmd(COM_DMA_CLK[COM], ENABLE); /*USART TX clean up*/ DMA_ClearFlag(COM_TX_DMA_STREAM[COM], COM_TX_DMA_FLAG_FEIF[COM] | COM_TX_DMA_FLAG_DMEIF[COM] | COM_TX_DMA_FLAG_TEIF[COM] | COM_TX_DMA_FLAG_HTIF[COM] | COM_TX_DMA_FLAG_TCIF[COM]); DMA_Cmd(COM_TX_DMA_STREAM[COM], DISABLE); DMA_DeInit(COM_TX_DMA_STREAM[COM]); /*USART RX Clean up*/ DMA_ClearFlag(COM_RX_DMA_STREAM[COM], COM_RX_DMA_FLAG_FEIF[COM] | COM_RX_DMA_FLAG_DMEIF[COM] | COM_RX_DMA_FLAG_TEIF[COM] | COM_RX_DMA_FLAG_HTIF[COM] | COM_RX_DMA_FLAG_TCIF[COM]); DMA_Cmd(COM_RX_DMA_STREAM[COM], DISABLE); DMA_DeInit(COM_RX_DMA_STREAM[COM]); /*USART TX Config*/ DMA_InitStructure.DMA_Channel = COM_TX_DMA_CHANNEL[COM]; DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t) COM_DR_ADDRESS[COM]; DMA_InitStructure.DMA_Memory0BaseAddr = COM_TX_BUFFER[COM]; /* This parameter will be configured durig communication */ DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; /* This parameter will be configured durig communication */ DMA_InitStructure.DMA_BufferSize = 0xFF; /* This parameter will be configured durig communication */ 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_Normal; DMA_InitStructure.DMA_Priority = DMA_Priority_High; DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable; DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full; DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; DMA_Init(COM_TX_DMA_STREAM[COM], &DMA_InitStructure); //DMA_ITConfig(COM_TX_DMA_STREAM[COM], DMA_IT_TC, ENABLE); /*USART RX Config*/ DMA_InitStructure.DMA_Channel = COM_RX_DMA_CHANNEL[COM]; DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t) COM_DR_ADDRESS[COM]; DMA_InitStructure.DMA_Memory0BaseAddr = COM_RX_BUFFER[COM]; /* This parameter will be configured durig communication */ DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory; /* This parameter will be configured durig communication */ DMA_Init(COM_RX_DMA_STREAM[COM], &DMA_InitStructure); //DMA_ITConfig(COM_RX_DMA_STREAM[COM], DMA_IT_TC, ENABLE); /* Enable USART */ USART_Cmd(COM_USART[COM], ENABLE); }
/*---------------------------------------------------------------------------- Initialize UART pins, Baudrate *----------------------------------------------------------------------------*/ void USART1_Init (void) { USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; /* Enable GPIO clock */ RCC_AHB1PeriphClockCmd(USARTxx_TX_GPIO_CLK | USARTxx_RX_GPIO_CLK, ENABLE); /* Enable USART clock */ USARTxx_CLK_INIT(USARTxx_CLK, ENABLE); /* Connect USART pins to AF7 */ GPIO_PinAFConfig(USARTxx_TX_GPIO_PORT, USARTxx_TX_SOURCE, USARTxx_TX_AF); GPIO_PinAFConfig(USARTxx_RX_GPIO_PORT, USARTxx_RX_SOURCE, USARTxx_RX_AF); /* Configure USART Tx and Rx as alternate function push-pull */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Pin = USARTxx_TX_PIN; GPIO_Init(USARTxx_TX_GPIO_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = USARTxx_RX_PIN; GPIO_Init(USARTxx_RX_GPIO_PORT, &GPIO_InitStructure); /* Enable the USART OverSampling by 8 */ USART_OverSampling8Cmd(USARTxx, ENABLE); /* USARTx configuration ----------------------------------------------------*/ /* USARTx configured as follow: - BaudRate = 5250000 baud - Maximum BaudRate that can be achieved when using the Oversampling by 8 is: (USART APB Clock / 8) Example: - (USART3 APB1 Clock / 8) = (42 MHz / 8) = 5250000 baud - (USART1 APB2 Clock / 8) = (84 MHz / 8) = 10500000 baud - Maximum BaudRate that can be achieved when using the Oversampling by 16 is: (USART APB Clock / 16) Example: (USART3 APB1 Clock / 16) = (42 MHz / 16) = 2625000 baud Example: (USART1 APB2 Clock / 16) = (84 MHz / 16) = 5250000 baud - Word Length = 8 Bits - one Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_Init(USARTxx, &USART_InitStructure); /* NVIC configuration */ /* Configure the Priority Group to 2 bits */ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); /* Enable the USARTx Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = USARTxx_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* Enable USART */ USART_Cmd(USARTxx, ENABLE); USART1->CR1 |= USART_SR_RXNE; }
/*UART1 configuration with DMA----------------------------------------------------------------------*/ void UART1_DMA_CONFIG(uint8_t *TxAddr, uint8_t *RxAddr, uint8_t size, uint32_t baudrate) { USART_InitTypeDef USART_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; DMA_InitTypeDef DMA_InitStructure; //Peripheral Clock Enable RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE); /*-----------------------USART1 GPIO configuration----------------------------*/ //Connect USART pins to AF (TX:PB6) (RX:PB7) GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_USART1); GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_USART1); //Configure USART Tx and Rx as alternate function push-pull (TX:PB6) (RX:PB7) GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOB, &GPIO_InitStructure); /*-----------------------USART1 configuration ------------------------------*/ //Enable the USART OverSampling by 8 USART_OverSampling8Cmd(USART1, ENABLE); /* USART1 configured as follow: - BaudRate = input of functions - Word Length = 8 Bits - One Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and Transmit enabled */ USART_InitStructure.USART_BaudRate = baudrate; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; //When using Parity the word length must be configured to 9 bits USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_Init(USART1, &USART_InitStructure); /*-----Configure DMA controller to manage USART TX and RX DMA request ------*/ //Configure DMA Initialization Structure DMA_InitStructure.DMA_BufferSize = size; DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable ; DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_1QuarterFull ; DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single ; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; DMA_InitStructure.DMA_PeripheralBaseAddr =(uint32_t) (&(USART1->DR)) ; DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_Priority = DMA_Priority_High; //Configure TX DMA DMA_InitStructure.DMA_Channel = DMA_Channel_4 ; DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral ; DMA_InitStructure.DMA_Memory0BaseAddr =(uint32_t)TxAddr ; DMA_Init(DMA2_Stream7, &DMA_InitStructure); //Configure RX DMA DMA_InitStructure.DMA_Channel = DMA_Channel_4 ; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory ; DMA_InitStructure.DMA_Memory0BaseAddr =(uint32_t)RxAddr ; DMA_Init(DMA2_Stream2, &DMA_InitStructure); //Enable USART USART_Cmd(USART1, ENABLE); }/*------------------------------------End of UART1_DMA_CONFIG functions----------------------------*/
// usart_init_ports(void) // Author Francisco Llobet // Use: Initializes ports using available configuration void usart_init_ports(void) { // Setup: // 1- Load configuration settings. // 2- Enable RCC peripheral clock. // 3- Enable GPIO clocks via RCC_AHB1PeriphClockCmd() // 4- Initialize alternate GPIO functions // 5- Run USART_Init(); // 6- Run USART_ClockInit(); for synchronous mode // 7- Run USART_ITConfig(); for interrupt config // 8- DMA_Init() for DMA init and USART_DMACmd() for channel request // 9- Enable USART with USART_Cmd(); // 10- Enable DMA using DMA_Cmd(); // Step 1 usart_init_configuration(); // Loading usart configuration usart_gpio_init_configuration(); // Loading gpio configuration // Step 2 RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); // Enabling clock for eDVS RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6, ENABLE); // Enabling clock for Robot RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); // Enabling clock for USB // Step 3: RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); // DMA init RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE); // Step 4 GPIO_Init(GPIOC, &GPIO_com_robot); // Robot, USART6 GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_USART6); GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_USART6); GPIO_PinAFConfig(GPIOC, GPIO_PinSource8, GPIO_AF_USART6); GPIO_PinAFConfig(GPIOC, GPIO_PinSource9, GPIO_AF_USART6); GPIO_Init(GPIOA, &GPIO_com_edvs); // eDVS, USART1 GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1); GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1); GPIO_PinAFConfig(GPIOA, GPIO_PinSource11, GPIO_AF_USART1); GPIO_PinAFConfig(GPIOA, GPIO_PinSource12, GPIO_AF_USART1); GPIO_Init(GPIOB, &GPIO_com_usb); // USB, USART3 GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_USART3); GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_USART3); GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_USART3); GPIO_PinAFConfig(GPIOB, GPIO_PinSource14, GPIO_AF_USART3); USART_OverSampling8Cmd(USART_ROBOT, ENABLE); // Enabling lower oversampling USART_OverSampling8Cmd(USART_EDVS, ENABLE); // Enabling lower oversampling USART_OverSampling8Cmd(USART_USB, ENABLE); // Enabling lower oversampling // Step 5 USART_Init(USART_USB, &usart_com_usb); // USB USART_Init(USART_EDVS, &usart_com_edvs); // eDVS USART_Init(USART_ROBOT,&usart_com_robot); // Robot // Step 9 START! USART_Cmd(USART_USB, ENABLE); // USB USART_Cmd(USART_EDVS, ENABLE); // eDVS USART_Cmd(USART_ROBOT, ENABLE); // Robot // Configuring interrupt setting USART_ITConfig(USART_USB, USART_IT_RXNE, ENABLE); // Enabling receive Interrupt for USART_USB USART_ITConfig(USART_EDVS, USART_IT_RXNE, ENABLE); // Enabling receive Interrupt for USART_EDVS USART_ITConfig(USART_ROBOT, USART_IT_RXNE, ENABLE); // Enabling receive Interrupt for USART_ROBOT }
//-------------------------------------------------------------- // init aller UARTs //-------------------------------------------------------------- void UB_Uart_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; UART_NAME_t nr; for(nr=0;nr<UART_ANZ;nr++) { // Clock enable der TX und RX Pins RCC_AHB1PeriphClockCmd(UART[nr].TX.CLK, ENABLE); RCC_AHB1PeriphClockCmd(UART[nr].RX.CLK, ENABLE); // Clock enable der UART if((UART[nr].UART==USART1) || (UART[nr].UART==USART6)) { RCC_APB2PeriphClockCmd(UART[nr].CLK, ENABLE); } else { RCC_APB1PeriphClockCmd(UART[nr].CLK, ENABLE); } // UART Alternative-Funktions mit den IO-Pins verbinden GPIO_PinAFConfig(UART[nr].TX.PORT,UART[nr].TX.SOURCE,UART[nr].AF); GPIO_PinAFConfig(UART[nr].RX.PORT,UART[nr].RX.SOURCE,UART[nr].AF); // UART als Alternative-Funktion mit PushPull GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; // TX-Pin GPIO_InitStructure.GPIO_Pin = UART[nr].TX.PIN; GPIO_Init(UART[nr].TX.PORT, &GPIO_InitStructure); // RX-Pin GPIO_InitStructure.GPIO_Pin = UART[nr].RX.PIN; GPIO_Init(UART[nr].RX.PORT, &GPIO_InitStructure); // Oversampling USART_OverSampling8Cmd(UART[nr].UART, ENABLE); // init mit Baudrate, 8Databits, 1Stopbit, keine Paritaet, kein RTS+CTS USART_InitStructure.USART_BaudRate = UART[nr].BAUD; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_Init(UART[nr].UART, &USART_InitStructure); // UART enable USART_Cmd(UART[nr].UART, ENABLE); // RX-Interrupt enable USART_ITConfig(UART[nr].UART, USART_IT_RXNE, ENABLE); // enable UART Interrupt-Vector NVIC_InitStructure.NVIC_IRQChannel = UART[nr].INT; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); // RX-Puffer vorbereiten UART_RX[nr].rx_buffer[0]=RX_END_CHR; UART_RX[nr].wr_ptr=0; UART_RX[nr].rd_ptr=0; UART_RX[nr].status=RX_EMPTY; } }
void VedioBoard_Com3Init(void) { USART_InitTypeDef USART_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; DMA_InitTypeDef DMA_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; /* Peripheral Clock Enable -------------------------------------------------*/ /* Enable GPIO clock */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOB, ENABLE); /* Enable USART clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); /* Enable the DMA clock */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE); /* USART3 GPIO configuration -----------------------------------------------*/ /* Connect USART pins to AF7 */ GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_USART3); GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_USART3); /* Configure USART Tx and Rx as alternate function push-pull */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; GPIO_Init(GPIOB, &GPIO_InitStructure); /* USART3 configuration ----------------------------------------------------*/ /* Enable the USART OverSampling by 8 */ USART_OverSampling8Cmd(USART3, ENABLE); /* USART3 configured as follow: - BaudRate = 5250000 baud - Maximum BaudRate that can be achieved when using the Oversampling by 8 is: (USART APB Clock / 8) Example: - (USART3 APB1 Clock / 8) = (42 MHz / 8) = 5250000 baud - (USART1 APB2 Clock / 8) = (84 MHz / 8) = 10500000 baud - Maximum BaudRate that can be achieved when using the Oversampling by 16 is: (USART APB Clock / 16) Example: (USART3 APB1 Clock / 16) = (42 MHz / 16) = 2625000 baud Example: (USART1 APB2 Clock / 16) = (84 MHz / 16) = 5250000 baud - Word Length = 8 Bits - one Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; /* When using Parity the word length must be configured to 9 bits */ USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_Init(USART3, &USART_InitStructure); /* Configure DMA controller to manage USART TX and RX DMA request ----------*/ /* Configure DMA Initialization Structure */ DMA_InitStructure.DMA_BufferSize = BOARDRXLEN; DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable ; DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_1QuarterFull ; DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single ; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; DMA_InitStructure.DMA_PeripheralBaseAddr =(uint32_t) (&(USART3->DR)) ; DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_Priority = DMA_Priority_High; /* Configure TX DMA */ // DMA_InitStructure.DMA_Channel = DMA_Channel_4 ; // DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral ; // DMA_InitStructure.DMA_Memory0BaseAddr =(uint32_t)BCTxBuffer; // // DMA_Init(DMA1_Stream3,&DMA_InitStructure); /* Configure RX DMA */ DMA_InitStructure.DMA_Channel = DMA_Channel_4 ; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory ; DMA_InitStructure.DMA_Memory0BaseAddr =(uint32_t)BCRxBuffer ; DMA_Init(DMA1_Stream1,&DMA_InitStructure); DMA_ITConfig(DMA1_Stream1, DMA_IT_TC, ENABLE); NVIC_InitStructure.NVIC_IRQChannel = DMA1_Stream1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 5; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* Enable USART */ USART_Cmd(USART3, ENABLE); }
void initUSART(){ /* * Si inizializza una struttura GPIO */ GPIO_InitTypeDef structGPIO; /* * Abilitazione del clock su APB2 -> USART1 */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); /* * Inizializzo la struttura del GPIO * Modalitˆ: AF USART1 * Configurazione: TX ! RX */ structGPIO.GPIO_Mode = GPIO_Mode_AF; structGPIO.GPIO_OType = GPIO_OType_PP; structGPIO.GPIO_Pin = TX_PIN | RX_PIN; structGPIO.GPIO_PuPd = GPIO_PuPd_UP; structGPIO.GPIO_Speed = GPIO_Speed_50MHz; /* * Conferma la configurazione definita sopra */ GPIO_Init(GPIOD,&structGPIO); GPIO_PinAFConfig(GPIOD, TX_PIN_SOURCE, GPIO_AF_USART2); GPIO_PinAFConfig(GPIOD, RX_PIN_SOURCE, GPIO_AF_USART2); /* * Inizializzazione della struttura per la USART */ USART_InitTypeDef USARTInit; /* * Abilitazione del segnale di clock */ /* * Configurazione della periferica USART */ USART_OverSampling8Cmd(USART2, ENABLE); USARTInit.USART_BaudRate = BAUDRATE; USARTInit.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USARTInit.USART_Mode = USART_Mode_Tx | USART_Mode_Rx; //TODO:attenzione USARTInit.USART_Parity = USART_Parity_No; USARTInit.USART_StopBits = USART_StopBits_1; USARTInit.USART_WordLength = USART_WordLength_8b; /* * Conferma della configurazione */ USART_Init(USART2,&USARTInit); USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); /* Inizializzazione della struttura per * l'uso del NVIC */ //NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4); NVIC_InitTypeDef NVIC_Inits; NVIC_Inits.NVIC_IRQChannel = USART1_IRQn; NVIC_Inits.NVIC_IRQChannelCmd = ENABLE; NVIC_Inits.NVIC_IRQChannelPreemptionPriority = 14; //NVIC_Inits.NVIC_IRQChannelSubPriority = 0; NVIC_Init(&NVIC_Inits); USART_Cmd(USART2, ENABLE); }