main(4288).c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : main.c
  5. * @brief : Main program body
  6. ******************************************************************************
  7. ** This notice applies to any and all portions of this file
  8. * that are not between comment pairs USER CODE BEGIN and
  9. * USER CODE END. Other portions of this file, whether
  10. * inserted by the user or by software development tools
  11. * are owned by their respective copyright owners.
  12. *
  13. * COPYRIGHT(c) 2019 STMicroelectronics
  14. *
  15. * Redistribution and use in source and binary forms, with or without modification,
  16. * are permitted provided that the following conditions are met:
  17. * 1. Redistributions of source code must retain the above copyright notice,
  18. * this list of conditions and the following disclaimer.
  19. * 2. Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  23. * may be used to endorse or promote products derived from this software
  24. * without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  27. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,p THE
  28. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  29. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  30. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  32. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  33. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  34. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  35. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36. *
  37. ******************************************************************************
  38. */
  39. /* USER CODE END Header */
  40. /* Includes ------------------------------------------------------------------*/
  41. #include "main.h"
  42. /* Private includes ----------------------------------------------------------*/
  43. /* USER CODE BEGIN Includes */
  44. /* USER CODE END Includes */
  45. /* Private typedef -----------------------------------------------------------*/
  46. /* USER CODE BEGIN PTD */
  47. /* USER CODE END PTD */
  48. /* Private define ------------------------------------------------------------*/
  49. /* USER CODE BEGIN PD */
  50. /* USER CODE END PD */
  51. /* Private macro -------------------------------------------------------------*/
  52. /* USER CODE BEGIN PM */
  53. /* USER CODE END PM */
  54. /* Private variables ---------------------------------------------------------*/
  55. TIM_HandleTypeDef htim6;
  56. UART_HandleTypeDef huart3;
  57. /* USER CODE BEGIN PV */
  58. uint8_t ring_buffer[150];
  59. uint32_t ring_header = 0;
  60. uint32_t ring_tail = 0;
  61. uint8_t UartDataisReved;
  62. uint8_t RGB_SensorIDAutoset = 0;
  63. volatile uint32_t UartTimerCnt = 0;
  64. volatile uint32_t LedTimerCnt = 0;
  65. volatile uint8_t rx3_data[1] = {0,};
  66. uint8_t buf[buf_size] = {0,};
  67. uint8_t MyControllerID = 0;
  68. uint8_t SensorID = 1;
  69. #define FirmwareUpdataAck 0x11
  70. #define FirmwareUpdataNak 0x22
  71. typedef enum{
  72. bluecell_stx = 0,
  73. bluecell_type = 1,
  74. bluecell_length,
  75. bluecell_crc,
  76. bluecell_ext,
  77. };
  78. /* USER CODE END PV */
  79. /* Private function prototypes -----------------------------------------------*/
  80. void SystemClock_Config(void);
  81. static void MX_GPIO_Init(void);
  82. static void MX_TIM6_Init(void);
  83. static void MX_USART3_UART_Init(void);
  84. static void MX_NVIC_Init(void);
  85. /* USER CODE BEGIN PFP */
  86. void Uart1_Data_Send(uint8_t* data,uint8_t size);
  87. /* USER CODE END PFP */
  88. /* Private user code ---------------------------------------------------------*/
  89. /* USER CODE BEGIN 0 */
  90. void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
  91. {
  92. if(huart->Instance == USART3)//RGB Comunication
  93. {
  94. ring_buffer[ring_header] = rx3_data[0];
  95. if(++ring_header>=100){ ring_header = 0; }
  96. HAL_UART_Receive_IT(&huart3,&rx3_data[0],1);
  97. }
  98. }
  99. void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
  100. {
  101. if(htim->Instance == TIM6){
  102. UartTimerCnt++;
  103. LedTimerCnt++;
  104. }
  105. }
  106. void Uart3_Data_Send(uint8_t* data,uint8_t size){
  107. HAL_UART_Transmit(&huart3, data,size, 10);
  108. }
  109. int _write (int file, uint8_t *ptr, uint16_t len)
  110. {
  111. HAL_UART_Transmit (&huart3, ptr, len, 10);
  112. return len;
  113. }
  114. #define StartAddr ((uint32_t)0x08004000)
  115. #if 1 // PYJ.2019.03.19_BEGIN --
  116. //----------------------------------------------------
  117. #define FLASH_USER StartAddr
  118. #define START_ADDR FLASH_USER
  119. #define END_ADDR FLASH_USER + 262144 // 256K
  120. //----------------------------------------------------
  121. #if 0 // PYJ.2019.03.20_BEGIN --
  122. void test_write() // ?“°ê¸°í•¨?ˆ˜
  123. {
  124. __HAL_RCC_TIM7_CLK_DISABLE(); // 매ì�¸???�´ë¨¸ë?? ? •ì§??•©?‹ˆ?‹¤
  125. uint32_t Address = 0;
  126. Address = StartAddr;
  127. // printf("================First============ \r\n");
  128. // for(uint8_t i=0;i<16;i++)
  129. // {
  130. // printf("%08x: %X\r\n", Address, *(uint32_t*)Address);
  131. // Address += 4;
  132. // }
  133. // HAL_FLASH_Unlock(); // lock ??�
  134. // HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, START_ADDR, (uint32_t)0x12345678); //test
  135. // HAL_FLASH_Lock(); // lock ?ž ê·¸ê¸°
  136. // __HAL_RCC_TIM7_CLK_ENABLE(); // 매ì�¸???�´ë¨¸ë?? ?ž¬?‹œ?ž‘?•©?‹ˆ?‹¤
  137. Address = StartAddr;
  138. printf("================Second============ \r\n");
  139. //while(Address < 0x0803FFFF)
  140. for(uint16_t i = 0; i<37273 ; i++)
  141. {
  142. printf("%02X", *(uint8_t*)Address);
  143. Address ++;
  144. }
  145. printf("%08x:",Address);
  146. }
  147. #endif // PYJ.2019.03.20_END --
  148. #define DATA_16_1 ((uint32_t)0x1234)
  149. #define DATA_16_2 ((uint32_t)0x5678)
  150. #if 1 // PYJ.2019.03.20_BEGIN --
  151. void test_read(void) // ?“°ê¸°í•¨?ˆ˜
  152. {
  153. uint32_t Address = 0x08000000;
  154. uint8_t aa = 0;
  155. for(uint32_t i = Address; i <= Address + 0x35d8; i++ ){
  156. printf("%02X ",*(uint8_t*)i);
  157. aa++;
  158. if(aa > 15){
  159. printf("\n");
  160. aa= 0;
  161. }
  162. }
  163. }
  164. #endif // PYJ.2019.03.20_END --
  165. #define ADDR_FLASH_PAGE_TEST StartAddr /* Base @ of Page 127, 1 Kbytes */
  166. #define FLASH_USER_START_ADDR ADDR_FLASH_PAGE_TEST /* Start @ of user Flash area */
  167. #define FLASH_USER_END_ADDR ADDR_FLASH_PAGE_TEST + ((uint32_t)0x000FFFF) /* End @ of user Flash area */
  168. uint32_t Address = StartAddr;
  169. uint8_t Flash_RGB_Data_Write(uint8_t* data){
  170. uint16_t Firmdata = 0;
  171. uint8_t ret = 0;
  172. // printf("%s\n",__func__);
  173. //
  174. for(uint8_t i = 0; i < data[bluecell_length] - 2; i+=2){
  175. Firmdata = (data[(bluecell_length + 1) + i] << 8);
  176. Firmdata += (data[(bluecell_length + 1) + (i + 1)]);
  177. // printf("i : %d ( %04x )\n",i,Firmdata);
  178. if(HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD,Address , (uint16_t)Firmdata) != HAL_OK){
  179. printf("HAL NOT OK \n");
  180. ret = 1;
  181. }
  182. Address += 2;
  183. HAL_Delay(5);
  184. }
  185. return ret;
  186. }
  187. uint8_t flashinit = 0;
  188. uint8_t Flash_write(uint8_t* data) // ?“°ê¸°í•¨?ˆ˜
  189. {
  190. /*Variable used for Erase procedure*/
  191. static FLASH_EraseInitTypeDef EraseInitStruct;
  192. static uint32_t PAGEError = 0;
  193. uint8_t ret = 0;
  194. /* Fill EraseInit structure*/
  195. EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;
  196. EraseInitStruct.PageAddress = FLASH_USER_START_ADDR;
  197. EraseInitStruct.NbPages = (FLASH_USER_END_ADDR - FLASH_USER_START_ADDR) / FLASH_PAGE_SIZE;
  198. __HAL_RCC_TIM6_CLK_DISABLE(); // 매ì�¸???�´ë¨¸ë?? ? •ì§??•©?‹ˆ?‹¤
  199. HAL_FLASH_Unlock(); // lock ??�
  200. if(flashinit == 0){
  201. flashinit= 1;
  202. //FLASH_PageErase(StartAddr);
  203. if (HAL_FLASHEx_Erase(&EraseInitStruct, &PAGEError) != HAL_OK){
  204. printf("Erase Failed \r\n");
  205. }else{
  206. // printf("Erase Success \r\n");
  207. }
  208. }
  209. // FLASH_If_Erase();
  210. ret = Flash_RGB_Data_Write(&data[blucell_stx]);
  211. HAL_FLASH_Lock(); // lock ?ž ê·¸ê¸°
  212. __HAL_RCC_TIM6_CLK_ENABLE(); // 매ì�¸???�´ë¨¸ë?? ?ž¬?‹œ?ž‘?•©?‹ˆ?‹¤
  213. return ret;
  214. }
  215. void flash_testwrite(void){
  216. static FLASH_EraseInitTypeDef EraseInitStruct;
  217. static uint32_t PAGEError = 0;
  218. uint8_t ret = 0;
  219. uint16_t data[2] = {0x1234,0x5678};
  220. /* Fill EraseInit structure*/
  221. EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;
  222. EraseInitStruct.PageAddress = FLASH_USER_START_ADDR;
  223. EraseInitStruct.NbPages = (FLASH_USER_END_ADDR - FLASH_USER_START_ADDR) / FLASH_PAGE_SIZE;
  224. __HAL_RCC_TIM6_CLK_DISABLE(); // 매ì�¸???�´ë¨¸ë?? ? •ì§??•©?‹ˆ?‹¤
  225. HAL_FLASH_Unlock(); // lock ??�
  226. if (HAL_FLASHEx_Erase(&EraseInitStruct, &PAGEError) != HAL_OK){
  227. printf("Erase Failed \r\n");
  228. }else{
  229. printf("Erase Success \r\n");
  230. }
  231. for(uint8_t i = 0; i < 2 ; i++){
  232. if(HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD,Address , (uint16_t)data[i]) != HAL_OK){
  233. printf("Write .... .......... \n");
  234. ret = 1;
  235. }else{
  236. printf("Write HAL OK \n");
  237. }
  238. Address += 2;
  239. }
  240. HAL_FLASH_Lock(); // lock ?ž ê·¸ê¸°
  241. __HAL_RCC_TIM6_CLK_ENABLE(); // 매ì�¸???�´ë¨¸ë?? ?ž¬?‹œ?ž‘?•©?‹ˆ?‹¤
  242. }
  243. void Flash_InitRead(void) // ?“°ê¸°í•¨?ˆ˜
  244. {
  245. uint32_t Address = 0;
  246. Address = StartAddr;
  247. for(uint8_t i = 1; i <= 8; i++ ){
  248. printf("%08x : %04X \n",Address ,*(uint16_t*)Address);
  249. Address += 2;
  250. printf("%08x : %04X \n",Address ,*(uint16_t*)Address);
  251. Address += 2;
  252. printf("%08x : %04X \n",Address ,*(uint16_t*)Address);
  253. Address += 2;
  254. }
  255. }
  256. void FirmwareUpdateStart(uint8_t* data){
  257. uint8_t ret = 0,crccheck = 0;
  258. uint8_t tempdata[5] = {0xbe,FirmwareUpdataAck,0x02,0,0xbe};
  259. crccheck = STH30_CheckCrc(&data[blucell_type],data[blucell_length],data[data[blucell_length] + 1]);
  260. if(crccheck == NO_ERROR){
  261. tempdata[bluecell_type] = FirmwareUpdataAck;
  262. if(data[bluecell_type] != 0xaa)
  263. ret = Flash_write(&data[0]);
  264. if(ret == 1)
  265. tempdata[bluecell_type] = FirmwareUpdataNak;
  266. HAL_Delay(5);
  267. }else{
  268. for(uint8_t i = 0; i < data[bluecell_length] + 3; i++)
  269. printf("%02x ",data[i]);
  270. printf("Check Sum error \n");
  271. tempdata[bluecell_type] = FirmwareUpdataNak;
  272. }
  273. tempdata[bluecell_crc] = STH30_CreateCrc(&tempdata[blucell_type],tempdata[blucell_length]);
  274. if(tempdata[bluecell_type] != 0xEE){
  275. Uart3_Data_Send(&tempdata[bluecell_stx],tempdata[bluecell_length] + 3);
  276. }
  277. }
  278. #endif // PYJ.2019.03.19_END --
  279. typedef void (*pFunction)(void);
  280. pFunction JumpToApplication;
  281. uint32_t JumpAddress;
  282. uint32_t FlashProtection = 0;
  283. #define APPLICATION_ADDRESS (uint32_t)0x08004000 /* Start user code address: ADDR_FLASH_PAGE_8 */
  284. /* USER CODE END 0 */
  285. /**
  286. * @brief The application entry point.
  287. * @retval int
  288. */
  289. int main(void)
  290. {
  291. /* USER CODE BEGIN 1 */
  292. uint8_t data[100] = {0,};
  293. uint8_t cnt = 0;
  294. uint8_t uartrecv = 0;
  295. /* USER CODE END 1 */
  296. /* MCU Configuration--------------------------------------------------------*/
  297. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  298. HAL_Init();
  299. /* USER CODE BEGIN Init */
  300. /* USER CODE END Init */
  301. /* Configure the system clock */
  302. SystemClock_Config();
  303. /* USER CODE BEGIN SysInit */
  304. /* USER CODE END SysInit */
  305. /* Initialize all configured peripherals */
  306. MX_GPIO_Init();
  307. MX_TIM6_Init();
  308. MX_USART3_UART_Init();
  309. /* Initialize interrupts */
  310. MX_NVIC_Init();
  311. /* USER CODE BEGIN 2 */
  312. HAL_TIM_Base_Start_IT(&htim6);
  313. HAL_UART_Receive_IT(&huart3, &rx3_data[0],1);
  314. setbuf(stdout, NULL); // \n ?��?��?��, printf �??????��?���????? ?��?��?��
  315. #if 1 // PYJ.2019.03.04_BEGIN --
  316. printf("****************************************\r\n");
  317. printf("RGB Project\r\n");
  318. printf("Build at %s %s\r\n", __DATE__, __TIME__);
  319. printf("Copyright (c) 2019. BLUECELL\r\n");
  320. printf("****************************************\r\n");
  321. #endif // PYJ.2019.03.04_END --
  322. // RGB_Sensor_PowerOnOff(0);
  323. FLASH_If_Init();
  324. Flash_InitRead();
  325. // flash_testwrite();
  326. // Flash_InitRead();
  327. /* USER CODE END 2 */
  328. /* Infinite loop */
  329. /* USER CODE BEGIN WHILE */
  330. while (1)
  331. {
  332. if(ring_tail != ring_header){ // <-------
  333. data[cnt++] = ring_buffer[ring_tail++];
  334. if(ring_tail >= 100){ ring_tail = 0; }
  335. UartTimerCnt = 0;
  336. uartrecv = 1;
  337. }
  338. if(uartrecv == 1 && UartTimerCnt > 100){
  339. // for(uint8_t i = 0; i < data[bluecell_length] + 3; i++)
  340. // printf("%02x ",data[i]);
  341. FirmwareUpdateStart(&data[0]);
  342. memset(&data[0],0,100);
  343. cnt = 0;
  344. uartrecv = 0;
  345. }
  346. if(LedTimerCnt > 500){
  347. HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_15);
  348. LedTimerCnt = 0;
  349. }
  350. /* Test if user code is programmed starting from address "APPLICATION_ADDRESS" */
  351. // if (((*(__IO uint32_t*)APPLICATION_ADDRESS) & 0x2FFE0000 ) == 0x20000000)
  352. {
  353. /* Jump to user application */
  354. JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4);
  355. JumpToApplication = (pFunction) JumpAddress;
  356. /* Initialize user application's Stack Pointer */
  357. __set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS);
  358. JumpToApplication();
  359. }
  360. /* USER CODE END WHILE */
  361. /* USER CODE BEGIN 3 */
  362. }
  363. /* USER CODE END 3 */
  364. }
  365. /**
  366. * @brief System Clock Configuration
  367. * @retval None
  368. */
  369. void SystemClock_Config(void)
  370. {
  371. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  372. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  373. /**Initializes the CPU, AHB and APB busses clocks
  374. */
  375. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  376. RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  377. RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
  378. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  379. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  380. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  381. RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL2;
  382. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  383. {
  384. Error_Handler();
  385. }
  386. /**Initializes the CPU, AHB and APB busses clocks
  387. */
  388. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  389. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  390. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  391. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  392. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  393. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  394. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
  395. {
  396. Error_Handler();
  397. }
  398. }
  399. /**
  400. * @brief NVIC Configuration.
  401. * @retval None
  402. */
  403. static void MX_NVIC_Init(void)
  404. {
  405. /* TIM6_IRQn interrupt configuration */
  406. HAL_NVIC_SetPriority(TIM6_IRQn, 0, 0);
  407. HAL_NVIC_EnableIRQ(TIM6_IRQn);
  408. /* USART3_IRQn interrupt configuration */
  409. HAL_NVIC_SetPriority(USART3_IRQn, 0, 0);
  410. HAL_NVIC_EnableIRQ(USART3_IRQn);
  411. }
  412. /**
  413. * @brief TIM6 Initialization Function
  414. * @param None
  415. * @retval None
  416. */
  417. static void MX_TIM6_Init(void)
  418. {
  419. /* USER CODE BEGIN TIM6_Init 0 */
  420. /* USER CODE END TIM6_Init 0 */
  421. TIM_MasterConfigTypeDef sMasterConfig = {0};
  422. /* USER CODE BEGIN TIM6_Init 1 */
  423. /* USER CODE END TIM6_Init 1 */
  424. htim6.Instance = TIM6;
  425. htim6.Init.Prescaler = 1600-1;
  426. htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
  427. htim6.Init.Period = 10-1;
  428. htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  429. if (HAL_TIM_Base_Init(&htim6) != HAL_OK)
  430. {
  431. Error_Handler();
  432. }
  433. sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  434. sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  435. if (HAL_TIMEx_MasterConfigSynchronization(&htim6, &sMasterConfig) != HAL_OK)
  436. {
  437. Error_Handler();
  438. }
  439. /* USER CODE BEGIN TIM6_Init 2 */
  440. /* USER CODE END TIM6_Init 2 */
  441. }
  442. /**
  443. * @brief USART3 Initialization Function
  444. * @param None
  445. * @retval None
  446. */
  447. static void MX_USART3_UART_Init(void)
  448. {
  449. /* USER CODE BEGIN USART3_Init 0 */
  450. /* USER CODE END USART3_Init 0 */
  451. /* USER CODE BEGIN USART3_Init 1 */
  452. /* USER CODE END USART3_Init 1 */
  453. huart3.Instance = USART3;
  454. huart3.Init.BaudRate = 115200;
  455. huart3.Init.WordLength = UART_WORDLENGTH_8B;
  456. huart3.Init.StopBits = UART_STOPBITS_1;
  457. huart3.Init.Parity = UART_PARITY_NONE;
  458. huart3.Init.Mode = UART_MODE_TX_RX;
  459. huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  460. huart3.Init.OverSampling = UART_OVERSAMPLING_16;
  461. if (HAL_UART_Init(&huart3) != HAL_OK)
  462. {
  463. Error_Handler();
  464. }
  465. /* USER CODE BEGIN USART3_Init 2 */
  466. /* USER CODE END USART3_Init 2 */
  467. }
  468. /**
  469. * @brief GPIO Initialization Function
  470. * @param None
  471. * @retval None
  472. */
  473. static void MX_GPIO_Init(void)
  474. {
  475. GPIO_InitTypeDef GPIO_InitStruct = {0};
  476. /* GPIO Ports Clock Enable */
  477. __HAL_RCC_GPIOC_CLK_ENABLE();
  478. __HAL_RCC_GPIOD_CLK_ENABLE();
  479. __HAL_RCC_GPIOB_CLK_ENABLE();
  480. /*Configure GPIO pin Output Level */
  481. HAL_GPIO_WritePin(GPIOC, GPIO_PIN_15, GPIO_PIN_RESET);
  482. /*Configure GPIO pin : PC15 */
  483. GPIO_InitStruct.Pin = GPIO_PIN_15;
  484. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  485. GPIO_InitStruct.Pull = GPIO_NOPULL;
  486. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  487. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  488. }
  489. /* USER CODE BEGIN 4 */
  490. /* USER CODE END 4 */
  491. /**
  492. * @brief This function is executed in case of error occurrence.
  493. * @retval None
  494. */
  495. void Error_Handler(void)
  496. {
  497. /* USER CODE BEGIN Error_Handler_Debug */
  498. /* User can add his own implementation to report the HAL error return state */
  499. /* USER CODE END Error_Handler_Debug */
  500. }
  501. #ifdef USE_FULL_ASSERT
  502. /**
  503. * @brief Reports the name of the source file and the source line number
  504. * where the assert_param error has occurred.
  505. * @param file: pointer to the source file name
  506. * @param line: assert_param error line source number
  507. * @retval None
  508. */
  509. void assert_failed(uint8_t *file, uint32_t line)
  510. {
  511. /* USER CODE BEGIN 6 */
  512. /* User can add his own implementation to report the file name and line number,
  513. tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  514. /* USER CODE END 6 */
  515. }
  516. #endif /* USE_FULL_ASSERT */
  517. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/