main.c 44 KB

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