| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631 |
- /* USER CODE BEGIN Header */
- /**
- ******************************************************************************
- * @file : main.c
- * @brief : Main program body
- ******************************************************************************
- * @attention
- *
- * Copyright (c) 2023 STMicroelectronics.
- * All rights reserved.
- *
- * This software is licensed under terms that can be found in the LICENSE file
- * in the root directory of this software component.
- * If no LICENSE file comes with this software, it is provided AS-IS.
- *
- ******************************************************************************
- */
- /* USER CODE END Header */
- /* Includes ------------------------------------------------------------------*/
- #include "main.h"
- #include "cmsis_os.h"
- #include "usb_device.h"
- /* Private includes ----------------------------------------------------------*/
- /* USER CODE BEGIN Includes */
- #include "ImC/imc_api.h"
- #include "ImC/imc_kernel.h"
- /* USER CODE END Includes */
- /* Private typedef -----------------------------------------------------------*/
- typedef StaticTask_t osStaticThreadDef_t;
- /* USER CODE BEGIN PTD */
- /* USER CODE END PTD */
- /* Private define ------------------------------------------------------------*/
- /* USER CODE BEGIN PD */
- #define FRAM_MEM_SIZE (0x100000) // 1 MiB = 2 * 512 * 1024 bytes
- #define MRAM_MEM_SIZE (0x800000) // 8 MiB = 2 * 4 * 1024 * 1024 bytes
- #define MEM_TYPE_MRAM (1)
- #define MEM_TYPE_FRAM (2)
- #define MEM_SIZE_HALF (3)
- #define MEM_SIZE_FULL (4)
- #define MEM_TEST_TYPE MEM_TYPE_MRAM
- #define MEM_TEST_SIZE MEM_SIZE_HALF
- #define MEM_TEST_ADDR (0x68000000U)
- #if !defined(MEM_TEST_TYPE)
- #error "Choose the memory type for test!"
- #endif
- #if !defined(MEM_TEST_SIZE)
- #error "Choose the memory size for test!"
- #endif
- #if (MEM_TEST_TYPE == MEM_TYPE_MRAM)
- #if (MEM_TEST_SIZE == MEM_SIZE_FULL)
- #define MEMORY_SIZE MRAM_MEM_SIZE
- #elif (MEM_TEST_SIZE == MEM_SIZE_HALF)
- #define MEMORY_SIZE (MRAM_MEM_SIZE / 2)
- #else
- #error "Invalid memory size"
- #endif
- #elif (MEM_TEST_TYPE == MEM_TYPE_FRAM)
- #if (MEM_TEST_SIZE == MEM_SIZE_FULL)
- #define MEMORY_SIZE FRAM_MEM_SIZE
- #elif (MEM_TEST_SIZE == MEM_SIZE_HALF)
- #define MEMORY_SIZE (FRAM_MEM_SIZE / 2)
- #else
- #error "Invalid memory size"
- #endif
- #else
- #error "Invalid memory type"
- #endif
- /* USER CODE END PD */
- /* Private macro -------------------------------------------------------------*/
- /* USER CODE BEGIN PM */
- /* USER CODE END PM */
- /* Private variables ---------------------------------------------------------*/
- ADC_HandleTypeDef hadc1;
- ADC_HandleTypeDef hadc2;
- FDCAN_HandleTypeDef hfdcan1;
- I2C_HandleTypeDef hi2c1;
- I2C_HandleTypeDef hi2c3;
- SPI_HandleTypeDef hspi1;
- SPI_HandleTypeDef hspi2;
- TIM_HandleTypeDef htim7;
- UART_HandleTypeDef huart4;
- UART_HandleTypeDef huart1;
- UART_HandleTypeDef huart2;
- UART_HandleTypeDef huart3;
- SRAM_HandleTypeDef hsram1;
- SRAM_HandleTypeDef hsram2;
- SRAM_HandleTypeDef hsram3;
- SRAM_HandleTypeDef hsram4;
- /* Definitions for taskEPS */
- osThreadId_t taskEPSHandle;
- uint32_t taskEPSBuffer[ 256 ];
- osStaticThreadDef_t taskEPSControlBlock;
- const osThreadAttr_t taskEPS_attributes = {
- .name = "taskEPS",
- .stack_mem = &taskEPSBuffer[0],
- .stack_size = sizeof(taskEPSBuffer),
- .cb_mem = &taskEPSControlBlock,
- .cb_size = sizeof(taskEPSControlBlock),
- .priority = (osPriority_t) osPriorityRealtime,
- };
- /* Definitions for taskSnap */
- osThreadId_t taskSnapHandle;
- uint32_t taskSnapBuffer[ 512 ];
- osStaticThreadDef_t taskSnapControlBlock;
- const osThreadAttr_t taskSnap_attributes = {
- .name = "taskSnap",
- .stack_mem = &taskSnapBuffer[0],
- .stack_size = sizeof(taskSnapBuffer),
- .cb_mem = &taskSnapControlBlock,
- .cb_size = sizeof(taskSnapControlBlock),
- .priority = (osPriority_t) osPriorityRealtime,
- };
- /* Definitions for taskAI */
- osThreadId_t taskAIHandle;
- uint32_t taskAIBuffer[ 37968 ];
- osStaticThreadDef_t taskAIControlBlock;
- const osThreadAttr_t taskAI_attributes = {
- .name = "taskAI",
- .stack_mem = &taskAIBuffer[0],
- .stack_size = sizeof(taskAIBuffer),
- .cb_mem = &taskAIControlBlock,
- .cb_size = sizeof(taskAIControlBlock),
- .priority = (osPriority_t) osPriorityNormal,
- };
- /* USER CODE BEGIN PV */
- /* USER CODE END PV */
- /* Private function prototypes -----------------------------------------------*/
- void SystemClock_Config(void);
- void PeriphCommonClock_Config(void);
- static void MX_GPIO_Init(void);
- static void MX_ADC1_Init(void);
- static void MX_FDCAN1_Init(void);
- static void MX_FMC_Init(void);
- static void MX_I2C1_Init(void);
- static void MX_I2C3_Init(void);
- static void MX_SPI1_Init(void);
- static void MX_SPI2_Init(void);
- static void MX_TIM7_Init(void);
- static void MX_UART4_Init(void);
- static void MX_USART1_UART_Init(void);
- static void MX_USART2_UART_Init(void);
- static void MX_USART3_UART_Init(void);
- static void MX_ICACHE_Init(void);
- static void MX_GTZC_Init(void);
- static void MX_ADC2_Init(void);
- void taskEPSRunner(void *argument);
- void taskSnapRunner(void *argument);
- void taskAIRunner(void *argument);
- void taskImcTest(void *argument);
- void taskImcTest_2(void *argument);
- /* USER CODE BEGIN PFP */
- /* USER CODE END PFP */
- /* Private user code ---------------------------------------------------------*/
- /* USER CODE BEGIN 0 */
- #ifdef __cplusplus
- extern "C" int _write(int32_t file, uint8_t *ptr, int32_t len) {
- #else
- int _write(int32_t file, uint8_t *ptr, int32_t len) {
- #endif
- if( HAL_UART_Transmit(&UART_HANDLER_SBC, ptr, len, len) == HAL_OK ) return len;
- else return 0;
- }
- void vApplicationStackOverflowHook(TaskHandle_t* pxTask , char* pcTaskName ) {
- __disable_irq();
- //todo: Indicate Overflow with LEDs
- printf("stack overflow at %s\r\n", pcTaskName);
- for(;;) ;
- }
- int32_t hal_uart_ifx_send(sc03mpd_ifx_t* ifx, uint8_t* buf, uint16_t len);
- int32_t hal_uart_ifx_recv(sc03mpd_ifx_t* ifx, uint8_t* buf, uint16_t len);
- int32_t hal_uart_ifx_send(sc03mpd_ifx_t* ifx, uint8_t* buf, uint16_t len)
- {
- return (HAL_UART_Transmit((UART_HandleTypeDef*)ifx->context, buf, len, 100) == HAL_OK)? len : -1;
- }
- int32_t hal_uart_ifx_recv(sc03mpd_ifx_t* ifx, uint8_t* buf, uint16_t len)
- {
- return (HAL_UARTEx_ReceiveToIdle((UART_HandleTypeDef*)ifx->context, buf, len, &len, 500) == HAL_OK)? len : -1;
- }
- /* USER CODE END 0 */
- /**
- * @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();
- /* Configure the peripherals common clocks */
- PeriphCommonClock_Config();
- /* GTZC initialisation */
- MX_GTZC_Init();
- /* USER CODE BEGIN SysInit */
- /* USER CODE END SysInit */
- /* Initialize all configured peripherals */
- MX_GPIO_Init();
- MX_ADC1_Init();
- MX_FDCAN1_Init();
- MX_FMC_Init();
- MX_I2C1_Init();
- MX_I2C3_Init();
- MX_SPI1_Init();
- MX_SPI2_Init();
- MX_TIM7_Init();
- MX_UART4_Init();
- MX_USART1_UART_Init();
- MX_USART2_UART_Init();
- MX_USART3_UART_Init();
- MX_ICACHE_Init();
- MX_USB_Device_Init();
- MX_ADC2_Init();
- /* USER CODE BEGIN 2 */
- #if (imcUSE_IMC_KERNEL == 1)
- imcInit();
- #endif
- printf("\r\n\r\n\r\n");
- printf("**************************\r\n");
- printf("** TEST APP INFORMATION **\r\n");
- printf(" - SBC M33 freeRTOS, truztzone, ADC test\r\n");
- printf(" - 2023.10.20. 10:00\r\n");
- printf("**************************\r\n");
- printf("\r\n\r\n\r\n");
- /* after SBC boot-up, sbc power gpio pin should be ON */
- imc_sbc_power_on(); // delay(param) should be 0ms
- /* USER CODE END 2 */
- /* Init scheduler */
- osKernelInitialize();
- /* 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 */
- /* USER CODE BEGIN RTOS_QUEUES */
- /* add queues, ... */
- /* USER CODE END RTOS_QUEUES */
- /* Create the thread(s) */
- /* creation of taskEPS */
- // taskEPSHandle = osThreadNew(taskEPSRunner, NULL, &taskEPS_attributes);
- /* creation of taskSnap */
- #if (imcUSE_IMC_KERNEL == 1)
- // taskSnapHandle = imcOsThreadNew(taskSnapRunner, NULL, &taskSnap_attributes);
- taskSnapHandle = imcOsThreadNew(taskImcTest, NULL, &taskSnap_attributes);
- taskEPSHandle = imcOsThreadNew(taskImcTest_2, NULL, &taskEPS_attributes);
- #else
- // taskSnapHandle = osThreadNew(taskSnapRunner, NULL, &taskSnap_attributes);
- #endif
- /* creation of taskAI */
- // taskAIHandle = osThreadNew(taskAIRunner, NULL, &taskAI_attributes);
- /* USER CODE BEGIN RTOS_THREADS */
- /* add threads, ... */
- /* USER CODE END RTOS_THREADS */
- /* USER CODE BEGIN RTOS_EVENTS */
- /* add events, ... */
- /* USER CODE END RTOS_EVENTS */
- /* 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 */
- }
- /**
- * @brief System Clock Configuration
- * @retval None
- */
- void SystemClock_Config(void)
- {
- RCC_OscInitTypeDef RCC_OscInitStruct = {0};
- RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
- /** Configure the main internal regulator output voltage
- */
- if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)
- {
- Error_Handler();
- }
- /** Configure LSE Drive Capability
- */
- HAL_PWR_EnableBkUpAccess();
- __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
- /** Initializes the RCC Oscillators according to the specified parameters
- * in the RCC_OscInitTypeDef structure.
- */
- RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE|RCC_OSCILLATORTYPE_LSE
- |RCC_OSCILLATORTYPE_MSI;
- RCC_OscInitStruct.HSEState = RCC_HSE_ON;
- RCC_OscInitStruct.LSEState = RCC_LSE_ON;
- RCC_OscInitStruct.MSIState = RCC_MSI_ON;
- RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;
- RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_6;
- RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
- RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
- RCC_OscInitStruct.PLL.PLLM = 1;
- RCC_OscInitStruct.PLL.PLLN = 16;
- RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV7;
- RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV4;
- RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV4;
- if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
- {
- Error_Handler();
- }
- /** Initializes the CPU, AHB and APB buses clocks
- */
- RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
- |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
- RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
- RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV2;
- RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
- RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
- if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
- {
- Error_Handler();
- }
- /** Enable MSI Auto calibration
- */
- HAL_RCCEx_EnableMSIPLLMode();
- }
- /**
- * @brief Peripherals Common Clock Configuration
- * @retval None
- */
- void PeriphCommonClock_Config(void)
- {
- RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
- /** Initializes the common periph clock
- */
- PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB|RCC_PERIPHCLK_ADC;
- PeriphClkInit.AdcClockSelection = RCC_ADCCLKSOURCE_PLLSAI1;
- PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLLSAI1;
- PeriphClkInit.PLLSAI1.PLLSAI1Source = RCC_PLLSAI1SOURCE_MSI;
- PeriphClkInit.PLLSAI1.PLLSAI1M = 1;
- PeriphClkInit.PLLSAI1.PLLSAI1N = 24;
- PeriphClkInit.PLLSAI1.PLLSAI1P = RCC_PLLP_DIV7;
- PeriphClkInit.PLLSAI1.PLLSAI1Q = RCC_PLLQ_DIV2;
- PeriphClkInit.PLLSAI1.PLLSAI1R = RCC_PLLR_DIV2;
- PeriphClkInit.PLLSAI1.PLLSAI1ClockOut = RCC_PLLSAI1_48M2CLK|RCC_PLLSAI1_ADC1CLK;
- if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
- {
- Error_Handler();
- }
- }
- /**
- * @brief ADC1 Initialization Function
- * @param None
- * @retval None
- */
- static void MX_ADC1_Init(void)
- {
- /* USER CODE BEGIN ADC1_Init 0 */
- /* USER CODE END ADC1_Init 0 */
- ADC_MultiModeTypeDef multimode = {0};
- ADC_ChannelConfTypeDef sConfig = {0};
- /* USER CODE BEGIN ADC1_Init 1 */
- /* USER CODE END ADC1_Init 1 */
- /** Common config
- */
- hadc1.Instance = ADC1;
- hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
- hadc1.Init.Resolution = ADC_RESOLUTION_12B;
- hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
- hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
- hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
- hadc1.Init.LowPowerAutoWait = DISABLE;
- hadc1.Init.ContinuousConvMode = DISABLE;
- hadc1.Init.NbrOfConversion = 1;
- hadc1.Init.DiscontinuousConvMode = DISABLE;
- hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
- hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
- hadc1.Init.DMAContinuousRequests = DISABLE;
- hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
- hadc1.Init.OversamplingMode = DISABLE;
- if (HAL_ADC_Init(&hadc1) != HAL_OK)
- {
- Error_Handler();
- }
- /** Configure the ADC multi-mode
- */
- multimode.Mode = ADC_MODE_INDEPENDENT;
- if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK)
- {
- Error_Handler();
- }
- /** Configure Regular Channel
- */
- sConfig.Channel = ADC_CHANNEL_1;
- sConfig.Rank = ADC_REGULAR_RANK_1;
- sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5;
- sConfig.SingleDiff = ADC_SINGLE_ENDED;
- sConfig.OffsetNumber = ADC_OFFSET_NONE;
- sConfig.Offset = 0;
- if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE BEGIN ADC1_Init 2 */
- /* USER CODE END ADC1_Init 2 */
- }
- /**
- * @brief ADC2 Initialization Function
- * @param None
- * @retval None
- */
- static void MX_ADC2_Init(void)
- {
- /* USER CODE BEGIN ADC2_Init 0 */
- /* USER CODE END ADC2_Init 0 */
- ADC_ChannelConfTypeDef sConfig = {0};
- /* USER CODE BEGIN ADC2_Init 1 */
- /* USER CODE END ADC2_Init 1 */
- /** Common config
- */
- hadc2.Instance = ADC2;
- hadc2.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
- hadc2.Init.Resolution = ADC_RESOLUTION_12B;
- hadc2.Init.DataAlign = ADC_DATAALIGN_RIGHT;
- hadc2.Init.ScanConvMode = ADC_SCAN_DISABLE;
- hadc2.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
- hadc2.Init.LowPowerAutoWait = DISABLE;
- hadc2.Init.ContinuousConvMode = DISABLE;
- hadc2.Init.NbrOfConversion = 1;
- hadc2.Init.DiscontinuousConvMode = DISABLE;
- hadc2.Init.ExternalTrigConv = ADC_SOFTWARE_START;
- hadc2.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
- hadc2.Init.DMAContinuousRequests = DISABLE;
- hadc2.Init.Overrun = ADC_OVR_DATA_PRESERVED;
- hadc2.Init.OversamplingMode = DISABLE;
- if (HAL_ADC_Init(&hadc2) != HAL_OK)
- {
- Error_Handler();
- }
- /** Configure Regular Channel
- */
- sConfig.Channel = ADC_CHANNEL_2;
- sConfig.Rank = ADC_REGULAR_RANK_1;
- sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5;
- sConfig.SingleDiff = ADC_SINGLE_ENDED;
- sConfig.OffsetNumber = ADC_OFFSET_NONE;
- sConfig.Offset = 0;
- if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE BEGIN ADC2_Init 2 */
- /* USER CODE END ADC2_Init 2 */
- }
- /**
- * @brief FDCAN1 Initialization Function
- * @param None
- * @retval None
- */
- static void MX_FDCAN1_Init(void)
- {
- /* USER CODE BEGIN FDCAN1_Init 0 */
- /* USER CODE END FDCAN1_Init 0 */
- /* USER CODE BEGIN FDCAN1_Init 1 */
- /* USER CODE END FDCAN1_Init 1 */
- hfdcan1.Instance = FDCAN1;
- hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1;
- hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC;
- hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;
- hfdcan1.Init.AutoRetransmission = DISABLE;
- hfdcan1.Init.TransmitPause = DISABLE;
- hfdcan1.Init.ProtocolException = DISABLE;
- hfdcan1.Init.NominalPrescaler = 16;
- hfdcan1.Init.NominalSyncJumpWidth = 1;
- hfdcan1.Init.NominalTimeSeg1 = 2;
- hfdcan1.Init.NominalTimeSeg2 = 2;
- hfdcan1.Init.DataPrescaler = 1;
- hfdcan1.Init.DataSyncJumpWidth = 1;
- hfdcan1.Init.DataTimeSeg1 = 1;
- hfdcan1.Init.DataTimeSeg2 = 1;
- hfdcan1.Init.StdFiltersNbr = 0;
- hfdcan1.Init.ExtFiltersNbr = 0;
- hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
- if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE BEGIN FDCAN1_Init 2 */
- /* USER CODE END FDCAN1_Init 2 */
- }
- /**
- * @brief GTZC Initialization Function
- * @param None
- * @retval None
- */
- static void MX_GTZC_Init(void)
- {
- /* USER CODE BEGIN GTZC_Init 0 */
- /* USER CODE END GTZC_Init 0 */
- /* USER CODE BEGIN GTZC_Init 1 */
- /* USER CODE END GTZC_Init 1 */
- /* USER CODE BEGIN GTZC_Init 2 */
- /* USER CODE END GTZC_Init 2 */
- }
- /**
- * @brief I2C1 Initialization Function
- * @param None
- * @retval None
- */
- static void MX_I2C1_Init(void)
- {
- /* USER CODE BEGIN I2C1_Init 0 */
- /* USER CODE END I2C1_Init 0 */
- /* USER CODE BEGIN I2C1_Init 1 */
- /* USER CODE END I2C1_Init 1 */
- hi2c1.Instance = I2C1;
- hi2c1.Init.Timing = 0x00707CBB;
- hi2c1.Init.OwnAddress1 = 0;
- hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
- hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
- hi2c1.Init.OwnAddress2 = 0;
- hi2c1.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
- hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
- hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
- if (HAL_I2C_Init(&hi2c1) != HAL_OK)
- {
- Error_Handler();
- }
- /** Configure Analogue filter
- */
- if (HAL_I2CEx_ConfigAnalogFilter(&hi2c1, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
- {
- Error_Handler();
- }
- /** Configure Digital filter
- */
- if (HAL_I2CEx_ConfigDigitalFilter(&hi2c1, 0) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE BEGIN I2C1_Init 2 */
- /* USER CODE END I2C1_Init 2 */
- }
- /**
- * @brief I2C3 Initialization Function
- * @param None
- * @retval None
- */
- static void MX_I2C3_Init(void)
- {
- /* USER CODE BEGIN I2C3_Init 0 */
- /* USER CODE END I2C3_Init 0 */
- /* USER CODE BEGIN I2C3_Init 1 */
- /* USER CODE END I2C3_Init 1 */
- hi2c3.Instance = I2C3;
- hi2c3.Init.Timing = 0x00707CBB;
- hi2c3.Init.OwnAddress1 = 0;
- hi2c3.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
- hi2c3.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
- hi2c3.Init.OwnAddress2 = 0;
- hi2c3.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
- hi2c3.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
- hi2c3.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
- if (HAL_I2C_Init(&hi2c3) != HAL_OK)
- {
- Error_Handler();
- }
- /** Configure Analogue filter
- */
- if (HAL_I2CEx_ConfigAnalogFilter(&hi2c3, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
- {
- Error_Handler();
- }
- /** Configure Digital filter
- */
- if (HAL_I2CEx_ConfigDigitalFilter(&hi2c3, 0) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE BEGIN I2C3_Init 2 */
- /* USER CODE END I2C3_Init 2 */
- }
- /**
- * @brief ICACHE Initialization Function
- * @param None
- * @retval None
- */
- static void MX_ICACHE_Init(void)
- {
- /* USER CODE BEGIN ICACHE_Init 0 */
- /* USER CODE END ICACHE_Init 0 */
- /* USER CODE BEGIN ICACHE_Init 1 */
- /* USER CODE END ICACHE_Init 1 */
- /** Enable instruction cache in 1-way (direct mapped cache)
- */
- if (HAL_ICACHE_ConfigAssociativityMode(ICACHE_1WAY) != HAL_OK)
- {
- Error_Handler();
- }
- if (HAL_ICACHE_Enable() != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE BEGIN ICACHE_Init 2 */
- /* USER CODE END ICACHE_Init 2 */
- }
- /**
- * @brief SPI1 Initialization Function
- * @param None
- * @retval None
- */
- static void MX_SPI1_Init(void)
- {
- /* USER CODE BEGIN SPI1_Init 0 */
- /* USER CODE END SPI1_Init 0 */
- /* USER CODE BEGIN SPI1_Init 1 */
- /* USER CODE END SPI1_Init 1 */
- /* SPI1 parameter configuration*/
- hspi1.Instance = SPI1;
- hspi1.Init.Mode = SPI_MODE_MASTER;
- hspi1.Init.Direction = SPI_DIRECTION_2LINES;
- hspi1.Init.DataSize = SPI_DATASIZE_4BIT;
- hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
- hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
- hspi1.Init.NSS = SPI_NSS_HARD_OUTPUT;
- hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
- hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
- hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
- hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
- hspi1.Init.CRCPolynomial = 7;
- hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
- hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
- if (HAL_SPI_Init(&hspi1) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE BEGIN SPI1_Init 2 */
- /* USER CODE END SPI1_Init 2 */
- }
- /**
- * @brief SPI2 Initialization Function
- * @param None
- * @retval None
- */
- static void MX_SPI2_Init(void)
- {
- /* USER CODE BEGIN SPI2_Init 0 */
- /* USER CODE END SPI2_Init 0 */
- /* USER CODE BEGIN SPI2_Init 1 */
- /* USER CODE END SPI2_Init 1 */
- /* SPI2 parameter configuration*/
- hspi2.Instance = SPI2;
- hspi2.Init.Mode = SPI_MODE_MASTER;
- hspi2.Init.Direction = SPI_DIRECTION_2LINES;
- hspi2.Init.DataSize = SPI_DATASIZE_4BIT;
- hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
- hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
- hspi2.Init.NSS = SPI_NSS_HARD_OUTPUT;
- hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
- hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
- hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
- hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
- hspi2.Init.CRCPolynomial = 7;
- hspi2.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
- hspi2.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
- if (HAL_SPI_Init(&hspi2) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE BEGIN SPI2_Init 2 */
- /* USER CODE END SPI2_Init 2 */
- }
- /**
- * @brief TIM7 Initialization Function
- * @param None
- * @retval None
- */
- static void MX_TIM7_Init(void)
- {
- /* USER CODE BEGIN TIM7_Init 0 */
- /* USER CODE END TIM7_Init 0 */
- TIM_MasterConfigTypeDef sMasterConfig = {0};
- /* USER CODE BEGIN TIM7_Init 1 */
- /* USER CODE END TIM7_Init 1 */
- htim7.Instance = TIM7;
- htim7.Init.Prescaler = 0;
- htim7.Init.CounterMode = TIM_COUNTERMODE_UP;
- htim7.Init.Period = 65535;
- htim7.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
- if (HAL_TIM_Base_Init(&htim7) != HAL_OK)
- {
- Error_Handler();
- }
- sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
- sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
- if (HAL_TIMEx_MasterConfigSynchronization(&htim7, &sMasterConfig) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE BEGIN TIM7_Init 2 */
- /* USER CODE END TIM7_Init 2 */
- }
- /**
- * @brief UART4 Initialization Function
- * @param None
- * @retval None
- */
- static void MX_UART4_Init(void)
- {
- /* USER CODE BEGIN UART4_Init 0 */
- /* USER CODE END UART4_Init 0 */
- /* USER CODE BEGIN UART4_Init 1 */
- /* USER CODE END UART4_Init 1 */
- huart4.Instance = UART4;
- huart4.Init.BaudRate = 115200;
- huart4.Init.WordLength = UART_WORDLENGTH_8B;
- huart4.Init.StopBits = UART_STOPBITS_1;
- huart4.Init.Parity = UART_PARITY_NONE;
- huart4.Init.Mode = UART_MODE_TX_RX;
- huart4.Init.HwFlowCtl = UART_HWCONTROL_NONE;
- huart4.Init.OverSampling = UART_OVERSAMPLING_16;
- huart4.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
- huart4.Init.ClockPrescaler = UART_PRESCALER_DIV1;
- huart4.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
- if (HAL_UART_Init(&huart4) != HAL_OK)
- {
- Error_Handler();
- }
- if (HAL_UARTEx_SetTxFifoThreshold(&huart4, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
- {
- Error_Handler();
- }
- if (HAL_UARTEx_SetRxFifoThreshold(&huart4, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
- {
- Error_Handler();
- }
- if (HAL_UARTEx_DisableFifoMode(&huart4) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE BEGIN UART4_Init 2 */
- /* USER CODE END UART4_Init 2 */
- }
- /**
- * @brief USART1 Initialization Function
- * @param None
- * @retval None
- */
- static void MX_USART1_UART_Init(void)
- {
- /* USER CODE BEGIN USART1_Init 0 */
- /* USER CODE END USART1_Init 0 */
- /* USER CODE BEGIN USART1_Init 1 */
- /* USER CODE END USART1_Init 1 */
- huart1.Instance = USART1;
- huart1.Init.BaudRate = 115200;
- huart1.Init.WordLength = UART_WORDLENGTH_8B;
- huart1.Init.StopBits = UART_STOPBITS_1;
- huart1.Init.Parity = UART_PARITY_NONE;
- huart1.Init.Mode = UART_MODE_TX_RX;
- huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
- huart1.Init.OverSampling = UART_OVERSAMPLING_16;
- huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
- huart1.Init.ClockPrescaler = UART_PRESCALER_DIV1;
- huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
- if (HAL_UART_Init(&huart1) != HAL_OK)
- {
- Error_Handler();
- }
- if (HAL_UARTEx_SetTxFifoThreshold(&huart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
- {
- Error_Handler();
- }
- if (HAL_UARTEx_SetRxFifoThreshold(&huart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
- {
- Error_Handler();
- }
- if (HAL_UARTEx_DisableFifoMode(&huart1) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE BEGIN USART1_Init 2 */
- /* USER CODE END USART1_Init 2 */
- }
- /**
- * @brief USART2 Initialization Function
- * @param None
- * @retval None
- */
- static void MX_USART2_UART_Init(void)
- {
- /* USER CODE BEGIN USART2_Init 0 */
- /* USER CODE END USART2_Init 0 */
- /* USER CODE BEGIN USART2_Init 1 */
- /* USER CODE END USART2_Init 1 */
- huart2.Instance = USART2;
- huart2.Init.BaudRate = 115200;
- huart2.Init.WordLength = UART_WORDLENGTH_8B;
- huart2.Init.StopBits = UART_STOPBITS_1;
- huart2.Init.Parity = UART_PARITY_NONE;
- huart2.Init.Mode = UART_MODE_TX_RX;
- huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
- huart2.Init.OverSampling = UART_OVERSAMPLING_16;
- huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
- huart2.Init.ClockPrescaler = UART_PRESCALER_DIV1;
- huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
- if (HAL_UART_Init(&huart2) != HAL_OK)
- {
- Error_Handler();
- }
- if (HAL_UARTEx_SetTxFifoThreshold(&huart2, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
- {
- Error_Handler();
- }
- if (HAL_UARTEx_SetRxFifoThreshold(&huart2, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
- {
- Error_Handler();
- }
- if (HAL_UARTEx_DisableFifoMode(&huart2) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE BEGIN USART2_Init 2 */
- /* USER CODE END USART2_Init 2 */
- }
- /**
- * @brief USART3 Initialization Function
- * @param None
- * @retval None
- */
- static void MX_USART3_UART_Init(void)
- {
- /* USER CODE BEGIN USART3_Init 0 */
- /* USER CODE END USART3_Init 0 */
- /* USER CODE BEGIN USART3_Init 1 */
- /*
- * use below code if code is re-generated by .ioc modification
- #if CAM_CHANGE_BAUDRATE
- UART_HANDLER_CAM.Init.BaudRate = 38400;
- #else
- UART_HANDLER_CAM.Init.BaudRate = 115200;
- #endif
- */
- /* USER CODE END USART3_Init 1 */
- huart3.Instance = USART3;
- huart3.Init.BaudRate = 115200;
- huart3.Init.WordLength = UART_WORDLENGTH_8B;
- huart3.Init.StopBits = UART_STOPBITS_1;
- huart3.Init.Parity = UART_PARITY_NONE;
- huart3.Init.Mode = UART_MODE_TX_RX;
- huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
- huart3.Init.OverSampling = UART_OVERSAMPLING_16;
- huart3.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
- huart3.Init.ClockPrescaler = UART_PRESCALER_DIV1;
- huart3.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
- if (HAL_UART_Init(&huart3) != HAL_OK)
- {
- Error_Handler();
- }
- if (HAL_UARTEx_SetTxFifoThreshold(&huart3, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
- {
- Error_Handler();
- }
- if (HAL_UARTEx_SetRxFifoThreshold(&huart3, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
- {
- Error_Handler();
- }
- if (HAL_UARTEx_DisableFifoMode(&huart3) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE BEGIN USART3_Init 2 */
- /* USER CODE END USART3_Init 2 */
- }
- /* FMC initialization function */
- static void MX_FMC_Init(void)
- {
- /* USER CODE BEGIN FMC_Init 0 */
- /* USER CODE END FMC_Init 0 */
- FMC_NORSRAM_TimingTypeDef Timing = {0};
- /* USER CODE BEGIN FMC_Init 1 */
- /* USER CODE END FMC_Init 1 */
- /** Perform the SRAM1 memory initialization sequence
- */
- hsram1.Instance = FMC_NORSRAM_DEVICE;
- hsram1.Extended = FMC_NORSRAM_EXTENDED_DEVICE;
- /* hsram1.Init */
- hsram1.Init.NSBank = FMC_NORSRAM_BANK1;
- hsram1.Init.DataAddressMux = FMC_DATA_ADDRESS_MUX_DISABLE;
- hsram1.Init.MemoryType = FMC_MEMORY_TYPE_SRAM;
- hsram1.Init.MemoryDataWidth = FMC_NORSRAM_MEM_BUS_WIDTH_16;
- hsram1.Init.BurstAccessMode = FMC_BURST_ACCESS_MODE_DISABLE;
- hsram1.Init.WaitSignalPolarity = FMC_WAIT_SIGNAL_POLARITY_LOW;
- hsram1.Init.WaitSignalActive = FMC_WAIT_TIMING_BEFORE_WS;
- hsram1.Init.WriteOperation = FMC_WRITE_OPERATION_ENABLE;
- hsram1.Init.WaitSignal = FMC_WAIT_SIGNAL_DISABLE;
- hsram1.Init.ExtendedMode = FMC_EXTENDED_MODE_DISABLE;
- hsram1.Init.AsynchronousWait = FMC_ASYNCHRONOUS_WAIT_DISABLE;
- hsram1.Init.WriteBurst = FMC_WRITE_BURST_DISABLE;
- hsram1.Init.ContinuousClock = FMC_CONTINUOUS_CLOCK_SYNC_ONLY;
- hsram1.Init.WriteFifo = FMC_WRITE_FIFO_ENABLE;
- hsram1.Init.NBLSetupTime = 0;
- hsram1.Init.PageSize = FMC_PAGE_SIZE_NONE;
- hsram1.Init.MaxChipSelectPulse = DISABLE;
- /* Timing */
- Timing.AddressSetupTime = 15;
- Timing.AddressHoldTime = 15;
- Timing.DataSetupTime = 30;
- Timing.DataHoldTime = 0;
- Timing.BusTurnAroundDuration = 2;
- Timing.CLKDivision = 16;
- Timing.DataLatency = 17;
- Timing.AccessMode = FMC_ACCESS_MODE_A;
- /* ExtTiming */
- if (HAL_SRAM_Init(&hsram1, &Timing, NULL) != HAL_OK)
- {
- Error_Handler( );
- }
- /** Perform the SRAM2 memory initialization sequence
- */
- hsram2.Instance = FMC_NORSRAM_DEVICE;
- hsram2.Extended = FMC_NORSRAM_EXTENDED_DEVICE;
- /* hsram2.Init */
- hsram2.Init.NSBank = FMC_NORSRAM_BANK2;
- hsram2.Init.DataAddressMux = FMC_DATA_ADDRESS_MUX_DISABLE;
- hsram2.Init.MemoryType = FMC_MEMORY_TYPE_SRAM;
- hsram2.Init.MemoryDataWidth = FMC_NORSRAM_MEM_BUS_WIDTH_16;
- hsram2.Init.BurstAccessMode = FMC_BURST_ACCESS_MODE_DISABLE;
- hsram2.Init.WaitSignalPolarity = FMC_WAIT_SIGNAL_POLARITY_LOW;
- hsram2.Init.WaitSignalActive = FMC_WAIT_TIMING_BEFORE_WS;
- hsram2.Init.WriteOperation = FMC_WRITE_OPERATION_ENABLE;
- hsram2.Init.WaitSignal = FMC_WAIT_SIGNAL_DISABLE;
- hsram2.Init.ExtendedMode = FMC_EXTENDED_MODE_DISABLE;
- hsram2.Init.AsynchronousWait = FMC_ASYNCHRONOUS_WAIT_DISABLE;
- hsram2.Init.WriteBurst = FMC_WRITE_BURST_DISABLE;
- hsram2.Init.ContinuousClock = FMC_CONTINUOUS_CLOCK_SYNC_ONLY;
- hsram2.Init.WriteFifo = FMC_WRITE_FIFO_ENABLE;
- hsram2.Init.NBLSetupTime = 0;
- hsram2.Init.PageSize = FMC_PAGE_SIZE_NONE;
- hsram2.Init.MaxChipSelectPulse = DISABLE;
- /* Timing */
- Timing.AddressSetupTime = 15;
- Timing.AddressHoldTime = 15;
- Timing.DataSetupTime = 30;
- Timing.DataHoldTime = 0;
- Timing.BusTurnAroundDuration = 2;
- Timing.CLKDivision = 16;
- Timing.DataLatency = 17;
- Timing.AccessMode = FMC_ACCESS_MODE_A;
- /* ExtTiming */
- if (HAL_SRAM_Init(&hsram2, &Timing, NULL) != HAL_OK)
- {
- Error_Handler( );
- }
- /** Perform the SRAM3 memory initialization sequence
- */
- hsram3.Instance = FMC_NORSRAM_DEVICE;
- hsram3.Extended = FMC_NORSRAM_EXTENDED_DEVICE;
- /* hsram3.Init */
- hsram3.Init.NSBank = FMC_NORSRAM_BANK3;
- hsram3.Init.DataAddressMux = FMC_DATA_ADDRESS_MUX_DISABLE;
- hsram3.Init.MemoryType = FMC_MEMORY_TYPE_PSRAM;
- hsram3.Init.MemoryDataWidth = FMC_NORSRAM_MEM_BUS_WIDTH_16;
- hsram3.Init.BurstAccessMode = FMC_BURST_ACCESS_MODE_DISABLE;
- hsram3.Init.WaitSignalPolarity = FMC_WAIT_SIGNAL_POLARITY_LOW;
- hsram3.Init.WaitSignalActive = FMC_WAIT_TIMING_BEFORE_WS;
- hsram3.Init.WriteOperation = FMC_WRITE_OPERATION_ENABLE;
- hsram3.Init.WaitSignal = FMC_WAIT_SIGNAL_DISABLE;
- hsram3.Init.ExtendedMode = FMC_EXTENDED_MODE_DISABLE;
- hsram3.Init.AsynchronousWait = FMC_ASYNCHRONOUS_WAIT_DISABLE;
- hsram3.Init.WriteBurst = FMC_WRITE_BURST_DISABLE;
- hsram3.Init.ContinuousClock = FMC_CONTINUOUS_CLOCK_SYNC_ONLY;
- hsram3.Init.WriteFifo = FMC_WRITE_FIFO_ENABLE;
- hsram3.Init.NBLSetupTime = 0;
- hsram3.Init.PageSize = FMC_PAGE_SIZE_NONE;
- hsram3.Init.MaxChipSelectPulse = DISABLE;
- /* Timing */
- Timing.AddressSetupTime = 15;
- Timing.AddressHoldTime = 15;
- Timing.DataSetupTime = 30;
- Timing.DataHoldTime = 0;
- Timing.BusTurnAroundDuration = 2;
- Timing.CLKDivision = 16;
- Timing.DataLatency = 17;
- Timing.AccessMode = FMC_ACCESS_MODE_A;
- /* ExtTiming */
- if (HAL_SRAM_Init(&hsram3, &Timing, NULL) != HAL_OK)
- {
- Error_Handler( );
- }
- /** Perform the SRAM4 memory initialization sequence
- */
- hsram4.Instance = FMC_NORSRAM_DEVICE;
- hsram4.Extended = FMC_NORSRAM_EXTENDED_DEVICE;
- /* hsram4.Init */
- hsram4.Init.NSBank = FMC_NORSRAM_BANK4;
- hsram4.Init.DataAddressMux = FMC_DATA_ADDRESS_MUX_DISABLE;
- hsram4.Init.MemoryType = FMC_MEMORY_TYPE_SRAM;
- hsram4.Init.MemoryDataWidth = FMC_NORSRAM_MEM_BUS_WIDTH_16;
- hsram4.Init.BurstAccessMode = FMC_BURST_ACCESS_MODE_DISABLE;
- hsram4.Init.WaitSignalPolarity = FMC_WAIT_SIGNAL_POLARITY_LOW;
- hsram4.Init.WaitSignalActive = FMC_WAIT_TIMING_BEFORE_WS;
- hsram4.Init.WriteOperation = FMC_WRITE_OPERATION_DISABLE;
- hsram4.Init.WaitSignal = FMC_WAIT_SIGNAL_DISABLE;
- hsram4.Init.ExtendedMode = FMC_EXTENDED_MODE_DISABLE;
- hsram4.Init.AsynchronousWait = FMC_ASYNCHRONOUS_WAIT_DISABLE;
- hsram4.Init.WriteBurst = FMC_WRITE_BURST_DISABLE;
- hsram4.Init.ContinuousClock = FMC_CONTINUOUS_CLOCK_SYNC_ONLY;
- hsram4.Init.WriteFifo = FMC_WRITE_FIFO_ENABLE;
- hsram4.Init.NBLSetupTime = 0;
- hsram4.Init.PageSize = FMC_PAGE_SIZE_NONE;
- hsram4.Init.MaxChipSelectPulse = DISABLE;
- /* Timing */
- Timing.AddressSetupTime = 15;
- Timing.AddressHoldTime = 15;
- Timing.DataSetupTime = 255;
- Timing.DataHoldTime = 0;
- Timing.BusTurnAroundDuration = 15;
- Timing.CLKDivision = 16;
- Timing.DataLatency = 17;
- Timing.AccessMode = FMC_ACCESS_MODE_A;
- /* ExtTiming */
- if (HAL_SRAM_Init(&hsram4, &Timing, NULL) != HAL_OK)
- {
- Error_Handler( );
- }
- /* USER CODE BEGIN FMC_Init 2 */
- /* USER CODE END FMC_Init 2 */
- }
- /**
- * @brief GPIO Initialization Function
- * @param None
- * @retval None
- */
- static void MX_GPIO_Init(void)
- {
- GPIO_InitTypeDef GPIO_InitStruct = {0};
- /* USER CODE BEGIN MX_GPIO_Init_1 */
- /* USER CODE END MX_GPIO_Init_1 */
- /* GPIO Ports Clock Enable */
- __HAL_RCC_GPIOE_CLK_ENABLE();
- __HAL_RCC_GPIOC_CLK_ENABLE();
- __HAL_RCC_GPIOF_CLK_ENABLE();
- __HAL_RCC_GPIOH_CLK_ENABLE();
- __HAL_RCC_GPIOA_CLK_ENABLE();
- __HAL_RCC_GPIOB_CLK_ENABLE();
- __HAL_RCC_GPIOG_CLK_ENABLE();
- __HAL_RCC_GPIOD_CLK_ENABLE();
- HAL_PWREx_EnableVddIO2();
- /*Configure GPIO pin Output Level */
- HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13|GPIO_PIN_6|GPIO_PIN_7, GPIO_PIN_RESET);
- /*Configure GPIO pin Output Level */
- HAL_GPIO_WritePin(GPIOF, GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_11, GPIO_PIN_RESET);
- /*Configure GPIO pin Output Level */
- HAL_GPIO_WritePin(GPIOB, GPIO_PIN_2, GPIO_PIN_RESET);
- /*Configure GPIO pin Output Level */
- HAL_GPIO_WritePin(GPIOG, GPIO_PIN_6|GPIO_PIN_11|GPIO_PIN_15, GPIO_PIN_RESET);
- /*Configure GPIO pin Output Level */
- HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
- /*Configure GPIO pin Output Level */
- HAL_GPIO_WritePin(GPIOD, GPIO_PIN_3, GPIO_PIN_RESET);
- /*Configure GPIO pins : PC13 PC6 */
- GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_6;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
- /*Configure GPIO pins : PF6 PF7 PF11 */
- GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_11;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
- /*Configure GPIO pins : PF8 PF9 PF10 */
- GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10;
- GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
- /*Configure GPIO pin : PB2 */
- GPIO_InitStruct.Pin = GPIO_PIN_2;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
- /*Configure GPIO pins : PG6 PG15 */
- GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_15;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
- /*Configure GPIO pin : PC7 */
- GPIO_InitStruct.Pin = GPIO_PIN_7;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
- /*Configure GPIO pin : PA8 */
- GPIO_InitStruct.Pin = GPIO_PIN_8;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
- /*Configure GPIO pin : PD2 */
- GPIO_InitStruct.Pin = GPIO_PIN_2;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- GPIO_InitStruct.Alternate = GPIO_AF12_SDMMC1;
- HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
- /*Configure GPIO pin : PD3 */
- GPIO_InitStruct.Pin = GPIO_PIN_3;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
- /*Configure GPIO pin : PG11 */
- GPIO_InitStruct.Pin = GPIO_PIN_11;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
- /* USER CODE BEGIN MX_GPIO_Init_2 */
- /* USER CODE END MX_GPIO_Init_2 */
- }
- /* USER CODE BEGIN 4 */
- /* USER CODE END 4 */
- /* USER CODE BEGIN Header_taskEPSRunner */
- /**
- * @brief Function implementing the taskEPS thread.
- * @param argument: Not used
- * @retval None
- */
- /* USER CODE END Header_taskEPSRunner */
- void taskEPSRunner(void *argument)
- {
- /* USER CODE BEGIN 5 */
- #if (EPS_CAP_VOLT_ADC)
- int capacitor_voltage0 = 0;
- //int capacitor_voltage1 = 0;
- /* Infinite loop */
- for(;;)
- {
- capacitor_voltage0 = measure_voltage(ADC_HANDLER_SBC, EPS_CAP_ID_SBC);
- //capacitor_voltage1 = measure_voltage(ADC_HANDLER_CAM, EPS_CAP_ID_CAM);
- //printf("\t\t\t\t\t\t[EPS] CAP VOLT: %d.%03d, %d.%03d\r\n", capacitor_voltage0/1000, capacitor_voltage0%1000, capacitor_voltage1/1000, capacitor_voltage1%1000);
- if (capacitor_voltage0 < EPS_CAP_VOLT_LOW_THRESHOLD_SBC)
- {
- printf("[EPS] CAP#%d < %dmV (TODO JIT CHECKPOINT)\r\n", EPS_CAP_ID_SBC, EPS_CAP_VOLT_LOW_THRESHOLD_SBC);
- // TODO: JIT CHECKPOINT
- imc_sbc_power_off();
- }
- osDelay(DELAY_AFTER_WORK);
- }
- #endif
- #if (EPS_CAP_VOLT_GPIO)
- /* energy_level: 1~7, and SBC power off when the level is 1 */
- uint8_t energy_level_prev = 8;
- uint8_t energy_level_curr = 8;
- /* Infinite loop */
- for(;;)
- {
- energy_level_curr = imc_get_energy_level();
- if (energy_level_curr != energy_level_prev)
- {
- printf("[EPS] E Level: %d\r\n",
- energy_level_curr);
- if (energy_level_curr <= EPS_SBC_OFF_LEVEL)
- {
- imc_sbc_power_off();
- }
- energy_level_prev = energy_level_curr;
- }
- osDelay(DELAY_AFTER_WORK);
- }
- #endif
- /* USER CODE END 5 */
- }
- /* USER CODE BEGIN Header_taskSnapRunner */
- /**
- * @brief Function implementing the taskSnap thread.
- * @param argument: Not used
- * @retval None
- */
- uint32_t trial = 1;
- extern uint16_t ilen;
- /* USER CODE END Header_taskSnapRunner */
- void taskSnapRunner(void *argument)
- {
- /* USER CODE BEGIN taskSnapRunner */
- sc03mpd_ifx_t ifx = {
- .context = (void*)&UART_HANDLER_CAM,
- .sendif = hal_uart_ifx_send,
- .recvif = hal_uart_ifx_recv,
- };
- uint8_t error_count = 0;
- /* Infinite loop */
- while (1)
- {
- printf ("\r\n\r\n\r\n#%ld\r\n\r\n", trial);
- trial++;
- // osSemaphoreWait(empty, osWaitForever);
- #if EPS_CAP_VOLT_ADC
- SC03MPD_ASSERT(imc_sc03mpd_cap_check (ADC_HANDLER_CAM), "[CAM] FAILED CAP volt", ERROR)
- #endif
- /*
- * 2022. 11. 10. TEST for EPS-SBC-CAM; SBC controls CAM ON/OFF; KETI EPS does NOT wait 2.5s for CAM init.
- */
- imc_cam_power_on();
- // (M33) moved from imc_sc03mpd_init
- printf("[CAM] wait %dms for boot-up\r\n", DELAY_AFTER_POWERUP);
- osDelay (DELAY_AFTER_POWERUP);
- MX_USART3_UART_Init();
- // (M33) moved from imc_sc03mpd_init
- SC03MPD_ASSERT(imc_sc03mpd_init(&ifx), "[CAM] FAILED init", ERROR)
- /* execute once when change CAM default baudrate */
- #if CAM_CHANGE_BAUDRATE
- sc03mpd_set_baud(&ifx, SC03MPD_BDR_115200, 1); // default: SC03MPD_BDR_38400
- printf ("[CAM] OK change default baudrate");
- while (1)
- {
- osDelay(1);
- }
- #endif
- #if 0
- /* image capture and download when GPIO pin 1 UP */
- /* wait for GPIO pin 1 UP */
- osEvent event = osMessageGet(queueSnapReqHandle, osWaitForever);
- if (event.status != osEventMessage)
- continue;
- printf("[CAM] frame capture requested (%lu)\r\n", event.value.v);
- #endif
- /*
- * 2022. 8. 25. fix logical seq. error under V0706 protocol; stop -> read length -> read data -> resume
- * 2022. 8. 26. simply combine three functions; asked by kylee
- */
- SC03MPD_ASSERT(imc_sc03mpd_capture(&ifx), "[CAM] FAILED capture", ERROR)
- /*
- * 2022. 11. 10. TEST for EPS-SBC-CAM
- */
- imc_cam_power_off();
- // error_count reset
- error_count = 0;
- /* DO SOMETHING */
- #if 0
- if (decodeMyImage((uint8_t*)IMG_RAM_ADDR, ilen, 0, 0, 0, NULL, 1) != DEC_ENON)
- goto ERROR;
- // osSemaphoreRelease(full);
- #else
- printf ("[SBC] wait %dms for DO SOMETHING\r\n", DELAY_DO_SOMETHING);
- osDelay(DELAY_DO_SOMETHING);
- #endif
- continue;
- ERROR:
- /*
- * 2022. 7. 20. failure --> UART stuck continuously; works only after HW reset
- * 2022. 8. 25. add USART3 init. and reset fn.; download or capture failure --> normal
- * 2022. 8. 25. after SC03MPD power off/on, works well after few failures
- * 2022. 11. 11. start of this while loop, CAM init is called
- * 2023. 10. 20. add error_count for handling successive errors
- */
- error_count++;
- printf("[CAM] ERROR HANDLING; CAM OFF > %dms delay > CAM ON\r\n", DELAY_BEFORE_ERR_HANDLING);
- imc_cam_power_off();
- // osSemaphoreRelease(empty);
- osDelay(DELAY_BEFORE_ERR_HANDLING); //imc_sbc_power_off();
- // ERROR 3 times -> SBC reboot
- if (error_count >= CAM_ERROR_COUNT_MAX) {
- error_count = 0;
- printf("[CAM] %d ERRORs continue and SBC OFF\r\n", CAM_ERROR_COUNT_MAX);
- imc_sbc_power_off();
- osDelay(DELAY_DO_SOMETHING);
- }
- continue;
- }
- #if 0
- EXIT:
- osDelay(1000);
- osThreadTerminate(NULL);
- #endif
- /* USER CODE END taskSnapRunner */
- }
- /* USER CODE BEGIN Header_taskAIRunner */
- /**
- * @brief Function implementing the taskAI thread.
- * @param argument: Not used
- * @retval None
- */
- /* USER CODE END Header_taskAIRunner */
- void taskAIRunner(void *argument)
- {
- /* USER CODE BEGIN taskAIRunner */
- /* Infinite loop */
- for(;;)
- {
- osDelay(DELAY_AFTER_WORK);
- }
- /* USER CODE END taskAIRunner */
- }
- void taskImcTest(void *argument) {
- int i = 0;
- while(1) {
- for(int j=0; j<10000000; j++) {
- __asm(" nop");
- }
- printf("i=%d\r\n", i++);
- imcREQUEST_CHECKPOINT();
- }
- }
- void taskImcTest_2(void *argument)
- {
- int i = 0;
- while (1)
- {
- for (int j = 0; j < 5000000; j++)
- {
- __asm(" nop");
- }
- printf("\tj=%d\r\n", i++);
- imcREQUEST_CHECKPOINT();
- }
- }
- /**
- * @brief Period elapsed callback in non blocking mode
- * @note This function is called when TIM2 interrupt took place, inside
- * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
- * a global variable "uwTick" used as application time base.
- * @param htim : TIM handle
- * @retval None
- */
- void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
- {
- /* USER CODE BEGIN Callback 0 */
- /* USER CODE END Callback 0 */
- if (htim->Instance == TIM2) {
- HAL_IncTick();
- }
- /* USER CODE BEGIN Callback 1 */
- /* USER CODE END Callback 1 */
- }
- /**
- * @brief This function is executed in case of error occurrence.
- * @retval None
- */
- void Error_Handler(void)
- {
- /* USER CODE BEGIN Error_Handler_Debug */
- /* User can add his own implementation to report the HAL error return state */
- __disable_irq();
- while (1)
- {
- }
- /* USER CODE END Error_Handler_Debug */
- }
- #ifdef USE_FULL_ASSERT
- /**
- * @brief Reports the name of the source file and the source line number
- * where the assert_param error has occurred.
- * @param file: pointer to the source file name
- * @param line: assert_param error line source number
- * @retval None
- */
- void assert_failed(uint8_t *file, uint32_t line)
- {
- /* USER CODE BEGIN 6 */
- /* User can add his own implementation to report the file name and line number,
- ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
- /* USER CODE END 6 */
- }
- #endif /* USE_FULL_ASSERT */
|