void BSP_Init() { NVIC_Configuration(); #if USING_SRAM_AS_HEAP > 0 FSMC_SRAM_Init(); #endif #if WATCHDOG_ENABLE > 0 WATCHDOG_setTimeOut(15); //如果15秒仍未启动完成,那么就复位 WATCHDOG_enable(); //调试时要屏蔽 #endif _init_alloc(HEAP_BASE, HEAP_TOP); USART1_Init(); USART2_Init(); USART3_Init(); #ifdef STM32F10X_CL UART4_Init(); UART5_Init(); #endif //STM32F10X_CL Delay_ms(10); }
void board_init(void) { printf("\n\n"); printf("BWCT FSB-A920-1\n"); printf("http://www.bwct.de\n"); printf("\n"); #if defined(SDRAM_128M) printf("AT92RM9200 180MHz 128MB\n"); #else printf("AT92RM9200 180MHz 64MB\n"); #endif printf("Initialising USART0\n"); USART0_Init(); printf("Initialising USART1\n"); USART1_Init(); printf("Initialising USART2\n"); USART2_Init(); printf("Initialising USART3\n"); USART3_Init(); printf("Initialising TWI\n"); EEInit(); printf("Initialising DS1672\n"); DS1672_Init(); printf("Initialising Ethernet\n"); printf("MAC %x:%x:%x:%x:%x:%x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); EMAC_Init(); EMAC_SetMACAddress(mac); printf("Initialising SD-card\n"); sdcard_init(); }
int main(void) { unsigned int nCount; unsigned char vEncoder[20]="--------------------"; int i; RCC_Configuration(); RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); NVIC_Configuration(); EXTI_Configuration(); USART1_Init(); USART2_Init(); USART3_Init(); UART4_Init(); UART5_Init(); SPI2_Init(); SysTick_Init(); //init_NRF24L01(); RX_Mode(); //nRF24L01_ISR(); while(1) { //Serial_PutString("While "); } }
void SysInit(void) { //__disable_irq(); SystemInit(); TICK_Init(1); RCC->APB2ENR = (RCC_APB2ENR_AFIOEN | /*enable clock for Alternate Function*/ RCC_APB2ENR_IOPAEN | /* enable clock for GPIOA*/ RCC_APB2ENR_IOPBEN | /*enable clock for GPIOB*/ RCC_APB2ENR_IOPCEN | /*enable clock for GPIOc*/ RCC_APB2ENR_SPI1EN /*enable clock for SPI1*/ ); RCC->CFGR |= RCC_CFGR_USBPRE; // precale is 1 for usb clock RCC->APB1ENR |= RCC_APB1ENR_USBEN;/*enable clock for USB*/ AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_JTAGDISABLE; //Disable JTAG funtion, keep SWJ funtion for debug(only user when PB3,PB4,PB5,PA15 user for another funtion) USART3_Init(SystemCoreClock,115200); __enable_irq(); }
//------------------------------------------------------------------------------ // === Initialize Function === //------------------------------------------------------------------------------ void Init_Main(void) { RCC_Configuration(); //RCC_GetClocksFreq(&rcc_clocks); GPIO_Configuration(); NVIC_Configuration(); DMA_Configuration(); ADC_Configuration(); TIM_Configuration(); EXTI_Configuration(); Tim_Encoder_initial(); USART1_Init(57600); // in 36mhz error 0% USART3_Init(115200);// in 72mhz error 0% //if (SysTick_Config(rcc_clocks.SYSCLK_Frequency / 1000)) //{ /* Capture error */ // while (1); //} }
/********************************** 功能说明 *********************************** * 移植串口 *******************************************************************************/ void vMBM_Serial_Init( uint32_t ulBaudRate, uint8_t ucDataBits, eMBParity eParity ) { USART3_Init( ulBaudRate ); USART3_PortInit( ); }
void RTC_Init(void) { uint32_t tout = 10000000; // GPIOC->CRH &= ~(GPIO_CRH_MODE14 | GPIO_CRH_CNF14 | GPIO_CRH_MODE15 | GPIO_CRH_CNF15); // Clear PC12 // GPIOC->CRH |= GPIO_CRH_CNF14_1 | GPIO_CRH_CNF15_1 | GPIO_CRH_MODE14_0 | GPIO_CRH_MODE15_0; RCC->APB1ENR |= RCC_APB1ENR_PWREN; // enable clock for Power interface PWR->CR |= PWR_CR_DBP; // enable access to RTC, BDC registers if(RTC_SanityCheck() != 0) { rtcTimeSec = RTC_GetCounter(); } //#ifdef RTC_USE_LSI // RCC->CSR |= RCC_CSR_LSION; // enable LSI // while ((RCC->CSR & RCC_CSR_LSIRDY) == 0); // Wait for LSERDY = 1 (LSI is ready) // RCC->BDCR |= (RCC_BDCR_RTCSEL_1 | RCC_BDCR_RTCEN); // set RTC clock source, enable RTC clock //#else // RCC->BDCR |= RCC_BDCR_LSEON; // while ((RCC->BDCR & RCC_BDCR_LSERDY) == 0); // RCC->BDCR |= (RCC_BDCR_RTCSEL_0 | RCC_BDCR_RTCEN); // set RTC clock source, enable RTC clock //#endif // RTC->CRL |= RTC_CRL_CNF; // set configuration mode // RTC->PRLH = 0; // set prescaler load register high //#ifdef RTC_USE_LSI // RTC->PRLL = (40000)/RTC_FREQUENCY - 1;// set prescaler load register low //#else // RTC->PRLL = 32768/RTC_FREQUENCY - 1;// set prescaler load register low //#endif tout = 10000000; RCC->BDCR |= RCC_BDCR_LSEON; while ((RCC->BDCR & RCC_BDCR_LSERDY) == 0) { tout--; if(tout == 0) break; } if(tout){ RCC->BDCR |= (RCC_BDCR_RTCSEL_0 | RCC_BDCR_RTCEN); // set RTC clock source, enable RTC clock RTC->CRL |= RTC_CRL_CNF; // set configuration mode RTC->PRLH = 0; // set prescaler load register high RTC->PRLL = 32768/RTC_FREQUENCY - 1;// set prescaler load register low } else { RCC->BDCR &= ~RCC_BDCR_LSEON; RCC->CSR |= RCC_CSR_LSION; // enable LSI while ((RCC->CSR & RCC_CSR_LSIRDY) == 0); // Wait for LSERDY = 1 (LSI is ready) RCC->BDCR |= (RCC_BDCR_RTCSEL_1 | RCC_BDCR_RTCEN); // set RTC clock source, enable RTC clock RTC->CRL |= RTC_CRL_CNF; // set configuration mode RTC->PRLH = 0; // set prescaler load register high } RTC->CNTH = 0; // set counter high RTC->CNTL = 0; // set counter low RTC->ALRH = 0; // set alarm high RTC->ALRL = 0; // set alarm low //interrupt enable NVIC->ISER[1] |= (1 << (RTCAlarm_IRQn & 0x1F)); // enable interrupt RTC->CRH = RTC_CRH_ALRIE; NVIC->ISER[0] |= (1 << (RTC_IRQn & 0x1F)); // enable interrupt RTC->CRL &= ~RTC_CRL_CNF; // reset configuration mode while ((RTC->CRL & RTC_CRL_RTOFF) == 0) // wait until write is finished { if(tout-- == 0) { USART3_Init(SystemCoreClock/2,__USART3_BAUDRATE); USART3_PutString("\r\nRTC Crystal 32k problem!\r\n"); USART3_PutString("\r\nRTC Crystal 32k problem!\r\n"); USART3_PutString("\r\nRTC Crystal 32k problem!\r\n"); USART3_PutString("\r\nRTC Crystal 32k problem!\r\n"); USART3_PutString("\r\nRTC Crystal 32k problem!\r\n"); break; } } //RTC_SetAlarm((60)); //PWR->CR &= ~PWR_CR_DBP; // disable access to RTC registers }
int main(void) { // u8 a[] = {0xAA, 0xAA, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,0x99,0xa0,0x04,0x10,0x08,0x01,0x08,0x99}; u8 a[] = {0x11, 0x22, 0x33,0x44, 0x55, 0x66, 0x77}; RobotRate rate; WheelSpeed wheelspeed; SystemInit(); USART1_Init(115200); USART2_Init(115200); USART3_Init(38400); UART4_Init(115200); CAN1_Init(); LED_Init(); // TIM2_Init(); TIM3_Init(); SysTick_Init(); Motor_init(); amp_init(); mag_sensor_init(); flash_init(); DelayMs(1000); //Time for Motor Driver Board to init //set_all_speedctl(); t3 = micros(); //*************************initial sensor***************************************************************// while(t < 0x15) { if(UART4RecvPtrR != UART4RecvPtrW) { op = AHRSCheckDataFrame(); if(op == ACC_METER || op == GYRO || op == ANGLE_OUTPUT || op == MAG_METER ) { SensorInitial(op); t++; } } t4 = micros(); time_taken = t4 - t3; if(time_taken > 3000000) { //break; } } sch_init(); sch_add_task(sensors, 6, 20); sch_add_task(AHRS_compute, 1, 50); // sch_add_task(led_task, 4, 100); sch_add_task(UART2Proc, 10, 20); // sch_add_task(UART3Proc, 3, 20); // sch_add_task(UART3Proc, 4, 20); // sch_add_task(FRIDCheck, 2, 20); sch_start(); while (1) { sch_dispatch_tasks(); //Welcome(); } }
int main(void) { u8 len=0; u8 temp[100]; u8 t=0; u8 flag=0; char mode='O'; long value=0; u8 counter=0; //char val2str[]="50"; char SelfCheck='O'; int D_val=0; u8 SelfCheckCounter=0; /////////////////////以上变量定义/////////////////////////// delay_init(72); USART1_Init(19200);//与地面站传递命令 USART2_Init(115200);//与X86板子传递命令 USART3_Init(115200);//调试用 HCSR04_Init(); ResetOLED(); OLED_Init(); Key_Init(); ///////////////以上初始化/////////////////////// OLED_ShowString(35,20,"READY",24); OLED_Refresh_Gram(); delay_ms(1000); OLED_Clear(); /////////////////////////////欢迎界面,提示准备工作///////////////////////////////// while(KEY==1) { OLED_ShowString(0,0,"Self checking now...",12); OLED_Refresh_Gram(); if(USART_RX2_STA&0x8000) { len=USART_RX2_STA&0x3fff;//得到此次接收到的数据长度 for(t=0;t<len;t++) { temp[t]=Rx2Buf[t]; while((USART2->SR&0X40)==0);//等待发送结束 } flag=1; USART_RX2_STA=0; }//接受来自X86的命令,用于自检。 if(flag==1) { SelfCheck=TempOrPressure(temp); { if(SelfCheck=='C') { value=ValueOfMea(temp); if(value==1) { OLED_ShowString(0,15,"Environment ok",12); SelfCheckCounter++; } if(value==2) { OLED_ShowString(0,30,"The data chain ok",12); } if(value==0) { OLED_ShowString(0,42,"Checking fail...",12); } } } memset(temp,0,sizeof(u8)*100); flag=0; }//先对开发环境进行自检,在VS下下发ok标志即可。 OLED_Refresh_Gram(); if(SelfCheckCounter==1)//如果已经通过了开发环境自检 { while(KEY==1)//不按强制退出就一直自检,直到成功 { if(DataChain_SelfTest()==1)//数据链自检完成 break; else continue; } SelfCheckCounter=0; break;//在不按按键强制退出的情况下,只有自检成功了才能退出。 } } OLED_Clear(); /////////////////////////以上对上位机的自检,按键强制结束////////////////// OLED_ShowString(0,0,"Parameters",16); OLED_ShowString(0,16,"X=",12); OLED_ShowString(0,28,"Y=",12); OLED_ShowString(0,40,"S=",12); OLED_ShowString(0,52,"D=",12); OLED_Refresh_Gram(); flag=0;//复位flag ///////////显示参数//////////////////////////////// //AutoLaunch(); ////////////////////////以上开始起飞///////////////////////////////// while(1) { if(USART_RX2_STA&0x8000) { len=USART_RX2_STA&0x3fff;//得到此次接收到的数据长度 for(t=0;t<len;t++) { temp[t]=Rx2Buf[t]; while((USART2->SR&0X40)==0);//等待发送结束 } flag=1; USART_RX2_STA=0; //printf3("%s\r\n",temp); }//接受来自X86的命令 if(flag==1) { mode=TempOrPressure(temp); if(mode=='S') { value=ValueOfMea(temp); { #ifdef __TRANSPARENT_MODE printf1("\"S\":\"%ld\"\r\n",value); #endif #ifdef __COMMAND_MODE E17_SendMsg(CMD_S_PARAM,value); #endif } OLED_ShowNum(20,40,value,6,12); // counter++; } if(mode=='X') { value=ValueOfMea(temp); { #ifdef __TRANSPARENT_MODE printf1("\"X\":\"%ld\"\r\n",value); #endif #ifdef __COMMAND_MODE E17_SendMsg(CMD_X_PARAM,value); #endif } OLED_ShowNum(20,16,value,6,12); // counter++; } else if(mode=='Y') { value=ValueOfMea(temp); { #ifdef __TRANSPARENT_MODE printf1("\"Y\":\"%ld\"\r\n",value); #endif #ifdef __COMMAND_MODE E17_SendMsg(CMD_Y_PARAM,value); #endif } OLED_ShowNum(20,28,value,6,12); // counter++; } { delay_ms(10);//太小在透传情况下可能出问题? { D_val=HCSR04_GetDistance_Filter(); #ifdef __TRANSPARENT_MODE printf1("\"D\":\"%ld\"\r\n",D_val); #endif #ifdef __COMMAND_MODE E17_SendMsg(CMD_D_PARAM,value); #endif } OLED_ShowNum(20,52,D_val,6,12); // counter=0; }//去掉了判断,每个周期都要做判断,同时进行距离的pid调控。 OLED_Refresh_Gram(); memset(temp,0,sizeof(u8)*100); flag=0; } } }