main.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  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, 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. I2C_HandleTypeDef hi2c3;
  56. TIM_HandleTypeDef htim6;
  57. UART_HandleTypeDef huart3;
  58. DMA_HandleTypeDef hdma_usart3_rx;
  59. DMA_HandleTypeDef hdma_usart3_tx;
  60. /* USER CODE BEGIN PV */
  61. /* USER CODE END PV */
  62. /* Private function prototypes -----------------------------------------------*/
  63. void SystemClock_Config(void);
  64. static void MX_GPIO_Init(void);
  65. static void MX_DMA_Init(void);
  66. static void MX_TIM6_Init(void);
  67. static void MX_I2C3_Init(void);
  68. static void MX_USART3_UART_Init(void);
  69. static void MX_NVIC_Init(void);
  70. /* USER CODE BEGIN PFP */
  71. void Atten_ButtonUnPressSet(bool set);
  72. bool Atten_ButtonUnPressGet(void);
  73. AttenButton_t Atten_ButtonPressGet(void);
  74. /* USER CODE END PFP */
  75. /* Private user code ---------------------------------------------------------*/
  76. /* USER CODE BEGIN 0 */
  77. uint8_t rx2_data[2];
  78. uint8_t ring_buf[buf_size];
  79. uint8_t count_in, count_out;
  80. uint32_t Timer10ms;
  81. uint8_t buf[buf_size] = {0,};
  82. volatile uint32_t UartTimerCnt = 0;
  83. volatile uint32_t LedTimerCnt = 0;
  84. volatile uint32_t ButtonLong_TimerCnt = 0;
  85. volatile uint32_t ButtonNext_TimerCnt = 0;
  86. volatile uint8_t chattering = 0,ButtonPressed = 0;
  87. uint8_t switchcnt[5] = {0,};
  88. uint8_t UartDataisReved;
  89. int _write (int file, uint8_t *ptr, uint16_t len)
  90. {
  91. HAL_UART_Transmit (&huart3, ptr, len, 10);
  92. return len;
  93. }
  94. uint8_t buttonChatteringset(uint8_t set){
  95. chattering = set;
  96. }
  97. uint8_t buttonChatteringget(uint8_t set){
  98. return chattering;
  99. }
  100. void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
  101. {
  102. uint8_t uartindex = 0;
  103. etError crccheck = 0;
  104. /* Prevent unused argument(s) compilation warning */
  105. if(htim->Instance == TIM6){
  106. UartTimerCnt++;
  107. LedTimerCnt++;
  108. if(Atten_ButtonUnPressGet() == true && Layer_Get() >= AChSetting_Change150M_Layer)
  109. ButtonLong_TimerCnt++;
  110. }
  111. /* NOTE : This function Should not be modified, when the callback is needed,
  112. the __HAL_TIM_PeriodElapsedCallback could be implemented in the user file
  113. */
  114. }
  115. void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
  116. {
  117. if(huart->Instance == USART3){
  118. ring_buf[count_in] = rx2_data[0];//(uint8_t)USART2->DR;
  119. if(ring_buf[count_in] == 0xEB)UartDataRecvSet(1);
  120. if(++count_in>=buf_size) count_in=0;
  121. HAL_UART_Receive_DMA(&huart3,&rx2_data,1);
  122. }
  123. #if 0 // PYJ.2019.08.30_BEGIN --
  124. if ((__HAL_UART_GET_FLAG(&huart3, UART_FLAG_RXNE) != RESET))
  125. {
  126. PutDataToUartQueue(&huart3, (uint8_t)(huart3.Instance->DR & (uint8_t)0x00FF));
  127. }
  128. __HAL_UART_CLEAR_PEFLAG(&huart3); /* clear event flag */
  129. return;
  130. #endif // PYJ.2019.08.30_END --
  131. }
  132. uint8_t button_press = 0;
  133. bool Unbutton_press = 0;
  134. void Atten_ButtonPressSet(AttenButton_t set){
  135. button_press = set;
  136. }
  137. AttenButton_t Atten_ButtonPressGet(void){
  138. return button_press;
  139. }
  140. void Atten_ButtonUnPressSet(bool set){
  141. Unbutton_press = set;
  142. }
  143. bool Atten_ButtonUnPressGet(void){
  144. return Unbutton_press;
  145. }
  146. __STATIC_INLINE void Pol_Delay_us(volatile uint32_t microseconds)
  147. {
  148. /* Go to number of cycles for system */
  149. microseconds *= (SystemCoreClock / 1000000);
  150. /* Delay till end */
  151. while (microseconds--);
  152. }
  153. void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
  154. {
  155. // HAL_Delay(100);
  156. // printf("%s : %d \r\n",__func__,__LINE__);
  157. if(GPIO_Pin == GPIO_PIN_8){
  158. if(Atten_ButtonUnPressGet() == false){
  159. // printf("Button_PRESS ESC \r\n",__func__,__LINE__);
  160. Atten_ButtonPressSet( Button_ESC);
  161. Atten_ButtonUnPressSet(true);
  162. }
  163. else{
  164. // printf("Button_UnPRESS ESC \r\n",__func__,__LINE__);
  165. ButtonLong_TimerCnt = 0;
  166. Atten_ButtonUnPressSet(false);
  167. return;
  168. }
  169. }
  170. if(GPIO_Pin == GPIO_PIN_12){
  171. if(Atten_ButtonUnPressGet() == false){
  172. // printf("Button_PRESS MENU \r\n",__func__,__LINE__);
  173. Atten_ButtonPressSet( Button_MENU);
  174. Atten_ButtonUnPressSet(true);
  175. }
  176. else{
  177. // printf("Button_UNPRESS MENU \r\n",__func__,__LINE__);
  178. ButtonLong_TimerCnt = 0;
  179. Atten_ButtonUnPressSet(false);
  180. return;
  181. }
  182. }
  183. if(GPIO_Pin == GPIO_PIN_13){
  184. if(Atten_ButtonUnPressGet() == false ){
  185. // printf("Button_UP UNPRESS \r\n",__func__,__LINE__);
  186. Atten_ButtonPressSet( Button_UP);
  187. Atten_ButtonUnPressSet(true);
  188. }
  189. else{
  190. if( HAL_GPIO_ReadPin(GPIOB, GPIO_Pin) == GPIO_PIN_SET){
  191. // printf("Button_UP PRESS \r\n",__func__,__LINE__);
  192. ButtonLong_TimerCnt = 0;
  193. Atten_ButtonUnPressSet(false);
  194. return;
  195. }
  196. }
  197. }
  198. if(GPIO_Pin == GPIO_PIN_14){
  199. if(Atten_ButtonUnPressGet() == false ){
  200. // printf("Button_DOWN UNPRESS \r\n",__func__,__LINE__);
  201. Atten_ButtonPressSet( Button_DOWN);
  202. Atten_ButtonUnPressSet(true);
  203. }
  204. else{
  205. if( HAL_GPIO_ReadPin(GPIOB, GPIO_Pin) == GPIO_PIN_SET){
  206. // printf("Button_DOWN PRESS \r\n",__func__,__LINE__);
  207. ButtonLong_TimerCnt = 0;
  208. Atten_ButtonUnPressSet(false);
  209. return;
  210. }
  211. }
  212. }
  213. if(GPIO_Pin == GPIO_PIN_15){
  214. if(Atten_ButtonUnPressGet() == false){
  215. // printf("Button_ENTER PRESS \r\n",__func__,__LINE__);
  216. Atten_ButtonPressSet( Button_ENTER);
  217. Atten_ButtonUnPressSet(true);
  218. }
  219. else{
  220. // printf("Button_ENTER UNPRESS \r\n",__func__,__LINE__);
  221. Atten_ButtonUnPressSet(false);
  222. ButtonLong_TimerCnt = 0;
  223. return;
  224. }
  225. }
  226. Pol_Delay_us(1000 *50);
  227. Character_Lcd_chMenu(Atten_ButtonPressGet());
  228. }
  229. void UartDataRecvSet(uint8_t val){
  230. UartDataisReved = val;
  231. }
  232. uint8_t UartDataRecvGet(void){
  233. return UartDataisReved;
  234. }
  235. volatile uint8_t uartindex = 0;
  236. /* USER CODE END 0 */
  237. /**
  238. * @brief The application entry point.
  239. * @retval int
  240. */
  241. int main(void)
  242. {
  243. /* USER CODE BEGIN 1 */
  244. //uint8_t writetemp[10] = {6,4,2,0,1,2,3,4,5,0xab};
  245. uint8_t tempdata[100] = {0,};
  246. Atten_Alarm_t Alarm_st;
  247. /* USER CODE END 1 */
  248. /* MCU Configuration--------------------------------------------------------*/
  249. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  250. HAL_Init();
  251. /* USER CODE BEGIN Init */
  252. /* USER CODE END Init */
  253. /* Configure the system clock */
  254. SystemClock_Config();
  255. /* USER CODE BEGIN SysInit */
  256. /* USER CODE END SysInit */
  257. /* Initialize all configured peripherals */
  258. MX_GPIO_Init();
  259. MX_DMA_Init();
  260. MX_TIM6_Init();
  261. MX_I2C3_Init();
  262. MX_USART3_UART_Init();
  263. /* Initialize interrupts */
  264. MX_NVIC_Init();
  265. /* USER CODE BEGIN 2 */
  266. HAL_TIM_Base_Start_IT(&htim6);
  267. HAL_UART_Receive_DMA(&huart3, &rx2_data,1);
  268. InitUartQueue(&TerminalQueue);
  269. setbuf(stdout, NULL); // \n ?��?��?��, printf �?????��?���???? ?��?��?��
  270. //
  271. // printf("PE43711_ATTEN_31_75DB_Trace : %02x \r\n",PE43711_ATTEN_31_75DB_Trace);
  272. // printf("PE43711_ATTEN_16DB_Trace : %02x \r\n",PE43711_ATTEN_16DB_Trace);
  273. // printf("PE43711_ATTEN_8DB_Trace : %02x \r\n",PE43711_ATTEN_8DB_Trace);
  274. // printf("PE43711_ATTEN_4DB_Trace : %02x \r\n",PE43711_ATTEN_4DB_Trace);
  275. // printf("PE43711_ATTEN_2DB_Trace : %02x \r\n",PE43711_ATTEN_2DB_Trace);
  276. // printf("PE43711_ATTEN_1DB_Trace : %02x \r\n",PE43711_ATTEN_1DB_Trace);
  277. /* USER CODE END 2 */
  278. /* Infinite loop */
  279. /* USER CODE BEGIN WHILE */
  280. #if 0 // PYJ.2019.03.04_BEGIN --
  281. printf("****************************************\r\n");
  282. printf("TEST Project\r\n");
  283. printf("Build at %s %s\r\n", __DATE__, __TIME__);
  284. printf("Copyright (c) 2019. BLUECELL\r\n");
  285. printf("****************************************\r\n");
  286. #endif // PYJ.2019.03.04_END --
  287. EEPROM_IM24CM01P_Init();
  288. LCD_M68_DataWrite_COMMAND_Init();
  289. Character_Lcd_chMenu(Power_On);
  290. memcpy(tempdata,&ATT_A_EN_30G1_28_28_5Ghz_Table.Atten_Table_31_5dB_Value,sizeof(Atten_Table_Value_t));
  291. Atten_Init();
  292. etError crccheck = 0;
  293. AttenButton_t Buttonpress = Button_NOP;
  294. while(1)
  295. {
  296. if(count_in != count_out){
  297. UartTimerCnt = 0;
  298. buf[uartindex++] = ring_buf[count_out];
  299. if(++count_out >= buf_size) count_out=0;
  300. }
  301. if((UartDataRecvGet() == 1 && UartTimerCnt > 100) || ButtonDataGet() == true){
  302. #if 0
  303. for(uint8_t i = 0; i < (uartindex); i++){
  304. // Uart_Data_Send(buf[i],1);
  305. printf("%02x ",buf[i]);
  306. }
  307. // printf("\r\n");
  308. #endif
  309. crccheck = STH30_CheckCrc(&buf[Bluecell_Type],buf[Bluecell_Length]+2,buf[3 + buf[Bluecell_Length]]);
  310. if(crccheck == CHECKSUM_ERROR){
  311. for(uint8_t i = 0; i < (uartindex); i++){
  312. printf("%02x ",buf[i]);
  313. }
  314. printf("\r\n");
  315. printf("CHECKSUM_ERROR RecvCRC : %02x , index %d\r\n",buf[3 + buf[Bluecell_Length]],5 + buf[Bluecell_Length]);
  316. }
  317. else if(crccheck == NO_ERROR){
  318. Atten_Operate_Mem_RW(&buf[Bluecell_STX]);
  319. LedTimerCnt = 0;
  320. }
  321. else{
  322. printf("What Happen?\r\n");
  323. /*NOP*/
  324. }
  325. memset(buf,0x00,buf_size);
  326. uartindex = 0;
  327. UartDataRecvSet(0);
  328. ButtonDataSet(false);
  329. }
  330. else{
  331. //Alarm Timer
  332. #if 0 // PYJ.2019.03.07_BEGIN --
  333. if(ButtonLong_TimerCnt > 500){
  334. Character_Lcd_chMenu(Atten_ButtonPressGet());
  335. ButtonLong_TimerCnt = 0;
  336. printf("ButtonLong_TimerCnt \r\n");
  337. }
  338. #endif // PYJ.2019.03.07_END --
  339. if(ButtonLong_TimerCnt > 500
  340. && (!HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_13)
  341. || !HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_14))){
  342. // printf("LONG KEY PRESS\r\n");
  343. Character_Lcd_chMenu(Atten_ButtonPressGet());
  344. ButtonLong_TimerCnt = 0;
  345. }
  346. if(LedTimerCnt > 500){
  347. Alarm_st = Atten_Alarm_Read();
  348. Alarm_Operate(Alarm_st);
  349. tempdata[Bluecell_STX] = 0xBE;
  350. tempdata[Bluecell_Type] = ATT_AB_ALARM_READ;
  351. tempdata[Bluecell_Length] = sizeof(Atten_Alarm_t) + 2;
  352. memcpy(&tempdata[Bluecell_DATA],&Alarm_st.Atten_Ach_Alarm_150M,sizeof(Atten_Alarm_t));
  353. tempdata[tempdata[Bluecell_Length] + 3] = STH30_CreateCrc(&tempdata[Bluecell_Type],tempdata[Bluecell_Length] + 2);
  354. tempdata[tempdata[Bluecell_Length] + 4] = 0xeb;
  355. Uart_Data_Send(&tempdata[Bluecell_STX],tempdata[Bluecell_Length]+5);
  356. HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_15);
  357. LedTimerCnt = 0;
  358. }
  359. }
  360. }
  361. // HAL_Delay(1);
  362. /* USER CODE END WHILE */
  363. /* USER CODE BEGIN 3 */
  364. /* USER CODE END 3 */
  365. }
  366. /**
  367. * @brief System Clock Configuration
  368. * @retval None
  369. */
  370. void SystemClock_Config(void)
  371. {
  372. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  373. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  374. /** Initializes the CPU, AHB and APB busses clocks
  375. */
  376. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  377. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  378. RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  379. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  380. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  381. RCC_OscInitStruct.PLL.PLLM = 13;
  382. RCC_OscInitStruct.PLL.PLLN = 195;
  383. RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  384. RCC_OscInitStruct.PLL.PLLQ = 4;
  385. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  386. {
  387. Error_Handler();
  388. }
  389. /** Initializes the CPU, AHB and APB busses clocks
  390. */
  391. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  392. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  393. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  394. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  395. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  396. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
  397. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK)
  398. {
  399. Error_Handler();
  400. }
  401. }
  402. /**
  403. * @brief NVIC Configuration.
  404. * @retval None
  405. */
  406. static void MX_NVIC_Init(void)
  407. {
  408. /* DMA1_Stream1_IRQn interrupt configuration */
  409. HAL_NVIC_SetPriority(DMA1_Stream1_IRQn, 0, 0);
  410. HAL_NVIC_EnableIRQ(DMA1_Stream1_IRQn);
  411. /* DMA1_Stream4_IRQn interrupt configuration */
  412. HAL_NVIC_SetPriority(DMA1_Stream4_IRQn, 0, 0);
  413. HAL_NVIC_EnableIRQ(DMA1_Stream4_IRQn);
  414. /* USART3_IRQn interrupt configuration */
  415. HAL_NVIC_SetPriority(USART3_IRQn, 0, 0);
  416. HAL_NVIC_EnableIRQ(USART3_IRQn);
  417. /* TIM6_DAC_IRQn interrupt configuration */
  418. HAL_NVIC_SetPriority(TIM6_DAC_IRQn, 0, 0);
  419. HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn);
  420. /* EXTI15_10_IRQn interrupt configuration */
  421. HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0);
  422. HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
  423. /* EXTI9_5_IRQn interrupt configuration */
  424. HAL_NVIC_SetPriority(EXTI9_5_IRQn, 0, 0);
  425. HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
  426. }
  427. /**
  428. * @brief I2C3 Initialization Function
  429. * @param None
  430. * @retval None
  431. */
  432. static void MX_I2C3_Init(void)
  433. {
  434. /* USER CODE BEGIN I2C3_Init 0 */
  435. /* USER CODE END I2C3_Init 0 */
  436. /* USER CODE BEGIN I2C3_Init 1 */
  437. /* USER CODE END I2C3_Init 1 */
  438. hi2c3.Instance = I2C3;
  439. hi2c3.Init.ClockSpeed = 400000;
  440. hi2c3.Init.DutyCycle = I2C_DUTYCYCLE_2;
  441. hi2c3.Init.OwnAddress1 = 0;
  442. hi2c3.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
  443. hi2c3.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
  444. hi2c3.Init.OwnAddress2 = 0;
  445. hi2c3.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
  446. hi2c3.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
  447. if (HAL_I2C_Init(&hi2c3) != HAL_OK)
  448. {
  449. Error_Handler();
  450. }
  451. /* USER CODE BEGIN I2C3_Init 2 */
  452. /* USER CODE END I2C3_Init 2 */
  453. }
  454. /**
  455. * @brief TIM6 Initialization Function
  456. * @param None
  457. * @retval None
  458. */
  459. static void MX_TIM6_Init(void)
  460. {
  461. /* USER CODE BEGIN TIM6_Init 0 */
  462. /* USER CODE END TIM6_Init 0 */
  463. TIM_MasterConfigTypeDef sMasterConfig = {0};
  464. /* USER CODE BEGIN TIM6_Init 1 */
  465. /* USER CODE END TIM6_Init 1 */
  466. htim6.Instance = TIM6;
  467. htim6.Init.Prescaler = 6000 -1;
  468. htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
  469. htim6.Init.Period = 10 - 1;
  470. htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  471. if (HAL_TIM_Base_Init(&htim6) != HAL_OK)
  472. {
  473. Error_Handler();
  474. }
  475. sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  476. sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  477. if (HAL_TIMEx_MasterConfigSynchronization(&htim6, &sMasterConfig) != HAL_OK)
  478. {
  479. Error_Handler();
  480. }
  481. /* USER CODE BEGIN TIM6_Init 2 */
  482. /* USER CODE END TIM6_Init 2 */
  483. }
  484. /**
  485. * @brief USART3 Initialization Function
  486. * @param None
  487. * @retval None
  488. */
  489. static void MX_USART3_UART_Init(void)
  490. {
  491. /* USER CODE BEGIN USART3_Init 0 */
  492. /* USER CODE END USART3_Init 0 */
  493. /* USER CODE BEGIN USART3_Init 1 */
  494. /* USER CODE END USART3_Init 1 */
  495. huart3.Instance = USART3;
  496. huart3.Init.BaudRate = 115200;
  497. huart3.Init.WordLength = UART_WORDLENGTH_8B;
  498. huart3.Init.StopBits = UART_STOPBITS_1;
  499. huart3.Init.Parity = UART_PARITY_NONE;
  500. huart3.Init.Mode = UART_MODE_TX_RX;
  501. huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  502. huart3.Init.OverSampling = UART_OVERSAMPLING_16;
  503. if (HAL_UART_Init(&huart3) != HAL_OK)
  504. {
  505. Error_Handler();
  506. }
  507. /* USER CODE BEGIN USART3_Init 2 */
  508. /* USER CODE END USART3_Init 2 */
  509. }
  510. /**
  511. * Enable DMA controller clock
  512. */
  513. static void MX_DMA_Init(void)
  514. {
  515. /* DMA controller clock enable */
  516. __HAL_RCC_DMA1_CLK_ENABLE();
  517. }
  518. /**
  519. * @brief GPIO Initialization Function
  520. * @param None
  521. * @retval None
  522. */
  523. static void MX_GPIO_Init(void)
  524. {
  525. GPIO_InitTypeDef GPIO_InitStruct = {0};
  526. /* GPIO Ports Clock Enable */
  527. __HAL_RCC_GPIOE_CLK_ENABLE();
  528. __HAL_RCC_GPIOC_CLK_ENABLE();
  529. __HAL_RCC_GPIOF_CLK_ENABLE();
  530. __HAL_RCC_GPIOH_CLK_ENABLE();
  531. __HAL_RCC_GPIOA_CLK_ENABLE();
  532. __HAL_RCC_GPIOB_CLK_ENABLE();
  533. __HAL_RCC_GPIOD_CLK_ENABLE();
  534. __HAL_RCC_GPIOG_CLK_ENABLE();
  535. /*Configure GPIO pin Output Level */
  536. HAL_GPIO_WritePin(GPIOE, GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5
  537. |GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11
  538. |GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_0, GPIO_PIN_RESET);
  539. /*Configure GPIO pin Output Level */
  540. HAL_GPIO_WritePin(GPIOC, GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_4|GPIO_PIN_5
  541. |GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12, GPIO_PIN_RESET);
  542. /*Configure GPIO pin Output Level */
  543. HAL_GPIO_WritePin(GPIOF, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_11
  544. |GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15, GPIO_PIN_RESET);
  545. /*Configure GPIO pin Output Level */
  546. HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7
  547. |GPIO_PIN_11, GPIO_PIN_RESET);
  548. /*Configure GPIO pin Output Level */
  549. HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7
  550. |GPIO_PIN_9, GPIO_PIN_RESET);
  551. /*Configure GPIO pin Output Level */
  552. HAL_GPIO_WritePin(GPIOD, GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14
  553. |GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2
  554. |GPIO_PIN_3|GPIO_PIN_6|GPIO_PIN_7, GPIO_PIN_RESET);
  555. /*Configure GPIO pin Output Level */
  556. HAL_GPIO_WritePin(GPIOG, GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5
  557. |GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_9|GPIO_PIN_11
  558. |GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14, GPIO_PIN_RESET);
  559. /*Configure GPIO pins : PE2 PE3 PE4 PE5
  560. PE8 PE9 PE10 PE11
  561. PE12 PE13 PE14 PE0 */
  562. GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5
  563. |GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11
  564. |GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_0;
  565. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  566. GPIO_InitStruct.Pull = GPIO_NOPULL;
  567. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  568. HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
  569. /*Configure GPIO pins : PC14 PC15 PC4 PC5
  570. PC10 PC11 PC12 */
  571. GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_4|GPIO_PIN_5
  572. |GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12;
  573. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  574. GPIO_InitStruct.Pull = GPIO_NOPULL;
  575. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  576. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  577. /*Configure GPIO pins : PF0 PF1 PF2 PF11
  578. PF13 PF14 PF15 */
  579. GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_11
  580. |GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
  581. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  582. GPIO_InitStruct.Pull = GPIO_NOPULL;
  583. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  584. HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
  585. /*Configure GPIO pins : PF6 PF7 PF8 */
  586. GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8;
  587. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  588. GPIO_InitStruct.Pull = GPIO_NOPULL;
  589. HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
  590. /*Configure GPIO pins : PC1 PC2 PC3 */
  591. GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3;
  592. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  593. GPIO_InitStruct.Pull = GPIO_NOPULL;
  594. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  595. /*Configure GPIO pins : PA4 PA5 PA6 PA7
  596. PA11 */
  597. GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7
  598. |GPIO_PIN_11;
  599. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  600. GPIO_InitStruct.Pull = GPIO_NOPULL;
  601. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  602. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  603. /*Configure GPIO pins : PB0 PB5 PB6 PB7
  604. PB9 */
  605. GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7
  606. |GPIO_PIN_9;
  607. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  608. GPIO_InitStruct.Pull = GPIO_NOPULL;
  609. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  610. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  611. /*Configure GPIO pins : PB12 PB13 PB14 PB15 */
  612. GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
  613. GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
  614. GPIO_InitStruct.Pull = GPIO_PULLUP;
  615. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  616. /*Configure GPIO pin : PD8 */
  617. GPIO_InitStruct.Pin = GPIO_PIN_8;
  618. GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
  619. GPIO_InitStruct.Pull = GPIO_PULLUP;
  620. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  621. /*Configure GPIO pins : PD11 PD12 PD13 PD14
  622. PD15 PD0 PD1 PD2
  623. PD3 PD6 PD7 */
  624. GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14
  625. |GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2
  626. |GPIO_PIN_3|GPIO_PIN_6|GPIO_PIN_7;
  627. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  628. GPIO_InitStruct.Pull = GPIO_NOPULL;
  629. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  630. HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  631. /*Configure GPIO pins : PG2 PG3 PG4 PG5
  632. PG6 PG7 PG9 PG11
  633. PG12 PG13 PG14 */
  634. GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5
  635. |GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_9|GPIO_PIN_11
  636. |GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14;
  637. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  638. GPIO_InitStruct.Pull = GPIO_NOPULL;
  639. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  640. HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
  641. }
  642. /* USER CODE BEGIN 4 */
  643. /* USER CODE END 4 */
  644. /**
  645. * @brief This function is executed in case of error occurrence.
  646. * @retval None
  647. */
  648. void Error_Handler(void)
  649. {
  650. /* USER CODE BEGIN Error_Handler_Debug */
  651. /* User can add his own implementation to report the HAL error return state */
  652. /* USER CODE END Error_Handler_Debug */
  653. }
  654. #ifdef USE_FULL_ASSERT
  655. /**
  656. * @brief Reports the name of the source file and the source line number
  657. * where the assert_param error has occurred.
  658. * @param file: pointer to the source file name
  659. * @param line: assert_param error line source number
  660. * @retval None
  661. */
  662. void assert_failed(uint8_t *file, uint32_t line)
  663. {
  664. /* USER CODE BEGIN 6 */
  665. /* User can add his own implementation to report the file name and line number,
  666. tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  667. /* USER CODE END 6 */
  668. }
  669. #endif /* USE_FULL_ASSERT */
  670. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/