static void prvSetupTimerInterrupt( void ) { EIC_IRQInitTypeDef EIC_IRQInitStructure; TB_InitTypeDef TB_InitStructure; /* Setup the EIC for the TB. */ EIC_IRQInitStructure.EIC_IRQChannelCmd = ENABLE; EIC_IRQInitStructure.EIC_IRQChannel = TB_IRQChannel; EIC_IRQInitStructure.EIC_IRQChannelPriority = 1; EIC_IRQInit(&EIC_IRQInitStructure); /* Setup the TB for the generation of the tick interrupt. */ TB_InitStructure.TB_Mode = TB_Mode_Timing; TB_InitStructure.TB_CounterMode = TB_CounterMode_Down; TB_InitStructure.TB_Prescaler = portPRESCALE - 1; TB_InitStructure.TB_AutoReload = ( ( configCPU_CLOCK_HZ / portPRESCALE ) / configTICK_RATE_HZ ); TB_Init(&TB_InitStructure); /* Enable TB Update interrupt */ TB_ITConfig(TB_IT_Update, ENABLE); /* Clear TB Update interrupt pending bit */ TB_ClearITPendingBit(TB_IT_Update); /* Enable TB */ TB_Cmd(ENABLE); }
/******************************************************************************* * Function Name : USB_Interrupts_Config * Description : configure and enable the USB interrupt Lines * Input : None. * Return : None. *******************************************************************************/ void USB_Interrupts_Config(void) { /* Enable and configure the priority of the USB_LP IRQ Channel*/ EIC_IRQInitStructure.EIC_IRQChannel = USB_LP_IRQChannel; EIC_IRQInitStructure.EIC_IRQChannelPriority = 5; EIC_IRQInitStructure.EIC_IRQChannelCmd = ENABLE; EIC_IRQInit(&EIC_IRQInitStructure); /* Enable and configure the priority of the USB_HP IRQ Channel*/ EIC_IRQInitStructure.EIC_IRQChannel = USB_HP_IRQChannel; EIC_IRQInitStructure.EIC_IRQChannelPriority = 7; EIC_IRQInitStructure.EIC_IRQChannelCmd = ENABLE; EIC_IRQInit(&EIC_IRQInitStructure); /* Enable the Interrupt controller to manage IRQ channel*/ EIC_IRQCmd(ENABLE); }
//--------------------------------------------------------------------------------------- void TIM0_Config() { TIM_InitTypeDef TIM_InitStructure; TIM_InitStructure.TIM_Mode = TIM_Mode_OCTiming; TIM_InitStructure.TIM_Prescaler = 60 - 1; TIM_InitStructure.TIM_ClockSource = TIM_ClockSource_Internal; TIM_InitStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_InitStructure.TIM_Channel = TIM_Channel_2; TIM_InitStructure.TIM_Period = 25 - 1; TIM_Init(TIM0, &TIM_InitStructure); TIM_ClearFlag(TIM0, TIM_FLAG_OC1 | TIM_FLAG_OC2 | TIM_FLAG_Update); TIM_ITConfig(TIM0, TIM_IT_Update, ENABLE); TIM_Cmd(TIM0, ENABLE); EIC_IRQInitTypeDef EIC_IRQInitStructure; EIC_IRQInitStructure.EIC_IRQChannel = TIM0_UP_IRQChannel; EIC_IRQInitStructure.EIC_IRQChannelPriority = 1; EIC_IRQInitStructure.EIC_IRQChannelCmd = ENABLE; EIC_IRQInit(&EIC_IRQInitStructure); EIC_IRQCmd(ENABLE); }
/* * 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 : 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); }