main.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : main.c
  5. * @brief : Main program body
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2023 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file
  13. * in the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. /* USER CODE END Header */
  19. /* Includes ------------------------------------------------------------------*/
  20. #include "main.h"
  21. #include "cmsis_os.h"
  22. #include "usb_device.h"
  23. /* Private includes ----------------------------------------------------------*/
  24. /* USER CODE BEGIN Includes */
  25. #include "ImC/imc_api.h"
  26. #include "ImC/imc_kernel.h"
  27. /* USER CODE END Includes */
  28. /* Private typedef -----------------------------------------------------------*/
  29. typedef StaticTask_t osStaticThreadDef_t;
  30. /* USER CODE BEGIN PTD */
  31. /* USER CODE END PTD */
  32. /* Private define ------------------------------------------------------------*/
  33. /* USER CODE BEGIN PD */
  34. #define FRAM_MEM_SIZE (0x100000) // 1 MiB = 2 * 512 * 1024 bytes
  35. #define MRAM_MEM_SIZE (0x800000) // 8 MiB = 2 * 4 * 1024 * 1024 bytes
  36. #define MEM_TYPE_MRAM (1)
  37. #define MEM_TYPE_FRAM (2)
  38. #define MEM_SIZE_HALF (3)
  39. #define MEM_SIZE_FULL (4)
  40. #define MEM_TEST_TYPE MEM_TYPE_MRAM
  41. #define MEM_TEST_SIZE MEM_SIZE_HALF
  42. #define MEM_TEST_ADDR (0x68000000U)
  43. #if !defined(MEM_TEST_TYPE)
  44. #error "Choose the memory type for test!"
  45. #endif
  46. #if !defined(MEM_TEST_SIZE)
  47. #error "Choose the memory size for test!"
  48. #endif
  49. #if (MEM_TEST_TYPE == MEM_TYPE_MRAM)
  50. #if (MEM_TEST_SIZE == MEM_SIZE_FULL)
  51. #define MEMORY_SIZE MRAM_MEM_SIZE
  52. #elif (MEM_TEST_SIZE == MEM_SIZE_HALF)
  53. #define MEMORY_SIZE (MRAM_MEM_SIZE / 2)
  54. #else
  55. #error "Invalid memory size"
  56. #endif
  57. #elif (MEM_TEST_TYPE == MEM_TYPE_FRAM)
  58. #if (MEM_TEST_SIZE == MEM_SIZE_FULL)
  59. #define MEMORY_SIZE FRAM_MEM_SIZE
  60. #elif (MEM_TEST_SIZE == MEM_SIZE_HALF)
  61. #define MEMORY_SIZE (FRAM_MEM_SIZE / 2)
  62. #else
  63. #error "Invalid memory size"
  64. #endif
  65. #else
  66. #error "Invalid memory type"
  67. #endif
  68. /* USER CODE END PD */
  69. /* Private macro -------------------------------------------------------------*/
  70. /* USER CODE BEGIN PM */
  71. /* USER CODE END PM */
  72. /* Private variables ---------------------------------------------------------*/
  73. ADC_HandleTypeDef hadc1;
  74. ADC_HandleTypeDef hadc2;
  75. FDCAN_HandleTypeDef hfdcan1;
  76. I2C_HandleTypeDef hi2c1;
  77. I2C_HandleTypeDef hi2c3;
  78. SPI_HandleTypeDef hspi1;
  79. SPI_HandleTypeDef hspi2;
  80. TIM_HandleTypeDef htim7;
  81. UART_HandleTypeDef huart4;
  82. UART_HandleTypeDef huart1;
  83. UART_HandleTypeDef huart2;
  84. UART_HandleTypeDef huart3;
  85. SRAM_HandleTypeDef hsram1;
  86. SRAM_HandleTypeDef hsram2;
  87. SRAM_HandleTypeDef hsram3;
  88. SRAM_HandleTypeDef hsram4;
  89. /* Definitions for taskEPS */
  90. osThreadId_t taskEPSHandle;
  91. uint32_t taskEPSBuffer[ 256 ];
  92. osStaticThreadDef_t taskEPSControlBlock;
  93. const osThreadAttr_t taskEPS_attributes = {
  94. .name = "taskEPS",
  95. .stack_mem = &taskEPSBuffer[0],
  96. .stack_size = sizeof(taskEPSBuffer),
  97. .cb_mem = &taskEPSControlBlock,
  98. .cb_size = sizeof(taskEPSControlBlock),
  99. .priority = (osPriority_t) osPriorityNormal,
  100. };
  101. /* Definitions for taskSnap */
  102. osThreadId_t taskSnapHandle;
  103. uint32_t taskSnapBuffer[ 512 ];
  104. osStaticThreadDef_t taskSnapControlBlock;
  105. const osThreadAttr_t taskSnap_attributes = {
  106. .name = "taskSnap",
  107. .stack_mem = &taskSnapBuffer[0],
  108. .stack_size = sizeof(taskSnapBuffer),
  109. .cb_mem = &taskSnapControlBlock,
  110. .cb_size = sizeof(taskSnapControlBlock),
  111. .priority = (osPriority_t) osPriorityRealtime,
  112. };
  113. /* Definitions for taskAI */
  114. osThreadId_t taskAIHandle;
  115. uint32_t taskAIBuffer[ 37968 ];
  116. osStaticThreadDef_t taskAIControlBlock;
  117. const osThreadAttr_t taskAI_attributes = {
  118. .name = "taskAI",
  119. .stack_mem = &taskAIBuffer[0],
  120. .stack_size = sizeof(taskAIBuffer),
  121. .cb_mem = &taskAIControlBlock,
  122. .cb_size = sizeof(taskAIControlBlock),
  123. .priority = (osPriority_t) osPriorityNormal,
  124. };
  125. /* USER CODE BEGIN PV */
  126. /* USER CODE END PV */
  127. /* Private function prototypes -----------------------------------------------*/
  128. void SystemClock_Config(void);
  129. void PeriphCommonClock_Config(void);
  130. static void MX_GPIO_Init(void);
  131. static void MX_ADC1_Init(void);
  132. static void MX_FDCAN1_Init(void);
  133. static void MX_FMC_Init(void);
  134. static void MX_I2C1_Init(void);
  135. static void MX_I2C3_Init(void);
  136. static void MX_SPI1_Init(void);
  137. static void MX_SPI2_Init(void);
  138. static void MX_TIM7_Init(void);
  139. static void MX_UART4_Init(void);
  140. static void MX_USART1_UART_Init(void);
  141. static void MX_USART2_UART_Init(void);
  142. static void MX_USART3_UART_Init(void);
  143. static void MX_ICACHE_Init(void);
  144. static void MX_GTZC_Init(void);
  145. static void MX_ADC2_Init(void);
  146. void taskEPSRunner(void *argument);
  147. void taskSnapRunner(void *argument);
  148. void taskAIRunner(void *argument);
  149. /* USER CODE BEGIN PFP */
  150. /* USER CODE END PFP */
  151. /* Private user code ---------------------------------------------------------*/
  152. /* USER CODE BEGIN 0 */
  153. #ifdef __cplusplus
  154. extern "C" int _write(int32_t file, uint8_t *ptr, int32_t len) {
  155. #else
  156. int _write(int32_t file, uint8_t *ptr, int32_t len) {
  157. #endif
  158. if( HAL_UART_Transmit(&UART_HANDLER_SBC, ptr, len, len) == HAL_OK ) return len;
  159. else return 0;
  160. }
  161. void vApplicationStackOverflowHook(TaskHandle_t* pxTask , char* pcTaskName ) {
  162. __disable_irq();
  163. //todo: Indicate Overflow with LEDs
  164. printf("stack overflow at %s\r\n", pcTaskName);
  165. for(;;) ;
  166. }
  167. int32_t hal_uart_ifx_send(sc03mpd_ifx_t* ifx, uint8_t* buf, uint16_t len);
  168. int32_t hal_uart_ifx_recv(sc03mpd_ifx_t* ifx, uint8_t* buf, uint16_t len);
  169. int32_t hal_uart_ifx_send(sc03mpd_ifx_t* ifx, uint8_t* buf, uint16_t len)
  170. {
  171. return (HAL_UART_Transmit((UART_HandleTypeDef*)ifx->context, buf, len, 100) == HAL_OK)? len : -1;
  172. }
  173. int32_t hal_uart_ifx_recv(sc03mpd_ifx_t* ifx, uint8_t* buf, uint16_t len)
  174. {
  175. return (HAL_UARTEx_ReceiveToIdle((UART_HandleTypeDef*)ifx->context, buf, len, &len, 500) == HAL_OK)? len : -1;
  176. }
  177. /* USER CODE END 0 */
  178. /**
  179. * @brief The application entry point.
  180. * @retval int
  181. */
  182. int main(void)
  183. {
  184. /* USER CODE BEGIN 1 */
  185. /* USER CODE END 1 */
  186. /* MCU Configuration--------------------------------------------------------*/
  187. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  188. HAL_Init();
  189. /* USER CODE BEGIN Init */
  190. /* USER CODE END Init */
  191. /* Configure the system clock */
  192. SystemClock_Config();
  193. /* Configure the peripherals common clocks */
  194. PeriphCommonClock_Config();
  195. /* GTZC initialisation */
  196. MX_GTZC_Init();
  197. /* USER CODE BEGIN SysInit */
  198. /* USER CODE END SysInit */
  199. /* Initialize all configured peripherals */
  200. MX_GPIO_Init();
  201. MX_ADC1_Init();
  202. MX_FDCAN1_Init();
  203. MX_FMC_Init();
  204. MX_I2C1_Init();
  205. MX_I2C3_Init();
  206. MX_SPI1_Init();
  207. MX_SPI2_Init();
  208. MX_TIM7_Init();
  209. MX_UART4_Init();
  210. MX_USART1_UART_Init();
  211. MX_USART2_UART_Init();
  212. MX_USART3_UART_Init();
  213. MX_ICACHE_Init();
  214. MX_USB_Device_Init();
  215. MX_ADC2_Init();
  216. /* USER CODE BEGIN 2 */
  217. #if (imcUSE_IMC_KERNEL == 1)
  218. imcInit();
  219. #endif
  220. printf("\r\n\r\n\r\n");
  221. printf("**************************\r\n");
  222. printf("** TEST APP INFORMATION **\r\n");
  223. printf(" - SBC M33 freeRTOS, truztzone, ADC test\r\n");
  224. printf(" - 2023.10.20. 10:00\r\n");
  225. printf("**************************\r\n");
  226. printf("\r\n\r\n\r\n");
  227. /* after SBC boot-up, sbc power gpio pin should be ON */
  228. imc_sbc_power_on(); // delay(param) should be 0ms
  229. /* USER CODE END 2 */
  230. /* Init scheduler */
  231. osKernelInitialize();
  232. /* USER CODE BEGIN RTOS_MUTEX */
  233. /* add mutexes, ... */
  234. /* USER CODE END RTOS_MUTEX */
  235. /* USER CODE BEGIN RTOS_SEMAPHORES */
  236. /* add semaphores, ... */
  237. /* USER CODE END RTOS_SEMAPHORES */
  238. /* USER CODE BEGIN RTOS_TIMERS */
  239. /* start timers, add new ones, ... */
  240. /* USER CODE END RTOS_TIMERS */
  241. /* USER CODE BEGIN RTOS_QUEUES */
  242. /* add queues, ... */
  243. /* USER CODE END RTOS_QUEUES */
  244. /* Create the thread(s) */
  245. /* creation of taskEPS */
  246. taskEPSHandle = osThreadNew(taskEPSRunner, NULL, &taskEPS_attributes);
  247. /* creation of taskSnap */
  248. #if (imcUSE_IMC_KERNEL == 1)
  249. taskSnapHandle = imcOsThreadNew(taskSnapRunner, NULL, &taskSnap_attributes);
  250. #else
  251. taskSnapHandle = osThreadNew(taskSnapRunner, NULL, &taskSnap_attributes);
  252. #endif
  253. /* creation of taskAI */
  254. taskAIHandle = osThreadNew(taskAIRunner, NULL, &taskAI_attributes);
  255. /* USER CODE BEGIN RTOS_THREADS */
  256. /* add threads, ... */
  257. /* USER CODE END RTOS_THREADS */
  258. /* USER CODE BEGIN RTOS_EVENTS */
  259. /* add events, ... */
  260. /* USER CODE END RTOS_EVENTS */
  261. /* Start scheduler */
  262. osKernelStart();
  263. /* We should never get here as control is now taken by the scheduler */
  264. /* Infinite loop */
  265. /* USER CODE BEGIN WHILE */
  266. while (1)
  267. {
  268. /* USER CODE END WHILE */
  269. /* USER CODE BEGIN 3 */
  270. }
  271. /* USER CODE END 3 */
  272. }
  273. /**
  274. * @brief System Clock Configuration
  275. * @retval None
  276. */
  277. void SystemClock_Config(void)
  278. {
  279. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  280. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  281. /** Configure the main internal regulator output voltage
  282. */
  283. if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)
  284. {
  285. Error_Handler();
  286. }
  287. /** Configure LSE Drive Capability
  288. */
  289. HAL_PWR_EnableBkUpAccess();
  290. __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
  291. /** Initializes the RCC Oscillators according to the specified parameters
  292. * in the RCC_OscInitTypeDef structure.
  293. */
  294. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE|RCC_OSCILLATORTYPE_LSE
  295. |RCC_OSCILLATORTYPE_MSI;
  296. RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  297. RCC_OscInitStruct.LSEState = RCC_LSE_ON;
  298. RCC_OscInitStruct.MSIState = RCC_MSI_ON;
  299. RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;
  300. RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_6;
  301. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  302. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  303. RCC_OscInitStruct.PLL.PLLM = 1;
  304. RCC_OscInitStruct.PLL.PLLN = 16;
  305. RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV7;
  306. RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV4;
  307. RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV4;
  308. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  309. {
  310. Error_Handler();
  311. }
  312. /** Initializes the CPU, AHB and APB buses clocks
  313. */
  314. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  315. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  316. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  317. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV2;
  318. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  319. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  320. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
  321. {
  322. Error_Handler();
  323. }
  324. /** Enable MSI Auto calibration
  325. */
  326. HAL_RCCEx_EnableMSIPLLMode();
  327. }
  328. /**
  329. * @brief Peripherals Common Clock Configuration
  330. * @retval None
  331. */
  332. void PeriphCommonClock_Config(void)
  333. {
  334. RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  335. /** Initializes the common periph clock
  336. */
  337. PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB|RCC_PERIPHCLK_ADC;
  338. PeriphClkInit.AdcClockSelection = RCC_ADCCLKSOURCE_PLLSAI1;
  339. PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLLSAI1;
  340. PeriphClkInit.PLLSAI1.PLLSAI1Source = RCC_PLLSAI1SOURCE_MSI;
  341. PeriphClkInit.PLLSAI1.PLLSAI1M = 1;
  342. PeriphClkInit.PLLSAI1.PLLSAI1N = 24;
  343. PeriphClkInit.PLLSAI1.PLLSAI1P = RCC_PLLP_DIV7;
  344. PeriphClkInit.PLLSAI1.PLLSAI1Q = RCC_PLLQ_DIV2;
  345. PeriphClkInit.PLLSAI1.PLLSAI1R = RCC_PLLR_DIV2;
  346. PeriphClkInit.PLLSAI1.PLLSAI1ClockOut = RCC_PLLSAI1_48M2CLK|RCC_PLLSAI1_ADC1CLK;
  347. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  348. {
  349. Error_Handler();
  350. }
  351. }
  352. /**
  353. * @brief ADC1 Initialization Function
  354. * @param None
  355. * @retval None
  356. */
  357. static void MX_ADC1_Init(void)
  358. {
  359. /* USER CODE BEGIN ADC1_Init 0 */
  360. /* USER CODE END ADC1_Init 0 */
  361. ADC_MultiModeTypeDef multimode = {0};
  362. ADC_ChannelConfTypeDef sConfig = {0};
  363. /* USER CODE BEGIN ADC1_Init 1 */
  364. /* USER CODE END ADC1_Init 1 */
  365. /** Common config
  366. */
  367. hadc1.Instance = ADC1;
  368. hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
  369. hadc1.Init.Resolution = ADC_RESOLUTION_12B;
  370. hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  371. hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
  372. hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
  373. hadc1.Init.LowPowerAutoWait = DISABLE;
  374. hadc1.Init.ContinuousConvMode = DISABLE;
  375. hadc1.Init.NbrOfConversion = 1;
  376. hadc1.Init.DiscontinuousConvMode = DISABLE;
  377. hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  378. hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  379. hadc1.Init.DMAContinuousRequests = DISABLE;
  380. hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
  381. hadc1.Init.OversamplingMode = DISABLE;
  382. if (HAL_ADC_Init(&hadc1) != HAL_OK)
  383. {
  384. Error_Handler();
  385. }
  386. /** Configure the ADC multi-mode
  387. */
  388. multimode.Mode = ADC_MODE_INDEPENDENT;
  389. if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK)
  390. {
  391. Error_Handler();
  392. }
  393. /** Configure Regular Channel
  394. */
  395. sConfig.Channel = ADC_CHANNEL_1;
  396. sConfig.Rank = ADC_REGULAR_RANK_1;
  397. sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5;
  398. sConfig.SingleDiff = ADC_SINGLE_ENDED;
  399. sConfig.OffsetNumber = ADC_OFFSET_NONE;
  400. sConfig.Offset = 0;
  401. if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  402. {
  403. Error_Handler();
  404. }
  405. /* USER CODE BEGIN ADC1_Init 2 */
  406. /* USER CODE END ADC1_Init 2 */
  407. }
  408. /**
  409. * @brief ADC2 Initialization Function
  410. * @param None
  411. * @retval None
  412. */
  413. static void MX_ADC2_Init(void)
  414. {
  415. /* USER CODE BEGIN ADC2_Init 0 */
  416. /* USER CODE END ADC2_Init 0 */
  417. ADC_ChannelConfTypeDef sConfig = {0};
  418. /* USER CODE BEGIN ADC2_Init 1 */
  419. /* USER CODE END ADC2_Init 1 */
  420. /** Common config
  421. */
  422. hadc2.Instance = ADC2;
  423. hadc2.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
  424. hadc2.Init.Resolution = ADC_RESOLUTION_12B;
  425. hadc2.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  426. hadc2.Init.ScanConvMode = ADC_SCAN_DISABLE;
  427. hadc2.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
  428. hadc2.Init.LowPowerAutoWait = DISABLE;
  429. hadc2.Init.ContinuousConvMode = DISABLE;
  430. hadc2.Init.NbrOfConversion = 1;
  431. hadc2.Init.DiscontinuousConvMode = DISABLE;
  432. hadc2.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  433. hadc2.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  434. hadc2.Init.DMAContinuousRequests = DISABLE;
  435. hadc2.Init.Overrun = ADC_OVR_DATA_PRESERVED;
  436. hadc2.Init.OversamplingMode = DISABLE;
  437. if (HAL_ADC_Init(&hadc2) != HAL_OK)
  438. {
  439. Error_Handler();
  440. }
  441. /** Configure Regular Channel
  442. */
  443. sConfig.Channel = ADC_CHANNEL_2;
  444. sConfig.Rank = ADC_REGULAR_RANK_1;
  445. sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5;
  446. sConfig.SingleDiff = ADC_SINGLE_ENDED;
  447. sConfig.OffsetNumber = ADC_OFFSET_NONE;
  448. sConfig.Offset = 0;
  449. if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)
  450. {
  451. Error_Handler();
  452. }
  453. /* USER CODE BEGIN ADC2_Init 2 */
  454. /* USER CODE END ADC2_Init 2 */
  455. }
  456. /**
  457. * @brief FDCAN1 Initialization Function
  458. * @param None
  459. * @retval None
  460. */
  461. static void MX_FDCAN1_Init(void)
  462. {
  463. /* USER CODE BEGIN FDCAN1_Init 0 */
  464. /* USER CODE END FDCAN1_Init 0 */
  465. /* USER CODE BEGIN FDCAN1_Init 1 */
  466. /* USER CODE END FDCAN1_Init 1 */
  467. hfdcan1.Instance = FDCAN1;
  468. hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1;
  469. hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC;
  470. hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;
  471. hfdcan1.Init.AutoRetransmission = DISABLE;
  472. hfdcan1.Init.TransmitPause = DISABLE;
  473. hfdcan1.Init.ProtocolException = DISABLE;
  474. hfdcan1.Init.NominalPrescaler = 16;
  475. hfdcan1.Init.NominalSyncJumpWidth = 1;
  476. hfdcan1.Init.NominalTimeSeg1 = 2;
  477. hfdcan1.Init.NominalTimeSeg2 = 2;
  478. hfdcan1.Init.DataPrescaler = 1;
  479. hfdcan1.Init.DataSyncJumpWidth = 1;
  480. hfdcan1.Init.DataTimeSeg1 = 1;
  481. hfdcan1.Init.DataTimeSeg2 = 1;
  482. hfdcan1.Init.StdFiltersNbr = 0;
  483. hfdcan1.Init.ExtFiltersNbr = 0;
  484. hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
  485. if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK)
  486. {
  487. Error_Handler();
  488. }
  489. /* USER CODE BEGIN FDCAN1_Init 2 */
  490. /* USER CODE END FDCAN1_Init 2 */
  491. }
  492. /**
  493. * @brief GTZC Initialization Function
  494. * @param None
  495. * @retval None
  496. */
  497. static void MX_GTZC_Init(void)
  498. {
  499. /* USER CODE BEGIN GTZC_Init 0 */
  500. /* USER CODE END GTZC_Init 0 */
  501. /* USER CODE BEGIN GTZC_Init 1 */
  502. /* USER CODE END GTZC_Init 1 */
  503. /* USER CODE BEGIN GTZC_Init 2 */
  504. /* USER CODE END GTZC_Init 2 */
  505. }
  506. /**
  507. * @brief I2C1 Initialization Function
  508. * @param None
  509. * @retval None
  510. */
  511. static void MX_I2C1_Init(void)
  512. {
  513. /* USER CODE BEGIN I2C1_Init 0 */
  514. /* USER CODE END I2C1_Init 0 */
  515. /* USER CODE BEGIN I2C1_Init 1 */
  516. /* USER CODE END I2C1_Init 1 */
  517. hi2c1.Instance = I2C1;
  518. hi2c1.Init.Timing = 0x00707CBB;
  519. hi2c1.Init.OwnAddress1 = 0;
  520. hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
  521. hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
  522. hi2c1.Init.OwnAddress2 = 0;
  523. hi2c1.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
  524. hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
  525. hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
  526. if (HAL_I2C_Init(&hi2c1) != HAL_OK)
  527. {
  528. Error_Handler();
  529. }
  530. /** Configure Analogue filter
  531. */
  532. if (HAL_I2CEx_ConfigAnalogFilter(&hi2c1, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
  533. {
  534. Error_Handler();
  535. }
  536. /** Configure Digital filter
  537. */
  538. if (HAL_I2CEx_ConfigDigitalFilter(&hi2c1, 0) != HAL_OK)
  539. {
  540. Error_Handler();
  541. }
  542. /* USER CODE BEGIN I2C1_Init 2 */
  543. /* USER CODE END I2C1_Init 2 */
  544. }
  545. /**
  546. * @brief I2C3 Initialization Function
  547. * @param None
  548. * @retval None
  549. */
  550. static void MX_I2C3_Init(void)
  551. {
  552. /* USER CODE BEGIN I2C3_Init 0 */
  553. /* USER CODE END I2C3_Init 0 */
  554. /* USER CODE BEGIN I2C3_Init 1 */
  555. /* USER CODE END I2C3_Init 1 */
  556. hi2c3.Instance = I2C3;
  557. hi2c3.Init.Timing = 0x00707CBB;
  558. hi2c3.Init.OwnAddress1 = 0;
  559. hi2c3.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
  560. hi2c3.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
  561. hi2c3.Init.OwnAddress2 = 0;
  562. hi2c3.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
  563. hi2c3.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
  564. hi2c3.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
  565. if (HAL_I2C_Init(&hi2c3) != HAL_OK)
  566. {
  567. Error_Handler();
  568. }
  569. /** Configure Analogue filter
  570. */
  571. if (HAL_I2CEx_ConfigAnalogFilter(&hi2c3, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
  572. {
  573. Error_Handler();
  574. }
  575. /** Configure Digital filter
  576. */
  577. if (HAL_I2CEx_ConfigDigitalFilter(&hi2c3, 0) != HAL_OK)
  578. {
  579. Error_Handler();
  580. }
  581. /* USER CODE BEGIN I2C3_Init 2 */
  582. /* USER CODE END I2C3_Init 2 */
  583. }
  584. /**
  585. * @brief ICACHE Initialization Function
  586. * @param None
  587. * @retval None
  588. */
  589. static void MX_ICACHE_Init(void)
  590. {
  591. /* USER CODE BEGIN ICACHE_Init 0 */
  592. /* USER CODE END ICACHE_Init 0 */
  593. /* USER CODE BEGIN ICACHE_Init 1 */
  594. /* USER CODE END ICACHE_Init 1 */
  595. /** Enable instruction cache in 1-way (direct mapped cache)
  596. */
  597. if (HAL_ICACHE_ConfigAssociativityMode(ICACHE_1WAY) != HAL_OK)
  598. {
  599. Error_Handler();
  600. }
  601. if (HAL_ICACHE_Enable() != HAL_OK)
  602. {
  603. Error_Handler();
  604. }
  605. /* USER CODE BEGIN ICACHE_Init 2 */
  606. /* USER CODE END ICACHE_Init 2 */
  607. }
  608. /**
  609. * @brief SPI1 Initialization Function
  610. * @param None
  611. * @retval None
  612. */
  613. static void MX_SPI1_Init(void)
  614. {
  615. /* USER CODE BEGIN SPI1_Init 0 */
  616. /* USER CODE END SPI1_Init 0 */
  617. /* USER CODE BEGIN SPI1_Init 1 */
  618. /* USER CODE END SPI1_Init 1 */
  619. /* SPI1 parameter configuration*/
  620. hspi1.Instance = SPI1;
  621. hspi1.Init.Mode = SPI_MODE_MASTER;
  622. hspi1.Init.Direction = SPI_DIRECTION_2LINES;
  623. hspi1.Init.DataSize = SPI_DATASIZE_4BIT;
  624. hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
  625. hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
  626. hspi1.Init.NSS = SPI_NSS_HARD_OUTPUT;
  627. hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
  628. hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
  629. hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
  630. hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  631. hspi1.Init.CRCPolynomial = 7;
  632. hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
  633. hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
  634. if (HAL_SPI_Init(&hspi1) != HAL_OK)
  635. {
  636. Error_Handler();
  637. }
  638. /* USER CODE BEGIN SPI1_Init 2 */
  639. /* USER CODE END SPI1_Init 2 */
  640. }
  641. /**
  642. * @brief SPI2 Initialization Function
  643. * @param None
  644. * @retval None
  645. */
  646. static void MX_SPI2_Init(void)
  647. {
  648. /* USER CODE BEGIN SPI2_Init 0 */
  649. /* USER CODE END SPI2_Init 0 */
  650. /* USER CODE BEGIN SPI2_Init 1 */
  651. /* USER CODE END SPI2_Init 1 */
  652. /* SPI2 parameter configuration*/
  653. hspi2.Instance = SPI2;
  654. hspi2.Init.Mode = SPI_MODE_MASTER;
  655. hspi2.Init.Direction = SPI_DIRECTION_2LINES;
  656. hspi2.Init.DataSize = SPI_DATASIZE_4BIT;
  657. hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
  658. hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
  659. hspi2.Init.NSS = SPI_NSS_HARD_OUTPUT;
  660. hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
  661. hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
  662. hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
  663. hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  664. hspi2.Init.CRCPolynomial = 7;
  665. hspi2.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
  666. hspi2.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
  667. if (HAL_SPI_Init(&hspi2) != HAL_OK)
  668. {
  669. Error_Handler();
  670. }
  671. /* USER CODE BEGIN SPI2_Init 2 */
  672. /* USER CODE END SPI2_Init 2 */
  673. }
  674. /**
  675. * @brief TIM7 Initialization Function
  676. * @param None
  677. * @retval None
  678. */
  679. static void MX_TIM7_Init(void)
  680. {
  681. /* USER CODE BEGIN TIM7_Init 0 */
  682. /* USER CODE END TIM7_Init 0 */
  683. TIM_MasterConfigTypeDef sMasterConfig = {0};
  684. /* USER CODE BEGIN TIM7_Init 1 */
  685. /* USER CODE END TIM7_Init 1 */
  686. htim7.Instance = TIM7;
  687. htim7.Init.Prescaler = 0;
  688. htim7.Init.CounterMode = TIM_COUNTERMODE_UP;
  689. htim7.Init.Period = 65535;
  690. htim7.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  691. if (HAL_TIM_Base_Init(&htim7) != HAL_OK)
  692. {
  693. Error_Handler();
  694. }
  695. sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  696. sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  697. if (HAL_TIMEx_MasterConfigSynchronization(&htim7, &sMasterConfig) != HAL_OK)
  698. {
  699. Error_Handler();
  700. }
  701. /* USER CODE BEGIN TIM7_Init 2 */
  702. /* USER CODE END TIM7_Init 2 */
  703. }
  704. /**
  705. * @brief UART4 Initialization Function
  706. * @param None
  707. * @retval None
  708. */
  709. static void MX_UART4_Init(void)
  710. {
  711. /* USER CODE BEGIN UART4_Init 0 */
  712. /* USER CODE END UART4_Init 0 */
  713. /* USER CODE BEGIN UART4_Init 1 */
  714. /* USER CODE END UART4_Init 1 */
  715. huart4.Instance = UART4;
  716. huart4.Init.BaudRate = 115200;
  717. huart4.Init.WordLength = UART_WORDLENGTH_8B;
  718. huart4.Init.StopBits = UART_STOPBITS_1;
  719. huart4.Init.Parity = UART_PARITY_NONE;
  720. huart4.Init.Mode = UART_MODE_TX_RX;
  721. huart4.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  722. huart4.Init.OverSampling = UART_OVERSAMPLING_16;
  723. huart4.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
  724. huart4.Init.ClockPrescaler = UART_PRESCALER_DIV1;
  725. huart4.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
  726. if (HAL_UART_Init(&huart4) != HAL_OK)
  727. {
  728. Error_Handler();
  729. }
  730. if (HAL_UARTEx_SetTxFifoThreshold(&huart4, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
  731. {
  732. Error_Handler();
  733. }
  734. if (HAL_UARTEx_SetRxFifoThreshold(&huart4, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
  735. {
  736. Error_Handler();
  737. }
  738. if (HAL_UARTEx_DisableFifoMode(&huart4) != HAL_OK)
  739. {
  740. Error_Handler();
  741. }
  742. /* USER CODE BEGIN UART4_Init 2 */
  743. /* USER CODE END UART4_Init 2 */
  744. }
  745. /**
  746. * @brief USART1 Initialization Function
  747. * @param None
  748. * @retval None
  749. */
  750. static void MX_USART1_UART_Init(void)
  751. {
  752. /* USER CODE BEGIN USART1_Init 0 */
  753. /* USER CODE END USART1_Init 0 */
  754. /* USER CODE BEGIN USART1_Init 1 */
  755. /* USER CODE END USART1_Init 1 */
  756. huart1.Instance = USART1;
  757. huart1.Init.BaudRate = 115200;
  758. huart1.Init.WordLength = UART_WORDLENGTH_8B;
  759. huart1.Init.StopBits = UART_STOPBITS_1;
  760. huart1.Init.Parity = UART_PARITY_NONE;
  761. huart1.Init.Mode = UART_MODE_TX_RX;
  762. huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  763. huart1.Init.OverSampling = UART_OVERSAMPLING_16;
  764. huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
  765. huart1.Init.ClockPrescaler = UART_PRESCALER_DIV1;
  766. huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
  767. if (HAL_UART_Init(&huart1) != HAL_OK)
  768. {
  769. Error_Handler();
  770. }
  771. if (HAL_UARTEx_SetTxFifoThreshold(&huart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
  772. {
  773. Error_Handler();
  774. }
  775. if (HAL_UARTEx_SetRxFifoThreshold(&huart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
  776. {
  777. Error_Handler();
  778. }
  779. if (HAL_UARTEx_DisableFifoMode(&huart1) != HAL_OK)
  780. {
  781. Error_Handler();
  782. }
  783. /* USER CODE BEGIN USART1_Init 2 */
  784. /* USER CODE END USART1_Init 2 */
  785. }
  786. /**
  787. * @brief USART2 Initialization Function
  788. * @param None
  789. * @retval None
  790. */
  791. static void MX_USART2_UART_Init(void)
  792. {
  793. /* USER CODE BEGIN USART2_Init 0 */
  794. /* USER CODE END USART2_Init 0 */
  795. /* USER CODE BEGIN USART2_Init 1 */
  796. /* USER CODE END USART2_Init 1 */
  797. huart2.Instance = USART2;
  798. huart2.Init.BaudRate = 115200;
  799. huart2.Init.WordLength = UART_WORDLENGTH_8B;
  800. huart2.Init.StopBits = UART_STOPBITS_1;
  801. huart2.Init.Parity = UART_PARITY_NONE;
  802. huart2.Init.Mode = UART_MODE_TX_RX;
  803. huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  804. huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  805. huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
  806. huart2.Init.ClockPrescaler = UART_PRESCALER_DIV1;
  807. huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
  808. if (HAL_UART_Init(&huart2) != HAL_OK)
  809. {
  810. Error_Handler();
  811. }
  812. if (HAL_UARTEx_SetTxFifoThreshold(&huart2, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
  813. {
  814. Error_Handler();
  815. }
  816. if (HAL_UARTEx_SetRxFifoThreshold(&huart2, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
  817. {
  818. Error_Handler();
  819. }
  820. if (HAL_UARTEx_DisableFifoMode(&huart2) != HAL_OK)
  821. {
  822. Error_Handler();
  823. }
  824. /* USER CODE BEGIN USART2_Init 2 */
  825. /* USER CODE END USART2_Init 2 */
  826. }
  827. /**
  828. * @brief USART3 Initialization Function
  829. * @param None
  830. * @retval None
  831. */
  832. static void MX_USART3_UART_Init(void)
  833. {
  834. /* USER CODE BEGIN USART3_Init 0 */
  835. /* USER CODE END USART3_Init 0 */
  836. /* USER CODE BEGIN USART3_Init 1 */
  837. /*
  838. * use below code if code is re-generated by .ioc modification
  839. #if CAM_CHANGE_BAUDRATE
  840. UART_HANDLER_CAM.Init.BaudRate = 38400;
  841. #else
  842. UART_HANDLER_CAM.Init.BaudRate = 115200;
  843. #endif
  844. */
  845. /* USER CODE END USART3_Init 1 */
  846. huart3.Instance = USART3;
  847. huart3.Init.BaudRate = 115200;
  848. huart3.Init.WordLength = UART_WORDLENGTH_8B;
  849. huart3.Init.StopBits = UART_STOPBITS_1;
  850. huart3.Init.Parity = UART_PARITY_NONE;
  851. huart3.Init.Mode = UART_MODE_TX_RX;
  852. huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  853. huart3.Init.OverSampling = UART_OVERSAMPLING_16;
  854. huart3.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
  855. huart3.Init.ClockPrescaler = UART_PRESCALER_DIV1;
  856. huart3.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
  857. if (HAL_UART_Init(&huart3) != HAL_OK)
  858. {
  859. Error_Handler();
  860. }
  861. if (HAL_UARTEx_SetTxFifoThreshold(&huart3, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
  862. {
  863. Error_Handler();
  864. }
  865. if (HAL_UARTEx_SetRxFifoThreshold(&huart3, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
  866. {
  867. Error_Handler();
  868. }
  869. if (HAL_UARTEx_DisableFifoMode(&huart3) != HAL_OK)
  870. {
  871. Error_Handler();
  872. }
  873. /* USER CODE BEGIN USART3_Init 2 */
  874. /* USER CODE END USART3_Init 2 */
  875. }
  876. /* FMC initialization function */
  877. static void MX_FMC_Init(void)
  878. {
  879. /* USER CODE BEGIN FMC_Init 0 */
  880. /* USER CODE END FMC_Init 0 */
  881. FMC_NORSRAM_TimingTypeDef Timing = {0};
  882. /* USER CODE BEGIN FMC_Init 1 */
  883. /* USER CODE END FMC_Init 1 */
  884. /** Perform the SRAM1 memory initialization sequence
  885. */
  886. hsram1.Instance = FMC_NORSRAM_DEVICE;
  887. hsram1.Extended = FMC_NORSRAM_EXTENDED_DEVICE;
  888. /* hsram1.Init */
  889. hsram1.Init.NSBank = FMC_NORSRAM_BANK1;
  890. hsram1.Init.DataAddressMux = FMC_DATA_ADDRESS_MUX_DISABLE;
  891. hsram1.Init.MemoryType = FMC_MEMORY_TYPE_SRAM;
  892. hsram1.Init.MemoryDataWidth = FMC_NORSRAM_MEM_BUS_WIDTH_16;
  893. hsram1.Init.BurstAccessMode = FMC_BURST_ACCESS_MODE_DISABLE;
  894. hsram1.Init.WaitSignalPolarity = FMC_WAIT_SIGNAL_POLARITY_LOW;
  895. hsram1.Init.WaitSignalActive = FMC_WAIT_TIMING_BEFORE_WS;
  896. hsram1.Init.WriteOperation = FMC_WRITE_OPERATION_ENABLE;
  897. hsram1.Init.WaitSignal = FMC_WAIT_SIGNAL_DISABLE;
  898. hsram1.Init.ExtendedMode = FMC_EXTENDED_MODE_DISABLE;
  899. hsram1.Init.AsynchronousWait = FMC_ASYNCHRONOUS_WAIT_DISABLE;
  900. hsram1.Init.WriteBurst = FMC_WRITE_BURST_DISABLE;
  901. hsram1.Init.ContinuousClock = FMC_CONTINUOUS_CLOCK_SYNC_ONLY;
  902. hsram1.Init.WriteFifo = FMC_WRITE_FIFO_ENABLE;
  903. hsram1.Init.NBLSetupTime = 0;
  904. hsram1.Init.PageSize = FMC_PAGE_SIZE_NONE;
  905. hsram1.Init.MaxChipSelectPulse = DISABLE;
  906. /* Timing */
  907. Timing.AddressSetupTime = 15;
  908. Timing.AddressHoldTime = 15;
  909. Timing.DataSetupTime = 30;
  910. Timing.DataHoldTime = 0;
  911. Timing.BusTurnAroundDuration = 2;
  912. Timing.CLKDivision = 16;
  913. Timing.DataLatency = 17;
  914. Timing.AccessMode = FMC_ACCESS_MODE_A;
  915. /* ExtTiming */
  916. if (HAL_SRAM_Init(&hsram1, &Timing, NULL) != HAL_OK)
  917. {
  918. Error_Handler( );
  919. }
  920. /** Perform the SRAM2 memory initialization sequence
  921. */
  922. hsram2.Instance = FMC_NORSRAM_DEVICE;
  923. hsram2.Extended = FMC_NORSRAM_EXTENDED_DEVICE;
  924. /* hsram2.Init */
  925. hsram2.Init.NSBank = FMC_NORSRAM_BANK2;
  926. hsram2.Init.DataAddressMux = FMC_DATA_ADDRESS_MUX_DISABLE;
  927. hsram2.Init.MemoryType = FMC_MEMORY_TYPE_SRAM;
  928. hsram2.Init.MemoryDataWidth = FMC_NORSRAM_MEM_BUS_WIDTH_16;
  929. hsram2.Init.BurstAccessMode = FMC_BURST_ACCESS_MODE_DISABLE;
  930. hsram2.Init.WaitSignalPolarity = FMC_WAIT_SIGNAL_POLARITY_LOW;
  931. hsram2.Init.WaitSignalActive = FMC_WAIT_TIMING_BEFORE_WS;
  932. hsram2.Init.WriteOperation = FMC_WRITE_OPERATION_ENABLE;
  933. hsram2.Init.WaitSignal = FMC_WAIT_SIGNAL_DISABLE;
  934. hsram2.Init.ExtendedMode = FMC_EXTENDED_MODE_DISABLE;
  935. hsram2.Init.AsynchronousWait = FMC_ASYNCHRONOUS_WAIT_DISABLE;
  936. hsram2.Init.WriteBurst = FMC_WRITE_BURST_DISABLE;
  937. hsram2.Init.ContinuousClock = FMC_CONTINUOUS_CLOCK_SYNC_ONLY;
  938. hsram2.Init.WriteFifo = FMC_WRITE_FIFO_ENABLE;
  939. hsram2.Init.NBLSetupTime = 0;
  940. hsram2.Init.PageSize = FMC_PAGE_SIZE_NONE;
  941. hsram2.Init.MaxChipSelectPulse = DISABLE;
  942. /* Timing */
  943. Timing.AddressSetupTime = 15;
  944. Timing.AddressHoldTime = 15;
  945. Timing.DataSetupTime = 30;
  946. Timing.DataHoldTime = 0;
  947. Timing.BusTurnAroundDuration = 2;
  948. Timing.CLKDivision = 16;
  949. Timing.DataLatency = 17;
  950. Timing.AccessMode = FMC_ACCESS_MODE_A;
  951. /* ExtTiming */
  952. if (HAL_SRAM_Init(&hsram2, &Timing, NULL) != HAL_OK)
  953. {
  954. Error_Handler( );
  955. }
  956. /** Perform the SRAM3 memory initialization sequence
  957. */
  958. hsram3.Instance = FMC_NORSRAM_DEVICE;
  959. hsram3.Extended = FMC_NORSRAM_EXTENDED_DEVICE;
  960. /* hsram3.Init */
  961. hsram3.Init.NSBank = FMC_NORSRAM_BANK3;
  962. hsram3.Init.DataAddressMux = FMC_DATA_ADDRESS_MUX_DISABLE;
  963. hsram3.Init.MemoryType = FMC_MEMORY_TYPE_PSRAM;
  964. hsram3.Init.MemoryDataWidth = FMC_NORSRAM_MEM_BUS_WIDTH_16;
  965. hsram3.Init.BurstAccessMode = FMC_BURST_ACCESS_MODE_DISABLE;
  966. hsram3.Init.WaitSignalPolarity = FMC_WAIT_SIGNAL_POLARITY_LOW;
  967. hsram3.Init.WaitSignalActive = FMC_WAIT_TIMING_BEFORE_WS;
  968. hsram3.Init.WriteOperation = FMC_WRITE_OPERATION_ENABLE;
  969. hsram3.Init.WaitSignal = FMC_WAIT_SIGNAL_DISABLE;
  970. hsram3.Init.ExtendedMode = FMC_EXTENDED_MODE_DISABLE;
  971. hsram3.Init.AsynchronousWait = FMC_ASYNCHRONOUS_WAIT_DISABLE;
  972. hsram3.Init.WriteBurst = FMC_WRITE_BURST_DISABLE;
  973. hsram3.Init.ContinuousClock = FMC_CONTINUOUS_CLOCK_SYNC_ONLY;
  974. hsram3.Init.WriteFifo = FMC_WRITE_FIFO_ENABLE;
  975. hsram3.Init.NBLSetupTime = 0;
  976. hsram3.Init.PageSize = FMC_PAGE_SIZE_NONE;
  977. hsram3.Init.MaxChipSelectPulse = DISABLE;
  978. /* Timing */
  979. Timing.AddressSetupTime = 15;
  980. Timing.AddressHoldTime = 15;
  981. Timing.DataSetupTime = 30;
  982. Timing.DataHoldTime = 0;
  983. Timing.BusTurnAroundDuration = 2;
  984. Timing.CLKDivision = 16;
  985. Timing.DataLatency = 17;
  986. Timing.AccessMode = FMC_ACCESS_MODE_A;
  987. /* ExtTiming */
  988. if (HAL_SRAM_Init(&hsram3, &Timing, NULL) != HAL_OK)
  989. {
  990. Error_Handler( );
  991. }
  992. /** Perform the SRAM4 memory initialization sequence
  993. */
  994. hsram4.Instance = FMC_NORSRAM_DEVICE;
  995. hsram4.Extended = FMC_NORSRAM_EXTENDED_DEVICE;
  996. /* hsram4.Init */
  997. hsram4.Init.NSBank = FMC_NORSRAM_BANK4;
  998. hsram4.Init.DataAddressMux = FMC_DATA_ADDRESS_MUX_DISABLE;
  999. hsram4.Init.MemoryType = FMC_MEMORY_TYPE_SRAM;
  1000. hsram4.Init.MemoryDataWidth = FMC_NORSRAM_MEM_BUS_WIDTH_16;
  1001. hsram4.Init.BurstAccessMode = FMC_BURST_ACCESS_MODE_DISABLE;
  1002. hsram4.Init.WaitSignalPolarity = FMC_WAIT_SIGNAL_POLARITY_LOW;
  1003. hsram4.Init.WaitSignalActive = FMC_WAIT_TIMING_BEFORE_WS;
  1004. hsram4.Init.WriteOperation = FMC_WRITE_OPERATION_DISABLE;
  1005. hsram4.Init.WaitSignal = FMC_WAIT_SIGNAL_DISABLE;
  1006. hsram4.Init.ExtendedMode = FMC_EXTENDED_MODE_DISABLE;
  1007. hsram4.Init.AsynchronousWait = FMC_ASYNCHRONOUS_WAIT_DISABLE;
  1008. hsram4.Init.WriteBurst = FMC_WRITE_BURST_DISABLE;
  1009. hsram4.Init.ContinuousClock = FMC_CONTINUOUS_CLOCK_SYNC_ONLY;
  1010. hsram4.Init.WriteFifo = FMC_WRITE_FIFO_ENABLE;
  1011. hsram4.Init.NBLSetupTime = 0;
  1012. hsram4.Init.PageSize = FMC_PAGE_SIZE_NONE;
  1013. hsram4.Init.MaxChipSelectPulse = DISABLE;
  1014. /* Timing */
  1015. Timing.AddressSetupTime = 15;
  1016. Timing.AddressHoldTime = 15;
  1017. Timing.DataSetupTime = 255;
  1018. Timing.DataHoldTime = 0;
  1019. Timing.BusTurnAroundDuration = 15;
  1020. Timing.CLKDivision = 16;
  1021. Timing.DataLatency = 17;
  1022. Timing.AccessMode = FMC_ACCESS_MODE_A;
  1023. /* ExtTiming */
  1024. if (HAL_SRAM_Init(&hsram4, &Timing, NULL) != HAL_OK)
  1025. {
  1026. Error_Handler( );
  1027. }
  1028. /* USER CODE BEGIN FMC_Init 2 */
  1029. /* USER CODE END FMC_Init 2 */
  1030. }
  1031. /**
  1032. * @brief GPIO Initialization Function
  1033. * @param None
  1034. * @retval None
  1035. */
  1036. static void MX_GPIO_Init(void)
  1037. {
  1038. GPIO_InitTypeDef GPIO_InitStruct = {0};
  1039. /* USER CODE BEGIN MX_GPIO_Init_1 */
  1040. /* USER CODE END MX_GPIO_Init_1 */
  1041. /* GPIO Ports Clock Enable */
  1042. __HAL_RCC_GPIOE_CLK_ENABLE();
  1043. __HAL_RCC_GPIOC_CLK_ENABLE();
  1044. __HAL_RCC_GPIOF_CLK_ENABLE();
  1045. __HAL_RCC_GPIOH_CLK_ENABLE();
  1046. __HAL_RCC_GPIOA_CLK_ENABLE();
  1047. __HAL_RCC_GPIOB_CLK_ENABLE();
  1048. __HAL_RCC_GPIOG_CLK_ENABLE();
  1049. __HAL_RCC_GPIOD_CLK_ENABLE();
  1050. HAL_PWREx_EnableVddIO2();
  1051. /*Configure GPIO pin Output Level */
  1052. HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13|GPIO_PIN_6|GPIO_PIN_7, GPIO_PIN_RESET);
  1053. /*Configure GPIO pin Output Level */
  1054. HAL_GPIO_WritePin(GPIOF, GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_11, GPIO_PIN_RESET);
  1055. /*Configure GPIO pin Output Level */
  1056. HAL_GPIO_WritePin(GPIOB, GPIO_PIN_2, GPIO_PIN_RESET);
  1057. /*Configure GPIO pin Output Level */
  1058. HAL_GPIO_WritePin(GPIOG, GPIO_PIN_6|GPIO_PIN_11|GPIO_PIN_15, GPIO_PIN_RESET);
  1059. /*Configure GPIO pin Output Level */
  1060. HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
  1061. /*Configure GPIO pin Output Level */
  1062. HAL_GPIO_WritePin(GPIOD, GPIO_PIN_3, GPIO_PIN_RESET);
  1063. /*Configure GPIO pins : PC13 PC6 */
  1064. GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_6;
  1065. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  1066. GPIO_InitStruct.Pull = GPIO_NOPULL;
  1067. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  1068. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  1069. /*Configure GPIO pins : PF6 PF7 PF11 */
  1070. GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_11;
  1071. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  1072. GPIO_InitStruct.Pull = GPIO_NOPULL;
  1073. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  1074. HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
  1075. /*Configure GPIO pins : PF8 PF9 PF10 */
  1076. GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10;
  1077. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  1078. GPIO_InitStruct.Pull = GPIO_NOPULL;
  1079. HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
  1080. /*Configure GPIO pin : PB2 */
  1081. GPIO_InitStruct.Pin = GPIO_PIN_2;
  1082. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  1083. GPIO_InitStruct.Pull = GPIO_NOPULL;
  1084. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  1085. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  1086. /*Configure GPIO pins : PG6 PG15 */
  1087. GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_15;
  1088. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  1089. GPIO_InitStruct.Pull = GPIO_NOPULL;
  1090. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  1091. HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
  1092. /*Configure GPIO pin : PC7 */
  1093. GPIO_InitStruct.Pin = GPIO_PIN_7;
  1094. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  1095. GPIO_InitStruct.Pull = GPIO_NOPULL;
  1096. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  1097. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  1098. /*Configure GPIO pin : PA8 */
  1099. GPIO_InitStruct.Pin = GPIO_PIN_8;
  1100. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  1101. GPIO_InitStruct.Pull = GPIO_NOPULL;
  1102. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  1103. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  1104. /*Configure GPIO pin : PD2 */
  1105. GPIO_InitStruct.Pin = GPIO_PIN_2;
  1106. GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  1107. GPIO_InitStruct.Pull = GPIO_NOPULL;
  1108. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  1109. GPIO_InitStruct.Alternate = GPIO_AF12_SDMMC1;
  1110. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  1111. /*Configure GPIO pin : PD3 */
  1112. GPIO_InitStruct.Pin = GPIO_PIN_3;
  1113. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  1114. GPIO_InitStruct.Pull = GPIO_NOPULL;
  1115. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  1116. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  1117. /*Configure GPIO pin : PG11 */
  1118. GPIO_InitStruct.Pin = GPIO_PIN_11;
  1119. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  1120. GPIO_InitStruct.Pull = GPIO_NOPULL;
  1121. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  1122. HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
  1123. /* USER CODE BEGIN MX_GPIO_Init_2 */
  1124. /* USER CODE END MX_GPIO_Init_2 */
  1125. }
  1126. /* USER CODE BEGIN 4 */
  1127. /* USER CODE END 4 */
  1128. /* USER CODE BEGIN Header_taskEPSRunner */
  1129. /**
  1130. * @brief Function implementing the taskEPS thread.
  1131. * @param argument: Not used
  1132. * @retval None
  1133. */
  1134. /* USER CODE END Header_taskEPSRunner */
  1135. void taskEPSRunner(void *argument)
  1136. {
  1137. /* USER CODE BEGIN 5 */
  1138. #if (EPS_CAP_VOLT_ADC)
  1139. int capacitor_voltage0 = 0;
  1140. //int capacitor_voltage1 = 0;
  1141. /* Infinite loop */
  1142. for(;;)
  1143. {
  1144. capacitor_voltage0 = measure_voltage(ADC_HANDLER_SBC, EPS_CAP_ID_SBC);
  1145. //capacitor_voltage1 = measure_voltage(ADC_HANDLER_CAM, EPS_CAP_ID_CAM);
  1146. //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);
  1147. if (capacitor_voltage0 < EPS_CAP_VOLT_LOW_THRESHOLD_SBC)
  1148. {
  1149. printf("[EPS] CAP#%d < %dmV (TODO JIT CHECKPOINT)\r\n", EPS_CAP_ID_SBC, EPS_CAP_VOLT_LOW_THRESHOLD_SBC);
  1150. // TODO: JIT CHECKPOINT
  1151. imc_sbc_power_off();
  1152. }
  1153. osDelay(DELAY_AFTER_WORK);
  1154. }
  1155. #endif
  1156. #if (EPS_CAP_VOLT_GPIO)
  1157. /* energy_level: 1~7, and SBC power off when the level is 1 */
  1158. uint8_t energy_level_prev = 8;
  1159. uint8_t energy_level_curr = 8;
  1160. /* Infinite loop */
  1161. for(;;)
  1162. {
  1163. energy_level_curr = imc_get_energy_level();
  1164. if (energy_level_curr != energy_level_prev)
  1165. {
  1166. printf("[EPS] E Level: %d\r\n",
  1167. energy_level_curr);
  1168. if (energy_level_curr <= EPS_SBC_OFF_LEVEL)
  1169. {
  1170. imc_sbc_power_off();
  1171. }
  1172. energy_level_prev = energy_level_curr;
  1173. }
  1174. osDelay(DELAY_AFTER_WORK);
  1175. }
  1176. #endif
  1177. /* USER CODE END 5 */
  1178. }
  1179. /* USER CODE BEGIN Header_taskSnapRunner */
  1180. /**
  1181. * @brief Function implementing the taskSnap thread.
  1182. * @param argument: Not used
  1183. * @retval None
  1184. */
  1185. uint32_t trial = 1;
  1186. extern uint16_t ilen;
  1187. /* USER CODE END Header_taskSnapRunner */
  1188. void taskSnapRunner(void *argument)
  1189. {
  1190. /* USER CODE BEGIN taskSnapRunner */
  1191. sc03mpd_ifx_t ifx = {
  1192. .context = (void*)&UART_HANDLER_CAM,
  1193. .sendif = hal_uart_ifx_send,
  1194. .recvif = hal_uart_ifx_recv,
  1195. };
  1196. uint8_t error_count = 0;
  1197. /* Infinite loop */
  1198. while (1)
  1199. {
  1200. printf ("\r\n\r\n\r\n#%ld\r\n\r\n", trial);
  1201. trial++;
  1202. // osSemaphoreWait(empty, osWaitForever);
  1203. #if EPS_CAP_VOLT_ADC
  1204. SC03MPD_ASSERT(imc_sc03mpd_cap_check (ADC_HANDLER_CAM), "[CAM] FAILED CAP volt", ERROR)
  1205. #endif
  1206. /*
  1207. * 2022. 11. 10. TEST for EPS-SBC-CAM; SBC controls CAM ON/OFF; KETI EPS does NOT wait 2.5s for CAM init.
  1208. */
  1209. imc_cam_power_on();
  1210. // (M33) moved from imc_sc03mpd_init
  1211. printf("[CAM] wait %dms for boot-up\r\n", DELAY_AFTER_POWERUP);
  1212. osDelay (DELAY_AFTER_POWERUP);
  1213. MX_USART3_UART_Init();
  1214. // (M33) moved from imc_sc03mpd_init
  1215. SC03MPD_ASSERT(imc_sc03mpd_init(&ifx), "[CAM] FAILED init", ERROR)
  1216. /* execute once when change CAM default baudrate */
  1217. #if CAM_CHANGE_BAUDRATE
  1218. sc03mpd_set_baud(&ifx, SC03MPD_BDR_115200, 1); // default: SC03MPD_BDR_38400
  1219. printf ("[CAM] OK change default baudrate");
  1220. while (1)
  1221. {
  1222. osDelay(1);
  1223. }
  1224. #endif
  1225. #if 0
  1226. /* image capture and download when GPIO pin 1 UP */
  1227. /* wait for GPIO pin 1 UP */
  1228. osEvent event = osMessageGet(queueSnapReqHandle, osWaitForever);
  1229. if (event.status != osEventMessage)
  1230. continue;
  1231. printf("[CAM] frame capture requested (%lu)\r\n", event.value.v);
  1232. #endif
  1233. /*
  1234. * 2022. 8. 25. fix logical seq. error under V0706 protocol; stop -> read length -> read data -> resume
  1235. * 2022. 8. 26. simply combine three functions; asked by kylee
  1236. */
  1237. SC03MPD_ASSERT(imc_sc03mpd_capture(&ifx), "[CAM] FAILED capture", ERROR)
  1238. /*
  1239. * 2022. 11. 10. TEST for EPS-SBC-CAM
  1240. */
  1241. imc_cam_power_off();
  1242. // error_count reset
  1243. error_count = 0;
  1244. /* DO SOMETHING */
  1245. #if 0
  1246. if (decodeMyImage((uint8_t*)IMG_RAM_ADDR, ilen, 0, 0, 0, NULL, 1) != DEC_ENON)
  1247. goto ERROR;
  1248. // osSemaphoreRelease(full);
  1249. #else
  1250. printf ("[SBC] wait %dms for DO SOMETHING\r\n", DELAY_DO_SOMETHING);
  1251. osDelay(DELAY_DO_SOMETHING);
  1252. #endif
  1253. continue;
  1254. ERROR:
  1255. /*
  1256. * 2022. 7. 20. failure --> UART stuck continuously; works only after HW reset
  1257. * 2022. 8. 25. add USART3 init. and reset fn.; download or capture failure --> normal
  1258. * 2022. 8. 25. after SC03MPD power off/on, works well after few failures
  1259. * 2022. 11. 11. start of this while loop, CAM init is called
  1260. * 2023. 10. 20. add error_count for handling successive errors
  1261. */
  1262. error_count++;
  1263. printf("[CAM] ERROR HANDLING; CAM OFF > %dms delay > CAM ON\r\n", DELAY_BEFORE_ERR_HANDLING);
  1264. imc_cam_power_off();
  1265. // osSemaphoreRelease(empty);
  1266. osDelay(DELAY_BEFORE_ERR_HANDLING); //imc_sbc_power_off();
  1267. // ERROR 3 times -> SBC reboot
  1268. if (error_count >= CAM_ERROR_COUNT_MAX) {
  1269. error_count = 0;
  1270. printf("[CAM] %d ERRORs continue and SBC OFF\r\n", CAM_ERROR_COUNT_MAX);
  1271. imc_sbc_power_off();
  1272. osDelay(DELAY_DO_SOMETHING);
  1273. }
  1274. continue;
  1275. }
  1276. #if 0
  1277. EXIT:
  1278. osDelay(1000);
  1279. osThreadTerminate(NULL);
  1280. #endif
  1281. /* USER CODE END taskSnapRunner */
  1282. }
  1283. /* USER CODE BEGIN Header_taskAIRunner */
  1284. /**
  1285. * @brief Function implementing the taskAI thread.
  1286. * @param argument: Not used
  1287. * @retval None
  1288. */
  1289. /* USER CODE END Header_taskAIRunner */
  1290. void taskAIRunner(void *argument)
  1291. {
  1292. /* USER CODE BEGIN taskAIRunner */
  1293. /* Infinite loop */
  1294. for(;;)
  1295. {
  1296. osDelay(DELAY_AFTER_WORK);
  1297. }
  1298. /* USER CODE END taskAIRunner */
  1299. }
  1300. /**
  1301. * @brief Period elapsed callback in non blocking mode
  1302. * @note This function is called when TIM2 interrupt took place, inside
  1303. * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
  1304. * a global variable "uwTick" used as application time base.
  1305. * @param htim : TIM handle
  1306. * @retval None
  1307. */
  1308. void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
  1309. {
  1310. /* USER CODE BEGIN Callback 0 */
  1311. /* USER CODE END Callback 0 */
  1312. if (htim->Instance == TIM2) {
  1313. HAL_IncTick();
  1314. }
  1315. /* USER CODE BEGIN Callback 1 */
  1316. /* USER CODE END Callback 1 */
  1317. }
  1318. /**
  1319. * @brief This function is executed in case of error occurrence.
  1320. * @retval None
  1321. */
  1322. void Error_Handler(void)
  1323. {
  1324. /* USER CODE BEGIN Error_Handler_Debug */
  1325. /* User can add his own implementation to report the HAL error return state */
  1326. __disable_irq();
  1327. while (1)
  1328. {
  1329. }
  1330. /* USER CODE END Error_Handler_Debug */
  1331. }
  1332. #ifdef USE_FULL_ASSERT
  1333. /**
  1334. * @brief Reports the name of the source file and the source line number
  1335. * where the assert_param error has occurred.
  1336. * @param file: pointer to the source file name
  1337. * @param line: assert_param error line source number
  1338. * @retval None
  1339. */
  1340. void assert_failed(uint8_t *file, uint32_t line)
  1341. {
  1342. /* USER CODE BEGIN 6 */
  1343. /* User can add his own implementation to report the file name and line number,
  1344. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  1345. /* USER CODE END 6 */
  1346. }
  1347. #endif /* USE_FULL_ASSERT */