//================================================================================== void vLink_SysTask( void *pvParameters ) { uint8_t sum=0, i=0; static char strk1[mainMAX_MSG_LEN]; static uint8_t k=0; xLCDMessage xMessage; /* Create the semaphore used by the ISR to wake this task. */ for( ;; ) { if( xSemaphoreTake( xUSART_RX_Semaphore, ( TickType_t )5 ) == pdTRUE ) { //printf("%c[1;1f%c[J", 27, 27); //ClearScreen for(i=0; i < mainMAX_MSG_LEN; i++) strk1[i] = 0; sprintf(strk1,"0x%02X 0x%02X 0x%02X k=%d", RX_MHU[0], RX_MHU[1], RX_MHU[2], k); //printf(strk1); xMessage.pcMessage = strk1; xMessage.pos = 0; xMessage.str = 2; /* Send the message to the LCD gatekeeper for display. */ xQueueSend( xLCDQueue, &xMessage, portMAX_DELAY ); k =0; xSemaphoreGive( xUSART_RX_Semaphore ); } else //time out { ++k; //printf("%d",k); //printf("Err! no link!"); xMessage.pcMessage = "Err! no link!"; xMessage.pos = 0; xMessage.str = 2; /* Send the message to the LCD gatekeeper for display. */ xQueueSend( xLCDQueue, &xMessage, portMAX_DELAY ); sum = 3 + 4 + 0xAA; sum = 255 - sum; ++sum; UART_ITConfig(MDR_UART1, UART_IT_RX, DISABLE); RS485_TX_ON; UART1_send_byte(0xAA); UART1_send_byte(3); UART1_send_byte(4); __disable_irq(); UART1_send_byte(sum); RS485_TX_OFF; __enable_irq(); UART_ITConfig(MDR_UART1, UART_IT_RX, ENABLE); } } }
int main() { uint32_t i; /*System clock configuration*/ SystemInit(); // *(volatile uint32_t *)(0x41001014) = 0x0060100; //clock setting 48MHz /* CLK OUT Set */ // PAD_AFConfig(PAD_PA,GPIO_Pin_2, PAD_AF2); // PAD Config - CLKOUT used 3nd Function /*using debugging*/ S_UART_Init(115200); /* UART0 and UART1 configuration*/ UART_StructInit(&UART_InitStructure); /* Configure UART0 */ UART_Init(UART0,&UART_InitStructure); /* Configure UART1 */ UART_Init(UART1,&UART_InitStructure); /* Configure Uart0 Interrupt Enable*/ UART_ITConfig(UART0, (UART_IT_FLAG_TXI|UART_IT_FLAG_RXI),ENABLE); /* NVIC configuration */ NVIC_ClearPendingIRQ(UART0_IRQn); NVIC_EnableIRQ(UART0_IRQn); /* Configure Uart1 Interrupt Enable*/ UART_ITConfig(UART1,(UART_IT_FLAG_TXI|UART_IT_FLAG_RXI),ENABLE); /* NVIC configuration */ NVIC_ClearPendingIRQ(UART1_IRQn); NVIC_EnableIRQ(UART1_IRQn); /*send the data from UART0 to UART1*/ printf("Send UART0\r\n"); for(i=0;i<409600;i++) { UartPutc(UART0,(uint8_t)i); } /*send the data from UART1 to UART0*/ printf("Send UART1\r\n"); for(i=0;i<409600;i++) { UartPutc(UART1,(uint8_t)i); } /*confirm the rx/tx data counter of Uart0,1 using Uart2*/ printf("Press Any Key\r\n"); while( S_UartGetc() != 0 ) { printf("uart0_rx_cnt = %d, uart0_tx_cnt = %d\r\n",uart0_rx_cnt, uart0_tx_cnt); printf("uart1_rx_cnt = %d, uart1_tx_cnt = %d\r\n",uart1_rx_cnt, uart1_tx_cnt); } }
int main(void) { //定义串口初始化结构 UART_InitTypeDef UART_InitStruct1; //初始化系统时钟 使用外部50M晶振 PLL倍频到100M SystemClockSetup(ClockSource_EX50M,CoreClock_100M); DelayInit(); //初始化LED LED_Init(LED_PinLookup_CHKATOM, kNumOfLED); //KBI 初始化 KBI_Init(KBI_PinLookup_CHKATOM, kNumOfKEY); UART_InitStruct1.UARTxMAP = UART4_RX_C14_TX_C15; //UART4模块 映射引脚:PTC14 PTC15 UART_InitStruct1.UART_BaudRate = 115200; //波特率 115200 UART_Init(&UART_InitStruct1); //初始化串口 //开启接收中断 UART_ITConfig(UART4, UART_IT_RDRF, ENABLE); //接通NVIC上对应串口中断线 NVIC_EnableIRQ(UART4_RX_TX_IRQn); //等待串口信息 while(1) { } }
int main(void) { //定义串口初始化结构 UART_InitTypeDef UART_InitStruct1; //初始化系统时钟 使用外部50M晶振 PLL倍频到100M SystemClockSetup(ClockSource_EX50M,CoreClock_100M); DelayInit(); //初始化LED LED_Init(LED_PinLookup_CHKATOM, kNumOfLED); //KBI 初始化 KBI_Init(KBI_PinLookup_CHKATOM, kNumOfKEY); UART_InitStruct1.UARTxMAP = UART4_RX_C14_TX_C15; //UART4模块 映射引脚:PTC14 PTC15 UART_InitStruct1.UART_BaudRate = 115200; //波特率 115200 UART_Init(&UART_InitStruct1); //初始化串口 //开启发送中断功能 UART_ITConfig(UART4,UART_IT_TDRE,ENABLE); //接通NVIC上对应串口中断线 NVIC_EnableIRQ(UART4_RX_TX_IRQn); //开始中断发送 UART_SendDataInt(UART4,gTestBuffer,sizeof(gTestBuffer)); //等待中断发送完成 while(UART_TxIntStruct1.IsComplete == FALSE); while(1) { LED_Toggle(kLED1); DelayMs(500); } }
int32_t uart_putc(uint8_t uartNum, uint8_t ch) { if(uartNum == 0) { if(IS_BUFFER_FULL(u0tx)) { BUFFER_CLEAR(u0tx); return RET_NOK; } else { BUFFER_IN(u0tx) = ch; BUFFER_IN_MOVE(u0tx, 1); UART_ITConfig(UART0,(UART_IT_FLAG_TXI),ENABLE); } } else if(uartNum == 1) { if(IS_BUFFER_FULL(u1tx)) { BUFFER_CLEAR(u1tx); return RET_NOK; } else { UartPutc(UART1,ch); //BUFFER_IN(u1tx) = ch; //BUFFER_IN_MOVE(u1tx, 1); //UART_ITConfig(UART1,(UART_IT_FLAG_TXI),ENABLE); } } return RET_OK; }
void Data_Uart_Init(void) { DMA_InitTypeDef DMA_InitStruct1; UART_DebugPortInit(Data_UARTx_Map,DMAUART_BANDRATE); UART_ITConfig(Data_UARTx,UART_IT_TDRE,ENABLE); UART_DMACmd(Data_UARTx,UART_DMAReq_Tx,ENABLE); DMA_InitStruct1.Channelx = DMA_UART_CHx; //使用DMA0通道 (0-15) DMA_InitStruct1.DMAAutoClose = ENABLE; //传输完毕后自动关闭 DMA_InitStruct1.EnableState = ENABLE; //初始化后不立即开始传输 DMA_InitStruct1.MinorLoopLength = Data_All_Length; //传输次数 DMA_InitStruct1.PeripheralDMAReq = UARTx_TRAN_DMAREQ; //UART 传输完成触发 DMA_InitStruct1.TransferBytes = 1; //每次传输一个字节 //配置目的地址传输参数 DMA_InitStruct1.DestBaseAddr = (uint32_t)DMA_UART_TX_DB; //指向目的地址 DMA_InitStruct1.DestDataSize = DMA_DST_8BIT; //数组为1Byte DMA_InitStruct1.DestMajorInc = 0; //执行一次大循环后 地址不增加 DMA_InitStruct1.DestMinorInc = 0; //每次传输完地址不增加 //配置源地址传输参数 DMA_InitStruct1.SourceBaseAddr = (uint32_t)DMA_UART_TX_SB; DMA_InitStruct1.SourceDataSize = DMA_SRC_8BIT; DMA_InitStruct1.SourceMajorInc = 0; DMA_InitStruct1.SourceMinorInc = 1; DMA_Init(&DMA_InitStruct1); //DMA_ITConfig(DMA0,DMA_IT_MAJOR,DMA_CH5,ENABLE);不启动DMA5中断服务函数 //NVIC_EnableIRQ(DMA5_IRQn); }
int main() { uint32_t i; /*System clock configuration*/ SystemInit(); /*using debugging*/ S_UART_Init(115200); /* UART0 and UART1 configuration*/ UART_StructInit(&UART_InitStructure); /* Configure UART0 */ UART_Init(UART0,&UART_InitStructure); /* Configure UART1 */ UART_Init(UART1,&UART_InitStructure); /* Configure Uart0 Interrupt Enable*/ UART_ITConfig(UART0, (UART_IT_FLAG_TXI|UART_IT_FLAG_RXI),ENABLE); /* NVIC configuration */ NVIC_ClearPendingIRQ(UART0_IRQn); NVIC_EnableIRQ(UART0_IRQn); /* Configure Uart1 Interrupt Enable*/ UART_ITConfig(UART1,(UART_IT_FLAG_TXI|UART_IT_FLAG_RXI),ENABLE); /* NVIC configuration */ NVIC_ClearPendingIRQ(UART1_IRQn); NVIC_EnableIRQ(UART1_IRQn); /*send the data from UART0 to UART1*/ printf("Send UART0\r\n"); for(i=0;i<409600;i++) { UartPutc(UART0,(uint8_t)i); } /*send the data from UART1 to UART0*/ printf("Send UART1\r\n"); for(i=0;i<409600;i++) { UartPutc(UART1,(uint8_t)i); } /*confirm the rx/tx data counter of Uart0,1 using Uart2*/ printf("Press Any Key\r\n"); while( S_UartGetc() != 0 ) { printf("uart0_rx_cnt = %d, uart0_tx_cnt = %d\r\n",uart0_rx_cnt, uart0_tx_cnt); printf("uart1_rx_cnt = %d, uart1_tx_cnt = %d\r\n",uart1_rx_cnt, uart1_tx_cnt); } }
int main() { int32_t ch; /*System clock configuration*/ SystemInit(); /* CLK OUT Set */ // PAD_AFConfig(PAD_PA,GPIO_Pin_2, PAD_AF2); // PAD Config - CLKOUT used 3nd Function /*using debugging*/ S_UART_Init(115200); UART_StructInit(&UART_InitStructure); //UART_Init(UART0,&UART_InitStructure); UART_Init(UART1,&UART_InitStructure); UART_ITConfig(UART0,(UART_IT_FLAG_RXI),ENABLE); UART_ITConfig(UART1,(UART_IT_FLAG_RXI),ENABLE); //UART_FIFO_Enable(UART0,0,4); UART_FIFO_Enable(UART1,0,0); //S_UART_ITConfig(S_UART_CTRL_RXI,ENABLE); /* NVIC configuration */ NVIC_ClearPendingIRQ(UART0_IRQn); NVIC_EnableIRQ(UART0_IRQn); NVIC_ClearPendingIRQ(UART1_IRQn); NVIC_EnableIRQ(UART1_IRQn); while(1) { ch = uart_getc(1); uart_putc(1,(uint8_t)ch); //printf("u1rx_cnt %d\r\n",u1rx_cnt); } }
//================================================================================== void link_PKBA(void) { uint8_t sum=0; PKDU.byte1=(PKDU.StatusKN)&0xFF; PKDU.byte2=((PKDU.StatusKN>>8)&3)|((PKDU.SchowPar<<4)&0xF0); sum=PKDU.byte1+PKDU.byte2+0xAA; sum=255-sum; ++sum; UART_ITConfig(MDR_UART1,UART_IT_RX, DISABLE); RS485_TX_ON; UART1_send_byte(0xAA); UART1_send_byte(PKDU.byte1); UART1_send_byte(PKDU.byte2); __disable_irq(); UART1_send_byte(sum); RS485_TX_OFF; __enable_irq(); UART_ITConfig(MDR_UART1,UART_IT_RX, ENABLE); }
static rt_err_t mm32_uart_control(struct rt_serial_device *serial, int cmd, void *arg) { struct mm32_uart *uart; RT_ASSERT(serial != RT_NULL); uart = (struct mm32_uart *)serial->parent.user_data; switch (cmd) { case RT_DEVICE_CTRL_CLR_INT: /* disable rx irq */ NVIC_DisableIRQ(uart->irq); UART_ITConfig(uart->uart, UART_IT_RXIEN, DISABLE); break; case RT_DEVICE_CTRL_SET_INT: /* enable rx irq */ NVIC_EnableIRQ(uart->irq); /* enable interrupt */ UART_ITConfig(uart->uart, UART_IT_RXIEN, ENABLE); break; } return RT_EOK; }
int main(void) { UART_InitTypeDef UART_InitStruct1; UART_InitStruct1.UARTxMAP= UART0_RX_PA14_TX_PA15; UART_InitStruct1.UART_BaudRate=115200; UART_Init(&UART_InitStruct1); UART_ITConfig(UART0,UART_IT_RDRF, ENABLE); NVIC_EnableIRQ(UART0_RX_TX_IRQn); OLED_Init(); while(1){ //UART_SendData(UART0,1); //OLED_Write_Char(2,2,ch); //UART_SendData(UART0,'x'); //UART_Send_String(UART0,"abcdefg"); } }
//================================================================================== void UART_init(void) { RST_CLK_PCLKcmd( RST_CLK_PCLK_UART1, ENABLE ); UART_BRGInit( MDR_UART1, UART_HCLKdiv1 ); UART_DeInit( MDR_UART1 ); NVIC_DisableIRQ( UART1_IRQn ); /* Initialize UART_InitStructure */ UART_InitStructure.UART_BaudRate = 9600; UART_InitStructure.UART_WordLength = UART_WordLength8b; UART_InitStructure.UART_StopBits = UART_StopBits2; UART_InitStructure.UART_Parity = UART_Parity_No; UART_InitStructure.UART_FIFOMode = UART_FIFO_OFF; UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_RXE | UART_HardwareFlowControl_TXE; UART_Init( MDR_UART1, &UART_InitStructure ); NVIC_EnableIRQ( UART1_IRQn ); UART_ITConfig( MDR_UART1, UART_IT_RX, ENABLE ); UART_Cmd( MDR_UART1,ENABLE ); }
int main(void) { DMA_InitTypeDef DMA_InitStruct1; SystemClockSetup(ClockSource_EX50M,CoreClock_100M); DelayInit(); LED_Init(LED_PinLookup_CHKATOM, kNumOfLED); UART_DebugPortInit(UART4_RX_C14_TX_C15, 115200); DisplayCPUInfo(); //开启UART 发送中断/DMA功能 UART_ITConfig(UART4,UART_IT_TDRE,ENABLE); //使能UART4 TX DMA发送 UART_DMACmd(UART4,UART_DMAReq_Tx,ENABLE); DMA_InitStruct1.Channelx = DMA_CH0; //使用DMA0通道 (0-15) DMA_InitStruct1.DMAAutoClose = ENABLE; //传输完毕后自动关闭 DMA_InitStruct1.EnableState = ENABLE; //初始化后立即开始传输 DMA_InitStruct1.MinorLoopLength = sizeof(UARTSendBuffer); //传输次数 DMA_InitStruct1.PeripheralDMAReq = UART4_TRAN_DMAREQ; //UART 传输完成触发 DMA_InitStruct1.TransferBytes = 1; //每次传输一个字节 //配置目的地址传输参数 DMA_InitStruct1.DestBaseAddr = (uint32_t)&(UART4->D); //指向目的地址 DMA_InitStruct1.DestDataSize = DMA_DST_8BIT; //数组为1Byte DMA_InitStruct1.DestMajorInc = 0; //执行一次大循环后 地址不增加 DMA_InitStruct1.DestMinorInc = 0; //每次传输完地址不增加 //配置源地址传输参数 DMA_InitStruct1.SourceBaseAddr = (uint32_t)UARTSendBuffer; DMA_InitStruct1.SourceDataSize = DMA_SRC_8BIT; DMA_InitStruct1.SourceMajorInc = 0; DMA_InitStruct1.SourceMinorInc = 1; //每次传输1个字节后地址自动加1 将后面的数据继续发送 DMA_Init(&DMA_InitStruct1); //等待传输完成 while(DMA_IsComplete(DMA_CH0) == FALSE); while(1) { } }
void UART0_Configure(u16 Baudrate) { UART_InitTypeDef UART_InitStructure; SCU_APBPeriphClockConfig(__UART0, ENABLE); // Enable the UART0 Clock /* UART0 configured as follow: - Word Length = 8 Bits - One Stop Bit - No parity - BaudRate taken from function argument - Hardware flow control Disabled - Receive and transmit enabled - Receive and transmit FIFOs are Disabled */ UART_StructInit(&UART_InitStructure); UART_InitStructure.UART_WordLength = UART_WordLength_8D; UART_InitStructure.UART_StopBits = UART_StopBits_1; UART_InitStructure.UART_Parity = UART_Parity_No ; UART_InitStructure.UART_BaudRate = Baudrate; UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_None; UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx; UART_InitStructure.UART_FIFO = UART_FIFO_Enable; UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; UART_DeInit(UART0); // reset uart 0 to default UART_Init(UART0, &UART_InitStructure); // initialize uart 0 // enable uart 0 interrupts selective UART_ITConfig(UART0, UART_IT_Receive | UART_IT_ReceiveTimeOut /*| UART_IT_FrameError*/, ENABLE); UART_Cmd(UART0, ENABLE); // enable uart 0 // configure the uart 0 interupt line VIC_Config(UART0_ITLine, VIC_IRQ, PRIORITY_UART0); // enable the uart 0 IRQ VIC_ITCmd(UART0_ITLine, ENABLE); }
/******************************************************************************* * Function Name : USB_CDC_SetLineCoding * Description : SetLineCoding CDC request handler. * : Stores received line coding settings and adjusts UART. * Output : None * Return : USB_Result *******************************************************************************/ USB_Result USB_CDC_SetLineCoding(uint16_t wINDEX, const USB_CDC_LineCoding_TypeDef* DATA) { assert_param(DATA); if (wINDEX != 0) { /* Invalid interface */ return USB_ERR_INV_REQ; } /* Adjust UART settings */ /* Baud rate */ UARTInitStructure.UART_BaudRate = DATA->dwDTERate; /* Stop bits */ switch (DATA->bCharFormat) { case USB_CDC_STOP_BITS1: UARTInitStructure.UART_StopBits = UART_StopBits1; break; case USB_CDC_STOP_BITS2: UARTInitStructure.UART_StopBits = UART_StopBits2; break; default : return USB_ERR_INV_REQ; } /* Parity */ switch (DATA->bParityType) { case USB_CDC_PARITY_NONE: UARTInitStructure.UART_Parity = UART_Parity_No; break; case USB_CDC_PARITY_ODD: UARTInitStructure.UART_Parity = UART_Parity_Odd; break; case USB_CDC_PARITY_EVEN: UARTInitStructure.UART_Parity = UART_Parity_Even; break; case USB_CDC_PARITY_MARK: UARTInitStructure.UART_Parity = UART_Parity_0; break; case USB_CDC_PARITY_SPACE: UARTInitStructure.UART_Parity = UART_Parity_1; break; default : return USB_ERR_INV_REQ; } /* Data bits */ switch (DATA->bDataBits) { case USB_CDC_DATA_BITS5: UARTInitStructure.UART_WordLength = UART_WordLength5b; break; case USB_CDC_DATA_BITS6: UARTInitStructure.UART_WordLength = UART_WordLength6b; break; case USB_CDC_DATA_BITS7: UARTInitStructure.UART_WordLength = UART_WordLength7b; break; case USB_CDC_DATA_BITS8: UARTInitStructure.UART_WordLength = UART_WordLength8b; break; default : return USB_ERR_INV_REQ; } /* Re-initialize UART */ UART_Cmd(UART, DISABLE); UART_DeInit(UART); UART_Init(UART, &UARTInitStructure); /* Enable sender, receiver and line state interrupts */ UART_ITConfig (UART, UART_IT_TX | UART_IT_RX #ifdef USB_CDC_STATE_REPORTING_SUPPORTED | UART_LINE_STATE_EVENTS #endif /* USB_CDC_STATE_REPORTING_SUPPORTED */ , ENABLE); UART_Cmd(UART, ENABLE); /* On success, store new values for GetLineCoding request fastening */ LineCoding = *DATA; return USB_SUCCESS; }
void UBloxInit(void) { SCU_APBPeriphClockConfig(__GPIO6, ENABLE); // Enable the GPIO6 Clock SCU_APBPeriphClockConfig(__UART0, ENABLE); // Enable the UART0 Clock GPIO_InitTypeDef gpio_init; // Configure pin GPIO6.6 to be UART0 Rx gpio_init.GPIO_Direction = GPIO_PinInput; gpio_init.GPIO_Pin = GPIO_Pin_6; gpio_init.GPIO_Type = GPIO_Type_PushPull; gpio_init.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable; gpio_init.GPIO_Alternate = GPIO_InputAlt1; // UART0 Rx GPIO_Init(GPIO6, &gpio_init); // Configure pin GPIO6.6 to be UART0 Tx gpio_init.GPIO_Direction = GPIO_PinOutput; gpio_init.GPIO_Pin = GPIO_Pin_7; gpio_init.GPIO_Type = GPIO_Type_PushPull; gpio_init.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable; gpio_init.GPIO_Alternate = GPIO_OutputAlt3; // UART0 Tx GPIO_Init(GPIO6, &gpio_init); UART1Init(UBLOX_INITIAL_BAUD); { // Set the port to UART UBX @ 57600. const uint8_t tx_buffer[28] = { 0xb5, 0x62, 0x06, 0x00, 0x14, 0x00, 0x01, 0x00, 0x00, 0x00, 0xd0, 0x08, 0x00, 0x00, 0x00, 0xe1, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd6, 0x8d }; UBloxTxBuffer(tx_buffer, 28); } Wait(150); UART1Init(UBLOX_OPERATING_BAUD); // Enable UART Rx interrupt. UART_ITConfig(UART0, UART_IT_Receive, ENABLE); VIC_Config(UART0_ITLine, VIC_IRQ, IRQ_PRIORITY_UART0); VIC_ITCmd(UART0_ITLine, ENABLE); { // Configure USB for UBX input with no output. const uint8_t tx_buffer[28] = { 0xb5, 0x62, 0x06, 0x00, 0x14, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x8c }; UBloxTxBuffer(tx_buffer, 28); } { // Set antenna flags to 0x0b and pins to 0x380f. const uint8_t tx_buffer[12] = { 0xb5, 0x62, 0x06, 0x13, 0x04, 0x00, 0x0b, 0x00, 0x0f, 0x38, 0x6f, 0x4f }; UBloxTxBuffer(tx_buffer, 12); } { // Set measurement period to 200ms (5Hz) with UTC reference. const uint8_t tx_buffer[14] = { 0xb5, 0x62, 0x06, 0x08, 0x06, 0x00, 0xc8, 0x00, 0x01, 0x00, 0x00, 0x00, 0xdd, 0x68 }; UBloxTxBuffer(tx_buffer, 14); } { // Configure TimPulse. const uint8_t tx_buffer[28] = { 0xb5, 0x62, 0x06, 0x07, 0x14, 0x00, 0x40, 0x42, 0x0f, 0x00, 0x90, 0x86, 0x03, 0x00, 0xff, 0x01, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfd, 0x70 }; UBloxTxBuffer(tx_buffer, 28); } { // Configure SBAS. const uint8_t tx_buffer[16] = { 0xb5, 0x62, 0x06, 0x16, 0x08, 0x00, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2b, 0xbd }; UBloxTxBuffer(tx_buffer, 16); } { // Configure navigation engine. const uint8_t tx_buffer[44] = { 0xb5, 0x62, 0x06, 0x24, 0x24, 0x00, 0xff, 0xff, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x10, 0x27, 0x00, 0x00, 0x08, 0x3c, 0x50, 0x00, 0x32, 0x00, 0x23, 0x00, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x97, 0xfa }; UBloxTxBuffer(tx_buffer, 44); } { // Configure navigation engine expert settings. const uint8_t tx_buffer[48] = { 0xb5, 0x62, 0x06, 0x23, 0x28, 0x00, 0x00, 0x00, 0x4c, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x10, 0x14, 0x00, 0x01, 0x00, 0x00, 0x00, 0xf8, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc9, 0xea }; UBloxTxBuffer(tx_buffer, 48); } { // Request NAV-POSLLH message to be output every measurement cycle. const uint8_t tx_buffer[11] = { 0xb5, 0x62, 0x06, 0x01, 0x03, 0x00, 0x01, 0x02, 0x01, 0x0e, 0x47 }; UBloxTxBuffer(tx_buffer, 11); } { // Request NAV-VELNED message to be output every measurement cycle. const uint8_t tx_buffer[11] = { 0xb5, 0x62, 0x06, 0x01, 0x03, 0x00, 0x01, 0x12, 0x01, 0x1e, 0x67 }; UBloxTxBuffer(tx_buffer, 11); } { // Request NAV-SOL message to be output every measurement cycle. const uint8_t tx_buffer[11] = { 0xb5, 0x62, 0x06, 0x01, 0x03, 0x00, 0x01, 0x06, 0x01, 0x12, 0x4f }; UBloxTxBuffer(tx_buffer, 11); } { // Request Time-UTC message to be output every 5 measurement cycles. const uint8_t tx_buffer[11] = { 0xb5, 0x62, 0x06, 0x01, 0x03, 0x00, 0x01, 0x21, 0x05, 0x31, 0x89 }; UBloxTxBuffer(tx_buffer, 11); } }
void prvSetupHardware( void ) { PORT_InitTypeDef PORT_InitStructure; UART_InitTypeDef UART_InitStructure; //SSP_InitTypeDef SPI_InitStructure; TIMER_CntInitTypeDef sTIM_CntInit; // TIMER_ChnInitTypeDef sTIM_ChnInit; //CLK /* Enable HSE clock oscillator */ RST_CLK_HSEconfig(RST_CLK_HSE_ON); while(RST_CLK_HSEstatus() == ERROR); RST_CLK_CPUclkSelection(RST_CLK_CPUclkCPU_C3); MDR_RST_CLK -> CPU_CLOCK |= 2;//CPU_C1 set HSE RST_CLK_HSIcmd(DISABLE); /* Enable the RTCHSE clock on all ports */ RST_CLK_PCLKcmd(ALL_PORTS_CLK, ENABLE); PORT_StructInit(&PORT_InitStructure);//reset struct /************************ LCD Initialization *************************/ /* Configure PORTA pins for data transfer to/from LCD */ PORT_InitStructure.PORT_Pin = LCD_DATA_BUS_8; PORT_InitStructure.PORT_FUNC = PORT_FUNC_PORT; PORT_InitStructure.PORT_SPEED = PORT_SPEED_SLOW; PORT_InitStructure.PORT_MODE = PORT_MODE_DIGITAL; PORT_InitStructure.PORT_OE = PORT_OE_IN; PORT_Init(MDR_PORTA, &PORT_InitStructure); /* Configure PORTE pin4 and pin5 for LCD crystals control */ PORT_InitStructure.PORT_Pin = KS0108_CS1 | KS0108_CS2 | KS0108_RS; PORT_InitStructure.PORT_OE = PORT_OE_OUT; PORT_Init(MDR_PORTE, &PORT_InitStructure); PORT_Init(MDR_PORTE, &PORT_InitStructure); PORT_InitStructure.PORT_Pin = KS0108_EN | KS0108_RW | KS0108_RES; PORT_Init(MDR_PORTC, &PORT_InitStructure); PORT_SetBits(MDR_PORTA, LCD_DATA_BUS_8); PORT_SetBits(MDR_PORTE, KS0108_CS1 | KS0108_CS2 | KS0108_RS); PORT_SetBits(MDR_PORTC, KS0108_EN | KS0108_RW | KS0108_RES); //Timer1 // TIMER1 RST_CLK_PCLKcmd(RST_CLK_PCLK_TIMER1,ENABLE); /* Reset all TIMER1 settings */ TIMER_DeInit(MDR_TIMER1); TIMER_BRGInit(MDR_TIMER1,TIMER_HCLKdiv1); /* TIM1 configuration ------------------------------------------------*/ /* Initializes the TIMERx Counter ------------------------------------*/ sTIM_CntInit.TIMER_IniCounter = 0; sTIM_CntInit.TIMER_Prescaler = 150;// sTIM_CntInit.TIMER_Period = 82; sTIM_CntInit.TIMER_CounterMode = TIMER_CntMode_ClkFixedDir; sTIM_CntInit.TIMER_CounterDirection = TIMER_CntDir_Up; sTIM_CntInit.TIMER_EventSource = TIMER_EvSrc_None; sTIM_CntInit.TIMER_FilterSampling = TIMER_FDTS_TIMER_CLK_div_1; sTIM_CntInit.TIMER_ARR_UpdateMode = TIMER_ARR_Update_Immediately; sTIM_CntInit.TIMER_ETR_FilterConf = TIMER_Filter_1FF_at_TIMER_CLK; sTIM_CntInit.TIMER_ETR_Prescaler = TIMER_ETR_Prescaler_None; sTIM_CntInit.TIMER_ETR_Polarity = TIMER_ETRPolarity_NonInverted; sTIM_CntInit.TIMER_BRK_Polarity = TIMER_BRKPolarity_NonInverted; TIMER_CntInit (MDR_TIMER1,&sTIM_CntInit); NVIC_EnableIRQ(Timer1_IRQn); TIMER_ITConfig(MDR_TIMER1,TIMER_STATUS_CNT_ARR, ENABLE); /* TMR1 enable */ TIMER_Cmd (MDR_TIMER1,ENABLE); // TIMER2 RST_CLK_PCLKcmd(RST_CLK_PCLK_TIMER2,ENABLE); /* Reset all TIMER1 settings */ TIMER_DeInit(MDR_TIMER2); TIMER_BRGInit(MDR_TIMER2,TIMER_HCLKdiv1); /* TIM2 configuration ------------------------------------------------*/ /* Initializes the TIMERx Counter ------------------------------------*/ sTIM_CntInit.TIMER_IniCounter = 0; sTIM_CntInit.TIMER_Prescaler = 0xf;// sTIM_CntInit.TIMER_Period = 0xffff; sTIM_CntInit.TIMER_CounterMode = TIMER_CntMode_ClkFixedDir; sTIM_CntInit.TIMER_CounterDirection = TIMER_CntDir_Up; sTIM_CntInit.TIMER_EventSource = TIMER_EvSrc_None; sTIM_CntInit.TIMER_FilterSampling = TIMER_FDTS_TIMER_CLK_div_1; sTIM_CntInit.TIMER_ARR_UpdateMode = TIMER_ARR_Update_Immediately; sTIM_CntInit.TIMER_ETR_FilterConf = TIMER_Filter_1FF_at_TIMER_CLK; sTIM_CntInit.TIMER_ETR_Prescaler = TIMER_ETR_Prescaler_None; sTIM_CntInit.TIMER_ETR_Polarity = TIMER_ETRPolarity_NonInverted; sTIM_CntInit.TIMER_BRK_Polarity = TIMER_BRKPolarity_NonInverted; TIMER_CntInit (MDR_TIMER2,&sTIM_CntInit); NVIC_EnableIRQ(Timer2_IRQn); TIMER_ITConfig(MDR_TIMER2,TIMER_STATUS_CNT_ARR, ENABLE); /* TMR2 enable */ TIMER_Cmd (MDR_TIMER2,ENABLE); // TIMER3 RST_CLK_PCLKcmd(RST_CLK_PCLK_TIMER3,ENABLE); /* Reset all TIMER3 settings */ TIMER_DeInit(MDR_TIMER3); TIMER_BRGInit(MDR_TIMER3,TIMER_HCLKdiv1); /* TIM3 configuration ------------------------------------------------*/ /* Initializes the TIMERx Counter ------------------------------------*/ sTIM_CntInit.TIMER_IniCounter = 0; sTIM_CntInit.TIMER_Prescaler = 0; sTIM_CntInit.TIMER_Period = 0xFFFF; sTIM_CntInit.TIMER_CounterMode = TIMER_CntMode_EvtFixedDir; sTIM_CntInit.TIMER_CounterDirection = TIMER_CntDir_Up; sTIM_CntInit.TIMER_EventSource = TIMER_EvSrc_CH1; sTIM_CntInit.TIMER_FilterSampling = TIMER_FDTS_TIMER_CLK_div_1; sTIM_CntInit.TIMER_ARR_UpdateMode = TIMER_ARR_Update_Immediately; sTIM_CntInit.TIMER_ETR_FilterConf = TIMER_Filter_1FF_at_TIMER_CLK; sTIM_CntInit.TIMER_ETR_Prescaler = TIMER_ETR_Prescaler_None; sTIM_CntInit.TIMER_ETR_Polarity = TIMER_ETRPolarity_NonInverted; sTIM_CntInit.TIMER_BRK_Polarity = TIMER_BRKPolarity_NonInverted; TIMER_CntInit (MDR_TIMER3,&sTIM_CntInit); // NVIC_EnableIRQ(Timer3_IRQn); // TIMER_ITConfig(MDR_TIMER3,TIMER_STATUS_CNT_ARR, ENABLE); /* Enable TIMER3 */ TIMER_Cmd(MDR_TIMER3,ENABLE); /************************ UART1 Initialization *************************/ PORT_StructInit(&PORT_InitStructure);//reset struct PORT_InitStructure.PORT_Pin = PORT_Pin_12|PORT_Pin_13;//RX TX PORT_InitStructure.PORT_FUNC = PORT_FUNC_OVERRID; PORT_InitStructure.PORT_MODE = PORT_MODE_DIGITAL; PORT_InitStructure.PORT_SPEED = PORT_SPEED_SLOW; PORT_Init(MDR_PORTE, &PORT_InitStructure); PORT_InitStructure.PORT_Pin = PORT_Pin_14;//EN RS485 PORT_InitStructure.PORT_OE =PORT_OE_OUT; PORT_InitStructure.PORT_PD = PORT_PD_OPEN; PORT_InitStructure.PORT_FUNC = PORT_FUNC_PORT; PORT_Init(MDR_PORTE, &PORT_InitStructure); RS485_TX_OFF; //UART1 RST_CLK_PCLKcmd(RST_CLK_PCLK_UART1,ENABLE); /* Set the HCLK division factor = 1 for UART1,UART2*/ UART_BRGInit(MDR_UART1, UART_HCLKdiv1); UART_DeInit(MDR_UART1); /* Disable interrupt on UART1 */ NVIC_DisableIRQ(UART1_IRQn); /* Initialize UART_InitStructure */ UART_InitStructure.UART_BaudRate = 38400; UART_InitStructure.UART_WordLength = UART_WordLength8b; UART_InitStructure.UART_StopBits = UART_StopBits1;//PKDU2 niobyi UART_InitStructure.UART_Parity = UART_Parity_No; UART_InitStructure.UART_FIFOMode = UART_FIFO_OFF; UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_RXE | UART_HardwareFlowControl_TXE; /* Configure UART1 parameters*/ UART_Init(MDR_UART1,&UART_InitStructure); NVIC_EnableIRQ(UART1_IRQn); UART_ITConfig(MDR_UART1,UART_IT_RX, ENABLE); /* Enables UART1 peripheral */ UART_Cmd(MDR_UART1,ENABLE); //PORT /************************ Joystick Initialization *************************/ /* Configure PORTC pins 10..14 for input to handle joystick events */ PORT_StructInit(&PORT_InitStructure);//reset struct PORT_InitStructure.PORT_Pin = ( PORT_Pin_10 | PORT_Pin_11 | PORT_Pin_12 | PORT_Pin_13 | PORT_Pin_14 ); PORT_InitStructure.PORT_OE = PORT_OE_IN; PORT_InitStructure.PORT_MODE = PORT_MODE_DIGITAL; PORT_InitStructure.PORT_FUNC = PORT_FUNC_PORT; PORT_InitStructure.PORT_SPEED = PORT_OUTPUT_OFF; PORT_Init( MDR_PORTC, &PORT_InitStructure ); /************************ LEDs Initialization *************************/ PORT_StructInit( &PORT_InitStructure );//reset struct /* Configure PORTD pins 10..14 for output to switch LEDs on/off */ PORT_InitStructure.PORT_Pin = LEDs_PINs; PORT_InitStructure.PORT_OE = PORT_OE_OUT; PORT_InitStructure.PORT_MODE = PORT_MODE_DIGITAL; PORT_InitStructure.PORT_FUNC = PORT_FUNC_PORT; PORT_InitStructure.PORT_SPEED = PORT_SPEED_SLOW; PORT_Init( MDR_PORTD, &PORT_InitStructure ); /* All LEDs switch off */ PORT_ResetBits(MDR_PORTD, LEDs_PINs); }
/* * See the serial2.h header file. */ xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength ) { xComPortHandle xReturn; UART_InitTypeDef UART_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; EIC_IRQInitTypeDef EIC_IRQInitStructure; /* Create the queues used to hold Rx and Tx characters. */ xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) ); xCharsForTx = xQueueCreate( uxQueueLength + 1, ( unsigned portBASE_TYPE ) sizeof( signed char ) ); /* If the queues were created correctly then setup the serial port hardware. */ if( ( xRxedChars != serINVALID_QUEUE ) && ( xCharsForTx != serINVALID_QUEUE ) ) { portENTER_CRITICAL(); { /* Enable the UART0 Clock. */ MRCC_PeripheralClockConfig( MRCC_Peripheral_UART0, ENABLE ); /* Configure the UART0_Tx as alternate function */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; GPIO_Init(GPIO0, &GPIO_InitStructure); /* Configure the UART0_Rx as input floating */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_Init(GPIO0, &GPIO_InitStructure); /* Configure UART0. */ UART_InitStructure.UART_WordLength = UART_WordLength_8D; UART_InitStructure.UART_StopBits = UART_StopBits_1; UART_InitStructure.UART_Parity = UART_Parity_No; UART_InitStructure.UART_BaudRate = ulWantedBaud; UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_None; UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx; UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; /* FIFO size 16 bytes, FIFO level 8 bytes */ UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; /* FIFO size 16 bytes, FIFO level 8 bytes */ UART_Init(UART0, &UART_InitStructure); /* Enable the UART0 */ UART_Cmd(UART0, ENABLE); /* Configure the IEC for the UART interrupts. */ EIC_IRQInitStructure.EIC_IRQChannelCmd = ENABLE; EIC_IRQInitStructure.EIC_IRQChannel = UART0_IRQChannel; EIC_IRQInitStructure.EIC_IRQChannelPriority = 1; EIC_IRQInit(&EIC_IRQInitStructure); xQueueEmpty = pdTRUE; UART_ITConfig( UART0, UART_IT_Transmit | UART_IT_Receive, ENABLE ); } portEXIT_CRITICAL(); } else { xReturn = ( xComPortHandle ) 0; } /* This demo file only supports a single port but we have to return something to comply with the standard demo header file. */ return xReturn; }
/******************************************************************************* * Function Name : VCOMFunc * Description : Demonstration of USB-to-UART VCOM bridge. * : Displays prompt on LCD, enables the bridge and waits for * : joystick SEL key pressed to stop bridging and return * : to main menu. * Input : None * Output : None * Return : None *******************************************************************************/ void VCOMFunc(void) { uint32_t key; /* Display prompt */ VCOMHelp(); /* Save current CPU CLOCK configuration */ temp_CPU_CLOCK = MDR_RST_CLK->CPU_CLOCK; temp_PLL_CONTROL = MDR_RST_CLK->PLL_CONTROL; Setup_CPU_Clock(); UARTConfiguration(); /* CDC layer initialization */ USB_CDC_Init(SendBuffer, 1, SET); /* UART configuration */ UARTInitStructure.UART_BaudRate = 14400; UARTInitStructure.UART_WordLength = UART_WordLength8b; UARTInitStructure.UART_StopBits = UART_StopBits1; UARTInitStructure.UART_Parity = UART_Parity_No; UARTInitStructure.UART_FIFOMode = UART_FIFO_OFF; UARTInitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_RXE | \ UART_HardwareFlowControl_TXE; /* With LBE bit set, output line of UARTTXD transmitter becomes to be bound to * UARTRXD receiver input. In order to run this example with UART physically * connected to PC, just comment this line */ /* UARTInitStructure.UART_HardwareFlowControl |= UART_HardwareFlowControl_LBE; */ UART_Init (UART,&UARTInitStructure); #ifdef USB_CDC_LINE_CODING_SUPPORTED /* Set line coding initial settings accordingly to UART ones above */ LineCoding.dwDTERate = UARTInitStructure.UART_BaudRate; LineCoding.bCharFormat = USB_CDC_STOP_BITS1; LineCoding.bParityType = USB_CDC_PARITY_NONE; LineCoding.bDataBits = USB_CDC_DATA_BITS8; #endif /* USB_CDC_LINE_CODING_SUPPORTED */ /* Set interrupt handlers */ pfUARTReceiverFunc = ReceiverFunc; pfUARTSenderFunc = SenderFunc; #ifdef USB_CDC_STATE_REPORTING_SUPPORTED pfUARTLineStateFunc = LineStateFunc; #endif /* USB_CDC_STATE_REPORTING_SUPPORTED */ /* Enable sender, receiver and line state interrupts */ UART_ITConfig (UART, UART_IT_TX | UART_IT_RX #ifdef USB_CDC_STATE_REPORTING_SUPPORTED | UART_LINE_STATE_EVENTS #endif /* USB_CDC_STATE_REPORTING_SUPPORTED */ , ENABLE); /* Enable bridge */ UART_Cmd(UART, ENABLE); Setup_USB(); /* Wait for SEL to quit */ key = GetKey(); for (; key != SEL; key = GetKey()) { } WAIT_UNTIL_KEY_RELEASED(SEL); /* Disable bridge */ UART_Cmd(UART, DISABLE); #if defined (USE_MDR32F9Q2_Rev0) || defined (USE_MDR32F9Q2_Rev1) PORTBRestoreConfig(); #endif /* defined (USE_MDR32F9Q2_Rev0) || defined (USE_MDR32F9Q2_Rev1) */ USB_CDC_ReceiveStop(); USB_DevicePowerOff(); /* Restore original CPU CLOCK configuration */ MDR_RST_CLK->CPU_CLOCK = temp_CPU_CLOCK; MDR_RST_CLK->PLL_CONTROL = temp_PLL_CONTROL; DisplayMenu(); }
/* * See the serial2.h header file. */ xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength ) { xComPortHandle xReturn; UART_InitTypeDef xUART1_Init; GPIO_InitTypeDef GPIO_InitStructure; /* Create the queues used to hold Rx characters. */ xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) ); /* Create the semaphore used to wake a task waiting for space to become available in the FIFO. */ vSemaphoreCreateBinary( xTxFIFOSemaphore ); /* If the queue/semaphore was created correctly then setup the serial port hardware. */ if( ( xRxedChars != serINVALID_QUEUE ) && ( xTxFIFOSemaphore != serINVALID_QUEUE ) ) { /* Pre take the semaphore so a task will block if it tries to access it. */ xSemaphoreTake( xTxFIFOSemaphore, 0 ); /* Configure the UART. */ xUART1_Init.UART_WordLength = UART_WordLength_8D; xUART1_Init.UART_StopBits = UART_StopBits_1; xUART1_Init.UART_Parity = UART_Parity_No; xUART1_Init.UART_BaudRate = ulWantedBaud; xUART1_Init.UART_HardwareFlowControl = UART_HardwareFlowControl_None; xUART1_Init.UART_Mode = UART_Mode_Tx_Rx; xUART1_Init.UART_FIFO = UART_FIFO_Enable; /* Enable the UART1 Clock */ SCU_APBPeriphClockConfig( __UART1, ENABLE ); /* Enable the GPIO3 Clock */ SCU_APBPeriphClockConfig( __GPIO3, ENABLE ); /* Configure UART1_Rx pin GPIO3.2 */ GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable; GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1 ; GPIO_Init( GPIO3, &GPIO_InitStructure ); /* Configure UART1_Tx pin GPIO3.3 */ GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable; GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2 ; GPIO_Init( GPIO3, &GPIO_InitStructure ); portENTER_CRITICAL(); { /* Configure the UART itself. */ UART_DeInit( UART1 ); UART_Init( UART1, &xUART1_Init ); UART_ITConfig( UART1, UART_IT_Receive | UART_IT_Transmit, ENABLE ); UART1->ICR = serCLEAR_ALL_INTERRUPTS; UART_LoopBackConfig( UART1, DISABLE ); UART_IrDACmd( IrDA1, DISABLE ); /* Configure the VIC for the UART interrupts. */ VIC_Config( UART1_ITLine, VIC_IRQ, 9 ); VIC_ITCmd( UART1_ITLine, ENABLE ); UART_Cmd( UART1, ENABLE ); lTaskWaiting = pdFALSE; } portEXIT_CRITICAL(); } else { xReturn = ( xComPortHandle ) 0; } /* This demo file only supports a single port but we have to return something to comply with the standard demo header file. */ return xReturn; }
/******************************************************************************* * Function Name : Set_System * Description : Set System clock. * Input : None. * Return : None. *******************************************************************************/ void Set_System(void) { GPIO_InitTypeDef GPIO_InitStructure; // EXTIT_InitTypeDef EXTIT_InitStructure; /* MRCC configuration --------------------------------------------------------*/ /* MRCC system reset(for debug purpose) */ MRCC_DeInit(); /* Wait for OSC4M start-up */ OSC4MStartUpStatus = MRCC_WaitForOSC4MStartUp(); if(OSC4MStartUpStatus == SUCCESS) { /* Set HCLK to 60MHz */ MRCC_HCLKConfig(MRCC_CKSYS_Div1); /* Set CKTIM to 60MHz */ MRCC_CKTIMConfig(MRCC_HCLK_Div1); /* Set PCLK to 30MHz */ MRCC_PCLKConfig(MRCC_CKTIM_Div2); /* Enable Flash burst mode */ CFG_FLASHBurstConfig(CFG_FLASHBurst_Enable); /* Set CKSYS to 60MHz */ MRCC_CKSYSConfig(MRCC_CKSYS_OSC4MPLL, MRCC_PLL_Mul_15); } /* Enbale No Clock Detected interrupt */ MRCC_ITConfig(MRCC_IT_NCKD, ENABLE); /* Enable GPIOs, USB and EXTIT clocks */ MRCC_PeripheralClockConfig(MRCC_Peripheral_GPIO | MRCC_Peripheral_EXTIT | MRCC_Peripheral_USB | MRCC_Peripheral_UART0, ENABLE); MRCC_IOVoltageRangeConfig(MRCC_IOVoltageRange_3V3); //EXTIT_ClearITPendingBit(EXTIT_ITLine14); //EXTIT_InitStructure.EXTIT_ITLine = EXTIT_ITLine14; //EXTIT_InitStructure.EXTIT_ITTrigger = EXTIT_ITTrigger_Rising; //EXTIT_InitStructure.EXTIT_ITLineCmd = ENABLE; //EXTIT_Init(&EXTIT_InitStructure); /* Configure P2.18 ( USB Suspend/Resume ) as Output push-pull */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_19; GPIO_Init(GPIO2, &GPIO_InitStructure); GPIO_WriteBit(GPIO2, GPIO_Pin_19, (BitAction)(0)); /* Configure P1.0 (D+ Pull up) as Output push-pull */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_Init(GPIO1, &GPIO_InitStructure); /* Configure P0.1 (RED LED) as Output push-pull */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; GPIO_Init(GPIO0, &GPIO_InitStructure); GPIO_WriteBit(GPIO0, GPIO_Pin_1, (BitAction)(1)); /* Configure the UART0_Tx as Alternate function Push-Pull */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; GPIO_Init(GPIO0, &GPIO_InitStructure); /* Configure the UART0_Rx as input floating */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_Init(GPIO0, &GPIO_InitStructure); UART_DeInit(UART0); UART_ITConfig(UART0, UART_IT_Receive, ENABLE); /* Configure the interrupt controller for UART0 channel */ EIC_IRQInitStructure.EIC_IRQChannel = UART0_IRQChannel; EIC_IRQInitStructure.EIC_IRQChannelPriority = 1; EIC_IRQInitStructure.EIC_IRQChannelCmd = ENABLE; EIC_IRQInit(&EIC_IRQInitStructure); }