main.c 45 KB

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