int eth_gpio_init(struct driver* driver) { unsigned char i; for(i=0; i<(sizeof(eth_gpio_rcc)/sizeof(eth_gpio_rcc[0])); i++) { if(rcc_config(ð_gpio_rcc[i], (GB_StateType)ENABLE)) return -1; } if(rcc_config(ð_syscfg_rcc, (GB_StateType)ENABLE)) return -1; SYSCFG_ETH_MediaInterfaceConfig(SYSCFG_ETH_MediaInterface_RMII); GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; /* Configure PA1, PA2 and PA7 */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_7; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOA, GPIO_PinSource1, GPIO_AF_ETH); GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_ETH); GPIO_PinAFConfig(GPIOA, GPIO_PinSource7, GPIO_AF_ETH); /* Configure PC1, PC4 and PC5 */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5; GPIO_Init(GPIOC, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOC, GPIO_PinSource1, GPIO_AF_ETH); GPIO_PinAFConfig(GPIOC, GPIO_PinSource4, GPIO_AF_ETH); GPIO_PinAFConfig(GPIOC, GPIO_PinSource5, GPIO_AF_ETH); /* Configure PG11, PG14 and PG13 */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_13 | GPIO_Pin_14; GPIO_Init(GPIOG, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOG, GPIO_PinSource11, GPIO_AF_ETH); GPIO_PinAFConfig(GPIOG, GPIO_PinSource13, GPIO_AF_ETH); GPIO_PinAFConfig(GPIOG, GPIO_PinSource14, GPIO_AF_ETH); /* Configure PH6 */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOH, &GPIO_InitStructure); return 0; }
//-------------- //main loop int main(void) { int i=0; for(i=0;i<100000ul;i++); rcc_config(); nvic_config(); gpio_config(); usart_config(); USART_puts(USART1, "USART BT initialization complete!\r\n"); // just send a message to indicate that it works MPU6050_I2C_Init(); MPU6050_Initialize(); if( MPU6050_TestConnection() == 1){ // connection success USART_puts(USART1, "I2C IMU connection initialization complete!\r\n"); }else{ // connection failed USART_puts(USART1, "I2C initialization failed!\r\n"); } //sysTick_Config_Mod(SysTick_CLKSource_HCLK_Div8, 10500000ul); // interruption every 1/2sec from systick sysTick_Config_Mod(SysTick_CLKSource_HCLK_Div8, 840000ul); // interruption every 0.04sec from systick while(1) { } }
int window_fan() { rcc_config(); delay_config(); led_debug_config(); motor_config(); led_blue_off(); led_green_off(); servo_config(); servo_set_pos(0); servo_start(); u32 i; u32 from = 0; u32 to = 180; u32 delay = 2000; while(1) { motor_forward(); led_blue_on(); led_green_off(); for(i=from; i<to; i++) { servo_set_pos(i); delay_ms(delay); } led_blue_off(); led_green_on(); for(i=to; i>from; i--) { servo_set_pos(i); delay_ms(delay); } motor_stop(); delay_ms(10000); } }
int reader_test() { rcc_config(); led_debug_config(); motor_config(); reed_config(); led_blue_off(); led_green_off(); uint8_t i; while(1) { // forward motor_forward(); led_blue_on(); reed_delay_left(); // stop motor_stop(); led_blue_off(); bigDelay(); bigDelay(); bigDelay(); // backward motor_back(); led_green_on(); reed_delay_right(); // stop motor_stop(); led_green_off(); bigDelay(); bigDelay(); bigDelay(); } }
int stepper_test() { rcc_config(); delay_config(); led_debug_config(); button_config(); pwm_config(); SysTick_Config( SystemCoreClock / 10000); pwm_start(); RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); uart_debug_config(); //pwm_set(10); // 10 - 100 ms // 100 - 10 ms // 1000 - 1 ms // 10,000 - 100 us // 100,000 - 10 us // 1,000,000 - 3 us led_blue_off(); led_green_off(); //TIM2->CCR2 = 10; RCC_ClocksTypeDef Sys_RCC_Clocks; RCC_GetClocksFreq(&Sys_RCC_Clocks); debugf("SYSCLK_Frequency : %d Hz\n", Sys_RCC_Clocks.SYSCLK_Frequency); debugf("HCLK_Frequency : %d Hz\n", Sys_RCC_Clocks.HCLK_Frequency); debugf("PCLK1_Frequency : %d Hz\n", Sys_RCC_Clocks.PCLK1_Frequency); debugf("PCLK2_Frequency : %d Hz\n", Sys_RCC_Clocks.PCLK2_Frequency); debugf("ADCCLK_Frequency : %d Hz\n", Sys_RCC_Clocks.ADCCLK_Frequency); int i=0; while(1) { //delay_ms(1000); for (int i=0; i<1000000; i++) {} if(i>100) i=0; i++; //TIM2->CCR2 = i; //TIM2->CR1 |= TIM_CR1_CEN; // led_green_on(); // led_blue_off(); // delay_ms(1000); // led_green_off(); // led_blue_on(); // delay_ms(1000); } }
static int eth_init(struct driver * driver) { struct eth_attr *attr = (struct eth_attr *)driver->attr; unsigned char i; for(i=0; i<3; i++) { if(rcc_config(driver->rcc+i, (GB_StateType)ENABLE)) return -1; } ETH_SoftwareReset();/* Software reset */ while (ETH_GetSoftwareResetStatus() == SET);/* Wait for software reset */ ETH_InitTypeDef ETH_InitStructure; /* 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_AutoNegotiation = ETH_AutoNegotiation_Disable; // ETH_InitStructure.ETH_Speed = ETH_Speed_10M; // ETH_InitStructure.ETH_Mode = ETH_Mode_FullDuplex; 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 */ if(ETH_SUCCESS == ETH_Init(Ð_InitStructure, attr->phy_addr)) ETH_DMAITConfig(ETH_DMA_IT_NIS | ETH_DMA_IT_R, ENABLE); else return -1; return 0; }