/** * @brief Main program. * @param None * @retval None */ int main(void) { uint32_t x; /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f072xb.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f0xx.c file */ /* initialization of the tables values for DAC signal generations */ for (x = 0; x < SIN1_ARRAY_SIZE; x++) { sin1_data[x] = (uint32_t) GenerateWave(INCREMENT1, DAC_AMPL_MAX); /* as the DAC buffer are enabled */ sin1_data[x] += sin1_data[x] << 16; } ConfigureGPIO(); ConfigureGPIOasAnalog(); ConfigureDAC(); ConfigureDMA(); ConfigureTIM7(); __WFI(); /* If an error occurs or the execution is stop by debugger, the wait mode is exited */ SysTick_Config(48000); /* 1ms config */ while (1) /* Infinite loop only reach in case of error */ { } }
/** * @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_stm32f072xb.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f0xx.c file PLL is set to x12 with a PREDIV /2 so the system clock SYSCLK = 48MHz */ ConfigureGPIO(); SetClockForADC(); CalibrateADC(); ConfigureGPIOforADC(); EnableADC(); ConfigureADC(); ConfigureDMA(); ADC1->CR |= ADC_CR_ADSTART; /* start the ADC conversions */ GPIOC->BSRR = (1<<9); /* switch on the green led */ __WFI(); /* No interrupt should occur, as only error could trigger an interrupt */ GPIOC->BRR = (1<<9); /* switch off the green led */ DisableADC(); SysTick_Config(48000); /* 1ms config */ while (1) /* Infinite loop */ { } }
/** * @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_stm32f072xb.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f0xx.c file PLL is set to x12 with a PREDIV /2 so the system clock SYSCLK = 48MHz */ ConfigureGPIO(); ConfigureExternalIT(); RCC->APB2ENR = RCC_APB2ENR_ADC1EN; /* Enable the peripheral clock of the ADC */ RCC->CFGR |= RCC_CFGR_PPRE_2; /* Set peripheral prescaler to /2 so PCLK = HCLK/2 = 24MHz */ CalibrateADC(); EnableADC(); ConfigureADC(); ConfigureDMA(); ADC1->CR |= ADC_CR_ADSTART; /* Start the ADC conversions */ while (error < ERROR_UNEXPECTED_DMA_IT) /* loop till no unrecoverable error */ { __WFI(); } DisableADC(); SysTick_Config(48000); /* 1ms config */ while (1) /* Infinite loop */ { } }
/** * @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_stm32f072xb.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f0xx.c file PLL is set to x12 with a PREDIV /2 so the system clock SYSCLK = 48MHz */ ConfigureGPIO(); ConfigureExternalIT(); SetClockForADC(); CalibrateADC(); ConfigureGPIOforADC(); EnableADC(); ConfigureADC(); CurrentChannel = 0; /* Initializes the CurrentChannel */ ADC1->CR |= ADC_CR_ADSTART; /* start the ADC conversions */ while (error == 0) /* loop till no unrecoverable error, should never be exited */ { __WFI(); } DisableADC(); SysTick_Config(48000); /* 1ms config */ while (1) /* Infinite loop */ { } }
/** * @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_stm32f072xb.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f0xx.c file */ ConfigureGPIO(); SysTick_Config(48000);/* 1ms config */ ConfigureTIMxForETR(); while (1) /* Infinite loop */ { } }
/** * @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_stm32f072xb.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f0xx.c file */ ConfigureGPIO(); RCC->CFGR |= RCC_CFGR_MCO_SYSCLK; /* Select system clock to be output on the MCO without prescaler */ /* Infinite loop */ while (1) { } }
/** * @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_stm32f072xb.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f0xx.c file PLL is set to x12 with a PREDIV /2 so the system clock SYSCLK = 48MHz */ /* defines the upper limit 15% above the factory value the value is adapted according to the application power supply versus the factory calibration power supply */ uint16_t vrefint_high = (*VREFINT_CAL_ADDR)* VDD_CALIB / VDD_APPLI * 115 / 100; /* defines the lower limit 15% below the factory value the value is adapted according to the application power supply versus the factory calibration power supply */ uint16_t vrefint_low = (*VREFINT_CAL_ADDR) * VDD_CALIB / VDD_APPLI * 85 / 100; ConfigureGPIO(); SetClockForADC(); CalibrateADC(); EnableADC(); ConfigureADC(); ConfigureTIM15(); ADC1->CR |= ADC_CR_ADSTART; /* start the ADC conversion */ while (error == 0) /* Loop till the measure is in the range */ { while ((ADC1->ISR & ADC_ISR_EOC) == 0); /* wait end of conversion */ if ((ADC1->DR > vrefint_high) && (ADC1->DR > vrefint_low)) { error |= WARNING_MEASURE; /* report a warning, the measure being out of range due to VDD shift */ } GPIOC->ODR ^= (1<<9); /* Toggle green led on PC9 */ } DisableADC(); SysTick_Config(48000); /* 1ms config */ while(1) { } }
/** * @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_stm32f072xb.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f0xx.c file */ ConfigureGPIO(); SysTick_Config(48000);/* 1ms config */ ConfigureTIMxAsPWM_Input(); ConfigureDMA(); GPIOC->BSRR = 1<<9; /* switch on green led */ while (error < ERROR_UNEXPECTED_DMA_IT) { __WFI(); } GPIOC->BRR = 1<<9; /* switch off green led */ while (1) /* Infinite loop */ { } }
void main(void) { char TempVar; // variable used for IMU chip Autotest unsigned char IMUAutotestResult; // structure used to store IMU data struct IMUData CurrentIMUData; // variable for CAN TX FIFO buffer struct CANTxMsg TempCANTxMsg; // variable for CAN RX FIFO buffer struct CANRxMsg TempCANRxMsg; //---------------------------------------------------- //---------- CPU internal configurations: ----------- //---------------------------------------------------- CLRWDT(); // clear watchdog timer at startup /* Configure the oscillator for the CPU */ ConfigureOscillator(); __delay_ms(10); // wait for Oscillator to be stabilized // configure CPU GPIO for IMU board ConfigureGPIO(); //USART Initialize(); ConfigureUSART1(); ConfigureUSART2(); // SPI initialize ConfigureSPI(); //CAN controller Initialize ECANInitialize(); //Set MASK and Filters for CAN ECANFiltersInit(); // Timers configuration ConfigureTimers(); //---------------------------------------------------- //---------- Global variables initialisation -------- //---------------------------------------------------- // tick counter initialisation TickCounter.AccelTick_ms=0; TickCounter.GyroTick_ms=1; TickCounter.MagnetTick_ms=2; // initialize CAN tx FIFO CANTxFifoInit(); CANRxFifoInit(); // initialise USART RX FIFO's USARTFifoInit (); //---------------------------------------------------- //------ external peripheral configurations: -------- //---------------------------------------------------- __delay_ms(10); // wait for reset to be released on external peripherals ISM_RESET = 0; // release reset of ISM module IMUInitRegisters(); // init of BMX055 chip IMUAutotestResult=IMUAutotest(); // launch IMU autotest //---------------------------------------------------- //---------- GSM startup delay ----------- //---------------------------------------------------- GSM_RTS=1; for(char i=0;i<200;i++) { __delay_ms(10); CLRWDT(); // clear watchdog timer each loop } GSM_RTS=0; __delay_ms(10); __delay_ms(10); //---------------------------------------------------- //---------- Ready to go in main loop: ----------- //---------- interrupts activation ----------- //---------------------------------------------------- ConfigureInterrupts(); LED1=1; // everything is initialized: enable the PWR/booted LED //---------------------------------------------------- //---------- GSM dummy AT command ----------- //---------------------------------------------------- USART1Write('A'); USART1Write('T'); USART1Write(0x0D); for(char i=0;i<10;i++) { __delay_ms(10); } //----------------------------------------------------- //------------- infinite main loop ---------- //---------------------------------------------------- while(1) { //-------------------------------------------------------------------------------- //------------- periodic tasks occures according to TickCounter variable---------- //-------------------------------------------------------------------------------- if(TickCounter.AccelTick_ms>IMU_TICK_PERIOD) { CLRWDT(); // clear watchdog timer each real time cycles LED2=1; TickCounter.AccelTick_ms=0; // reset IMU tick counter to 0 CurrentIMUData = IMUUpdateData(); // update IMU data from sensor // send Accelerometer data to CAN Fifo TempCANTxMsg.data_TX[0]=(char)(CurrentIMUData.XAccelerationData>>8); //fill data buffer TempCANTxMsg.data_TX[1]=(char)(CurrentIMUData.XAccelerationData); TempCANTxMsg.data_TX[2]=(char)(CurrentIMUData.YAccelerationData>>8); TempCANTxMsg.data_TX[3]=(char)(CurrentIMUData.YAccelerationData); TempCANTxMsg.data_TX[4]=(char)(CurrentIMUData.ZAccelerationData>>8); TempCANTxMsg.data_TX[5]=(char)(CurrentIMUData.ZAccelerationData); TempCANTxMsg.data_TX[6]=0; TempCANTxMsg.data_TX[7]=0; TempCANTxMsg.dataLen= ACCEL_DATA_MESSAGE_LEN; TempCANTxMsg.id = (CAN_MESSAGE_IMU_TYPE << 7 | CAN_DEVICE_ADRESS <<4 | ACCEL_DATA_MESSAGE_ADRESS ); TempCANTxMsg.flags = ECAN_TX_STD_FRAME; if(!CANTxFifo.Fifofull) PutCANTxFifo(TempCANTxMsg); LED2=0; } if(TickCounter.GyroTick_ms>IMU_TICK_PERIOD) { //LED2=1; TickCounter.GyroTick_ms=0; // reset IMU tick counter to 0 // send Gyro data to CAN Fifo TempCANTxMsg.data_TX[0]=(char)(CurrentIMUData.XGyroscopeData>>8); TempCANTxMsg.data_TX[1]=(char)(CurrentIMUData.XGyroscopeData); TempCANTxMsg.data_TX[2]=(char)(CurrentIMUData.YGyroscopeData>>8); TempCANTxMsg.data_TX[3]=(char)(CurrentIMUData.YGyroscopeData); TempCANTxMsg.data_TX[4]=(char)(CurrentIMUData.ZGyroscopeData>>8); TempCANTxMsg.data_TX[5]=(char)(CurrentIMUData.ZGyroscopeData); TempCANTxMsg.dataLen= GYRO_DATA_MESSAGE_LEN; TempCANTxMsg.id = (CAN_MESSAGE_IMU_TYPE << 7 | CAN_DEVICE_ADRESS <<4 | GYRO_DATA_MESSAGE_ADRESS ); TempCANTxMsg.flags = ECAN_TX_STD_FRAME; if(!CANTxFifo.Fifofull) PutCANTxFifo(TempCANTxMsg); }