/** Flash memory init */ void Flash_Init(void) { MX_GPIO_Init(); MX_SPI1_Init(); HAL_SPI_MspInit(&hspi1); Flash_CS(SET); }
void stm32_soc_init(void) { HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /**Configure the Systick interrupt time */ HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/RHINO_CONFIG_TICKS_PER_SECOND); /*default uart init*/ stduart_init(); brd_peri_init(); MX_DMA_Init(); MX_SAI1_Init(); MX_SPI1_Init(); MX_CRC_Init(); #ifdef STARTERKIT_AUDIO drv_codec_nau8810_init(); audio_init(); #endif }
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_I2C2_Init(); MX_RTC_Init(); MX_SPI1_Init(); MX_SPI3_Init(); MX_USB_OTG_FS_PCD_Init(); //HAL_SPI_MspInit(&hspi3); /* USER CODE BEGIN 2 */ //begin(); //setWrap(false); //fillRect(0,0,128,20,ColorHSV(1200,255,255)); // USART_TypeDef USB_UART; // HAL_UART_MspInit(&USB_UART); // HAL_UART_Init(&USB_UART); /* USER CODE END 2 */ /* Infinite loop */ char test[5]= "test"; /* USER CODE BEGIN WHILE */ while (1) { // fillRect(0,0,128,128,ColorHSV(1200,255,255)); HAL_GPIO_WritePin(RED_GPIO_Port, RED_Pin, GPIO_PIN_SET); HAL_Delay(500); HAL_GPIO_WritePin(RED_GPIO_Port, RED_Pin, GPIO_PIN_RESET); HAL_Delay(500); } /* 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_SPI1_Init(); MX_USART2_UART_Init(); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ int code = init(); if(code < 0) { UART_Printf("init() failed with code %d, terminating.\r\n", code); return 0; } while (1) { loop(); /* 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_DMA_Init(); MX_SPI1_Init(); MX_TIM2_Init(); MX_TIM3_Init(); MX_TIM7_Init(); MX_TIM10_Init(); MX_TIM11_Init(); MX_TIM13_Init(); MX_TIM14_Init(); MX_USART1_UART_Init(); MX_USART2_UART_Init(); /* USER CODE BEGIN 2 */ HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1); //Motor1 HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_4); //Motor2 HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1); //Motor3 HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_4); //Motor4 /* 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 */ /* 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_SPI1_Init(); MX_USART2_UART_Init(); MX_FATFS_Init(); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ init(); while (1) { loop(); /* 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_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 */ int spi_slave_enabled = 0; int uart_slave_enabled = 0; /* 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(); MX_GPIO_Init(); USB_Soft_Disconnect(); MX_DMA_Init(); MX_I2C2_Init(); HAL_DIP_Switches_Init(); spi_slave_enabled = HAL_SPI_Slave_Enabled(); uart_slave_enabled = HAL_UART_Slave_Enabled(); MX_I2C3_Init(); if (spi_slave_enabled) { MX_SPI1_Init(); } if (uart_slave_enabled) { MX_USART6_UART_Init(); } MX_USB_DEVICE_Init(); /* USER CODE BEGIN 2 */ nav10_init(); /* USER CODE END 2 */ nav10_main(); return 0; /* Note: Control will never reach this point. */ }
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 */ /* 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_USART1_UART_Init(); MX_SPI1_Init(); MX_TIM1_Init(); MX_TIM3_Init(); HAL_TIM_Base_Start(&htim1); static char buf[50]; NRF24L01_Reset(); NRF24L01_Initialize(); HAL_Delay(150); CX10_init(); HAL_Delay(50); CX10_bind(); while (1) { process_CX10(); HAL_Delay(6); } }
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*/ HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_SPI1_Init(); /* USER CODE BEGIN 2 */ init_cc2500(); /* USER CODE END 2 */ /* USER CODE BEGIN 3 */ /* Infinite loop */ while (1) { HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6); HAL_Delay(500); // __WFI(); // wait for interrupt } /* USER CODE END 3 */ }
int main(void) { /* USER CODE BEGIN 1 */ // AxesRaw_t data; FRESULT res; /* FatFs function common result code */ uint32_t byteswritten, bytesread; /* File write/read counts */ char rtext[256]; /* File read buffer */ // HALL_SENS_PWR_ON; // CLAMP_SENS_PWR_ON; // 1. SPI1 is for ACC /* 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_SDIO_SD_Init(); MX_SPI1_Init(); MX_SPI2_Init(); MX_USART1_UART_Init(); MX_USART2_UART_Init(); MX_FATFS_Init(); MX_RTC_Init(); /* USER CODE BEGIN 2 */ HAL_RTCEx_DeactivateWakeUpTimer(&hrtc); HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 1, RTC_WAKEUPCLOCK_CK_SPRE_16BITS); EXTI0_IRQHandler_Config(); // EXTI13_IRQHandler_Config(); // HAL_DBGMCU_EnableDBGStopMode(); //HALL_SENS_PWR_ON; //CLAMP_SENS_PWR_OFF; // init gpio before! UC_2_8V; printf("FW start\r\n"); LIS3DH_PreInit(); LIS3DH_SetMode(LIS3DH_NORMAL); //reg1 LIS3DH_SetODR(LIS3DH_ODR_400Hz); //reg1 LIS3DH_SetAxis(LIS3DH_X_ENABLE | LIS3DH_Y_ENABLE | LIS3DH_Z_ENABLE ); //reg1 //Direct IRQ from watemark and overrun to 1st pin. reg3 LIS3DH_SetInt1Pin(LIS3DH_CLICK_ON_PIN_INT1_DISABLE | LIS3DH_I1_INT1_ON_PIN_INT1_DISABLE | LIS3DH_I1_INT2_ON_PIN_INT1_DISABLE | LIS3DH_I1_DRDY1_ON_INT1_DISABLE | LIS3DH_I1_DRDY2_ON_INT1_DISABLE | LIS3DH_WTM_ON_INT1_ENABLE | LIS3DH_INT1_OVERRUN_DISABLE); //REG4 LIS3DH_SetBDU(MEMS_ENABLE); LIS3DH_SetFullScale(LIS3DH_FULLSCALE_2); //reg4 //REG5 LIS3DH_FIFOModeEnable(LIS3DH_FIFO_STREAM_MODE); //Enable store into FIFO reg5 LIS3DH_Int1LatchEnable(MEMS_ENABLE); //LIS3DH_FIFO_CTRL_REG LIS3DH_SetTriggerInt(LIS3DH_TRIG_INT1); LIS3DH_SetWaterMark(15); // watermark for irq generation from fifo LIS3DH_FIFO_CTRL_REG LIS3DH_ReadFIFO(); // clean FIFO and reset IRQ while (1) { //LIS3DH_GetInt1Src(&resp); //printf("INT1SRC %i ", resp); /*LIS3DH_GetFifoSourceBit(LIS3DH_FIFO_SRC_WTM, &resp); printf("WTM %i ", resp); LIS3DH_GetReg3Bit(LIS3DH_I1_WTM, &resp); printf("WMBIT %i ", resp); LIS3DH_GetFifoSourceFSS(&resp); printf("FIFO %i\r\n", resp); //LIS3DH_GetIntCounter(&resp); //printf("Interrupts counter=%i\r\n", resp); if (resp > 26) { //rep: //LIS3DH_GetFifoSourceFSS(&resp); //printf("> %i recs in FIFO (while)\r\n", resp); //HAL_Delay(15); //LIS3DH_GetInt1Src(&resp); /* rep: if(LIS3DH_GetAccAxesRaw(&data)==1){ LIS3DH_GetFifoSourceBit(LIS3DH_FIFO_SRC_WTM, &resp); //printf("X=%6d Y=%6d Z=%6d \r\n", data.AXIS_X, data.AXIS_Y, data.AXIS_Z); printf(" READ WTM%i\r\n", resp); } else { printf("ER\r\n"); } LIS3DH_GetFifoSourceFSS(&resp); if (resp > 0) goto rep; LIS3DH_ResetInt1Latch(); LIS3DH_FIFOModeEnable(LIS3DH_FIFO_STREAM_MODE);*/ LIS3DH_ReadFIFO(); HAL_Delay(2000); } //ENABLE ALL IRQs //LIS3DH_SetInt1Pin(LIS3DH_CLICK_ON_PIN_INT1_DISABLE | LIS3DH_I1_INT1_ON_PIN_INT1_ENABLE | LIS3DH_I1_INT2_ON_PIN_INT1_ENABLE | LIS3DH_I1_DRDY1_ON_INT1_ENABLE | LIS3DH_I1_DRDY2_ON_INT1_ENABLE | LIS3DH_WTM_ON_INT1_ENABLE | LIS3DH_INT1_OVERRUN_ENABLE); //LIS3DH_SetInt2Pin(LIS3DH_CLICK_ON_PIN_INT2_DISABLE | LIS3DH_I2_INT1_ON_PIN_INT2_ENABLE | LIS3DH_I2_INT2_ON_PIN_INT2_ENABLE | LIS3DH_I2_BOOT_ON_INT2_ENABLE | LIS3DH_INT_ACTIVE_HIGH); // HAL_Delay(2000); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ // if(LIS3DH_GetAccAxesRaw(&data)==1){ // printf("X=%6d Y=%6d Z=%6d \r\n", data.AXIS_X, data.AXIS_Y, data.AXIS_Z); // } else { // printf("ER\r\n"); // } HAL_Delay(50); // lowest_power(); //go to stop. Wakeup on RTC wakeup or 1st or 2d PIN wakeup } //SDIO FAT PART. //ENABLE_2_5V; //DC-DC enable SD_PWR_ON; //Power to SD card //INIT SD and CARD after because no power to sd HAL_Delay(50); MX_SDIO_SD_Init(); MX_FATFS_Init(); /*##-1- FatFS: Link the SD disk I/O driver ##########*/ if(FATFS_LinkDriver(&SD_Driver, SDPath) == 0){ /* success: set the orange LED on */ //HAL_GPIO_WritePin(GPIOG, GPIO_PIN_7, GPIO_PIN_RESET); /*##-2- Register the file system object to the FatFs module NB! mout right now! ###*/ res = f_mount(&SDFatFs, (TCHAR const*)SD_Path, 1) ; if(res != FR_OK){ /* FatFs Initialization Error : set the red LED on */ printf ("Problem fmount\r\n"); while(1); } else { /*##-3- Create a FAT file system (format) on the logical drive#*/ /* WARNING: Formatting the uSD card will delete all content on the device */ res = f_mkfs((TCHAR const*)SD_Path, 0, 0); if(res != FR_OK){ /* FatFs Format Error : set the red LED on */ printf ("Problem f_mkfs\r\n"); while(1); } else { /*##-4- Create & Open a new text file object with write access#*/ if(f_open(&MyFile, "Hello.txt", FA_CREATE_ALWAYS | FA_WRITE) != FR_OK){ /* 'Hello.txt' file Open for write Error : set the red LED on */ printf ("Problem f_open\r\n"); while(1); } else { /*##-5- Write data to the text file ####################*/ res = f_write(&MyFile, wtext, sizeof(wtext), (void*)&byteswritten); if((byteswritten == 0) || (res != FR_OK)){ /* 'Hello.txt' file Write or EOF Error : set the red LED on */ printf ("Problem f_write\r\n"); while(1); } else { /*##-6- Successful open/write : set the blue LED on */ // HAL_GPIO_WritePin(GPIOG, GPIO_PIN_12, GPIO_PIN_RESET); f_close(&MyFile); /*##-7- Open the text file object with read access #*/ if(f_open(&MyFile, "Hello.txt", FA_READ) != FR_OK){ /* 'Hello.txt' file Open for read Error : set the red LED on */ //HAL_GPIO_WritePin(GPIOG, GPIO_PIN_10, GPIO_PIN_RESET); printf ("Problem f_open\r\n"); while(1); } else { /*##-8- Read data from the text file #########*/ res = f_read(&MyFile, rtext, sizeof(wtext), &bytesread); // if((strcmp(rtext,wtext)!=0)|| (res != FR_OK)){ // /* 'Hello.txt' file Read or EOF Error : set the red LED on */ // printf ("Problem f_read\r\n"); // while(1); // } else { // printf ("FAT operation done OK!\r\n"); /* Successful read : set the green LED On */ //HAL_GPIO_WritePin(GPIOG, GPIO_PIN_6, GPIO_PIN_RESET); /*##-9- Close the open text file ################*/ f_close(&MyFile); } } } } } } /*##-10- Unlink the micro SD disk I/O driver #########*/ FATFS_UnLinkDriver(SD_Path); /* 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_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 main(void) { /* USER CODE BEGIN 1 */ myDaq = new DaqADS1298(); //printf("Hello\n"); /* 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(); myDaq->initGPIO(); MX_SDIO_SD_Init(); MX_SPI1_Init(); MX_SPI2_Init(); MX_SPI3_Init(); MX_FATFS_Init(); /* Test SD card module */ uint32_t wbytes; /* File write counts */ uint8_t wtext[] = "text to write logical disk"; /* File write buffer */ if(f_mount(&mynewdiskFatFs, (TCHAR const*)mynewdiskPath, 0) == FR_OK) { if(f_open(&MyFile, "STM32.TXT", FA_CREATE_ALWAYS | FA_WRITE) == FR_OK) { if(f_write(&MyFile, wtext, sizeof(wtext), &wbytes) == FR_OK) { f_close(&MyFile); } } } myDaq->setSpiHandle(&hspi1); myDaq->setup(); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ }
void processCommand(){ uint32_t lengthTxData = 0; uint32_t addr = 0; uint32_t i; uint32_t temp; //At minimun resent length of trame and command name (minimun header) //Data_buffer_Transmit[0] = 0; //Low byte of length set in sendAndWaitIfNotReadyAndValidCommand before send //Data_buffer_Transmit[1] = 0; // High byte of length set in sendAndWaitIfNotReadyAndValidCommand before send Data_buffer_Transmit[2] = rx_raw_Frame[2]; //at minimum, answer is Low byte of command Data_buffer_Transmit[3] = rx_raw_Frame[3]; //at minimum, answer is Hight byte of command switch (lowHighByteToInt(rx_raw_Frame[2],rx_raw_Frame[3]) ){ case FPGA_COMMAND : receiveRawDataFromFPGABySPI[2] = LOBYTE(FPGA_DATA); receiveRawDataFromFPGABySPI[3] = HIBYTE(FPGA_DATA); HAL_SPI_Receive_DMA(&hspi1, *(&receiveRawDataFromFPGABySPI) + 4, 8186 ); //Offset + 4 lenght & command type lengthTxData = lowHighByteToInt(rx_raw_Frame[0],rx_raw_Frame[1]); //resend same length to receive the answer of SPI COMMAND //Cs low to start spi HAL_GPIO_WritePin(GPIOC,GPIO_PIN_9,0); HAL_SPI_Transmit_DMA(&hspi3,*(&rx_raw_Frame)+4, lengthTxData-4); break; case LOOPBACK : //Copy frame in tx buffer to send the same thing just a loopback for testing purpose memcpy (Data_buffer_Transmit,rx_raw_Frame,rx_raw_FrameLen); mustValidCommandAfterSend = 1; sendUSB(Data_buffer_Transmit,rx_raw_FrameLen); //endProcessCommandAllowReceiveAgain(); //sendAndWaitIfNotReady(rx_raw_FrameLen); break; case LED1 : Data_buffer_Transmit[4] = rx_raw_Frame[4]; //resend value of led lengthTxData = 4+1; //increment length because send a value of led HAL_GPIO_WritePin(GPIOA,GPIO_PIN_9,rx_raw_Frame[4] & 1 ); //Change value of led //sendAndWaitIfNotReadyAndValidCommand(lengthTxData); //If you don't want answer just endProcessCommandAllowReceiveAgain(); break; case LED2 : Data_buffer_Transmit[4] = rx_raw_Frame[4] ; //resend value of led lengthTxData = 4 + 1; //increment length because send a value of led HAL_GPIO_WritePin(GPIOA,GPIO_PIN_10,rx_raw_Frame[4] & 1 );//Change value of led //sendAndWaitIfNotReadyAndValidCommand(lengthTxData); //If you don't want answer just endProcessCommandAllowReceiveAgain(); break; case START_FPGA : HAL_SPI_DeInit(&hspi2); //Nce FPGA enable HAL_GPIO_WritePin(GPIOD,GPIO_PIN_2,0); //short pulse nconfig on release reconfigure fpga //HAL_GPIO_WritePin(GPIOC,GPIO_PIN_0,0); Delay(1000); HAL_GPIO_WritePin(GPIOC,GPIO_PIN_0,1); Delay(5000); //Restart SPI1 to receive data from FPGA __SPI1_RELEASE_RESET(); MX_SPI1_Init(); endProcessCommandAllowReceiveAgain(); break; case STOP_FPGA : //Stop SPI1 ( receive data from FPGA) //To avoid some problem, when reset fpga (upload) 100ns pulse generate fake edge and shift (1bit) the reveived data __SPI1_FORCE_RESET(); //HAL_SPI_MspDeInit(&hspi1); //Nce FPGA disable HAL_GPIO_WritePin(GPIOD,GPIO_PIN_2,1); //nconfig on release reconfigure fpga HAL_GPIO_WritePin(GPIOC,GPIO_PIN_0,0); Delay(5000); //wait to be sure that the fpga was stopped MX_SPI2_Init(); sFLASH_READID(); //Must read ID to wake up the memory Delay(5000); //HAL_SPI_MspInit(&hspi1); endProcessCommandAllowReceiveAgain(); break; case ERASE_FIRMWARE : Data_buffer_Transmit[4] = 1; lengthTxData = 4 + 1; //increment length because send a value (1=ok) //sFLASH_ERASE_BULK(); //slow replaced by just erasing 2 sectors sFLASH_ERASE(); mustValidCommandAfterSend = 1; sendUSB(Data_buffer_Transmit,lengthTxData); break; case READ_PAGE_FIRMWARE : if (rx_raw_Frame[6] <= 31) {//Just check number of page if not less than 31 do nothing lengthTxData = (uint32_t)rx_raw_Frame[6] * 256; Data_buffer_Transmit[4] = rx_raw_Frame[4]; //low byte Number of the first page Data_buffer_Transmit[5] = rx_raw_Frame[5]; //high byte Number of the first page Data_buffer_Transmit[6] = rx_raw_Frame[6]; //Nb of page addr=lowHighByteToInt(rx_raw_Frame[4],rx_raw_Frame[5])*256; sFLASH_Read(*(&Data_buffer_Transmit)+7,addr,lengthTxData); mustValidCommandAfterSend = 1; sendUSB(Data_buffer_Transmit,lengthTxData+7); }else{ Data_buffer_Transmit[2] = LOBYTE(COMMAND_NOT_FOUND); Data_buffer_Transmit[3] = HIBYTE(COMMAND_NOT_FOUND); mustValidCommandAfterSend = 1; sendUSB(Data_buffer_Transmit,4); } break; case WRITE_PAGE_FIRMWARE : //Data_buffer_Transmit[4] = rx_raw_Frame[4]; //low byte Number of the first page //Data_buffer_Transmit[5] = rx_raw_Frame[5]; //high byte Number of the first page //Data_buffer_Transmit[6] = rx_raw_Frame[6]; //Nb of page (31 max) addr=lowHighByteToInt(rx_raw_Frame[4],rx_raw_Frame[5])*256; for (int i=0;i< rx_raw_Frame[6];i++){ sFLASH_WritePage(*(&rx_raw_Frame)+7+i*256,addr+i*256,256); } endProcessCommandAllowReceiveAgain(); break; case GET_VERSION_NUMBER : lengthTxData = 18; memcpy(&Data_buffer_Transmit[4],&versionNumber,lengthTxData); mustValidCommandAfterSend = 1; sendUSB(Data_buffer_Transmit,lengthTxData+4); break; default: //mustValidCommandAfterSend = 1; //sendAndWaitIfNotReady(lengthTxData); //If you don't want answer just endProcessCommandAllowReceiveAgain(); } }
int main(void) { GPIO_InitTypeDef GPIO_InitStruct; uint32_t treg; /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); DBGMCU->CR = 0xFFFFFFFF; /* Initialize all configured peripherals */ MX_GPIO_Init(); ADC_Init_my(); I2C1_Init_my(); RTC_my_Init(); MX_SPI1_Init(); MX_TIM1_Init(); NVIC_EnableIRQ (EXTI0_IRQn); // // HAL_PWR_EnterSLEEPMode(treg, PWR_SLEEPENTRY_WFE); // /* USER CODE BEGIN 2 */ // if(TM_STMPE811_Init() == TM_STMPE811_State_Ok) // { // if (TM_I2C_Read(STMPE811_I2C, LM75_ADDRESS, 0x00) == 0) // { // TM_ILI9341_Puts(60, 40, "Error init LM75", &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_RED); // } // // TM_I2C_Write(STMPE811_I2C, STMPE811_ADDRESS, STMPE811_INT_CTRL, 0x03); // TM_I2C_Write(STMPE811_I2C, STMPE811_ADDRESS, STMPE811_INT_STA, 0x01); // TM_I2C_Write(STMPE811_I2C, STMPE811_ADDRESS, STMPE811_INT_EN, 0x01); // // }; // // if (f_mount(&FatFs, "0:", 1) == FR_OK) // { // //Get time // TM_RTC_GetDateTime(&datatime, TM_RTC_Format_BIN); // // sprintf(buffer, "0:F%02d_%02d_%04d.txt", datatime.date, datatime.month, datatime.year); // sprintf(file_name_data, "0:%04d_%02d_%02d_Watt.txt", datatime.year+2000, datatime.month, datatime.date); // temp_sd_res = f_open(&fil, (TCHAR*) file_name_data, FA_OPEN_EXISTING | FA_READ | FA_WRITE); // if (temp_sd_res != FR_OK) // { // if (f_open(&fil, file_name_data, FA_CREATE_NEW | FA_READ | FA_WRITE) == FR_OK) // {//write redline // sprintf(buffer, "Data\t\tTime\t\tVoltage\tCurrent\tWatt\n"); // if(f_lseek(&fil, f_size(&fil)) == FR_OK){}; // // /* If we put more than 0 characters (everything OK) */ // if (f_puts(buffer, &fil) > 0) { // if (TM_FATFS_DriveSize(&total, &free_fat) == FR_OK) { // /* Data for drive size are valid */ // /* Close file, don't forget this! */ // f_close(&fil); // } // } // } // } // else f_close(&fil);//file exists, was openned and must be closed // // sprintf(file_name_tempr, "0:%04d_%02d_%02d_Tempr_Pr.txt", datatime.year+2000, datatime.month, datatime.date); // temp_sd_res = f_open(&fil, (TCHAR*) file_name_tempr, FA_OPEN_EXISTING | FA_READ | FA_WRITE); // if (temp_sd_res != FR_OK) // { // if (f_open(&fil, file_name_tempr, FA_CREATE_NEW | FA_READ | FA_WRITE) == FR_OK) // {//write redline // sprintf(buffer, "Data\t\tTime\t\tTempr\tPresure\n"); // if(f_lseek(&fil, f_size(&fil)) == FR_OK){}; // // /* If we put more than 0 characters (everything OK) */ // if (f_puts(buffer, &fil) > 0) { // if (TM_FATFS_DriveSize(&total, &free_fat) == FR_OK) { // /* Data for drive size are valid */ // /* Close file, don't forget this! */ // f_close(&fil); // } // } // } // } // else f_close(&fil);//file exists, was openned and must be closed // temp_sd_res = f_open(&fil, "0:Tempr.txt", FA_OPEN_EXISTING | FA_READ | FA_WRITE); // if (temp_sd_res != FR_OK) // { // if (f_open(&fil, "0:Tempr.txt", FA_CREATE_NEW | FA_READ | FA_WRITE) == FR_OK) // {//write redline // sprintf(buffer, "Data\t\tTime\t\tVoltage\tTempr\tPresure\n"); // if(f_lseek(&fil, f_size(&fil)) == FR_OK){}; // // /* If we put more than 0 characters (everything OK) */ // if (f_puts(buffer, &fil) > 0) { // if (TM_FATFS_DriveSize(&total, &free_fat) == FR_OK) { // /* Data for drive size are valid */ // /* Close file, don't forget this! */ // f_close(&fil); // } // } // } // } // else f_close(&fil);//file exists, was openned and must be closed // // /* Unmount drive, don't forget this! */ // f_mount(0, "0:", 1); // // }//end mount SD /* 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, 256); defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL); /* USER CODE BEGIN RTOS_THREADS */ osThreadDef(UserTask, UserDefaultTask, osPriorityNormal, 0, 256); UserTaskHandle = osThreadCreate(osThread(UserTask), NULL); /* 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(); /* 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_USART1_UART_Init(); MX_USART2_UART_Init(); MX_SPI1_Init(); /* USER CODE BEGIN 2 */ /* 硬件初始化开始 */ // USART_printf( &BSP_USART_PRINT, "开始硬件初始化!\n"); /* 初始化输出 */ ControlOut_Init( ); /* 初始化控制模式 */ ModeControl_Init( ); /* 初始化主控模块 */ DataProcess_Init( ); /*启动循环接收DMA*/ HAL_UART_Receive_DMA(&BSP_USART_SENSOR, (uint8_t*)&gUSART1_RX_TMP, 1); /* 硬件初始化结束 */ // USART_printf( &BSP_USART_PRINT, "硬件初始化结束 !\n"); /* 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 MainTask */ osThreadDef(MainTask, StartMainTask, osPriorityBelowNormal, 0, 128); MainTaskHandle = osThreadCreate(osThread(MainTask), NULL); /* definition and creation of DataParseTask */ osThreadDef(DataParseTask, StartDataParseTask, osPriorityNormal, 0, 160); DataParseTaskHandle = osThreadCreate(osThread(DataParseTask), NULL); /* definition and creation of DataProcessTask */ osThreadDef(DataProcessTask, StartDataProcessTask, osPriorityAboveNormal, 0, 256); DataProcessTaskHandle = osThreadCreate(osThread(DataProcessTask), NULL); /* definition and creation of DataOutTask */ osThreadDef(DataOutTask, StartDataOutTask, osPriorityHigh, 0, 160); DataOutTaskHandle = osThreadCreate(osThread(DataOutTask), NULL); /* definition and creation of PrintTask */ osThreadDef(PrintTask, StartPrintTask, osPriorityBelowNormal, 0, 128); PrintTaskHandle = osThreadCreate(osThread(PrintTask), NULL); /* USER CODE BEGIN RTOS_THREADS */ /* add threads, ... */ /* USER CODE END RTOS_THREADS */ /* Create the queue(s) */ /* definition and creation of ReceiveDataQueue */ osMessageQDef(ReceiveDataQueue, 128, uint8_t); ReceiveDataQueueHandle = osMessageCreate(osMessageQ(ReceiveDataQueue), NULL); /* definition and creation of PrintQueues */ osMessageQDef(PrintQueues, 512, uint8_t); PrintQueuesHandle = osMessageCreate(osMessageQ(PrintQueues), NULL); /* USER CODE BEGIN RTOS_QUEUES */ /* add queues, ... */ /* 创建传感器采集值邮箱 */ gSenorDataMail = osMailCreate(osMailQ(gSenorDataMail), NULL); /* 创建处理结果输出邮箱 */ gControlDataMail = osMailCreate(osMailQ(gSenorDataMail), NULL); /* 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) { /* 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_ADC_Init(); MX_SPI1_Init(); MX_USB_DEVICE_Init(); MX_TIM14_Init(); HAL_FLASH_Unlock(); EE_Init(); EE_ReadVariable(VirtAddVarTab[0], &x_low_th); EE_ReadVariable(VirtAddVarTab[1], &x_high_th); EE_ReadVariable(VirtAddVarTab[2], &y_low_th); EE_ReadVariable(VirtAddVarTab[3], &y_high_th); HAL_FLASH_Lock(); HAL_ADC_Start_DMA(&hadc, (uint32_t*)axis, 5); while (1) { HAL_GPIO_WritePin(SPI1_nCS_GPIO_Port, SPI1_nCS_Pin, GPIO_PIN_SET); HAL_TIM_Base_Start_IT(&htim14); while (!u100ticks) /* do nothing for 100 us */; HAL_TIM_Base_Stop_IT(&htim14); u100ticks = 0; HAL_StatusTypeDef status = HAL_SPI_Receive(&hspi1, rx_buffer, sizeof(rx_buffer), 3000); switch(status) { case HAL_OK: report.buttons[0] = 0x00; // report.buttons[1] = 0x00; report.buttons[2] = 0x00; if ((rx_buffer[0] & 0xff) != 0xff) // if all bits of rx_buffer[0] is 1 assume shifter is disconnected { if (rx_buffer[0] & 4) report.buttons[0] |= 1; else report.buttons[0] &= ~1; if (rx_buffer[0] & 1) report.buttons[0] |= (1 << 1); else report.buttons[0] &= ~(1 << 1); if (rx_buffer[0] & 2) report.buttons[0] |= (1 << 2); else report.buttons[0] &= ~(1 << 2); if (rx_buffer[0] & 8) report.buttons[0] |= (1 << 3); else report.buttons[0] &= ~(1 << 3); if (rx_buffer[1] & 1) report.buttons[2] |= 1; else report.buttons[2] &= ~1; if (rx_buffer[1] & 2) report.buttons[2] |= (1 << 1); else report.buttons[2] &= ~(1 << 1); if (rx_buffer[1] & 4) report.buttons[2] |= (1 << 2); else report.buttons[2] &= ~(1 << 2); if (rx_buffer[1] & 8) report.buttons[2] |= (1 << 3); else report.buttons[2] &= ~(1 << 3); if (rx_buffer[1] & 32) report.buttons[0] |= (1 << 4); else report.buttons[0] &= ~(1 << 4); if (rx_buffer[1] & 128) report.buttons[0] |= (1 << 5); else report.buttons[0] &= ~(1 << 5); if (rx_buffer[1] & 64) report.buttons[0] |= (1 << 6); else report.buttons[0] &= ~(1 << 6); if (rx_buffer[1] & 16) report.buttons[0] |= (1 << 7); else report.buttons[0] &= ~(1 << 7); } break; case HAL_TIMEOUT: case HAL_BUSY: case HAL_ERROR: Error_Handler(); default: report.buttons[0] = 0xff; break; } HAL_GPIO_WritePin(SPI1_nCS_GPIO_Port, SPI1_nCS_Pin, GPIO_PIN_RESET); report.id = 0x01; x_axis = ((X_AXIS << 2) + x_axis * 96) / 100; y_axis = ((Y_AXIS << 2) + y_axis * 96) / 100; if (rx_buffer[0] & 16) { if (y_axis < y_low_th) // stick towards player { report.buttons[1] = 128; report.buttons[2] &= ~(1 << 4); } else if (y_axis > y_high_th) // stick opposite to player { report.buttons[1] = 0; // neutral report.buttons[2] |= (1 << 4); } else { report.buttons[1] = 0; // neutral report.buttons[2] &= ~(1 << 4); } } else { report.buttons[1] &= ~(1 << 7); report.buttons[2] &= ~(1 << 4); if (y_axis < y_low_th) // stick towards player { if (x_axis < x_low_th) { if (!report.buttons[1]) report.buttons[1] = 2; // 2nd gear } else if (!report.buttons[1]) { report.buttons[1] = (x_axis > x_high_th) ? ((rx_buffer[0] & 64) ? 64 : 32) : 8; } } else { if (y_axis > y_high_th) // stick opposite to player { if (x_axis < x_low_th) { if (!report.buttons[1]) report.buttons[1] = 1; // 1st gear } else if (!report.buttons[1]) { report.buttons[1] = (x_axis > x_high_th) ? 16 : 4; } } else { report.buttons[1] = 0; // neutral } } } report.axis[0] = x_axis; report.axis[1] = y_axis; if (report2send == 2) { HAL_FLASH_Unlock(); EE_WriteVariable(VirtAddVarTab[0], x_low_th); EE_WriteVariable(VirtAddVarTab[1], x_high_th); EE_WriteVariable(VirtAddVarTab[2], y_low_th); EE_WriteVariable(VirtAddVarTab[3], y_high_th); HAL_FLASH_Lock(); report2send = 0; } if (hUsbDeviceFS.pClassData && ((USBD_HID_HandleTypeDef *)hUsbDeviceFS.pClassData)->state == HID_IDLE) { USBD_HID_SendReport(&hUsbDeviceFS, (uint8_t *)&report, sizeof(report)); } } }
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_USART1_UART_Init(); MX_SPI1_Init(); MX_IRTIM_Init(); MX_TIM16_Init(); MX_TIM17_Init(); /* USER CODE BEGIN 2 */ BSP_SERIAL_FLASH_Init(); LASERTAG_BOARD_Init(); //uint32_t FlashId; uint8_t TxTemp[16] = "TEST"; uint8_t RXTemp[16]; BSP_SERIAL_FLASH_EraseSector(0x000000); BSP_SERIAL_FLASH_WritePage(0x000000, (uint8_t*) TxTemp, 16); BSP_SERIAL_FLASH_ReadData(0x000000, (uint8_t*) RXTemp, 16); HAL_Delay(1500); BSP_SERIAL_FLASH_ReadData(0x000002, (uint8_t*) RXTemp, 16); /* 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 */ HAL_GPIO_TogglePin(LD4_GPIO_Port, LD4_Pin); //blue HAL_Delay(1500); } /* 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_USART3_UART_Init(); MX_SPI1_Init(); MX_SPI2_Init(); /* USER CODE BEGIN 2 */ uint8_t init_bytes[] = { 0x07, 0x40, 0xC0, 0x01, 0x00, 0x8C, 0x8E, 0x00 }; for (int i = 0; i < 2; i++) { HAL_GPIO_WritePin(SPI_CS_GPIO_Port, SPI_CS_Pin, GPIO_PIN_RESET); HAL_SPI_Transmit(&hspi1, (uint8_t*) (&init_bytes[i]), 1, 1000); HAL_GPIO_WritePin(SPI_CS_GPIO_Port, SPI_CS_Pin, GPIO_PIN_SET); } for (int i = 0; i < 0x16; i++) { HAL_GPIO_WritePin(SPI_CS_GPIO_Port, SPI_CS_Pin, GPIO_PIN_RESET); HAL_SPI_Transmit(&hspi1, (uint8_t*) (&init_bytes[2]), 1, 1000); HAL_SPI_Transmit(&hspi1, (uint8_t*) (&init_bytes[4]), 1, 1000); init_bytes[2]++; HAL_GPIO_WritePin(SPI_CS_GPIO_Port, SPI_CS_Pin, GPIO_PIN_SET); } HAL_GPIO_WritePin(SPI_CS_GPIO_Port, SPI_CS_Pin, GPIO_PIN_RESET); HAL_SPI_Transmit(&hspi1, (uint8_t*) (&init_bytes[5]), 1, 1000); HAL_GPIO_WritePin(SPI_CS_GPIO_Port, SPI_CS_Pin, GPIO_PIN_SET); // ds3234_set_time(); vfd_display(); ds3234_set_reg(DS3234_REG_CONTROL, 0x00); // vfd_write_display_flag(0x03, 0x04); // vfd_write_display_flag(0x0F, 0x03); while (1) { }; /* 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, osPriorityIdle, 0, 128); defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL); /* definition and creation of myTask02 */ osThreadDef(myTask02, StartTask02, osPriorityNormal, 0, 128); myTask02Handle = osThreadCreate(osThread(myTask02), NULL); /* definition and creation of myTask03 */ osThreadDef(myTask03, StartTask03, osPriorityNormal, 0, 128); myTask03Handle = osThreadCreate(osThread(myTask03), NULL); /* definition and creation of myTask01 */ osThreadDef(myTask01, StartTask01, osPriorityNormal, 0, 128); myTask01Handle = osThreadCreate(osThread(myTask01), NULL); /* definition and creation of myTask04 */ osThreadDef(myTask04, StartTask04, osPriorityNormal, 0, 128); myTask04Handle = osThreadCreate(osThread(myTask04), 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 */ char i = 0; while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ HAL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin); HAL_GPIO_TogglePin(LED2_GPIO_Port, LED2_Pin); HAL_GPIO_TogglePin(LED3_GPIO_Port, LED3_Pin); HAL_GPIO_TogglePin(LED4_GPIO_Port, LED4_Pin); aTxBuffer[30] = ((i++) % 10) + '0'; HAL_UART_Transmit(&huart3, aTxBuffer, RXBUFFERSIZE, 5000); HAL_Delay(1000); } /* 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_FSMC_Init(); MX_SPI1_Init(); MX_USART1_UART_Init(); /* USER CODE BEGIN 2 */ LCD_Init(LCD_ORIENTATION_PORTRAIT); LCD_setFont(SmallFont); LCD_setBackColor(VGA_BLACK); LCD_fillScr(VGA_BLACK); TSC2046_Init(); TSC2046_Calibration(); LCD_fillScr(VGA_BLACK); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ char buf[100]; int16_t xpos, ypos; while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ LCD_setColor(VGA_BLUE); LCD_drawRect(0, 0, 10, 10); while(!Is_Touhcing()); while (Is_Touhcing()) { // read xpos = TSC2046_Get_Position_X(); ypos = TSC2046_Get_Position_Y(); // clear if (xpos > LCD_WIDTH - 20 && ypos > LCD_HEIGHT - 20) { LCD_fillScr(VGA_BLACK); } // print sprintf(buf, "(x,y)=(%04d, %04d)", xpos, ypos); LCD_setColor(VGA_RED); LCD_setBackColor(VGA_BLACK); LCD_print(buf, 20, 300, 0); // draw pen LCD_setColor(rand() | 0b0111101111101111); LCD_fillCircle(xpos, ypos, 3); // clear button LCD_setColor(VGA_WHITE); LCD_fillRect(LCD_WIDTH - 20, LCD_HEIGHT - 20, LCD_WIDTH - 1, LCD_HEIGHT - 1); // pen indicator LCD_setColor(VGA_GREEN); LCD_drawRect(0, 0, 10, 10); } } /* 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_USART2_UART_Init(); MX_SPI1_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); osThreadDef(compassTask, StartCompassTask, osPriorityNormal, 0, 128); compassTaskHandle = osThreadCreate(osThread(compassTask), NULL); osThreadDef(laserTask, StartLaserTask, osPriorityNormal, 0, 128); laserTaskHandle = osThreadCreate(osThread(laserTask), 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(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_SPI1_Init(); MX_SPI2_Init(); MX_USART1_UART_Init(); /* USER CODE BEGIN 2 */ lcd_fillL(); delay(0xFF); lcd_clearL(); delay(0xFF); lcd_fillR(); delay(0xFF); lcd_clearR(); delay(0xFF); set_xL(0); set_yL(0); delay(0xFF); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { set_xL(0); set_yL(0); set_xR(0); set_yR(0); for(int l=0;l<4;l++) { switch(l) { case 1: { vivod(1,0,0, "1"); vivod(1,1,0, "2"); vivod(1,2,0, "3"); vivod(1,3,0, "4"); vivod(1,4,0, "5"); vivod(1,5,0, "6"); vivod(1,6,0, "7"); vivod(1,7,0, "8"); vivod(2,0,0, "-1"); vivod(2,1,0, "-2"); vivod(2,2,0, "-3"); vivod(2,3,0, "-4"); vivod(2,4,0, "-5"); vivod(2,5,0, "-6"); vivod(2,6,0, "-7"); vivod(2,7,0, "-8"); break; } case 2: { delay(5); vivod(1,0,0,"9"); vivod(1,1,0, "10"); vivod(1,2,0, "11"); vivod(1,3,0, "12"); vivod(1,4,0, "13"); vivod(1,5,0, "14"); vivod(1,6,0, "15"); vivod(1,7,0, "16"); vivod(2,0,0, "-9"); vivod(2,1,0, "-10"); vivod(2,2,0, "-11"); vivod(2,3,0, "-12"); vivod(2,4,0, "-13"); vivod(2,5,0, "-14"); vivod(2,6,0, "-15"); vivod(2,7,0, "-16"); break; } case 3: { delay(5); vivod(1,0,0,"17"); vivod(1,1,0, "18"); vivod(1,2,0, "19"); vivod(1,3,0, "20"); vivod(1,4,0, "21"); vivod(1,5,0, "22"); vivod(1,6,0, "23"); vivod(1,7,0, "24"); vivod(2,0,0, "-17"); vivod(2,1,0, "-18"); vivod(2,2,0, "-19"); vivod(2,3,0, "-20"); vivod(2,4,0, "-21"); vivod(2,5,0, "-22"); vivod(2,6,0, "-23"); vivod(2,7,0, "-24"); break; } } } delay(5); set_xL(0); set_yL(0); set_xR(0); set_yR(0); lcd_clearL(); lcd_clearR(); /* 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(); char is_joint = 1; if(is_joint) { // init multiplexer pins MX_SPI1_Init(); } else { MPX_UART_Init(); } MX_USART1_UART_Init(); MX_USART2_UART_Init(); /* USER CODE BEGIN 2 */ LED_init(); if(is_joint) { // set spi chip select high HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET); //init_2D(hspi1, GPIOB, GPIO_PIN_1); init_1D(); } else { // set spi chip select high MPX_UART_ONOFF(1); } huart_T = &huart2; huart_U = &huart1; float alpha, beta, delta; /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ USART_RX_FINISHED=0; USART_TX_FINISHED=1; // if(HAL_UART_Receive_IT(huart_U, (uint8_t *)aRxBuffer, RXBUFFERSIZE) != HAL_OK) // { // char error = 1; // } int i = 0; //MPX_UART_Open(3); while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ if(is_joint & USART_TX_FINISHED) { get_2D(hspi1, GPIOB, GPIO_PIN_1, &alpha, &beta); get_1D(hspi1, GPIOA, GPIO_PIN_4, &delta); length = snprintf(usart_buffer, 128, "%f : %f : %f\r\n", alpha, beta, delta); USART_TX_FINISHED = 0; HAL_UART_Transmit(huart_T, usart_buffer, length, 20); } else { //length = snprintf(usart_buffer, 128, "hello"); //MPX_UART_Transmit(huart_T, i%5, usart_buffer, length, 20); //HAL_Delay(200); //length = snprintf(usart_buffer, 128, "hello\r\n", alpha, beta, delta); //HAL_UART_Transmit(huart_U, usart_buffer, length, 20); } // // if(USART_RX_FINISHED==1) // { // if(aRxBuffer[0]=='r') // { // HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_0); // } // else if(aRxBuffer[0]=='b') // { // HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_4); // } // /*else if(aRxBuffer[0]=='g') // { // HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_1); // }*/ // else // { // //HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_1); // HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_4); // HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_0); // } // // HAL_UART_Transmit(huart_T, aRxBuffer, RXBUFFERSIZE, 20); // // USART_RX_FINISHED=0; // // if(HAL_UART_Receive_IT(huart_U, (uint8_t *)aRxBuffer, RXBUFFERSIZE) != HAL_OK) // { // char error = 1; // } // } //HAL_UART_Transmit(&huart2, "ABC", 3, 20); i++; } /* 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"); } }