/** * @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_stm32f4xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f4xx.c file */ /* Initialize LEDs mounted on STM324xG-EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); /* Configure EXTI Line0 (connected to PA0 pin) in interrupt mode */ EXTILine0_Config(); /* Configure EXTI Line14 (connected to PB14 pin) in interrupt mode */ EXTILine14_Config(); /* Generate software interrupt: simulate a falling edge applied on EXTI0 line */ EXTI_GenerateSWInterrupt(EXTI_Line0); while (1) { } }
int main(void) { GPIO_InitTypeDef GPIO_InitDef; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOG, ENABLE); GPIO_InitDef.GPIO_Pin = GPIO_Pin_All; GPIO_InitDef.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitDef.GPIO_OType = GPIO_OType_PP; GPIO_InitDef.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitDef.GPIO_Speed = GPIO_Speed_2MHz; //Initialize pins GPIO_Init(GPIOG, &GPIO_InitDef); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); GPIO_InitDef.GPIO_Pin = GPIO_Pin_All; GPIO_InitDef.GPIO_Mode = GPIO_Mode_IN; GPIO_InitDef.GPIO_OType = GPIO_OType_PP; GPIO_InitDef.GPIO_PuPd = GPIO_PuPd_DOWN; GPIO_InitDef.GPIO_Speed = GPIO_Speed_2MHz; //Initialize pins GPIO_Init(GPIOA, &GPIO_InitDef); GPIO_SetBits(GPIOA, GPIO_Pin_All); EXTILine11_Config(); EXTILine12_Config(); EXTILine13_Config(); EXTILine14_Config(); while (1) { /*if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0)) { GPIO_SetBits(GPIOG, GPIO_Pin_13 | GPIO_Pin_14); } else if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_1)) { GPIO_SetBits(GPIOG, GPIO_Pin_13); GPIO_ResetBits(GPIOG, GPIO_Pin_14); } else if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_2)) { GPIO_SetBits(GPIOG, GPIO_Pin_14); GPIO_ResetBits(GPIOG, GPIO_Pin_13); }*/ // else { // GPIO_ResetBits(GPIOG, GPIO_Pin_13 | GPIO_Pin_14); // } } }
void pyb_cc3000_spi_init(void) { DEBUG_printf("pyb_cc3000_spi_init\n"); // enable SPI clock RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE); // GPIO clocks should already be enabled /*!< SPI pins configuration *************************************************/ /*!< Connect SPI pins to AF5 */ GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_SPI2); GPIO_PinAFConfig(GPIOB, GPIO_PinSource14, GPIO_AF_SPI2); GPIO_PinAFConfig(GPIOB, GPIO_PinSource15, GPIO_AF_SPI2); GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; 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_DOWN; GPIO_Init(GPIOB, &GPIO_InitStructure); /* inf.baudRate = 100000; // FIXME - just slow for debug inf.spiMode = SPIF_SPI_MODE_1; // Mode 1 CPOL= 0 CPHA= 1 */ /*!< SPI configuration */ SPI_InitTypeDef SPI_InitStructure; SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; SPI_InitStructure.SPI_Mode = SPI_Mode_Master; SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; // should be correct SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; // clock is low when idle SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; // data latched on second edge, which is falling edge for low-idle SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; // software control SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8; // clock freq = f_PCLK / this_prescale_value SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; // should be correct SPI_InitStructure.SPI_CRCPolynomial = 7; // ? SPI_Init(SPI2, &SPI_InitStructure); /*!< Enable the SPI */ SPI_Cmd(SPI2, ENABLE); /* // WLAN CS, EN and WALN IRQ Configuration jshSetPinStateIsManual(WLAN_CS_PIN, false); jshPinOutput(WLAN_CS_PIN, 1); // de-assert CS jshSetPinStateIsManual(WLAN_EN_PIN, false); jshPinOutput(WLAN_EN_PIN, 0); // disable WLAN jshSetPinStateIsManual(WLAN_IRQ_PIN, true); jshPinSetState(WLAN_IRQ_PIN, JSHPINSTATE_GPIO_IN_PULLUP); // flip into read mode with pullup */ // configure wlan CS and EN pins GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOC, &GPIO_InitStructure); pyb_cc3000_set_cs(1); // de-assert CS pyb_cc3000_set_en(0); // disable wlan // configure EXTI on A14 EXTILine14_Config(); // wait a little (ensure that WLAN takes effect) sys_tick_delay_ms(500); // force a 500ms delay! FIXME }