void InitSCCB(void) { GPIO_InitTypeDef GPIO_InitStructure; //TXZZSCCB_DDR|=(1<<SCCB_SIO_C)|(1<<SCCB_SIO_D); //TXZZSCCB_PORT|=(1<<SCCB_SIO_C)|(1<<SCCB_SIO_D); GPIO_InitStructure.GPIO_Pin = SCCB_SCL_PIN | SCCB_SDA_PIN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD; GPIO_Init(GPIOE, &GPIO_InitStructure); GPIOE->BSRR =((1<<SCCB_SIO_D) | (1<<SCCB_SIO_C)); // XCLK핀은 받드시 PA8을 사용해야 합니다. // PA8에만 Alternate function으로 MCO기능이됨. GPIO_InitStructure.GPIO_Pin = CAMERA_XCLK_PIN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(CAMERA_XCLK_PORT, &GPIO_InitStructure); #if 0 #ifdef STM32F10X_CL RCC_MCOConfig(RCC_MCO_HSI );//hsi #else RCC_MCOConfig(RCC_MCO_HSE );//hsi #endif #endif RCC_MCOConfig(RCC_MCO_HSE );//HSE=25000000Hz }
static void s_hal_brdcfg_device_switch__mco_initialise(void) { // this function initialises MCO in order to provide clock ref to switch. // PA8 is MCO. it must be configured = Output mode, max speed 50 MHz + Alternate function output Push-pull (B) // also, we connect pll3 at 50mhz to it // clock gpioa as alternate function RCC->APB2ENR |= 0x00000005; // init pa8 GPIOA->CRH &= 0xFFFFFFF0; GPIOA->CRH |= 0x0000000B; // set pll3 clock output to 50mhz: (25mhz/5)*10 = 50mhz, thus we use multiplier 10 RCC_PLL3Config(RCC_PLL3Mul_10); // enable pll3 RCC_PLL3Cmd(ENABLE); // wait until it is ready while(RCC_GetFlagStatus(RCC_FLAG_PLL3RDY) == RESET); // connect mco on pa8 with pll3 RCC_MCOConfig(RCC_MCO_PLL3CLK); }
/****************************************************************************** * @brief 时钟信号输出功能 * @param none * @retval None ******************************************************************************/ void Board_MCO_Init(void) { /* Get 4.9152MHz on PA8 pin (MCO) */ RCC_MCOConfig(RCC_MCOSource_SYSCLK,RCC_MCODiv_4); Pin_MCO_Init(); }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /* Configure the System clock frequency, HCLK, PCLK2 and PCLK1 prescalers */ SetSysClock(); /* This function fills the RCC_ClockFreq structure with the current frequencies of different on chip clocks (for debug purpose) */ RCC_GetClocksFreq(&RCC_ClockFreq); /* Enable Clock Security System(CSS): this will generate an NMI exception when HSE clock fails */ RCC_ClockSecuritySystemCmd(ENABLE); /* NVIC configuration ------------------------------------------------------*/ NVIC_Configuration(); /* Initialize Leds mounted on STM3210X-EVAL board --------------------------*/ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* Output HSE clock on MCO pin ---------------------------------------------*/ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); RCC_MCOConfig(RCC_MCO_HSE); while (1) { /* Toggle LED1 */ STM_EVAL_LEDToggle(LED1); /* Insert delay */ Delay(DELAY_COUNT); /* Toggle LED2 */ STM_EVAL_LEDToggle(LED2); /* Insert delay */ Delay(DELAY_COUNT); /* Toggle LED3 */ STM_EVAL_LEDToggle(LED3); /* Insert delay */ Delay(DELAY_COUNT); /* Toggle LED4 */ STM_EVAL_LEDToggle(LED4); /* Insert a delay */ Delay(DELAY_COUNT); } }
//////////////////////////// //╣д─▄Б║╠р╣Е╩▒оМ //guanfu_wang void XCLK_init_ON(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP ; GPIO_Init(GPIOA, &GPIO_InitStructure); RCC_MCOConfig(RCC_MCO_HSE );//hsi }
void initial_mco(void) { GPIO_InitTypeDef structGPIO; RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); structGPIO.GPIO_Pin = GPIO_Pin_8; //i2c2 structGPIO.GPIO_Mode = GPIO_Mode_AF; structGPIO.GPIO_Speed = GPIO_Speed_50MHz; structGPIO.GPIO_OType = GPIO_OType_PP; structGPIO.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &structGPIO); GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_0); RCC_MCOConfig(RCC_MCOSource_HSE); }
void MCO_Proc(void *pdata) { GPIO_InitTypeDef GPIO_InitStructure; RCC_ClocksTypeDef RCC_ClockFreq; pdata = pdata; RCC_GetClocksFreq(&RCC_ClockFreq); /* Output HSE clock on MCO pin ---------------------------------------------*/ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); while(1) { RCC_MCOConfig(RCC_MCO_PLLCLK_Div2); OSTimeDly(OS_TICKS_PER_SEC*10); RCC_MCOConfig(RCC_MCO_HSE); OSTimeDly(OS_TICKS_PER_SEC*10); RCC_MCOConfig(RCC_MCO_PLLCLK_Div2); OSTimeDly(OS_TICKS_PER_SEC*10); } }
void ld3320_sclk_out(void) { /* PA8 输出 8M 波形 */ GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE); /* MCO configure */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA,&GPIO_InitStructure); RCC_MCOConfig( RCC_MCO_PLLCLK_Div2); //36M }
void RCC_Config(void) { RCC_DeInit(); RCC_HSEConfig(RCC_HSE_ON); //Включим внешний генератор while (SUCCESS != RCC_WaitForHSEStartUp()); //Подождем запуска генератора RCC_PLLCmd(DISABLE); RCC_PLLConfig(RCC_PLLSource_PREDIV1,RCC_PLLMul_12); //Вход ПЛЛ внешний генератор умножим на 12 RCC_PLLCmd(ENABLE); RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); //Системное тактирование от ПЛЛ RCC_HCLKConfig(RCC_SYSCLK_Div1); //Тактирование AHB с делением 1 RCC_PCLKConfig(RCC_HCLK_Div8); //Тактирование переферии с делением 8 RCC_ADCCLKConfig(RCC_ADCCLK_PCLK_Div2); //Тактирование АЦП RCC_I2CCLKConfig(RCC_I2C1CLK_SYSCLK); //Тактируем шину I2C от системного тактирования RCC_USARTCLKConfig(RCC_USART1CLK_PCLK); //Тактируем UART от шини переферии RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA + RCC_AHBPeriph_GPIOB,ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1 + RCC_APB2Periph_USART1 + RCC_APB2Periph_TIM1 + RCC_APB2Periph_TIM15, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM14, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); #ifdef MCO_ENABLE GPIOA_Struct_init.GPIO_Pin = GPIO_Pin_8; GPIOA_Struct_init.GPIO_Mode = GPIO_Mode_AF; GPIOA_Struct_init.GPIO_Speed = GPIO_Speed_Level_2; GPIOA_Struct_init.GPIO_OType = GPIO_OType_PP; GPIO_Init(GPIOA,&GPIOA_Struct_init); RCC_MCOConfig(RCC_MCOSource_SYSCLK); while (1); #else RCC_MCOConfig(RCC_MCOSource_NoClock); #endif /*MCO_ENABLE */ };
static void GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; /* Disable the JTAG interface and enable the SWJ interface */ GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE); /* PC5 CODEC CS */ GPIO_InitStructure.GPIO_Pin = CODEC_CSB_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init(CODEC_CSB_PORT, &GPIO_InitStructure); // WS GPIO_InitStructure.GPIO_Pin = CODEC_I2S_WS_PIN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; #if CODEC_MASTER_MODE GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; #else GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; #endif GPIO_Init(CODEC_I2S_WS_PORT, &GPIO_InitStructure); // CK GPIO_InitStructure.GPIO_Pin = CODEC_I2S_CK_PIN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz; #if CODEC_MASTER_MODE GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; #else GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; #endif GPIO_Init(CODEC_I2S_CK_PORT, &GPIO_InitStructure); // SD GPIO_InitStructure.GPIO_Pin = CODEC_I2S_SD_PIN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(CODEC_I2S_SD_PORT, &GPIO_InitStructure); #ifdef CODEC_USE_MCO /* MCO configure */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA,&GPIO_InitStructure); RCC_MCOConfig(RCC_MCO_HSE); #endif }
void GPIO_ENETConfiguration(void) { RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE); GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 ; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOC, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOB, &GPIO_InitStructure); /* Configure PA1 and PA7 as input */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_7; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOC, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOE, &GPIO_InitStructure); GPIO_WriteBit(GPIOE, GPIO_Pin_9, Bit_SET); RCC_PLL3Config(RCC_PLL3Mul_10); RCC_PLL3Cmd(ENABLE); while (RCC_GetFlagStatus(RCC_FLAG_PLL3RDY) == RESET); RCC_MCOConfig(RCC_MCO_PLL3CLK); }
int main(void) { RCC_DeInit(); clockInit(); GPIO_InitTypeDef gpio; RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); GPIO_StructInit(&gpio); gpio.GPIO_Pin = GPIO_Pin_8; gpio.GPIO_Mode = GPIO_Mode_AF; gpio.GPIO_Speed = GPIO_Speed_40MHz; gpio.GPIO_OType = GPIO_OType_PP; GPIO_Init(GPIOA, &gpio); RCC_MCOConfig(RCC_MCOSource_HSI, RCC_MCODiv_16); while (1) { } }
/** * @brief Configures the Ethernet Interface * @param None * @retval None */ void Ethernet_Configuration(void) { ETH_InitTypeDef ETH_InitStructure; /* MII/RMII Media interface selection ------------------------------------------*/ #ifdef MII_MODE /* Mode MII with STM3210C-EVAL */ GPIO_ETH_MediaInterfaceConfig(GPIO_ETH_MediaInterface_MII); /* Get HSE clock = 25MHz on PA8 pin (MCO) */ RCC_MCOConfig(RCC_MCO_HSE); #elif defined RMII_MODE /* Mode RMII with STM3210C-EVAL */ GPIO_ETH_MediaInterfaceConfig(GPIO_ETH_MediaInterface_RMII); // /* Set PLL3 clock output to 50MHz (25MHz /5 *10 =50MHz) */ // RCC_PLL3Config(RCC_PLL3Mul_10); // /* Enable PLL3 */ // RCC_PLL3Cmd(ENABLE); // /* Wait till PLL3 is ready */ // while (RCC_GetFlagStatus(RCC_FLAG_PLL3RDY) == RESET) // {} // // /* Get PLL3 clock on PA8 pin (MCO) */ // RCC_MCOConfig(RCC_MCO_PLL3CLK); #endif /* Reset ETHERNET on AHB Bus */ ETH_DeInit(); /* Software reset */ ETH_SoftwareReset(); /* Wait for software reset */ while (ETH_GetSoftwareResetStatus() == SET); /* ETHERNET Configuration ------------------------------------------------------*/ /* Call ETH_StructInit if you don't like to configure all ETH_InitStructure parameter */ ETH_StructInit(Ð_InitStructure); /* Fill ETH_InitStructure parametrs */ /*------------------------ MAC -----------------------------------*/ ETH_InitStructure.ETH_AutoNegotiation = ETH_AutoNegotiation_Enable ; ETH_InitStructure.ETH_LoopbackMode = ETH_LoopbackMode_Disable; ETH_InitStructure.ETH_RetryTransmission = ETH_RetryTransmission_Disable; ETH_InitStructure.ETH_AutomaticPadCRCStrip = ETH_AutomaticPadCRCStrip_Disable; ETH_InitStructure.ETH_ReceiveAll = ETH_ReceiveAll_Disable; ETH_InitStructure.ETH_BroadcastFramesReception = ETH_BroadcastFramesReception_Enable; ETH_InitStructure.ETH_PromiscuousMode = ETH_PromiscuousMode_Disable; ETH_InitStructure.ETH_MulticastFramesFilter = ETH_MulticastFramesFilter_Perfect; ETH_InitStructure.ETH_UnicastFramesFilter = ETH_UnicastFramesFilter_Perfect; #ifdef CHECKSUM_BY_HARDWARE ETH_InitStructure.ETH_ChecksumOffload = ETH_ChecksumOffload_Enable; #endif /*------------------------ DMA -----------------------------------*/ /* When we use the Checksum offload feature, we need to enable the Store and Forward mode: the store and forward guarantee that a whole frame is stored in the FIFO, so the MAC can insert/verify the checksum, if the checksum is OK the DMA can handle the frame otherwise the frame is dropped */ ETH_InitStructure.ETH_DropTCPIPChecksumErrorFrame = ETH_DropTCPIPChecksumErrorFrame_Enable; ETH_InitStructure.ETH_ReceiveStoreForward = ETH_ReceiveStoreForward_Enable; ETH_InitStructure.ETH_TransmitStoreForward = ETH_TransmitStoreForward_Enable; ETH_InitStructure.ETH_ForwardErrorFrames = ETH_ForwardErrorFrames_Disable; ETH_InitStructure.ETH_ForwardUndersizedGoodFrames = ETH_ForwardUndersizedGoodFrames_Disable; ETH_InitStructure.ETH_SecondFrameOperate = ETH_SecondFrameOperate_Enable; ETH_InitStructure.ETH_AddressAlignedBeats = ETH_AddressAlignedBeats_Enable; ETH_InitStructure.ETH_FixedBurst = ETH_FixedBurst_Enable; ETH_InitStructure.ETH_RxDMABurstLength = ETH_RxDMABurstLength_32Beat; ETH_InitStructure.ETH_TxDMABurstLength = ETH_TxDMABurstLength_32Beat; ETH_InitStructure.ETH_DMAArbitration = ETH_DMAArbitration_RoundRobin_RxTx_2_1; /* Configure Ethernet */ ETH_Init(Ð_InitStructure, PHY_ADDRESS); /* Enable the Ethernet Rx Interrupt */ ETH_DMAITConfig(ETH_DMA_IT_NIS | ETH_DMA_IT_R, ENABLE); }
/** * @brief Main program. * @param None * @retval None */ int main(void) { GPIO_InitTypeDef GPIO_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_ClocksTypeDef RCC_ClockFreq; /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f0xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f0xx.c file */ /* Initialize Leds mounted on STM32072B-EVAL*/ STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* Turn on LED3 and LED4 */ STM_EVAL_LEDOn(LED3); STM_EVAL_LEDOn(LED4); /* This function fills the RCC_ClockFreq structure with the current frequencies of different on chip clocks (for debug purpose) **************/ RCC_GetClocksFreq(&RCC_ClockFreq); /* Enable Clock Security System(CSS): this will generate an NMI exception when HSE clock fails *****************************************************/ RCC_ClockSecuritySystemCmd(ENABLE); /* Enable and configure RCC global IRQ channel, will be used to manage HSE ready and PLL ready interrupts. These interrupts are enabled in stm32f0xx_it.c file **********************/ #ifdef USE_STM320518_EVAL NVIC_InitStructure.NVIC_IRQChannel = RCC_IRQn; #else NVIC_InitStructure.NVIC_IRQChannel = RCC_CRS_IRQn; #endif /* USE_STM320518_EVAL */ NVIC_InitStructure.NVIC_IRQChannelPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* Output HSE clock on MCO1 pin(PA8) ****************************************/ /* Enable the GPIOA Clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); /* MCO pin configuration: PA8 */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_0); /* Output System Clock on MCO pin */ #ifdef USE_STM320518_EVAL RCC_MCOConfig(RCC_MCOSource_SYSCLK); #else RCC_MCOConfig(RCC_MCOSource_SYSCLK, RCC_MCOPrescaler_1); #endif /* USE_STM320518_EVAL */ while (1) { /* Toggle LED4 */ STM_EVAL_LEDToggle(LED4); /* Insert a delay */ Delay(0x4FFFF); /* Toggle LED3 */ STM_EVAL_LEDToggle(LED3); /* Insert a delay */ Delay(0x3FFFF); } }
int main() { __disable_irq(); // ------------------------------------------------------------------ // Desc: System Clk Config // // HCLK = PCLK2 = SYSCLK = 72M // PCLK1 = 36M // ------------------------------------------------------------------ SystemInit(); // SysTick_Config(SystemCoreClock / 1000); #if 0 // ------------------------------------------------------------------ // Desc: CLK OUTPUT for measure // ------------------------------------------------------------------ //PA8 alternate mode GPIO_InitTypeDef GPIO_InitStructure; RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_0); RCC_MCOConfig(RCC_MCOSource_PLLCLK,RCC_MCOPrescaler_1); // while(1); #endif // ------------------------------------------------------------------ // Desc: Debug // ------------------------------------------------------------------ DebugInit(); // d_printf("UART debug Init OK\r\n"); // ------------------------------------------------------------------ // Desc: ILX511 CLK ON // ------------------------------------------------------------------ #if 1 { GPIO_InitTypeDef GPIO_InitStructure; RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOB, &GPIO_InitStructure); } #endif #if 0 ILX_Init(); __enable_irq(); ILX_CLKOn(); delay_nms(50);//CCD power up ConvertOn(); #endif #if 0 d_printf("\r\n-------------------\r\n"); { uint32_t i; for(i=32;i<2048+32;i++) d_printf("0x%04X ",data[i]); } #endif #if 0 USBInit(); #endif #if 0 while (1) { if (bDeviceState == CONFIGURED) { CDC_Receive_DATA(); if (Receive_length != 0) { if (packet_sent == 1) CDC_Send_DATA ((unsigned char*)Receive_Buffer,Receive_length); Receive_length = 0; } } } #endif while(1); return 0; }
/** * @brief Configures the DP83848V : Ethernet RMII Interface. * @param None * @retval None */ void ET_STM32_ETH_Configuration(void) { vu32 Value = 0; GPIO_InitTypeDef GPIO_InitStructure; ETH_InitTypeDef ETH_InitStructure; /* Enable ETHERNET Clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_ETH_MAC | RCC_AHBPeriph_ETH_MAC_Tx | RCC_AHBPeriph_ETH_MAC_Rx, ENABLE); // Start Initial GPIO For Interface DP83848V // Initial ET-STM32F ARM KIT Ethernet Interface = RMII Mode // PA1 <- ETH_RMII_REF_CLK(Default) // PA2 -> ETH_RMII_MDIO(Default) // PA8 -> MCO(Default) // PB11 -> ETH_RMII_TXEN(Default) // PB12 -> ETH_RMII_TXD0(Default) // PB13 -> ETH_RMII_TXD1(Default) // PC1 -> ETH_RMII_MDC(Default) // PD8 <- ETH_RMII_RXDV(Remap) // PD9 <- ETH_RMII_RXD0(Remap) // PD10 <- ETH_RMII_RXD1(Remap) // Configure PA2 as alternate function push-pull GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //PA2 = ETH_RMII_MDIO GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); // Configure PC1 as alternate function push-pull GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; //PC1 = ETH_RMII_MDC GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOC, &GPIO_InitStructure); // Configure PB11, PB12 and PB13 as alternate function push-pull GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | //PB11 = ETH_RMII_TXEN GPIO_Pin_12 | //PB12 = ETH_RMII_TXD0 GPIO_Pin_13; //PB13 = ETH_RMII_TXD1 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOB, &GPIO_InitStructure); // Configure PA1 as input GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; //PA1 = ETH_RMII_REF_CLK GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA, &GPIO_InitStructure); // ETHERNET pins remapp in ET-STM32F ARM KIT board: RX_DV and RxD[1:0] // PD8=CRS_DV(RMII Remap) // PD9=RXD0(RMII Remap) // PD10=RXD1(RMII Remap) GPIO_PinRemapConfig(GPIO_Remap_ETH, ENABLE); // Configure PD8, PD9, PD10 as input GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | //PD8 = ETH_RMII_RX_DV GPIO_Pin_9 | //PD9 = ETH_RMII_RXD0 GPIO_Pin_10; //PD10 = ETH_RMII_RXD1 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOD, &GPIO_InitStructure); /* Start of Config MCO Clock = 50MHz on PA8 */ // Configure MCO (PA8) as alternate function push-pull GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; //PA8 = MCO GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); // set PLL3 clock output to 50MHz (25MHz / 5 * 10 = 50MHz) RCC_PLL3Config(RCC_PLL3Mul_10); // Enable PLL3 RCC_PLL3Cmd(ENABLE); // Wait till PLL3 is ready while (RCC_GetFlagStatus(RCC_FLAG_PLL3RDY) == RESET){} // Get clock PLL3 clock on PA8 pin RCC_MCOConfig(RCC_MCO_PLL3CLK); /*End of Initial MCO Clock = 50MHz on PA8 */ //Initial Ethernet Interface = RMII Mode GPIO_ETH_MediaInterfaceConfig(GPIO_ETH_MediaInterface_RMII); /* Reset ETHERNET on AHB Bus */ ETH_DeInit(); /* Software reset */ ETH_SoftwareReset(); /* Wait for software reset */ while(ETH_GetSoftwareResetStatus()==SET); /* ETHERNET Configuration ------------------------------------------------------*/ /* Call ETH_StructInit if you don't like to configure all ETH_InitStructure parameter */ ETH_StructInit(Ð_InitStructure); /* Fill ETH_InitStructure parametrs */ /*------------------------ MAC -----------------------------------*/ ETH_InitStructure.ETH_AutoNegotiation = ETH_AutoNegotiation_Enable ; //ETH_InitStructure.ETH_Speed = ETH_Speed_100M; //Test 100 MHz ETH_InitStructure.ETH_LoopbackMode = ETH_LoopbackMode_Disable; //ETH_InitStructure.ETH_Mode = ETH_Mode_FullDuplex; //Test ETH_InitStructure.ETH_RetryTransmission = ETH_RetryTransmission_Disable; ETH_InitStructure.ETH_AutomaticPadCRCStrip = ETH_AutomaticPadCRCStrip_Disable; ETH_InitStructure.ETH_ReceiveAll = ETH_ReceiveAll_Enable; ETH_InitStructure.ETH_BroadcastFramesReception = ETH_BroadcastFramesReception_Disable; ETH_InitStructure.ETH_PromiscuousMode = ETH_PromiscuousMode_Disable; ETH_InitStructure.ETH_MulticastFramesFilter = ETH_MulticastFramesFilter_Perfect; ETH_InitStructure.ETH_UnicastFramesFilter = ETH_UnicastFramesFilter_Perfect; /* Configure ETHERNET */ Value = ETH_Init(Ð_InitStructure, PHY_ADDRESS); }
/** * @brief Configures TIM16 to measure the LSI oscillator frequency. * @param None * @retval None */ void TIM16_ConfigForLSI(void) { NVIC_InitTypeDef NVIC_InitStructure; TIM_ICInitTypeDef TIM_ICInitStructure; /* Enable peripheral clocks ------------------------------------------------*/ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Allow access to the RTC */ PWR_BackupAccessCmd(ENABLE); /* Reset RTC Domain */ RCC_BackupResetCmd(ENABLE); RCC_BackupResetCmd(DISABLE); /*!< LSI Enable */ RCC_LSICmd(ENABLE); /*!< Wait till LSI is ready */ while (RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET) {} /* Select the RTC Clock Source */ RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI); /* Enable the RTC Clock */ RCC_RTCCLKCmd(ENABLE); /* Wait for RTC APB registers synchronisation */ RTC_WaitForSynchro(); /* Enable TIM16 clocks */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM16, ENABLE); /* Enable the TIM16 Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_TIM16_IRQn; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* Configure TIM16 prescaler */ TIM_PrescalerConfig(TIM16, 0, TIM_PSCReloadMode_Immediate); /* Connect internally the TM14_CH1 Input Capture to the LSI clock output */ TIM_RemapConfig(TIM16, TIM16_MCO); RCC_MCOConfig(RCC_MCOSource_LSI); /* TIM16 configuration: Input Capture mode --------------------- The LSI oscillator is connected to TIM16 CH1 The Rising edge is used as active edge, The TIM16 CCR1 is used to compute the frequency value ------------------------------------------------------------ */ TIM_ICInitStructure.TIM_Channel = TIM_Channel_1; TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV8; TIM_ICInitStructure.TIM_ICFilter = 0; TIM_ICInit(TIM16, &TIM_ICInitStructure); /* TIM16 Counter Enable */ TIM_Cmd(TIM16, ENABLE); /* Reset the flags */ TIM16->SR = 0; /* Enable the CC1 Interrupt Request */ TIM_ITConfig(TIM16, TIM_IT_CC1, ENABLE); }
void System_IO_Config(void) { RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC, ENABLE); //-----------------Reset Mmcu-------------------- GPIO_InitStructure.GPIO_Pin = MMCU_RST_PIN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(MMCU_RST_PORT, &GPIO_InitStructure); GPIO_ResetBits(MMCU_RST_PORT,MMCU_RST_PIN); //----------------------CAN-------------------- GPIO_InitStructure.GPIO_Pin = CAN_EN_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz; GPIO_Init(CAN_EN_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = CAN_STB_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz; GPIO_Init(CAN_STB_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = CAN_ERR_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz; GPIO_Init(CAN_ERR_PORT, &GPIO_InitStructure); /* Configure CAN pin: RX */ GPIO_InitStructure.GPIO_Pin = CAN_RX_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(CAN_RX_PORT, &GPIO_InitStructure); /* Configure CAN pin: TX */ GPIO_InitStructure.GPIO_Pin = CAN_TX_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(CAN_TX_PORT, &GPIO_InitStructure); //GPIO_PinRemapConfig(GPIO_Remap1_CAN1, ENABLE); /* Configure CAN2 pin: RX */ GPIO_InitStructure.GPIO_Pin = CAN2_RX_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(CAN2_RX_PORT, &GPIO_InitStructure); /* Configure CAN pin: TX */ GPIO_InitStructure.GPIO_Pin = CAN2_TX_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(CAN2_TX_PORT, &GPIO_InitStructure); //GPIO_PinRemapConfig(GPIO_Remap1_CAN, ENABLE); CAN_STB_SET() ; CAN_EN_SET(); #if Clock_Output_MCO == 1 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); RCC_MCOConfig(RCC_MCO_PLLCLK_Div2); #endif }
/** * @brief Configures TIM16 to measure the LSI oscillator frequency. * @param None * @retval LSI Frequency */ static uint32_t GetLSIFrequency(void) { NVIC_InitTypeDef NVIC_InitStructure; TIM_ICInitTypeDef TIM_ICInitStructure; RCC_ClocksTypeDef RCC_ClockFreq; /* TIM16 configuration *******************************************************/ /* Enable TIM16 clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM16, ENABLE); /* Reset TIM16 registers */ TIM_DeInit(TIM16); /* Configure TIM16 prescaler */ TIM_PrescalerConfig(TIM16, 0, TIM_PSCReloadMode_Immediate); /* Connect internally the TIM16_CH1 to the RTC clock output */ TIM16->OR = 0x3; #if defined(STM32F303xC) RCC_MCOConfig(RCC_MCOSource_LSI); #else /* STM32F334x8 || STM32F302x8 || STM32F303xE */ RCC_MCOConfig(RCC_MCOSource_LSI, RCC_MCOPrescaler_1); #endif /* STM32F303xC */ /* TIM16 configuration: Input Capture mode --------------------- The reference clock(LSE or external) is connected to TIM16 CH1 The Rising edge is used as active edge, The TIM16 CCR1 is used to compute the frequency value ------------------------------------------------------------ */ TIM_ICInitStructure.TIM_Channel = TIM_Channel_1; TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV8; TIM_ICInitStructure.TIM_ICFilter = 0x0; TIM_ICInit(TIM16, &TIM_ICInitStructure); /* Enable the TIM16 global Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_TIM16_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* Enable TIM16 counter */ TIM_Cmd(TIM16, ENABLE); /* Reset the flags */ TIM16->SR = 0; /* Enable the CC1 Interrupt Request */ TIM_ITConfig(TIM16, TIM_IT_CC1, ENABLE); /* Wait until the TIM16 get 2 LSI edges (refer to TIM16_IRQHandler() in stm32F30x_it.c file) ******************************************************/ while(CaptureNumber != 2) { } /* Deinitialize the TIM16 peripheral registers to their default reset values */ TIM_DeInit(TIM16); /* Compute the LSI frequency, depending on TIM16 input clock frequency (PCLK1)*/ /* Get SYSCLK, HCLK and PCLKx frequency */ RCC_GetClocksFreq(&RCC_ClockFreq); /* PCLK1 prescaler equal to 1 => TIMCLK = PCLK1 */ return (LsiFreq); }
/** * @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 */ /* Configure the System clock frequency, HCLK, PCLK2 and PCLK1 prescalers */ SetSysClock(); /* This function fills the RCC_ClockFreq structure with the current frequencies of different on chip clocks (for debug purpose) */ RCC_GetClocksFreq(&RCC_ClockFreq); /* Enable Clock Security System(CSS): this will generate an NMI exception when HSE clock fails */ RCC_ClockSecuritySystemCmd(ENABLE); /* NVIC configuration ------------------------------------------------------*/ NVIC_Configuration(); /* Initialize Leds mounted on STM3210X-EVAL board --------------------------*/ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* Output HSE clock on MCO pin ---------------------------------------------*/ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); RCC_MCOConfig(RCC_MCO_HSE); while (1) { /* Toggle LED1 */ STM_EVAL_LEDToggle(LED1); /* Insert delay */ Delay(DELAY_COUNT); /* Toggle LED2 */ STM_EVAL_LEDToggle(LED2); /* Insert delay */ Delay(DELAY_COUNT); /* Toggle LED3 */ STM_EVAL_LEDToggle(LED3); /* Insert delay */ Delay(DELAY_COUNT); /* Toggle LED4 */ STM_EVAL_LEDToggle(LED4); /* Insert a delay */ Delay(DELAY_COUNT); } }
int main(void) { uint32_t stop_time; uint32_t start_time; RCC_ClocksTypeDef RCC_Clocks; NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4); systick_millis_init(); UART_Init(); timer7_us_init(); delay_us_init(); //LEDS gpio_pinSetup(GPIOC, GPIO_Pin_8, GPIO_Mode_OUT, GPIO_OType_PP, GPIO_PuPd_NOPULL, GPIO_Speed_40MHz); GPIO_WriteBit(GPIOC, GPIO_Pin_8, Bit_SET); //CLOCK OUTPUT PA8 gpio_pinSetup_AF(GPIOA, GPIO_Pin_8, GPIO_AF_MCO, GPIO_OType_PP, GPIO_PuPd_NOPULL, GPIO_Speed_40MHz); RCC_MCOConfig(RCC_MCOSource_SYSCLK, RCC_MCODiv_1); printLn(); printStringLn("------------------------------------------------"); printStringLn("System initialized."); RCC_GetClocksFreq(&RCC_Clocks); printString("SYSCLK_Frequency: "); printNumberLn(RCC_Clocks.SYSCLK_Frequency, DEC); printString("HCLK_Frequency: "); printNumberLn(RCC_Clocks.HCLK_Frequency, DEC); printString("PCLK1_Frequency: "); printNumberLn(RCC_Clocks.PCLK1_Frequency, DEC); printString("PCLK2_Frequency: "); printNumberLn(RCC_Clocks.PCLK2_Frequency, DEC); printString("SYSCLKSource: "); printNumberLn(RCC_GetSYSCLKSource(), DEC); printString("PRESCALER TIM2: "); printNumberLn(TIM_GetPrescaler(TIM3), DEC); printStringLn("------------------------------------------------"); while (1) { GPIO_ToggleBits(GPIOC, GPIO_Pin_8); TIM_SetCounter(TIM7, 0); TIM_Cmd(TIM7, ENABLE); start_time = TIM_GetCounter(TIM7); delay_us(25); stop_time = TIM_GetCounter(TIM7); TIM_Cmd(TIM7, DISABLE); printNumberLn(stop_time - start_time, DEC); delay(100); printNumberLn(millis(), DEC); } }
void stm32f107EthInitGpio(NetInterface *interface) { GPIO_InitTypeDef GPIO_InitStructure; //STM3210C-EVAL evaluation board? #if defined(USE_STM3210C_EVAL) //Enable AFIO clock RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); //Enable GPIO clocks RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD, ENABLE); //Configure MCO (PA8) as an output GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); //Configure MCO pin to output the HSE clock (25MHz) RCC_MCOConfig(RCC_MCO_HSE); //Select MII interface mode GPIO_ETH_MediaInterfaceConfig(GPIO_ETH_MediaInterface_MII); //Configure MII_MDIO (PA2) GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); //Configure MII_PPS_OUT (PB5), ETH_MII_TXD3 (PB8), MII_TX_EN (PB11), //MII_TXD0 (PB12) and MII_TXD1 (PB13) GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_8 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOB, &GPIO_InitStructure); //Configure MII_MDC (PC1) and MII_TXD2 (PC2) GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOC, &GPIO_InitStructure); //Configure ETH_MII_CRS (PA0), ETH_MII_RX_CLK (PA1) and ETH_MII_COL (PA3) GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_3; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA, &GPIO_InitStructure); //Configure ETH_MII_RX_ER (PB10) GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOB, &GPIO_InitStructure); //Configure ETH_MII_TX_CLK (PC3) GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOC, &GPIO_InitStructure); //Configure ETH_MII_RX_DV (PD8), ETH_MII_RXD0 (PD9), ETH_MII_RXD1 (PD10), //ETH_MII_RXD2 (PD11) and ETH_MII_RXD3 (PD12) GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOD, &GPIO_InitStructure); //Remap Ethernet pins GPIO_PinRemapConfig(GPIO_Remap_ETH, ENABLE); //STM32-P107 evaluation board? #elif defined(USE_STM32_P107) //Enable AFIO clock RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); //Enable GPIO clocks RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC, ENABLE); //Configure MCO (PA8) as an output GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); //Configure PLL3 to output a 50MHz clock RCC_PLL3Config(RCC_PLL3Mul_10); //Enable PLL3 RCC_PLL3Cmd(ENABLE); //Wait for the PLL3 to lock while(RCC_GetFlagStatus(RCC_FLAG_PLL3RDY) == RESET); //Configure MCO pin to output the PLL3 clock RCC_MCOConfig(RCC_MCO_PLL3CLK); //Select RMII interface mode GPIO_ETH_MediaInterfaceConfig(GPIO_ETH_MediaInterface_RMII); //Configure ETH_MDIO (PA2) GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); //Configure ETH_RMII_TX_EN (PB11), ETH_RMII_TXD0 (PB12) and ETH_RMII_TXD1 (PB13) GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOB, &GPIO_InitStructure); //Configure ETH_MDC (PC1) GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOC, &GPIO_InitStructure); //Configure ETH_RMII_REF_CLK (PA1) and ETH_RMII_CRS_DV (PA7) GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_7; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA, &GPIO_InitStructure); //Configure ETH_RMII_RXD0 (PC4) and ETH_RMII_RXD1 (PC5) GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOC, &GPIO_InitStructure); //Do not remap Ethernet pins GPIO_PinRemapConfig(GPIO_Remap_ETH, DISABLE); #endif }
/** * @brief Main program. * @param None * @retval None */ void RCC_Example(void) { GPIO_InitTypeDef GPIO_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_ClocksTypeDef RCC_ClockFreq; /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f30x.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f30x.c file */ /* Initialize LEDs mounted on STM32303C-EVAL board ***************************/ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* Turn on LED1 and LED3 */ STM_EVAL_LEDOn(LED1); STM_EVAL_LEDOn(LED3); /* This function fills the RCC_ClockFreq structure with the current frequencies of different on chip clocks (for debug purpose) **************/ RCC_GetClocksFreq(&RCC_ClockFreq); /* Enable Clock Security System(CSS): this will generate an NMI exception when HSE clock fails *****************************************************/ RCC_ClockSecuritySystemCmd(ENABLE); /* Enable and configure RCC global IRQ channel, will be used to manage HSE ready and PLL ready interrupts. These interrupts are enabled in stm32f30x_it.c file **********************/ NVIC_InitStructure.NVIC_IRQChannel = RCC_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* Output HSE clock on MCO1 pin(PA8) ****************************************/ /* Enable the GPIOA peripheral */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); /* Configure MCO1 pin(PA8) in alternate function */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOA, &GPIO_InitStructure); /* HSE clock selected to output on MCO1 pin(PA8)*/ RCC_MCOConfig(RCC_MCOSource_HSE); /* Infinite loop */ while (1) { /* Toggle LED2 and LED4 */ STM_EVAL_LEDToggle(LED2); STM_EVAL_LEDToggle(LED4); /* Insert a delay */ Delay(0x7FFFF); /* Toggle LED1 and LED3 */ STM_EVAL_LEDToggle(LED1); STM_EVAL_LEDToggle(LED3); /* Insert a delay */ Delay(0x7FFFF); } }
/** * @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 */ /* This function fills the RCC_ClockFreq structure with the current frequencies of different on chip clocks (for debug purpose) */ RCC_GetClocksFreq(&RCC_ClockFreq); /* Enable Clock Security System(CSS): this will generate an NMI exception when HSE clock fails */ RCC_ClockSecuritySystemCmd(ENABLE); /* Initialize LEDs mounted on STM32L152-EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* Turn on LED1 and LED3 */ STM_EVAL_LEDOn(LED1); STM_EVAL_LEDOn(LED3); /* Enable and configure RCC global IRQ channel */ NVIC_InitStructure.NVIC_IRQChannel = RCC_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* Enable the GPIOA peripheral */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); /* Output the system clock on MCO pin (PA.08) */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOA, &GPIO_InitStructure); /* System clock selected to output on MCO pin (PA.08)*/ RCC_MCOConfig(RCC_MCOSource_SYSCLK, RCC_MCODiv_1); while (1) { /* Toggle LED2 and LED4 */ STM_EVAL_LEDToggle(LED2); STM_EVAL_LEDToggle(LED4); /* Insert a delay */ Delay(0xFFFF); /* Toggle LED1 and LED3 */ STM_EVAL_LEDToggle(LED1); STM_EVAL_LEDToggle(LED3); /* Insert a delay */ Delay(0xFFFF); } }
int main() { RCC_Config(); // to read and write to AFIO_remap AFIO_clock must first be eanble NVIC_Config(); TIM_Config(); GPIO_Config(); EXTI_Configuration(); initUsart(); //initBT(); // Only for debug the clock tree *********************************************** // Put the clock configuration into RCC_APB2PeriphClockCmd RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); /* Output clock on MCO pin ---------------------------------------------*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); // RCC_MCOConfig(RCC_MCO_HSE); // Put on MCO pin the: freq. of external crystal RCC_MCOConfig(RCC_MCO_SYSCLK); // Put on MCO pin the: System clock selected // //RTCInit(); RCC_GetClocksFreq(&RCC_Clocks); writeStringUSART2("\033[2J"); //clear usart 2 screen writeStringUSART1("\033[2J"); //clear usart 1 screen writeStringUSART1(" <<<<- Welcome To Hinkens Cobra Bluetooth ->>>>\n\n\r"); while(1) { if(GPIO_ReadInputDataBit(GPIOB, COBRA_BOARDSWITCH)== false) writeStringUSART1("On Hook\n\r"); else //Luren är lyft { writeStringUSART1("Phone is off hook!\n\r Dial: \n\r"); acceptCall(); //accept incoming call Delay(Delay_10ms); //for(counter = 0 ; counter < 10 ; counter++) while(TIM_GetITStatus(TIM2, TIM_IT_Update) == RESET) // { dialed_number = 0; while(GPIO_ReadInputDataBit(GPIOB, COBRA_DIALING)== true && GPIO_ReadInputDataBit(GPIOB, COBRA_BOARDSWITCH)== true)//Wait for user to start dialing { //writeStringUSART1("Timer Counter: %d\r\n",TIM_GetCounter(TIM2)); if(state == 1 && dialingFlag == true) //check if timer has run out and user has started a call { writeStringUSART1("time is up dialing number: "); for (int x = 0; x < counter; x++) { //printf("%d", number[x] ); } sendPhoneNumber(number, counter); writeStringUSART1("\r\n"); dialingFlag = false; state = 0; counter = 0; } } Delay(Delay_100ms); //Wait for switch to debounce while(GPIO_ReadInputDataBit(GPIOB, COBRA_DIALING) == false) { dialingFlag = true; state = 0; TIM_SetCounter(TIM2, 0); TIM_Cmd(TIM2, ENABLE); //Start timer //RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); Delay(Delay_10ms); Delay(Delay_10ms); //Now count how many times the mechnical switch toggles if(GPIO_ReadInputDataBit(GPIOB, COBRA_PULSE)== false && pulseFlag == 1) { pulseFlag = 0; dialed_number ++; } else if(GPIO_ReadInputDataBit(GPIOB, COBRA_PULSE) == true && pulseFlag == 0) { pulseFlag = 1; //Do notthing just idle.. } Delay(Delay_10ms); } Delay(Delay_100ms); if(dialed_number != 0) // to handle the error of a extra loop after dialed number { dialed_number--; //Rotary always has one extra closure that must be taken off number[counter] = dialed_number; counter ++; } if(GPIO_ReadInputDataBit(GPIOB, COBRA_BOARDSWITCH)== false) //Hunng upp { hangUp(); //hang-up command to bluettooh writeStringUSART1("Hung up!\n\r"); counter = 0; break; } //printf("%d\n\r", dialed_number); }//end for loop } Delay(Delay_100ms); }//end while(1) }//end 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_stm32f0xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f0xx.c file */ /* Configure Clocks */ RCC_Config(); /* Initialize LEDs, Key Button and LCD available on STM320518-EVAL board *****************************************************/ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* Initialize the LCD */ STM320518_LCD_Init(); /* Display message on LCD ***********************************************/ /* Clear the LCD */ LCD_Clear(White); /* Set the LCD Back Color */ LCD_SetBackColor(Blue); /* Set the LCD Text Color */ LCD_SetTextColor(Yellow); LCD_DisplayStringLine(Line0, MESSAGE1); LCD_DisplayStringLine(Line1, MESSAGE2); /* Set the LCD Back Color */ LCD_SetBackColor(White); /* Set the LCD Text Color */ LCD_SetTextColor(Blue); /* Configure the Push buttons in Polling mode */ STM_EVAL_PBInit(BUTTON_KEY, Mode_GPIO); /* if STM32 device is set as Master */ #ifdef I2C_MASTER /* Configure and enable the systick timer to generate an interrupt each 1 ms */ SysTick_Config((SystemCoreClock / 1000)); /* Deinitialize I2Cx Device */ CPAL_I2C_DeInit(&MASTERSTRUCTURE); /* Initialize CPAL I2C structure parameters values */ CPAL_I2C_StructInit(&MASTERSTRUCTURE); #ifdef CPAL_I2C_DMA_PROGMODEL MASTERSTRUCTURE.wCPAL_Options = CPAL_OPT_NO_MEM_ADDR | CPAL_OPT_DMATX_TCIT; MASTERSTRUCTURE.CPAL_ProgModel = CPAL_PROGMODEL_DMA; #elif defined (CPAL_I2C_IT_PROGMODEL) MASTERSTRUCTURE.wCPAL_Options = CPAL_OPT_NO_MEM_ADDR; MASTERSTRUCTURE.CPAL_ProgModel = CPAL_PROGMODEL_INTERRUPT; #else #error "Please select one of the programming model (in main.h)" #endif /* Set I2C Speed */ MASTERSTRUCTURE.pCPAL_I2C_Struct->I2C_Timing = MASTER_I2C_TIMING; /* Select Master Mode */ MASTERSTRUCTURE.CPAL_Mode = CPAL_MODE_MASTER; /* Initialize I2Cx Device*/ CPAL_I2C_Init(&MASTERSTRUCTURE); /* Infinite loop */ while(1) { /* Initialize Transfer parameters */ MASTERSTRUCTURE.pCPAL_TransferTx = &sTxStructure; sTxStructure.wNumData = BufferSize; sTxStructure.pbBuffer = (uint8_t*)BufferTX; sTxStructure.wAddr1 = OWNADDRESS; /* Update LCD Display */ LCD_SetBackColor(White); LCD_SetTextColor(Blue); LCD_DisplayStringLine(Line8, MEASSAGE_EMPTY); LCD_DisplayStringLine(Line5, MESSAGE4); LCD_DisplayStringLine(Line6, MESSAGE5); /* wait until Key button is pushed */ while(STM_EVAL_PBGetState(BUTTON_KEY)); /* Update LCD Display */ LCD_DisplayStringLine(Line5, MEASSAGE_EMPTY); LCD_DisplayStringLine(Line6, MEASSAGE_EMPTY); /* Write operation */ CPAL_I2C_Write(&MASTERSTRUCTURE); /* Wait until communication finishes */ while ((MASTERSTRUCTURE.CPAL_State != CPAL_STATE_READY) && (MASTERSTRUCTURE.CPAL_State != CPAL_STATE_ERROR)); if (TransferStatus == PASSED) { /* Update LCD Display */ LCD_SetBackColor(Red); LCD_SetTextColor(White); LCD_DisplayStringLine(Line8, MESSAGE6); } else { TransferStatus = PASSED; } Delay(1000); } #endif /* I2C_MASTER */ /* if STM32 device is set as Slave */ #ifdef I2C_SLAVE /* GPIOA Periph clock enable */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); /* Output System Clock on MCO pin (PA.08) */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); RCC_MCOConfig(RCC_MCOSource_SYSCLK); /* Deinitialize I2Cx Device */ CPAL_I2C_DeInit(&SLAVESTRUCTURE); /* Initialize CPAL I2C structure parameters values */ CPAL_I2C_StructInit(&SLAVESTRUCTURE); #ifdef CPAL_I2C_DMA_PROGMODEL SLAVESTRUCTURE.wCPAL_Options = CPAL_OPT_I2C_NACK_ADD | CPAL_OPT_I2C_WAKEUP_STOP | CPAL_OPT_DMARX_TCIT; SLAVESTRUCTURE.CPAL_ProgModel = CPAL_PROGMODEL_DMA; #elif defined (CPAL_I2C_IT_PROGMODEL) SLAVESTRUCTURE.wCPAL_Options = CPAL_OPT_I2C_NACK_ADD | CPAL_OPT_I2C_WAKEUP_STOP; SLAVESTRUCTURE.CPAL_ProgModel = CPAL_PROGMODEL_INTERRUPT; #else #error "Please select one of the programming model (in main.h)" #endif /* Configure Own address 1 */ SLAVESTRUCTURE.pCPAL_I2C_Struct->I2C_OwnAddress1 = OWNADDRESS; /* Set I2C Speed */ SLAVESTRUCTURE.pCPAL_I2C_Struct->I2C_Timing = SLAVE_I2C_TIMING; /* Select Slave Mode */ SLAVESTRUCTURE.CPAL_Mode = CPAL_MODE_SLAVE; /* Initialize I2Cx Device*/ CPAL_I2C_Init(&SLAVESTRUCTURE); /* Infinite loop */ while(1) { /* Reset BufferRX value */ Reset_bBuffer(BufferRX, (uint16_t)BufferSize); /* Initialize Transfer parameters */ SLAVESTRUCTURE.pCPAL_TransferRx = &sRxStructure; sRxStructure.wNumData = BufferSize; sRxStructure.pbBuffer = (uint8_t*)BufferRX; /* Update LCD Display */ LCD_SetBackColor(White); LCD_SetTextColor(Blue); LCD_DisplayStringLine(Line8, MEASSAGE_EMPTY); LCD_DisplayStringLine(Line9, MEASSAGE_EMPTY); LCD_DisplayStringLine(Line5, MESSAGE7); Delay(1000); /* Update LCD Display */ LCD_DisplayStringLine(Line5, MEASSAGE_EMPTY); LCD_DisplayStringLine(Line6, MESSAGE8); /* Read operation */ CPAL_I2C_Read(&SLAVESTRUCTURE); /* Enter Stop Mode and wait for interrupt to wake up */ PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); /* Wait until communication finishes */ while ((SLAVESTRUCTURE.CPAL_State != CPAL_STATE_READY) && (SLAVESTRUCTURE.CPAL_State != CPAL_STATE_ERROR)); /* Configure SystemClock*/ RestoreConfiguration(); /* Configure and enable the systick timer to generate an interrupt each 1 ms */ SysTick_Config((SystemCoreClock / 1000)); /* Update LCD Display */ LCD_DisplayStringLine(Line6, MEASSAGE_EMPTY); LCD_SetBackColor(Red); LCD_SetTextColor(White); LCD_DisplayStringLine(Line8, MESSAGE9); /* If are received correctly */ if (Compare_bBuffer((uint8_t*)BufferTX, BufferRX, BufferSize) == PASSED ) { /* Update LCD Display */ LCD_DisplayStringLine(Line9, MESSAGE6); } else { /* Update LCD Display */ LCD_DisplayStringLine(Line9, MESSAGE10); } Delay(1500); } #endif /* I2C_SLAVE */ }
int main(void) { #if defined(DEBUG) /* * Send a greeting to the standard output (the semi-hosting debug channel * on Debug, ignored on Release). */ printf("Hello ARM World!\n"); #endif /* * At this stage the microcontroller clock setting is already configured, * this is done through SystemInit() function which is called from startup * file (startup_cm.c) before to branch to application main. * To reconfigure the default setting of SystemInit() function, refer to * system_stm32f10x.c file */ /* Use SysTick as reference for the timer */ SysTick_Config(SystemCoreClock / SYSTICK_FREQUENCY_HZ); /* GPIO Periph clock enable for LED */ RCC_AHBPeriphClockCmd(LD_GPIO_PORT_CLK, ENABLE); GPIO_InitTypeDef GPIO_InitStructure; /* Configure the GPIO_LED pins LD3 & LD4*/ GPIO_InitStructure.GPIO_Pin = LD_GREEN_GPIO_PIN | LD_BLUE_GPIO_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init(LD_GPIO_PORT, &GPIO_InitStructure); GPIO_ResetBits(LD_GPIO_PORT, LD_GREEN_GPIO_PIN); GPIO_ResetBits(LD_GPIO_PORT, LD_BLUE_GPIO_PIN); /* GPIO Periph clock enable for MCO */ RCC_AHBPeriphClockCmd(MCO_GPIO_PORT_CLK, ENABLE); GPIO_InitStructure.GPIO_Pin = MCO_GPIO_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz; GPIO_Init(MCO_GPIO_PORT, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_MCO); RCC_MCOConfig(RCC_MCOSource_SYSCLK , RCC_MCODiv_8); int seconds = 0; /* Infinite loop */ while (1) { /* Assume the LED is active low */ /* Turn on led by setting the pin low */ GPIO_ResetBits(LD_GPIO_PORT, LD_GREEN_GPIO_PIN); Delay(BLINK_TICKS); /* Turn off led by setting the pin high */ GPIO_SetBits(LD_GPIO_PORT, LD_GREEN_GPIO_PIN); Delay(BLINK_TICKS); ++seconds; #if defined(DEBUG) /* * Count seconds on the debug channel. */ printf("Second %d\n", seconds); #endif } }