main.c 45 KB

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