void range_finder_init() { /* MCU Configuration----------------------------------------------------------*/ /* Initialize all configured peripherals */ MX_I2C1_Init(); tca9545_init(); tca9545_set(Channel_0); /* these almost just redo what already done just above by CubeMx Init */ XNUCLEO6180XA1_GPIO_Init(); XNUCLEO6180XA1_I2C1_Init(&hi2c1); tca9545Channel_e channel; for(channel = Channel_0; channel <= Channel_3; channel++) { tca9545_set(channel); MyDev_Init(myDev); // your code init device variable MyDev_SetChipEnable(myDev); // your code assert chip enable MyDev_uSleep(1000); // your code sleep at least 1 msec VL6180x_InitData(myDev); VL6180x_Prepare(myDev); } }
int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_I2C1_Init(); MX_TIM16_Init(); MX_USART1_UART_Init(); /* USER CODE BEGIN 2 */ SET_BIT(USART1->CR1, USART_CR1_RXNEIE); sensact::cOneWireApplication testApp; sensact::cOneWire::Start(&testApp); testApp.Run(&hi2c1); return 0; }
int main(void) { HAL_Init(); SystemClock_Config(); MX_GPIO_Init(); MX_CAN_Init(); MX_I2C1_Init(); MX_USART3_UART_Init(); MX_USART2_UART_Init(); MX_USART1_UART_Init(); MX_TIM1_Init(); USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS); USBD_RegisterClass(&hUsbDeviceFS, &USBD_CUSTOM_HID); USBD_CUSTOM_HID_RegisterInterface(&hUsbDeviceFS, &USBD_CustomHID_fops_FS); USBD_Start(&hUsbDeviceFS); while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_1); HAL_Delay(blinkingDelay); } /* USER CODE END 3 */ }
int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_DMA_Init(); MX_ADC1_Init(); MX_I2C1_Init(); MX_RTC_Init(); MX_SPI2_Init(); MX_TIM1_Init(); MX_TIM2_Init(); MX_TIM3_Init(); MX_TIM4_Init(); MX_USART3_UART_Init(); /* USER CODE BEGIN 2 */ encoderInit(); pwmInit(); // adcInit(); uartInit(); timInterruptInit(); gyroInit(GYROHIGH); calibrateGyro(); // rotaryRight(800); // HAL_Delay(500); // rotaryLeft(800); drive(VEL); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ }
int main(void) { /* USER CODE BEGIN 1 */ SCB->VTOR = FLASH_START_SECTOR_ADDR; SEGGER_RTT_Init(); /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_ADC1_Init(); MX_I2C1_Init(); MX_I2C2_Init(); MX_SPI1_Init(); MX_TIM3_Init(); MX_USART2_UART_Init(); MX_RTC_Init(); /* USER CODE BEGIN 2 */ //as7000_init(); /* USER CODE END 2 */ /* Call init function for freertos objects (in freertos.c) */ MX_FREERTOS_Init(); /* Start scheduler */ osKernelStart(); /* We should never get here as control is now taken by the scheduler */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ }
int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_COMP1_Init(); MX_COMP2_Init(); MX_I2C1_Init(); MX_TIM3_Init(); MX_USART1_UART_Init(); MX_ADC_Init(); MX_DMA_Init(); /* USER CODE BEGIN 2 */ init_all(); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { period_time_check_flags(); // if (HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_4) != GPIO_PIN_RESET) // { // HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_10); // buzzer(beeps,1); // buzzer_speed(100); // } /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ speed_counter++; } /* USER CODE END 3 */ }
/** * @brief The application entry point. * @retval int */ int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration--------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_USART2_UART_Init(); MX_I2C1_Init(); MX_TIM2_Init(); /* USER CODE BEGIN 2 */ Display_Init(); CircularBuff_Init(); DisplayUpdater_Init(); HAL_TIM_Base_Start_IT(&htim2); //start timer2 in interrupt mode. /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ __WFI(); // CPU sleep } /* USER CODE END 3 */ }
int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_DMA_Init(); MX_ADC1_Init(); MX_I2C1_Init(); MX_IWDG_Init(); MX_SDADC1_Init(); MX_SDADC2_Init(); MX_TSC_Init(); MX_TIM2_Init(); MX_TIM3_Init(); MX_SDADC3_Init(); MX_USB_DEVICE_Init(); MX_RTC_Init(); MX_TIM6_Init(); MX_TIM7_Init(); /* USER CODE BEGIN 2 */ Setup(); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ loop(); } /* USER CODE END 3 */ }
int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_DMA_Init(); MX_ADC1_Init(); MX_I2C1_Init(); MX_SPI1_Init(); MX_TIM1_Init(); MX_TIM4_Init(); MX_TIM6_Init(); MX_USART1_UART_Init(); MX_USART2_UART_Init(); MX_USART3_UART_Init(); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ FlyMain(); } /* USER CODE END 3 */ }
int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_I2C1_Init(); MX_TIM1_Init(); MX_TIM3_Init(); MX_ADC1_Init(); MX_TIM2_Init(); /* USER CODE BEGIN 2 */ //Start PWM HAL_TIM_Base_Start(&htim1); HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_ALL); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5); HAL_Delay(100); /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ }
int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* System interrupt init*/ /* Sets the priority grouping field */ HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_0); HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_DMA_Init(); MX_I2C1_Init(); MX_I2S2_Init(); MX_I2S3_Init(); MX_SPI1_Init(); MX_SPI4_Init(); MX_TIM3_Init(); MX_USART2_UART_Init(); MX_USB_DEVICE_Init(); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ /*## FatFS: Link the USER disk I/O driver ###############################*/ USER_DriverNum = FATFS_LinkDriver(&USER_Driver, USER_Path); /* USER CODE BEGIN 3 */ dabstick_loop(); // endless return 0; /* USER CODE END 3 */ }
int main(void) { /* USER CODE BEGIN 1 */ uint32_t i; /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_I2C1_Init(); MX_RTC_Init(); MX_USART1_UART_Init(); /* USER CODE BEGIN 2 */ for(i=0; i<ARRAY_SIZE; i++){ write_data[i] = i; } // Write some data to the selected address FRAM_MultiByte_Write(&hi2c1, 0x10000, &write_data[0], ARRAY_SIZE); // Read the data from the selected address FRAM_MultiByte_Selective_Read(&hi2c1, 0x10000, &read_data[0], ARRAY_SIZE); /* USER CODE END 2 */ /* USER CODE BEGIN 3 */ /* Infinite loop */ while (1) { } /* USER CODE END 3 */ }
void board_init() { /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); MX_GPIO_Init(); #if ENABLE_UART MX_USART1_UART_Init(); uart_printf("\r\n\r\nUART online!\r\n"); #endif MX_ADC_Init(); MX_I2C1_Init(); uart_printf("board_init done\r\n"); }
int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_I2C1_Init(); MX_USART2_UART_Init(); /* USER CODE BEGIN 2 */ HAL_DBGMCU_EnableDBGSleepMode(); HAL_SuspendTick(); // we don't want systick to wake us up every 1ms main_app(); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI); } /* USER CODE END 3 */ }
int main(void) { /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_DMA_Init(); MX_ADC1_Init(); MX_I2C1_Init(); MX_TIM10_Init(); MX_TIM11_Init(); MX_USART1_UART_Init(); xTaskCreate(task_safety, "Safety", 350, NULL, 1, NULL); xTaskCreate(task_master, "Master", 350, NULL, 1, NULL); xTaskCreate(task_control, "Control", 1000, NULL, 3, NULL); xTaskCreate(task_test, "Test", 500, NULL, 4, NULL); update_coefficients_QUEUE = xQueueCreate(3, sizeof(uint8_t)); control_sig_QUEUE = xQueueCreate(3, sizeof(int16_t));; vSemaphoreCreateBinary(testing_SEMAPHORE); vSemaphoreCreateBinary(data_SEMAPHORE); osKernelStart(); /* We should never get here as control is now taken by the scheduler */ /* Infinite loop */ while (1) { } }
int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_ADC_Init(); MX_I2C1_Init(); MX_RTC_Init(); MX_USART1_UART_Init(); MX_SPI2_Init(); /* Initialize interrupts */ MX_NVIC_Init(); /* USER CODE BEGIN 2 */ HAL_ADCEx_Calibration_Start(&hadc, ADC_SINGLE_ENDED); /* Enable Ultra low power mode */ HAL_PWREx_EnableUltraLowPower(); __HAL_RCC_WAKEUPSTOP_CLK_CONFIG(RCC_STOP_WAKEUPCLOCK_HSI); /* Buffer used for transmission on USART1 */ char tx1_buffer[120]; RFM95_init(&hspi2); uint8_t payload_buff[14]; PAYLOAD_Garden payload_garden; payload_garden.MessageType = 50; payload_garden.MessageId = 0; // Start in sensing mode. state = MAIN_STATE_SENSE; /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ /* Do some work */ if (state == MAIN_STATE_SENSE) { HAL_ADC_Start(&hadc); // junk readings payload_garden.Temperature = TEMPERATURE_external(); payload_garden.CpuTemperature = TEMPERATURE_cpu(); HAL_GPIO_WritePin(GPIOA, LED_Pin, GPIO_PIN_SET); payload_garden.MessageId++; payload_garden.VCC = BATTERY_vcc(); payload_garden.ChargeMv = BATTERY_ChargeMv(); payload_garden.ChargeMa = BATTERY_ChargeMa(); /* Get the light reading while the adc gets ready */ payload_garden.Light = LIGHT_lux(); payload_garden.Temperature = TEMPERATURE_external(); payload_garden.CpuTemperature = TEMPERATURE_cpu(); HAL_ADC_Stop(&hadc); sprintf(tx1_buffer, "id:%d, vcc:%d, mv:%d, ma:%d, C:%d, cpuC:%d, lux:%d\n", payload_garden.MessageId, payload_garden.VCC, payload_garden.ChargeMv, payload_garden.ChargeMa, payload_garden.Temperature, payload_garden.CpuTemperature, payload_garden.Light); HAL_UART_Transmit(&huart1, (uint8_t*) tx1_buffer, strlen(tx1_buffer), 1000); PAYLOAD_Garden_serialize(payload_garden, payload_buff); RFM95_send(&hspi2, payload_buff, 14); state = MAIN_STATE_TX; } /* Do nothing while the transmission is in progress */ else if (state == MAIN_STATE_TX) { if (dio0_action == 1) { RFM95_setMode(&hspi2, RFM95_MODE_SLEEP); state = MAIN_STATE_SLEEP; } //TMP while interrupts are investigated //HAL_Delay(30); //state = MAIN_STATE_SLEEP; } /* Now that all the work is done, sleep until its time to do it all again */ else if (state == MAIN_STATE_SLEEP) { HAL_GPIO_WritePin(GPIOA, LED_Pin, GPIO_PIN_RESET); //TMP while RFM is diabled //HAL_Delay(1000); /* Turn off the pin interrupts */ HAL_NVIC_DisableIRQ(EXTI4_15_IRQn); HAL_SuspendTick(); /* Enter Stop Mode */ HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 60, RTC_WAKEUPCLOCK_CK_SPRE_16BITS); HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI); HAL_RTCEx_DeactivateWakeUpTimer(&hrtc); HAL_ResumeTick(); /* Turn on the pin interrupts */ HAL_NVIC_EnableIRQ(EXTI4_15_IRQn); state = MAIN_STATE_SENSE; } } /* USER CODE END 3 */ }
int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_ADC_Init(); MX_DAC_Init(); MX_I2C1_Init(); MX_RTC_Init(); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ //int loopCnt = 0; while (1) { Button_Function buttonFunction = checkButtonFunction(); if (buttonFunction == BTNFUNC_STATECHN) { wakeupSleepState = (wakeupSleepState == STATE_WAKEUP) ? STATE_SLEEP : STATE_WAKEUP; } if (buttonFunction == BTNFUNC_CAL) { setSensorDevPwr(DEV_PWR_ON); getSnrDrvDacVal(); setSensorDevPwr(DEV_PWR_OFF); wakeupSleepState = STATE_WAKEUP; } if (wakeupSleepState == STATE_WAKEUP) { uint16_t snrAdcVal = 0; setBlueToothDevPwr(DEV_PWR_ON); setSensorDevPwr(DEV_PWR_ON); setSysWakeUpLed(LED_ON); setSysStsLed(LED_OFF); int snrDrvDacVal = readEEPROM32(EEPROM_ADDR_SNRDRVVAL); if ((snrDrvDacVal < 1) || (snrDrvDacVal > 0xFFF)) { getSnrDrvDacVal(); } snrAdcVal = (uint16_t)dacOutAdcIn(snrDrvDacVal, ADC_CHANNEL_8); if (snrAdcVal > SNR_PASS_THRESHOLD) { setTestPassLed(LED_ON); setTestFailLed(LED_OFF); } else { setTestFailLed(LED_ON); setTestPassLed(LED_OFF); } if (hi2c1.State == HAL_I2C_STATE_READY) { setBleSig(BLESIG_HI); if (HAL_I2C_Slave_Transmit(&hi2c1, (uint8_t *)&snrAdcVal, 2, 3000) == HAL_OK) { setSysStsLed(LED_ON); HAL_Delay(100); setSysStsLed(LED_OFF); HAL_Delay(100); setSysStsLed(LED_ON); HAL_Delay(100); setSysStsLed(LED_OFF); } else { setSysStsLed(LED_ON); HAL_Delay(300); setSysStsLed(LED_OFF); } } else { setSysWakeUpLed(LED_OFF); HAL_Delay(100); setSysWakeUpLed(LED_ON); HAL_Delay(100); setSysWakeUpLed(LED_OFF); HAL_Delay(100); setSysWakeUpLed(LED_ON); HAL_Delay(100); } setTestFailLed(LED_OFF); setTestPassLed(LED_OFF); HAL_Delay(1000); setBleSig(BLESIG_LO); HAL_Delay(1000); } else { goSleep(); } /* loopCnt++; if (loopCnt >= 2) { loopCnt = 0; } */ /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ }
int main(void) { /* USER CODE BEGIN 1 */ CMDLINE_CONTEXT cmd_context; const char *zhonx_info = (char *)CONFIG_ZHONX_INFO_ADDR; /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_DMA_Init(); MX_ADC1_Init(); MX_ADC2_Init(); MX_ADC3_Init(); MX_I2C1_Init(); MX_RNG_Init(); MX_TIM1_Init(); MX_TIM2_Init(); MX_TIM3_Init(); MX_TIM4_Init(); MX_TIM5_Init(); MX_TIM6_Init(); MX_TIM7_Init(); MX_TIM8_Init(); MX_TIM11_Init(); MX_USART3_UART_Init(); /* USER CODE BEGIN 2 */ expanderInit(); HAL_Delay(100); mainControlInit(); ssd1306Init(0); timesBaseInit(); ledPowerBlink(990, 10); settingsInit(); mulimeterInit(); bluetoothInit(); toneInit(); spyPostInit(); positionControlSetPositionType(GYRO); mainControlSetFollowType(NO_FOLLOW); toneSetVolulme(100); tone(F4, 50); toneItMode(A4, 50); // Register Output callback cmd_context.out = blockingPrintf; // Initialize Command Line module cmdline_init(&cmd_context); // Check if robot name is populated in Flash memset(zhonxName, 0, sizeof(zhonxName)); // Retrieve ZHONX information from flash if any if (zhonx_info[0] == 'Z') { strcpy(zhonxName, zhonx_info); } while (zhonxName[0] == 0) { menu(zhonxNameMenu); } while (1) { menu(mainMenu); powerOffConfirmation(); } /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) ; /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ /* USER CODE END 3 */ }
static void main_task(void *pvParameters) { int i; char ch; bool selftestPasses = true; /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_I2C1_Init(); MX_USART1_UART_Init(); MX_SPI1_Init(); MX_USB_DEVICE_Init(); // Light up all LEDs to test ledOn(ledRanging); ledOn(ledSync); ledOn(ledMode); printf("\r\n\r\n====================\r\n"); printf("SYSTEM\t: CPU-ID: "); for (i=0; i<12; i++) { printf("%02x", uid[i]); } printf("\r\n"); // Initializing pressure sensor (if present ...) lps25hInit(&hi2c1); testSupportPrintStart("Initializing pressure sensor"); if (lps25hTestConnection()) { printf("[OK]\r\n"); lps25hSetEnabled(true); } else { printf("[FAIL] (%u)\r\n", (unsigned int)hi2c1.ErrorCode); selftestPasses = false; } testSupportPrintStart("Pressure sensor self-test"); testSupportReport(&selftestPasses, lps25hSelfTest()); // Initializing i2c eeprom eepromInit(&hi2c1); testSupportPrintStart("EEPROM self-test"); testSupportReport(&selftestPasses, eepromTest()); cfgInit(); // Initialising radio testSupportPrintStart("Initialize UWB "); uwbInit(); if (uwbTest()) { printf("[OK]\r\n"); } else { printf("[ERROR]: %s\r\n", uwbStrError()); selftestPasses = false; } if (!selftestPasses) { printf("TEST\t: One or more self-tests failed, blocking startup!\r\n"); usbcommSetSystemStarted(true); } // Printing UWB configuration struct uwbConfig_s * uwbConfig = uwbGetConfig(); printf("CONFIG\t: Address is 0x%X\r\n", uwbConfig->address[0]); printf("CONFIG\t: Mode is %s\r\n", uwbAlgorithmName(uwbConfig->mode)); printf("CONFIG\t: Tag mode anchor list (%i): ", uwbConfig->anchorListSize); for (i = 0; i < uwbConfig->anchorListSize; i++) { printf("0x%02X ", uwbConfig->anchors[i]); } printf("\r\n"); HAL_Delay(500); ledOff(ledRanging); ledOff(ledSync); ledOff(ledMode); printf("SYSTEM\t: Node started ...\r\n"); printf("SYSTEM\t: Press 'h' for help.\r\n"); usbcommSetSystemStarted(true); // Starts UWB protocol uwbStart(); // Main loop ... while(1) { usbcommPrintWelcomeMessage(); ledTick(); // // Measure pressure // if (uwbConfig.mode != modeSniffer) { // if(lps25hGetData(&pressure, &temperature, &asl)) { // pressure_ok = true; // } else { // printf("Fail reading pressure\r\n"); // printf("pressure not ok\r\n"); // } // } // Accepts serial commands #ifdef USE_FTDI_UART if (HAL_UART_Receive(&huart1, (uint8_t*)&ch, 1, 0) == HAL_OK) { #else if(usbcommRead(&ch, 1)) { #endif handleInput(ch); } } } /* Function required to use "printf" to print on serial console */ int _write (int fd, const void *buf, size_t count) { // stdout if (fd == 1) { #ifdef USE_FTDI_UART HAL_UART_Transmit(&huart1, (uint8_t *)buf, count, HAL_MAX_DELAY); #else usbcommWrite(buf, count); #endif } // stderr if (fd == 2) { HAL_UART_Transmit(&huart1, (uint8_t *)buf, count, HAL_MAX_DELAY); } return count; } static void handleInput(char ch) { bool configChanged = true; static enum menu_e {mainMenu, modeMenu} currentMenu = mainMenu; switch (currentMenu) { case mainMenu: switch (ch) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': changeAddress(ch - '0'); break; case 'a': changeMode(MODE_ANCHOR); break; case 't': changeMode(MODE_TAG); break; case 's': changeMode(MODE_SNIFFER); break; case 'm': printModeList(); printf("Type 0-9 to choose new mode...\r\n"); currentMenu = modeMenu; configChanged = false; break; case 'd': restConfig(); break; case 'h': help(); configChanged = false; break; case '#': productionTestsRun(); printf("System halted, reset to continue\r\n"); while(true){} break; default: configChanged = false; break; } break; case modeMenu: switch(ch) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': changeMode(ch - '0'); currentMenu = mainMenu; break; default: printf("Incorrect mode '%c'\r\n", ch); currentMenu = mainMenu; configChanged = false; break; } break; } if (configChanged) { printf("EEPROM configuration changed, restart for it to take effect!\r\n"); } }
int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_CAN_Init(); MX_I2C1_Init(); MX_SPI1_Init(); MX_USART1_UART_Init(); MX_USART3_UART_Init(); /* USER CODE BEGIN 2 */ /* these calls are from arduino main */ init(); initVariant(); HAL_Delay(3000); /* Wait 3 seconds to enable a serial coms channel */ /* Usart6 is linked to printf for diagnostic use It is also mapped to alternate function pins 12 and 14. This code is adapted from the prinf demo in the STM32F401 Nucleo examples folder */ //printf("Serial backchannel enabled.\r\n"); /* Arduino optionally sets up USB callback stream here #if defined(USBCON) USBDevice.attach(); #endif */ setup(); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ loop(); /* Arduino callback if (serialEventRun) serialEventRun(); */ } /* USER CODE END 3 */ }
int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_DMA_Init(); MX_CRC_Init(); MX_I2C1_Init(); MX_SPI2_Init(); MX_TIM2_Init(); MX_TIM3_Init(); MX_TIM4_Init(); MX_USART2_UART_Init(); /* USER CODE BEGIN 2 */ HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); // reinitialize uart with speed from config huart2.Init.BaudRate = USART_DEBUG_SPEED; HAL_UART_Init(&huart2); DEBUG_PRINTF("Hello, Lepton!\n\r"); fflush(stdout); lepton_init(); HAL_Delay(1000); init_lepton_command_interface(); #ifdef ENABLE_LEPTON_AGC enable_lepton_agc(); #endif #ifdef Y16 enable_telemetry(); #else enable_rgb888(PSUEDOCOLOR_LUT); #endif DEBUG_PRINTF("reading_tmp007_regs...\n\r"); read_tmp007_regs(); DEBUG_PRINTF("Initialized...\n\r"); HAL_Delay(250); MX_USB_DEVICE_Init(); PT_INIT(&lepton_task_pt); PT_INIT(&usb_task_pt); PT_INIT(&uart_task_pt); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ PT_SCHEDULE(lepton_task(&lepton_task_pt)); PT_SCHEDULE(usb_task(&usb_task_pt)); PT_SCHEDULE(uart_task(&uart_task_pt)); PT_SCHEDULE(button_task(&button_task_pt)); } /* USER CODE END 3 */ }
int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_I2C1_Init(); MX_USART1_UART_Init(); MX_TIM16_Init(); MX_TIM17_Init(); /* USER CODE BEGIN 2 */ g_config = g_config_default; #ifdef USE_I2C g_i2c = I2cMaster_Init(&hi2c1); InitializeDisplay(g_i2c); I2cEEPROM_Init(&g_eeprom, g_i2c, EEPROMADDR, 1, 8); #endif #ifdef USE_SERIAL UsartInit(&huart1); #endif #if defined(USE_I2C) && defined(USE_LCD) I2cLcd_Clear(&g_lcd); I2cLcd_PrintStr(&g_lcd, "Hello"); #endif #if defined(USE_SERIAL) && defined(USE_EEPROM) #define TESTSIZE 2048/8 HAL_StatusTypeDef st; uint8_t i2cBuffer[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; /* for(uint16_t i = 0; i < TESTSIZE; i += sizeof(i2cBuffer)) { if(!(i & (sizeof(i2cBuffer)-1))) { st = I2cEEPROM_Write(&g_eeprom, i, i2cBuffer, sizeof(i2cBuffer)); } } for (uint16_t i = 0; i < TESTSIZE; ++i) { if(!(i & (sizeof(i2cBuffer)-1))) { st = I2cEEPROM_Read(&g_eeprom, i, i2cBuffer, sizeof(i2cBuffer)); UsartSendStr("\r\n", 1); UsartPrintUint(i, 4, 1); UsartSendStr(" ", 1); } UsartPrintByte(i2cBuffer[i&(sizeof(i2cBuffer)-1)], 2, 1); UsartSendStr(" ", 1); } UsartSendStr("\r\n", 1); for(uint16_t i = 0; i < TESTSIZE; i += sizeof(i2cBuffer)) { if(!(i & (sizeof(i2cBuffer)-1))) { for(uint16_t j = 0; j<sizeof(i2cBuffer); ++j) i2cBuffer[j] = i+j; st = I2cEEPROM_Write(&g_eeprom, i, i2cBuffer, sizeof(i2cBuffer)); } } for (uint16_t i = 0; i < TESTSIZE; ++i) { if(!(i & (sizeof(i2cBuffer)-1))) { st = I2cEEPROM_Read(&g_eeprom, i, i2cBuffer, sizeof(i2cBuffer)); UsartSendStr("\r\n", 1); UsartPrintUint(i, 4, 1); UsartSendStr(" ", 1); } UsartPrintByte(i2cBuffer[i&(sizeof(i2cBuffer)-1)], 2, 1); UsartSendStr(" ", 1); } UsartSendStr("\r\n", 1); */ { LIVECONFIG config; if (I2cEEPROM_Read(&g_eeprom, EESTART, &config, sizeof(config)) == HAL_OK) { I2cMaster_WaitCallback(g_i2c); if (config.magic == 0xA5) g_config = config; } } for (uint16_t i = 0; i < TESTSIZE; ++i) { if(!(i & (sizeof(i2cBuffer)-1))) { st = I2cEEPROM_Read(&g_eeprom, i, i2cBuffer, sizeof(i2cBuffer)); UsartSendStr("\r\n", 1); UsartPrintUint(i, 4, 1); UsartSendStr(" ", 1); } UsartPrintByte(i2cBuffer[i&(sizeof(i2cBuffer)-1)], 2, 1); UsartSendStr(" ", 1); } UsartSendStr("\r\n", 1); #endif HAL_TIM_IC_Start_IT(&htim16, TIM_CHANNEL_1); HAL_TIM_IC_Start_IT(&htim17, TIM_CHANNEL_1); HAL_UART_Receive_IT(&huart1, g_lineBuffer, sizeof(g_lineBuffer)); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { if (g_lineReceived) { ProcessInput(&g_config, (char*) g_lineBuffer); //DisplayInput(&i2clcd); g_lineReceived = 0; HAL_UART_Receive_IT(&huart1, g_lineBuffer, sizeof(g_lineBuffer)); } if(g_statuses[0].trigger) { DisplayResults(0); g_statuses[0].trigger = 0; } if(g_statuses[1].trigger) { DisplayResults(1); g_statuses[1].trigger = 0; } /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ }
/** * @brief Main program * @param None * @retval None */ int main(void) { /* This sample code shows how to use GPIO HAL API to toggle LED2 IOs in an infinite loop. */ /* STM32F0xx HAL library initialization: - Configure the Flash prefetch - Systick timer is configured by default as source of time base, but user can eventually implement his proper time base source (a general purpose timer for example or other time source), keeping in mind that Time base duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and handled in milliseconds basis. - Low Level Initialization */ HAL_Init(); /* Configure the system clock to 48 MHz */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_I2C1_Init(); MX_USART2_UART_Init(); printf("\n\r\n\rDuvitech 2015\n\r"); printf("George Vigelette\n\r"); printf("[email protected]\n\r\n\r"); printf("initializing temperature sensor...\n\r"); if(BSP_HUM_TEMP_Init() != HUM_TEMP_OK || BSP_HUM_TEMP_CheckID() != HUM_TEMP_OK) { printf("problem with temperature sensor\n\r"); } printf("initializing pressure sensor...\n\r"); if(BSP_PRESSURE_Init() != PRESSURE_OK || BSP_PRESSURE_CheckID() != PRESSURE_OK) { printf("problem with pressure sensor\n\r"); } printf("initializing magnetometer sensor...\n\r"); if(BSP_MAGNETO_Init() != MAGNETO_OK || BSP_MAGNETO_Check_M_ID() != MAGNETO_OK) { printf("problem with magnetometer sensor\n\r"); } printf("initializing imu sensor...\n\r"); if(BSP_IMU_6AXES_Init() != IMU_6AXES_OK || BSP_IMU_6AXES_Check_XG_ID() != IMU_6AXES_OK) { printf("problem with imu sensor\n\r"); } printf("Running...\n\r"); while (1) { HAL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_PIN); /* Insert delay 100 ms */ HAL_Delay(100); } }
int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_DMA_Init(); MX_ADC1_Init(); MX_ADC3_Init(); MX_I2C1_Init(); MX_SPI1_Init(); MX_SPI2_Init(); MX_TIM1_Init(); MX_TIM2_Init(); MX_USB_OTG_FS_PCD_Init(); /* USER CODE BEGIN 2 */ TIM1->CCR1 = 0x300; TIM1->CCR2 = 0x300; TIM2->CCR2 = 0x60; // Настройка deathTime pwm.init(); /* bugfix */ pwmDeathTime.setValue(10); htim1.Instance->BDTR &= ~TIM_BDTR_DTG; htim1.Instance->BDTR |= pwm.computeDeathTime(pwmDeathTime.getValueFlt()); HAL_TIM_Base_Start(&htim1); // Выходной сигнал для ацп HAL_TIM_OC_Start(&htim2, TIM_CHANNEL_2); // Выходной сигнал для ацп HAL_TIM_OC_Start(&htim1, TIM_CHANNEL_3); // HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_1); // HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_2); // pwm.start(); // HAL_TIMEx_PWMN_Start(&htim1,TIM_CHANNEL_1); // HAL_TIMEx_PWMN_Start(&htim1,TIM_CHANNEL_2); __HAL_RCC_DMA2_CLK_ENABLE(); HAL_ADC_Start_DMA(&hadc1, (uint32_t*)adc1.getBufer(), adc1.getBuferSize()); HAL_ADC_Start_DMA(&hadc3, (uint32_t*)adc3.getBufer(), adc3.getBuferSize()); //------------------------------------------------------------------------------ // Низкоуровневая инициализация //------------------------------------------------------------------------------ // Разрешение выходов буферов GPIOC->BSRR = BIT_14; // Инициализация SPI портов //------------------------------------------------------------------------------ // Агрегация объектов // Определяется только при инициализации программы //------------------------------------------------------------------------------ mainMenu.addObserver( &menuEngine ); // Объект menuEngine подписался на рассылку событий, объявленных в IControlCommands //------------------------------------------------------------------------------ // Начальные условия //------------------------------------------------------------------------------ menuEngine.setMenuValue(""); // Затычка на время отсутствия FRAM. Инициализация float данных vICalibrating.setValue(vICalibrating.getValue()); vUDcBusCodeUCal.setValue(vUDcBusCodeUCal.getValue()); vUDcBusCodeZero.setValue(vUDcBusCodeZero.getValue()); vIChargeCodeICal.setValue(vIChargeCodeICal.getValue()); vUChargeCodeUCal.setValue(vUChargeCodeUCal.getValue()); vIChargeCodeZero.setValue(vIChargeCodeZero.getValue()); vUChargeCodeZero.setValue(vUChargeCodeZero.getValue()); vDcBusLoadVoltageDifferent.setValue(vDcBusLoadVoltageDifferent.getValue()); /* USER CODE END 2 */ /* Call init function for freertos objects (in freertos.c) */ MX_FREERTOS_Init(); /* Start scheduler */ osKernelStart(); /* We should never get here as control is now taken by the scheduler */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ }
int _not_using_this_main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_DCMI_Init(); MX_DMA2D_Init(); MX_ETH_Init(); MX_FMC_Init(); MX_I2C1_Init(); MX_LTDC_Init(); MX_QUADSPI_Init(); MX_SDMMC1_SD_Init(); MX_SPDIFRX_Init(); MX_USART1_UART_Init(); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ /* USER CODE BEGIN RTOS_MUTEX */ /* add mutexes, ... */ /* USER CODE END RTOS_MUTEX */ /* USER CODE BEGIN RTOS_SEMAPHORES */ /* add semaphores, ... */ /* USER CODE END RTOS_SEMAPHORES */ /* USER CODE BEGIN RTOS_TIMERS */ /* start timers, add new ones, ... */ /* USER CODE END RTOS_TIMERS */ /* Create the thread(s) */ /* definition and creation of defaultTask */ osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 128); defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL); /* USER CODE BEGIN RTOS_THREADS */ /* add threads, ... */ /* USER CODE END RTOS_THREADS */ /* USER CODE BEGIN RTOS_QUEUES */ /* add queues, ... */ /* USER CODE END RTOS_QUEUES */ /* Start scheduler */ osKernelStart(); /* We should never get here as control is now taken by the scheduler */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ }
int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_ADC_Init(); MX_I2C1_Init(); MX_RTC_Init(); MX_USART1_UART_Init(); MX_SPI2_Init(); /* USER CODE BEGIN 2 */ /* Buffer used for transmission on USART1 */ char tx1_buffer[80]; uint8_t count = 0; /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ sprintf(tx1_buffer, "Count is %d\n", count); HAL_UART_Transmit(&huart1, (uint8_t*) tx1_buffer, strlen(tx1_buffer), 5000); count++; uint16_t adc_val = ADS1015_SingleEnded(&hi2c1, ADS1015_ADDRESS, 3, ADS1015_GAIN_ONE); sprintf(tx1_buffer, "adc_val: %d\n", adc_val); HAL_UART_Transmit(&huart1, (uint8_t*) tx1_buffer, strlen(tx1_buffer), 5000); //ADS1015_writeRegister(&hi2c1, ADS1015_ADDRESS, ADS1015_REG_POINTER_CONFIG, ADS1015_REG_CONFIG_MUX_SINGLE_3); //HAL_Delay(ADS1015_CONVERSIONDELAY); // uint16_t adc_val = ADS1015_readRegister(&hi2c1, ADS1015_ADDRESS, ADS1015_REG_POINTER_CONVERT); //sprintf(tx1_buffer, "adc_val: %04X\n", adc_val); // HAL_UART_Transmit(&huart1, (uint8_t*) tx1_buffer, strlen(tx1_buffer), 5000); HAL_GPIO_TogglePin(GPIOA, LED_Pin); HAL_Delay(1000); } /* USER CODE END 3 */ }
int main(void) { /* USER CODE BEGIN 1 */ /* Data initialization */ int_T i; /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_ADC1_Init(); MX_ADC2_Init(); MX_CAN1_Init(); MX_CAN2_Init(); MX_DAC_Init(); MX_I2C1_Init(); MX_SPI2_Init(); MX_SPI3_Init(); MX_SPI4_Init(); MX_TIM2_Init(); MX_TIM3_Init(); MX_TIM5_Init(); MX_TIM8_Init(); MX_TIM9_Init(); MX_TIM13_Init(); MX_USART1_UART_Init(); MX_USART2_UART_Init(); MX_USART6_UART_Init(); /* USER CODE BEGIN 2 */ /* Systick configuration and enable SysTickHandler interrupt */ if (SysTick_Config((uint32_t)(SystemCoreClock * 0.5))) { autoReloadTimerLoopVal_S = 1; do { autoReloadTimerLoopVal_S++; } while ((uint32_t)(SystemCoreClock * 0.5)/autoReloadTimerLoopVal_S > SysTick_LOAD_RELOAD_Msk); SysTick_Config((uint32_t)(SystemCoreClock * 0.5)/autoReloadTimerLoopVal_S); } remainAutoReloadTimerLoopVal_S = autoReloadTimerLoopVal_S;//Set nb of loop to do /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ for (i=0;i<1;i++) { OverrunFlags[i] = 0; } /* Model initialization call */ Test_Stateflow_initialize(); /* Infinite loop */ /* Real time from systickHandler */ while (1) { /*Process tasks every solver time*/ if (remainAutoReloadTimerLoopVal_S == 0) { remainAutoReloadTimerLoopVal_S = autoReloadTimerLoopVal_S; /* Check base rate for overrun */ if (OverrunFlags[0]) { rtmSetErrorStatus(Test_Stateflow_M, "Overrun"); } OverrunFlags[0] = true; /* Step the model for base rate */ Test_Stateflow_step(); /* Get model outputs here */ /* Indicate task for base rate complete */ OverrunFlags[0] = false; } } /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ /* USER CODE END 3 */ }
int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_I2C1_Init(); MX_USART1_UART_Init(); /* USER CODE BEGIN 2 */ uint8_t res = SSD1306_Init(); printf("OLED init: %d\n", res); SSD1306_GotoXY(10,27); SSD1306_Puts("OLED inited", &Font_7x10, 1); SSD1306_GotoXY(10,52); SSD1306_Puts("Lutsai Alexander", &Font_7x10, 1); SSD1306_UpdateScreen(); //display HAL_Delay(1000); SSD1306_Fill(0); //clear oled int y1 = 64, y2 = 0; while(y1 > 0) { SSD1306_DrawLine(0, y1, 128, y2, 1); SSD1306_UpdateScreen(); y1 -= 2; y2 += 2; } HAL_Delay(1000); SSD1306_Fill(1); //clear oled SSD1306_UpdateScreen(); SSD1306_DrawCircle(64, 32, 25, 0); SSD1306_UpdateScreen(); SSD1306_DrawCircle(128, 32, 25, 0); SSD1306_UpdateScreen(); SSD1306_DrawCircle(0, 32, 25, 0); SSD1306_UpdateScreen(); SSD1306_DrawCircle(32, 32, 25, 0); SSD1306_UpdateScreen(); SSD1306_DrawCircle(96, 32, 25, 0); SSD1306_UpdateScreen(); HAL_Delay(1000); SSD1306_Fill(0); //clear oled SSD1306_UpdateScreen(); int32_t i = -100; char buf[10]; while(i<=100) { memset(&buf[0], 0, sizeof(buf)); sprintf(buf, "%d", i); SSD1306_GotoXY(50,27); SSD1306_Puts(buf, &Font_7x10, 1); SSD1306_DrawLine(64, 10, (i+100)*128/200, (i+100)*64/200, 1); SSD1306_UpdateScreen(); SSD1306_Fill(0); //clear oled i++; } SSD1306_GotoXY(50,27); sprintf(buf, "END"); SSD1306_Puts(buf, &Font_7x10, 1); SSD1306_GotoXY(10,52); SSD1306_Puts("Lutsai Alexander", &Font_7x10, 1); SSD1306_UpdateScreen(); SSD1306_Fill(0); //clear oled HAL_Delay(1000); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ uint32_t lst = 0, cu; while (1) { /* USER CODE END WHILE */ cu = HAL_GetTick(); SSD1306_GotoXY(30,27); sprintf(buf, "fps: %f", 1000.0 / (double)(cu - lst)); SSD1306_Puts(buf, &Font_7x10, 1); SSD1306_GotoXY(7,52); SSD1306_Puts("Lutsai Alexander", &Font_7x10, 1); SSD1306_UpdateScreen(); SSD1306_Fill(0); //clear oled lst = cu; /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ }
/** * @brief The application entry point. * * @retval None */ int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_I2C1_Init(); MX_TIM3_Init(); //MX_IWDG_Init(); MX_TIM14_Init(); MX_TIM16_Init(); MX_TIM17_Init(); /* USER CODE BEGIN 2 */ HAL_TIM_Encoder_Start(&htim3, TIM_CHANNEL_ALL); HAL_NVIC_SetPriority(TIM3_IRQn, 0, 0); HAL_NVIC_EnableIRQ(TIM3_IRQn); HAL_TIM_Base_Start_IT(&htim3); // Seconds Counter startup duty HAL_TIM_Base_Start_IT(&htim14); HAL_TIM_Base_Stop_IT(&htim14); HAL_TIM_Base_Start_IT(&htim16); HAL_TIM_Base_Start_IT(&htim17); HAL_GPIO_WritePin(GPIOA, LED_RED_PIN, GPIO_PIN_RESET); ssd1306_Init(); current_cursor = exposition; /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ //HAL_IWDG_Refresh(&hiwdg); if(__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_SYSCLKSOURCE_STATUS_HSE) HAL_GPIO_WritePin(GPIOA, LED_GREEN_PIN, GPIO_PIN_SET); else HAL_GPIO_WritePin(GPIOA, LED_GREEN_PIN, GPIO_PIN_RESET); if (update_screen_flag) { ssd1306_Fill(Black); ssd1306_UpdateScreen(); update_screen_flag = 0; } if (seconds_counter > STOP_TIME_SEC) //if more than 10 s need to stop { // Entering STOP Mode Procedure seconds_counter = 0; GPIO_InitTypeDef GPIO_InitStruct; ssd1306_WriteCommand(0xAE); // OLED Off GPIO_InitStruct.Pin = ENC_BUTTON_PIN; GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING_FALLING; GPIO_InitStruct.Pull = GPIO_PULLDOWN; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); HAL_NVIC_SetPriority(EXTI4_15_IRQn, 0, 0); HAL_NVIC_EnableIRQ(EXTI4_15_IRQn); HAL_GPIO_WritePin(GPIOA, LED_GREEN_PIN|LED_RED_PIN|GATE_PIN|FOCUS_PIN, GPIO_PIN_RESET); HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFE); // Exit from STOP Mode procedure SystemClock_Config(); ssd1306_WriteCommand(0xAF); // OLED On GPIO_InitStruct.Pin = ENC_BUTTON_PIN; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_PULLDOWN; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); current_state = menu_navigation; } Menu(); if (current_state == running_timer || current_state == running_interval) { if(gate_flag) { // Reset Gate & Focus HAL_GPIO_WritePin(GPIOA, FOCUS_PIN, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOA, GATE_PIN, GPIO_PIN_RESET); HAL_TIM_Base_Stop_IT(&htim14); HAL_Delay(500); __HAL_TIM_SET_COUNTER(&htim14, 0); HAL_TIM_Base_Start_IT(&htim14); gate_flag = 0; // If not last shot, go to Interval state if(tmp_num_shots != 0) { tmp_int_minutes = set_int_minutes; tmp_int_sec = set_int_sec; tmp_exp_minutes = set_exp_minutes; tmp_exp_sec = set_exp_sec; current_state = running_interval; HAL_GPIO_WritePin(GPIOA, LED_RED_PIN,GPIO_PIN_RESET); // 1s LED Off } else { HAL_TIM_Base_Stop_IT(&htim14); __HAL_TIM_SET_COUNTER(&htim14, 0); HAL_GPIO_WritePin(GPIOA, LED_RED_PIN,GPIO_PIN_RESET); // 1s LED Off tmp_exp_minutes = set_exp_minutes; tmp_exp_sec = set_exp_sec; current_state = menu_navigation; update_screen_flag = 1; } } } if (exiting_run) { HAL_TIM_Base_Stop_IT(&htim16); HAL_Delay(1000); exiting_run = 0; HAL_TIM_Base_Start_IT(&htim16); HAL_GPIO_WritePin(GPIOA, FOCUS_PIN, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOA, GATE_PIN, GPIO_PIN_RESET); } } /* USER CODE END 3 */ }
int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* System interrupt init*/ /* Sets the priority grouping field */ HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_1); HAL_NVIC_SetPriority(SysTick_IRQn, 0, 1); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_DMA_Init(); MX_ADC1_Init(); MX_I2C1_Init(); MX_TIM1_Init(); MX_TIM3_Init(); MX_TIM4_Init(); MX_TIM6_Init(); MX_TIM7_Init(); MX_TIM8_Init(); MX_TIM10_Init(); MX_USART3_UART_Init(); /* USER CODE BEGIN 2 */ HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, SET); /* USER CODE END 2 */ /* USER CODE BEGIN 3 */ // test_Expander(); ssd1306Init(0); test_Telemeters(); ADXRS620_Init(); TimesBase_Init(); test_Encoders(); Straight_Control_Start(GYRO); test_Beeper(); Led_Power_Blink(990, 10, 0); //test_Gyro(); Debug_ADXRS620(); //Debug_Straight_Control(); while(1); // test_Encoders(); // test_Vbat(); // test_EasterEgg(); //test_Gyro(); // test_Motor_Move(); // test_Motors(); // test_Telemeters(); // HAL_Delay(1000); // test_LineSensors(); // test_Oled(); // test_IR_Sensors(); /* USER CODE END 3 */ }