main.c 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : main.c
  5. * @brief : Main program body
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* USER CODE END Header */
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "main.h"
  22. /* Private includes ----------------------------------------------------------*/
  23. /* USER CODE BEGIN Includes */
  24. /* USER CODE END Includes */
  25. /* Private typedef -----------------------------------------------------------*/
  26. /* USER CODE BEGIN PTD */
  27. typedef enum {
  28. Tube_A = 3,
  29. Tube_B = 2,
  30. Tube_D = 1,
  31. Tube_E = 0
  32. } tube_pos_t;
  33. /* USER CODE END PTD */
  34. /* Private define ------------------------------------------------------------*/
  35. /* USER CODE BEGIN PD */
  36. #define SPI_BUFFER_SIZE 5
  37. /* Display timeout, sec */
  38. #define DISP_WDT_TIME 10
  39. /* USER CODE END PD */
  40. /* Private macro -------------------------------------------------------------*/
  41. /* USER CODE BEGIN PM */
  42. /* USER CODE END PM */
  43. /* Private variables ---------------------------------------------------------*/
  44. /* USER CODE BEGIN PV */
  45. static LL_RCC_ClocksTypeDef rcc_clocks;
  46. /**
  47. * Nixi Tube cathodes map in Byte Array:
  48. * {E0 E9 E8 E7 E6 E5 E4 E3}
  49. * {E2 E1 D0 D9 D8 D7 D6 D5}
  50. * {D4 D3 D2 D1 B0 B9 B8 B7}
  51. * {B6 B5 B4 B3 B2 B1 A0 A9}
  52. * {A8 A7 A6 A5 A4 A3 A2 A1}
  53. *
  54. * Shift register bit map in Tube cathodes (from 0 to 1):
  55. * {5.7 5.6 5.5 5.4 5.3 5.2 5.1 5.0 4.7 4.6} VL5/E
  56. * {4.5 4.4 4.3 4.2 4.1 4.0 3.7 3.6 3.5 3.4} VL4/D
  57. * {3.3 3.2 3.1 3.0 2.7 2.6 2.5 2.4 2.3 2.2} VL2/B
  58. * {2.1 2.0 1.7 1.6 1.5 1.4 1.3 1.2 1.1 1.0} VL1/A
  59. */
  60. static const uint16_t nixieCathodeMap[4][10] = {
  61. {0x8000, 0x0040, 0x0080, 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000},
  62. {0x2000, 0x0010, 0x0020, 0x0040, 0x0080, 0x0100, 0x0200, 0x0400, 0x0800, 0x1000},
  63. {0x0800, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, 0x0100, 0x0200, 0x0400},
  64. {0x0200, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, 0x0100}
  65. };
  66. static const uint8_t nixieCathodeMask[4][2] = {{0x00, 0x3f}, {0xc0, 0x0f}, {0xf0, 0x03}, {0xc0, 0x00}};
  67. static uint8_t tubesBuffer[SPI_BUFFER_SIZE] = {0};
  68. static rtc_t Clock;
  69. static struct bme280_dev SensorDev;
  70. static struct bme280_data SensorData;
  71. static int8_t Humidity, Temperature;
  72. static nt16_t Pressure;
  73. static btn_t Button[BTN_NUM] = {
  74. {0, evBTN1Pressed, evBTN1Holded, BTN1_PIN},
  75. {0, evBTN2Pressed, evBTN2Pressed, BTN2_PIN},
  76. {0, evBTN3Pressed, evBTN3Pressed, BTN3_PIN},
  77. {0, evBTN4Pressed, evBTN4Holded, BTN4_PIN}
  78. };
  79. static volatile uint8_t dispWDT = 0;
  80. /* USER CODE END PV */
  81. /* Private function prototypes -----------------------------------------------*/
  82. void SystemClock_Config(void);
  83. static void MX_GPIO_Init(void);
  84. static void MX_DMA_Init(void);
  85. static void MX_I2C1_Init(void);
  86. static void MX_SPI1_Init(void);
  87. static void MX_TIM3_Init(void);
  88. static void MX_TIM14_Init(void);
  89. static void MX_TIM16_Init(void);
  90. static void MX_TIM17_Init(void);
  91. static void MX_USART1_UART_Init(void);
  92. /* USER CODE BEGIN PFP */
  93. static void showDigit(tube_pos_t pos, uint8_t dig);
  94. static void tubes_Refresh(void);
  95. int8_t user_i2c_read(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len);
  96. int8_t user_i2c_write(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len);
  97. int8_t i2c_check_err(void);
  98. static void sensorStartMeasure(void);
  99. static void sensorGetData(void);
  100. static void btnProcess(void);
  101. /* USER CODE END PFP */
  102. /* Private user code ---------------------------------------------------------*/
  103. /* USER CODE BEGIN 0 */
  104. /* USER CODE END 0 */
  105. /**
  106. * @brief The application entry point.
  107. * @retval int
  108. */
  109. int main(void)
  110. {
  111. /* USER CODE BEGIN 1 */
  112. /* USER CODE END 1 */
  113. /* MCU Configuration--------------------------------------------------------*/
  114. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  115. LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SYSCFG);
  116. LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR);
  117. /* System interrupt init*/
  118. /* Peripheral interrupt init*/
  119. /* RCC_IRQn interrupt configuration */
  120. NVIC_SetPriority(RCC_IRQn, 0);
  121. NVIC_EnableIRQ(RCC_IRQn);
  122. /* USER CODE BEGIN Init */
  123. /* USER CODE END Init */
  124. /* Configure the system clock */
  125. SystemClock_Config();
  126. /* USER CODE BEGIN SysInit */
  127. LL_LPM_EnableSleep();
  128. LL_LPM_DisableSleepOnExit();
  129. LL_RCC_GetSystemClocksFreq(&rcc_clocks);
  130. /* USER CODE END SysInit */
  131. /* Initialize all configured peripherals */
  132. MX_GPIO_Init();
  133. MX_DMA_Init();
  134. MX_I2C1_Init();
  135. MX_SPI1_Init();
  136. MX_TIM3_Init();
  137. MX_TIM14_Init();
  138. MX_TIM16_Init();
  139. MX_TIM17_Init();
  140. MX_USART1_UART_Init();
  141. /* USER CODE BEGIN 2 */
  142. RTOS_Init();
  143. /* Initialize Event State Machine */
  144. ES_Init(stShowTime);
  145. /* Start RGB PWM */
  146. LL_TIM_CC_EnableChannel(TIM3, LL_TIM_CHANNEL_CH1);
  147. LL_TIM_CC_EnableChannel(TIM3, LL_TIM_CHANNEL_CH2);
  148. LL_TIM_CC_EnableChannel(TIM3, LL_TIM_CHANNEL_CH3);
  149. LL_TIM_EnableCounter(TIM3);
  150. /* Start Tube PWR PWM */
  151. LL_TIM_CC_EnableChannel(TIM14, LL_TIM_CHANNEL_CH1);
  152. LL_TIM_EnableCounter(TIM14);
  153. /* Enable tube power */
  154. TUBE_PWR_ON;
  155. /* Set DMA source and destination addresses. */
  156. /* Source: Address of the SPI buffer. */
  157. DMA1_Channel1->CMAR = (uint32_t)&tubesBuffer;
  158. /* Destination: SPI1 data register. */
  159. DMA1_Channel1->CPAR = (uint32_t)&(SPI1->DR);
  160. /* Set DMA data transfer length (SPI buffer length). */
  161. DMA1_Channel1->CNDTR = SPI_BUFFER_SIZE;
  162. /* Enable SPI+DMA transfer */
  163. SPI1->CR2 |= SPI_CR2_TXDMAEN;
  164. SPI1->CR1 |= SPI_CR1_SPE;
  165. tubes_Refresh();
  166. IN15_OFF;
  167. RTC_Init();
  168. int8_t rsltSensor;
  169. SensorDev.dev_id = (BME280_I2C_ADDR_PRIM << 1);
  170. SensorDev.intf = BME280_I2C_INTF;
  171. SensorDev.read = user_i2c_read;
  172. SensorDev.write = user_i2c_write;
  173. SensorDev.delay_ms = tdelay_ms;
  174. rsltSensor = bme280_init(&SensorDev);
  175. if (rsltSensor == BME280_OK) {
  176. Flag.BME280 = 1;
  177. }
  178. /* Set tasks for Sheduler */
  179. RTOS_SetTask(btnProcess, 1, BTN_SCAN_PERIOD);
  180. /* USER CODE END 2 */
  181. /* USER CODE BEGIN WHILE */
  182. RTC_ReadAll(&Clock);
  183. if (Flag.BME280 != 0) {
  184. /* BME280 Recommended mode of operation: Indoor navigation */
  185. SensorDev.settings.osr_h = BME280_OVERSAMPLING_1X;
  186. SensorDev.settings.osr_p = BME280_OVERSAMPLING_16X;
  187. SensorDev.settings.osr_t = BME280_OVERSAMPLING_2X;
  188. SensorDev.settings.filter = BME280_FILTER_COEFF_16;
  189. rsltSensor = bme280_set_sensor_settings((BME280_OSR_PRESS_SEL | BME280_OSR_TEMP_SEL | BME280_OSR_HUM_SEL | BME280_FILTER_SEL), &SensorDev);
  190. RTOS_SetTask(sensorStartMeasure, 103, 1000);
  191. RTOS_SetTask(sensorGetData, 603, 1000);
  192. }
  193. es_event_t event = eventNull;
  194. COLOR_RGB(0xFF, 0x12, 0x0); // Nixie color. FF7E00 or FFBF00
  195. showTime();
  196. /* Infinite loop */
  197. while (1)
  198. {
  199. /* new second interrupt from RTC */
  200. if (Flag.RTC_IRQ != 0) {
  201. Flag.RTC_IRQ = 0;
  202. RTC_ReadAll(&Clock);
  203. ES_PlaceEvent(evNewSecond);
  204. if (dispWDT != 0) {
  205. dispWDT --;
  206. if (dispWDT == 0) {
  207. ES_PlaceEvent(evDisplayWDT);
  208. }
  209. }
  210. } /* end of New second */
  211. /* USER CODE END WHILE */
  212. /* USER CODE BEGIN 3 */
  213. event = ES_GetEvent();
  214. if (event) {
  215. ES_Dispatch(event);
  216. }
  217. RTOS_DispatchTask();
  218. __WFI();
  219. }
  220. /* USER CODE END 3 */
  221. }
  222. /**
  223. * @brief Launch SPI transaction.
  224. * @retval None
  225. */
  226. static void tubes_Refresh(void) {
  227. LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_1);
  228. }
  229. /**
  230. * @brief Check I2C fjr errors.
  231. * @retval I2C return code
  232. */
  233. int8_t i2c_check_err(void) {
  234. int8_t r = I2C_RET_OK;
  235. if ((I2C1->ISR & I2C_ISR_NACKF) != 0) {
  236. /* device not present */
  237. r = I2C_RET_NACK;
  238. } else if ((I2C1->ISR & (I2C_ISR_ARLO | I2C_ISR_BERR)) != 0) {
  239. /* other error */
  240. r = I2C_RET_ERR;
  241. }
  242. if (r != I2C_RET_OK) {
  243. /* restart I2C and clear flags */
  244. I2C1->CR1 &= ~I2C_CR1_PE;
  245. while ((I2C1->CR1 & I2C_CR1_PE) != 0) {};
  246. I2C1->CR1 |= I2C_CR1_PE;
  247. }
  248. return r;
  249. }
  250. /**
  251. * @brief Read len bytes from I2C bus to data by reg_addr.
  252. * @retval I2C return code
  253. */
  254. int8_t user_i2c_read(const uint8_t id, const uint8_t reg_addr, uint8_t *data, const uint16_t len) {
  255. int8_t r = I2C_RET_OK;
  256. Flag.I2C_RX_End = 0;
  257. Flag.I2C_RX_Err = 0;
  258. Flag.I2C_TX_Err = 0;
  259. /* wait for i2c */
  260. while ( I2C1->ISR & I2C_ISR_BUSY ) { __NOP(); };
  261. /* prepare i2c for sending reg addr */
  262. I2C1->CR2 &= ~( I2C_CR2_SADD | I2C_CR2_NBYTES | I2C_CR2_RD_WRN);
  263. I2C1->CR2 |= ( id | 1 << I2C_CR2_NBYTES_Pos );
  264. /* gen START */
  265. I2C1->CR2 |= ( I2C_CR2_START );
  266. /* wait for byte request or any error */
  267. while ((I2C1->ISR & (I2C_ISR_ARLO | I2C_ISR_BERR | I2C_ISR_NACKF | I2C_ISR_TXE)) == 0) { __NOP(); };
  268. if ((I2C2->ISR & I2C_ISR_TXE) != 0) {
  269. /* device ok, send reg addr */
  270. I2C1->TXDR = reg_addr;
  271. } else {
  272. r = i2c_check_err();
  273. if (r != I2C_RET_OK) {
  274. Flag.I2C_TX_Err = 1;
  275. return r;
  276. }
  277. }
  278. /* wait for i2c or any error */
  279. while (((I2C1->ISR & I2C_ISR_BUSY) != 0) && ((I2C1->ISR & (I2C_ISR_ARLO | I2C_ISR_BERR | I2C_ISR_NACKF)) == 0)) { __NOP(); };
  280. r = i2c_check_err();
  281. if (r != I2C_RET_OK) {
  282. Flag.I2C_TX_Err = 1;
  283. return r;
  284. }
  285. /* prepare dma channel for receiving data */
  286. DMA1_Channel2->CMAR = (uint32_t)data;
  287. DMA1_Channel2->CPAR = (uint32_t)&(I2C1->RXDR);
  288. DMA1_Channel2->CNDTR = len;
  289. DMA1_Channel2->CCR |= DMA_CCR_EN;
  290. /* prepare i2c for receiving data */
  291. I2C1->CR2 &= ~( I2C_CR2_SADD | I2C_CR2_NBYTES | I2C_CR2_RD_WRN);
  292. I2C1->CR2 |= ( id | len << I2C_CR2_NBYTES_Pos | I2C_CR2_RD_WRN);
  293. /* launch receiving */
  294. I2C1->CR1 |= ( I2C_CR1_RXDMAEN );
  295. I2C1->CR2 |= ( I2C_CR2_START );
  296. /* wait for receiving data */
  297. while ((Flag.I2C_RX_End == 0) && (Flag.I2C_RX_Err == 0)) { __NOP(); };
  298. return r;
  299. }
  300. /**
  301. * @brief Write len bytes to I2C bus from data by reg_addr.
  302. * @retval I2C return code
  303. */
  304. int8_t user_i2c_write(const uint8_t id, const uint8_t reg_addr, uint8_t *data, const uint16_t len) {
  305. int8_t r = I2C_RET_OK;
  306. Flag.I2C_TX_End = 0;
  307. Flag.I2C_TX_Err = 0;
  308. DMA1_Channel3->CMAR = (uint32_t)data;
  309. DMA1_Channel3->CPAR = (uint32_t)&(I2C1->TXDR);
  310. DMA1_Channel3->CNDTR = len;
  311. while ( I2C1->ISR & I2C_ISR_BUSY ) {};
  312. I2C1->CR2 &= ~( I2C_CR2_SADD | I2C_CR2_NBYTES | I2C_CR2_RD_WRN);
  313. I2C1->CR2 |= ( id | (len + 1) << I2C_CR2_NBYTES_Pos );
  314. I2C1->CR2 |= ( I2C_CR2_START );
  315. while ((I2C1->ISR & (I2C_ISR_ARLO | I2C_ISR_BERR | I2C_ISR_NACKF | I2C_ISR_TXE)) == 0) { __NOP(); };
  316. if ((I2C2->ISR & I2C_ISR_TXE) != 0) {
  317. I2C1->TXDR = reg_addr;
  318. } else {
  319. r = i2c_check_err();
  320. if (r != I2C_RET_OK) {
  321. Flag.I2C_TX_Err = 1;
  322. return r;
  323. }
  324. }
  325. DMA1_Channel3->CCR |= DMA_CCR_EN;
  326. I2C1->CR1 |= ( I2C_CR1_TXDMAEN );
  327. return r;
  328. }
  329. /**
  330. * Sensor
  331. */
  332. static void sensorStartMeasure(void) {
  333. bme280_set_sensor_mode(BME280_FORCED_MODE, &SensorDev);
  334. }
  335. static void sensorGetData(void) {
  336. bme280_get_sensor_data(BME280_ALL, &SensorData, &SensorDev);
  337. int32_t tmp;
  338. tmp = SensorData.humidity + 512;
  339. Humidity = (int8_t)(tmp / 1024);
  340. tmp = SensorData.temperature + 50;
  341. Temperature = (int8_t)(tmp / 100);
  342. /* in 32-bit arithmetics pressure in Pa */
  343. tmp = SensorData.pressure * 1000;
  344. tmp += 66661;
  345. tmp /= 133322;
  346. /* pressure in mmHg */
  347. Pressure.s16.u8H = (uint8_t)(tmp / 100);
  348. Pressure.s16.u8L = (uint8_t)(tmp % 100);
  349. }
  350. /**
  351. * @brief System Clock Configuration
  352. * @retval None
  353. */
  354. void SystemClock_Config(void)
  355. {
  356. /* HSI configuration and activation */
  357. LL_RCC_HSI_Enable();
  358. while(LL_RCC_HSI_IsReady() != 1)
  359. {
  360. }
  361. /* Main PLL configuration and activation */
  362. LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_2, 9, LL_RCC_PLLR_DIV_3);
  363. LL_RCC_PLL_Enable();
  364. LL_RCC_PLL_EnableDomain_SYS();
  365. while(LL_RCC_PLL_IsReady() != 1)
  366. {
  367. }
  368. /* Set AHB prescaler*/
  369. LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
  370. /* Sysclk activation on the main PLL */
  371. LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL);
  372. while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL)
  373. {
  374. }
  375. /* Set APB1 prescaler*/
  376. LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
  377. LL_Init1msTick(24000000);
  378. /* Update CMSIS variable (which can be updated also through SystemCoreClockUpdate function) */
  379. LL_SetSystemCoreClock(24000000);
  380. LL_RCC_SetI2CClockSource(LL_RCC_I2C1_CLKSOURCE_HSI);
  381. }
  382. /**
  383. * @brief I2C1 Initialization Function
  384. * @param None
  385. * @retval None
  386. */
  387. static void MX_I2C1_Init(void)
  388. {
  389. /* USER CODE BEGIN I2C1_Init 0 */
  390. /* USER CODE END I2C1_Init 0 */
  391. LL_I2C_InitTypeDef I2C_InitStruct = {0};
  392. LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
  393. LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB);
  394. /**I2C1 GPIO Configuration
  395. PB8 ------> I2C1_SCL
  396. PB9 ------> I2C1_SDA
  397. */
  398. GPIO_InitStruct.Pin = LL_GPIO_PIN_8;
  399. GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  400. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  401. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN;
  402. GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
  403. GPIO_InitStruct.Alternate = LL_GPIO_AF_6;
  404. LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  405. GPIO_InitStruct.Pin = LL_GPIO_PIN_9;
  406. GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  407. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  408. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN;
  409. GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
  410. GPIO_InitStruct.Alternate = LL_GPIO_AF_6;
  411. LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  412. /* Peripheral clock enable */
  413. LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C1);
  414. /* I2C1 DMA Init */
  415. /* I2C1_RX Init */
  416. LL_DMA_SetPeriphRequest(DMA1, LL_DMA_CHANNEL_2, LL_DMAMUX_REQ_I2C1_RX);
  417. LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_2, LL_DMA_DIRECTION_PERIPH_TO_MEMORY);
  418. LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_2, LL_DMA_PRIORITY_MEDIUM);
  419. LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_2, LL_DMA_PERIPH_NOINCREMENT);
  420. LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_2, LL_DMA_MEMORY_INCREMENT);
  421. LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_2, LL_DMA_PDATAALIGN_BYTE);
  422. LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_2, LL_DMA_MDATAALIGN_BYTE);
  423. /* I2C1_TX Init */
  424. LL_DMA_SetPeriphRequest(DMA1, LL_DMA_CHANNEL_3, LL_DMAMUX_REQ_I2C1_TX);
  425. LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_3, LL_DMA_DIRECTION_MEMORY_TO_PERIPH);
  426. LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_3, LL_DMA_PRIORITY_MEDIUM);
  427. LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_3, LL_DMA_PERIPH_NOINCREMENT);
  428. LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_3, LL_DMA_MEMORY_INCREMENT);
  429. LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_3, LL_DMA_PDATAALIGN_BYTE);
  430. LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_3, LL_DMA_MDATAALIGN_BYTE);
  431. /* I2C1 interrupt Init */
  432. /* USER CODE BEGIN I2C1_Init 1 */
  433. /* Enable DMA transfer complete/error interrupts */
  434. LL_DMA_EnableIT_TC(DMA1, LL_DMA_CHANNEL_2);
  435. LL_DMA_EnableIT_TE(DMA1, LL_DMA_CHANNEL_2);
  436. LL_DMA_EnableIT_TC(DMA1, LL_DMA_CHANNEL_3);
  437. LL_DMA_EnableIT_TE(DMA1, LL_DMA_CHANNEL_3);
  438. /* USER CODE END I2C1_Init 1 */
  439. /** I2C Initialization
  440. */
  441. I2C_InitStruct.PeripheralMode = LL_I2C_MODE_I2C;
  442. I2C_InitStruct.Timing = 0x0010061A;
  443. I2C_InitStruct.AnalogFilter = LL_I2C_ANALOGFILTER_ENABLE;
  444. I2C_InitStruct.DigitalFilter = 0;
  445. I2C_InitStruct.OwnAddress1 = 0;
  446. I2C_InitStruct.TypeAcknowledge = LL_I2C_ACK;
  447. I2C_InitStruct.OwnAddrSize = LL_I2C_OWNADDRESS1_7BIT;
  448. LL_I2C_EnableAutoEndMode(I2C1);
  449. LL_I2C_SetOwnAddress2(I2C1, 0, LL_I2C_OWNADDRESS2_NOMASK);
  450. LL_I2C_DisableOwnAddress2(I2C1);
  451. LL_I2C_DisableGeneralCall(I2C1);
  452. LL_I2C_DisableClockStretching(I2C1);
  453. LL_I2C_Init(I2C1, &I2C_InitStruct);
  454. /* USER CODE BEGIN I2C1_Init 2 */
  455. /* USER CODE END I2C1_Init 2 */
  456. }
  457. /**
  458. * @brief SPI1 Initialization Function
  459. * @param None
  460. * @retval None
  461. */
  462. static void MX_SPI1_Init(void)
  463. {
  464. /* USER CODE BEGIN SPI1_Init 0 */
  465. /* USER CODE END SPI1_Init 0 */
  466. LL_SPI_InitTypeDef SPI_InitStruct = {0};
  467. LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
  468. /* Peripheral clock enable */
  469. LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SPI1);
  470. LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB);
  471. /**SPI1 GPIO Configuration
  472. PB3 ------> SPI1_SCK
  473. PB5 ------> SPI1_MOSI
  474. */
  475. GPIO_InitStruct.Pin = LL_GPIO_PIN_3;
  476. GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  477. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  478. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN;
  479. GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  480. GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
  481. LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  482. GPIO_InitStruct.Pin = LL_GPIO_PIN_5;
  483. GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  484. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  485. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN;
  486. GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  487. GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
  488. LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  489. /* SPI1 DMA Init */
  490. /* SPI1_TX Init */
  491. LL_DMA_SetPeriphRequest(DMA1, LL_DMA_CHANNEL_1, LL_DMAMUX_REQ_SPI1_TX);
  492. LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_1, LL_DMA_DIRECTION_MEMORY_TO_PERIPH);
  493. LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PRIORITY_HIGH);
  494. LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MODE_CIRCULAR);
  495. LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PERIPH_NOINCREMENT);
  496. LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MEMORY_INCREMENT);
  497. LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PDATAALIGN_BYTE);
  498. LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MDATAALIGN_BYTE);
  499. /* SPI1 interrupt Init */
  500. NVIC_SetPriority(SPI1_IRQn, 0);
  501. NVIC_EnableIRQ(SPI1_IRQn);
  502. /* USER CODE BEGIN SPI1_Init 1 */
  503. /* Enable DMA transfer complete/error interrupts */
  504. LL_DMA_EnableIT_TC(DMA1, LL_DMA_CHANNEL_1);
  505. LL_DMA_EnableIT_TE(DMA1, LL_DMA_CHANNEL_1);
  506. /* USER CODE END SPI1_Init 1 */
  507. /* SPI1 parameter configuration*/
  508. SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX;
  509. SPI_InitStruct.Mode = LL_SPI_MODE_MASTER;
  510. SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_8BIT;
  511. SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_LOW;
  512. SPI_InitStruct.ClockPhase = LL_SPI_PHASE_1EDGE;
  513. SPI_InitStruct.NSS = LL_SPI_NSS_SOFT;
  514. SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV16;
  515. SPI_InitStruct.BitOrder = LL_SPI_MSB_FIRST;
  516. SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE;
  517. SPI_InitStruct.CRCPoly = 7;
  518. LL_SPI_Init(SPI1, &SPI_InitStruct);
  519. LL_SPI_SetStandard(SPI1, LL_SPI_PROTOCOL_MOTOROLA);
  520. LL_SPI_DisableNSSPulseMgt(SPI1);
  521. /* USER CODE BEGIN SPI1_Init 2 */
  522. /* USER CODE END SPI1_Init 2 */
  523. }
  524. /**
  525. * @brief TIM3 Initialization Function
  526. * @param None
  527. * @retval None
  528. */
  529. static void MX_TIM3_Init(void)
  530. {
  531. /* USER CODE BEGIN TIM3_Init 0 */
  532. /* USER CODE END TIM3_Init 0 */
  533. LL_TIM_InitTypeDef TIM_InitStruct = {0};
  534. LL_TIM_OC_InitTypeDef TIM_OC_InitStruct = {0};
  535. LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
  536. /* Peripheral clock enable */
  537. LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM3);
  538. /* USER CODE BEGIN TIM3_Init 1 */
  539. /* USER CODE END TIM3_Init 1 */
  540. TIM_InitStruct.Prescaler = 94;
  541. TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
  542. TIM_InitStruct.Autoreload = 255;
  543. TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
  544. LL_TIM_Init(TIM3, &TIM_InitStruct);
  545. LL_TIM_EnableARRPreload(TIM3);
  546. LL_TIM_OC_EnablePreload(TIM3, LL_TIM_CHANNEL_CH1);
  547. TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM1;
  548. TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE;
  549. TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE;
  550. TIM_OC_InitStruct.CompareValue = 25;
  551. TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH;
  552. LL_TIM_OC_Init(TIM3, LL_TIM_CHANNEL_CH1, &TIM_OC_InitStruct);
  553. LL_TIM_OC_DisableFast(TIM3, LL_TIM_CHANNEL_CH1);
  554. LL_TIM_OC_EnablePreload(TIM3, LL_TIM_CHANNEL_CH2);
  555. TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE;
  556. TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE;
  557. LL_TIM_OC_Init(TIM3, LL_TIM_CHANNEL_CH2, &TIM_OC_InitStruct);
  558. LL_TIM_OC_DisableFast(TIM3, LL_TIM_CHANNEL_CH2);
  559. LL_TIM_OC_EnablePreload(TIM3, LL_TIM_CHANNEL_CH3);
  560. TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE;
  561. TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE;
  562. LL_TIM_OC_Init(TIM3, LL_TIM_CHANNEL_CH3, &TIM_OC_InitStruct);
  563. LL_TIM_OC_DisableFast(TIM3, LL_TIM_CHANNEL_CH3);
  564. LL_TIM_SetTriggerOutput(TIM3, LL_TIM_TRGO_RESET);
  565. LL_TIM_DisableMasterSlaveMode(TIM3);
  566. /* USER CODE BEGIN TIM3_Init 2 */
  567. /* USER CODE END TIM3_Init 2 */
  568. LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA);
  569. LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB);
  570. /**TIM3 GPIO Configuration
  571. PA6 ------> TIM3_CH1
  572. PA7 ------> TIM3_CH2
  573. PB0 ------> TIM3_CH3
  574. */
  575. GPIO_InitStruct.Pin = PWM_R_Pin;
  576. GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  577. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  578. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  579. GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
  580. GPIO_InitStruct.Alternate = LL_GPIO_AF_1;
  581. LL_GPIO_Init(PWM_R_GPIO_Port, &GPIO_InitStruct);
  582. GPIO_InitStruct.Pin = PWM_G_Pin;
  583. GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  584. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  585. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  586. GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
  587. GPIO_InitStruct.Alternate = LL_GPIO_AF_1;
  588. LL_GPIO_Init(PWM_G_GPIO_Port, &GPIO_InitStruct);
  589. GPIO_InitStruct.Pin = PWM_B_Pin;
  590. GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  591. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  592. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  593. GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
  594. GPIO_InitStruct.Alternate = LL_GPIO_AF_1;
  595. LL_GPIO_Init(PWM_B_GPIO_Port, &GPIO_InitStruct);
  596. }
  597. /**
  598. * @brief TIM14 Initialization Function
  599. * @param None
  600. * @retval None
  601. */
  602. static void MX_TIM14_Init(void)
  603. {
  604. /* USER CODE BEGIN TIM14_Init 0 */
  605. /* USER CODE END TIM14_Init 0 */
  606. LL_TIM_InitTypeDef TIM_InitStruct = {0};
  607. LL_TIM_OC_InitTypeDef TIM_OC_InitStruct = {0};
  608. LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
  609. /* Peripheral clock enable */
  610. LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM14);
  611. /* TIM14 interrupt Init */
  612. NVIC_SetPriority(TIM14_IRQn, 0);
  613. NVIC_EnableIRQ(TIM14_IRQn);
  614. /* USER CODE BEGIN TIM14_Init 1 */
  615. /* USER CODE END TIM14_Init 1 */
  616. TIM_InitStruct.Prescaler = 240;
  617. TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
  618. TIM_InitStruct.Autoreload = 1000;
  619. TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
  620. LL_TIM_Init(TIM14, &TIM_InitStruct);
  621. LL_TIM_EnableARRPreload(TIM14);
  622. LL_TIM_OC_EnablePreload(TIM14, LL_TIM_CHANNEL_CH1);
  623. TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM1;
  624. TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE;
  625. TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE;
  626. TIM_OC_InitStruct.CompareValue = 750;
  627. TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH;
  628. LL_TIM_OC_Init(TIM14, LL_TIM_CHANNEL_CH1, &TIM_OC_InitStruct);
  629. LL_TIM_OC_DisableFast(TIM14, LL_TIM_CHANNEL_CH1);
  630. /* USER CODE BEGIN TIM14_Init 2 */
  631. /* USER CODE END TIM14_Init 2 */
  632. LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB);
  633. /**TIM14 GPIO Configuration
  634. PB1 ------> TIM14_CH1
  635. */
  636. GPIO_InitStruct.Pin = PWM_T_Pin;
  637. GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  638. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  639. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  640. GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
  641. GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
  642. LL_GPIO_Init(PWM_T_GPIO_Port, &GPIO_InitStruct);
  643. }
  644. /**
  645. * @brief TIM16 Initialization Function
  646. * @param None
  647. * @retval None
  648. */
  649. static void MX_TIM16_Init(void)
  650. {
  651. /* USER CODE BEGIN TIM16_Init 0 */
  652. /* USER CODE END TIM16_Init 0 */
  653. LL_TIM_InitTypeDef TIM_InitStruct = {0};
  654. LL_TIM_OC_InitTypeDef TIM_OC_InitStruct = {0};
  655. LL_TIM_BDTR_InitTypeDef TIM_BDTRInitStruct = {0};
  656. /* Peripheral clock enable */
  657. LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM16);
  658. /* TIM16 interrupt Init */
  659. NVIC_SetPriority(TIM16_IRQn, 0);
  660. NVIC_EnableIRQ(TIM16_IRQn);
  661. /* USER CODE BEGIN TIM16_Init 1 */
  662. /* USER CODE END TIM16_Init 1 */
  663. TIM_InitStruct.Prescaler = 24;
  664. TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
  665. TIM_InitStruct.Autoreload = 1000;
  666. TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
  667. TIM_InitStruct.RepetitionCounter = 0;
  668. LL_TIM_Init(TIM16, &TIM_InitStruct);
  669. LL_TIM_EnableARRPreload(TIM16);
  670. LL_TIM_OC_EnablePreload(TIM16, LL_TIM_CHANNEL_CH1);
  671. TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM1;
  672. TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE;
  673. TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE;
  674. TIM_OC_InitStruct.CompareValue = 0;
  675. TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH;
  676. TIM_OC_InitStruct.OCNPolarity = LL_TIM_OCPOLARITY_HIGH;
  677. TIM_OC_InitStruct.OCIdleState = LL_TIM_OCIDLESTATE_LOW;
  678. TIM_OC_InitStruct.OCNIdleState = LL_TIM_OCIDLESTATE_LOW;
  679. LL_TIM_OC_Init(TIM16, LL_TIM_CHANNEL_CH1, &TIM_OC_InitStruct);
  680. LL_TIM_OC_DisableFast(TIM16, LL_TIM_CHANNEL_CH1);
  681. TIM_BDTRInitStruct.OSSRState = LL_TIM_OSSR_DISABLE;
  682. TIM_BDTRInitStruct.OSSIState = LL_TIM_OSSI_DISABLE;
  683. TIM_BDTRInitStruct.LockLevel = LL_TIM_LOCKLEVEL_OFF;
  684. TIM_BDTRInitStruct.DeadTime = 0;
  685. TIM_BDTRInitStruct.BreakState = LL_TIM_BREAK_DISABLE;
  686. TIM_BDTRInitStruct.BreakPolarity = LL_TIM_BREAK_POLARITY_HIGH;
  687. TIM_BDTRInitStruct.BreakFilter = LL_TIM_BREAK_FILTER_FDIV1;
  688. TIM_BDTRInitStruct.AutomaticOutput = LL_TIM_AUTOMATICOUTPUT_DISABLE;
  689. LL_TIM_BDTR_Init(TIM16, &TIM_BDTRInitStruct);
  690. /* USER CODE BEGIN TIM16_Init 2 */
  691. /* USER CODE END TIM16_Init 2 */
  692. }
  693. /**
  694. * @brief TIM17 Initialization Function
  695. * @param None
  696. * @retval None
  697. */
  698. static void MX_TIM17_Init(void)
  699. {
  700. /* USER CODE BEGIN TIM17_Init 0 */
  701. /* USER CODE END TIM17_Init 0 */
  702. LL_TIM_InitTypeDef TIM_InitStruct = {0};
  703. LL_TIM_OC_InitTypeDef TIM_OC_InitStruct = {0};
  704. LL_TIM_BDTR_InitTypeDef TIM_BDTRInitStruct = {0};
  705. /* Peripheral clock enable */
  706. LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM17);
  707. /* TIM17 interrupt Init */
  708. NVIC_SetPriority(TIM17_IRQn, 0);
  709. NVIC_EnableIRQ(TIM17_IRQn);
  710. /* USER CODE BEGIN TIM17_Init 1 */
  711. /* USER CODE END TIM17_Init 1 */
  712. TIM_InitStruct.Prescaler = 240;
  713. TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
  714. TIM_InitStruct.Autoreload = 1000;
  715. TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
  716. TIM_InitStruct.RepetitionCounter = 100;
  717. LL_TIM_Init(TIM17, &TIM_InitStruct);
  718. LL_TIM_EnableARRPreload(TIM17);
  719. LL_TIM_OC_EnablePreload(TIM17, LL_TIM_CHANNEL_CH1);
  720. TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM1;
  721. TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE;
  722. TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE;
  723. TIM_OC_InitStruct.CompareValue = 0;
  724. TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH;
  725. TIM_OC_InitStruct.OCNPolarity = LL_TIM_OCPOLARITY_HIGH;
  726. TIM_OC_InitStruct.OCIdleState = LL_TIM_OCIDLESTATE_LOW;
  727. TIM_OC_InitStruct.OCNIdleState = LL_TIM_OCIDLESTATE_LOW;
  728. LL_TIM_OC_Init(TIM17, LL_TIM_CHANNEL_CH1, &TIM_OC_InitStruct);
  729. LL_TIM_OC_DisableFast(TIM17, LL_TIM_CHANNEL_CH1);
  730. TIM_BDTRInitStruct.OSSRState = LL_TIM_OSSR_DISABLE;
  731. TIM_BDTRInitStruct.OSSIState = LL_TIM_OSSI_DISABLE;
  732. TIM_BDTRInitStruct.LockLevel = LL_TIM_LOCKLEVEL_OFF;
  733. TIM_BDTRInitStruct.DeadTime = 0;
  734. TIM_BDTRInitStruct.BreakState = LL_TIM_BREAK_DISABLE;
  735. TIM_BDTRInitStruct.BreakPolarity = LL_TIM_BREAK_POLARITY_HIGH;
  736. TIM_BDTRInitStruct.BreakFilter = LL_TIM_BREAK_FILTER_FDIV1;
  737. TIM_BDTRInitStruct.AutomaticOutput = LL_TIM_AUTOMATICOUTPUT_DISABLE;
  738. LL_TIM_BDTR_Init(TIM17, &TIM_BDTRInitStruct);
  739. /* USER CODE BEGIN TIM17_Init 2 */
  740. /* USER CODE END TIM17_Init 2 */
  741. }
  742. /**
  743. * @brief USART1 Initialization Function
  744. * @param None
  745. * @retval None
  746. */
  747. static void MX_USART1_UART_Init(void)
  748. {
  749. /* USER CODE BEGIN USART1_Init 0 */
  750. /* USER CODE END USART1_Init 0 */
  751. LL_USART_InitTypeDef USART_InitStruct = {0};
  752. LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
  753. /* Peripheral clock enable */
  754. LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1);
  755. LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB);
  756. /**USART1 GPIO Configuration
  757. PB6 ------> USART1_TX
  758. PB7 ------> USART1_RX
  759. */
  760. GPIO_InitStruct.Pin = LL_GPIO_PIN_6;
  761. GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  762. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  763. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  764. GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  765. GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
  766. LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  767. GPIO_InitStruct.Pin = LL_GPIO_PIN_7;
  768. GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  769. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  770. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  771. GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  772. GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
  773. LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  774. /* USART1 interrupt Init */
  775. NVIC_SetPriority(USART1_IRQn, 0);
  776. NVIC_EnableIRQ(USART1_IRQn);
  777. /* USER CODE BEGIN USART1_Init 1 */
  778. /* USER CODE END USART1_Init 1 */
  779. USART_InitStruct.PrescalerValue = LL_USART_PRESCALER_DIV1;
  780. USART_InitStruct.BaudRate = 115200;
  781. USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B;
  782. USART_InitStruct.StopBits = LL_USART_STOPBITS_1;
  783. USART_InitStruct.Parity = LL_USART_PARITY_NONE;
  784. USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX_RX;
  785. USART_InitStruct.HardwareFlowControl = LL_USART_HWCONTROL_NONE;
  786. USART_InitStruct.OverSampling = LL_USART_OVERSAMPLING_16;
  787. LL_USART_Init(USART1, &USART_InitStruct);
  788. LL_USART_SetTXFIFOThreshold(USART1, LL_USART_FIFOTHRESHOLD_1_8);
  789. LL_USART_SetRXFIFOThreshold(USART1, LL_USART_FIFOTHRESHOLD_1_8);
  790. LL_USART_DisableFIFO(USART1);
  791. LL_USART_ConfigAsyncMode(USART1);
  792. /* USER CODE BEGIN WKUPType USART1 */
  793. /* USER CODE END WKUPType USART1 */
  794. LL_USART_Enable(USART1);
  795. /* Polling USART1 initialisation */
  796. while((!(LL_USART_IsActiveFlag_TEACK(USART1))) || (!(LL_USART_IsActiveFlag_REACK(USART1))))
  797. {
  798. }
  799. /* USER CODE BEGIN USART1_Init 2 */
  800. /* USER CODE END USART1_Init 2 */
  801. }
  802. /**
  803. * Enable DMA controller clock
  804. */
  805. static void MX_DMA_Init(void)
  806. {
  807. /* Init with LL driver */
  808. /* DMA controller clock enable */
  809. LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA1);
  810. /* DMA interrupt init */
  811. /* DMA1_Channel1_IRQn interrupt configuration */
  812. NVIC_SetPriority(DMA1_Channel1_IRQn, 0);
  813. NVIC_EnableIRQ(DMA1_Channel1_IRQn);
  814. /* DMA1_Channel2_3_IRQn interrupt configuration */
  815. NVIC_SetPriority(DMA1_Channel2_3_IRQn, 0);
  816. NVIC_EnableIRQ(DMA1_Channel2_3_IRQn);
  817. }
  818. /**
  819. * @brief GPIO Initialization Function
  820. * @param None
  821. * @retval None
  822. */
  823. static void MX_GPIO_Init(void)
  824. {
  825. LL_EXTI_InitTypeDef EXTI_InitStruct = {0};
  826. LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
  827. /* GPIO Ports Clock Enable */
  828. LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB);
  829. LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOC);
  830. LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA);
  831. /**/
  832. LL_GPIO_ResetOutputPin(LC0_GPIO_Port, LC0_Pin);
  833. /**/
  834. LL_GPIO_ResetOutputPin(LC1_GPIO_Port, LC1_Pin);
  835. /**/
  836. LL_GPIO_ResetOutputPin(LC2_GPIO_Port, LC2_Pin);
  837. /**/
  838. LL_GPIO_ResetOutputPin(LC3_GPIO_Port, LC3_Pin);
  839. /**/
  840. LL_GPIO_ResetOutputPin(SHDN_GPIO_Port, SHDN_Pin);
  841. /**/
  842. LL_GPIO_ResetOutputPin(Latch_GPIO_Port, Latch_Pin);
  843. /**/
  844. GPIO_InitStruct.Pin = LC0_Pin;
  845. GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
  846. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  847. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  848. GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
  849. LL_GPIO_Init(LC0_GPIO_Port, &GPIO_InitStruct);
  850. /**/
  851. GPIO_InitStruct.Pin = LC1_Pin;
  852. GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
  853. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  854. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  855. GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
  856. LL_GPIO_Init(LC1_GPIO_Port, &GPIO_InitStruct);
  857. /**/
  858. GPIO_InitStruct.Pin = LC2_Pin;
  859. GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
  860. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  861. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  862. GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
  863. LL_GPIO_Init(LC2_GPIO_Port, &GPIO_InitStruct);
  864. /**/
  865. GPIO_InitStruct.Pin = LC3_Pin;
  866. GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
  867. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  868. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  869. GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
  870. LL_GPIO_Init(LC3_GPIO_Port, &GPIO_InitStruct);
  871. /**/
  872. GPIO_InitStruct.Pin = SHDN_Pin;
  873. GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
  874. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  875. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  876. GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
  877. LL_GPIO_Init(SHDN_GPIO_Port, &GPIO_InitStruct);
  878. /**/
  879. GPIO_InitStruct.Pin = LL_GPIO_PIN_5;
  880. GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
  881. GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  882. LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  883. /**/
  884. GPIO_InitStruct.Pin = LL_GPIO_PIN_2;
  885. GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
  886. GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  887. LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  888. /**/
  889. GPIO_InitStruct.Pin = BTN1_Pin;
  890. GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
  891. GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
  892. LL_GPIO_Init(BTN1_GPIO_Port, &GPIO_InitStruct);
  893. /**/
  894. GPIO_InitStruct.Pin = BTN2_Pin;
  895. GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
  896. GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
  897. LL_GPIO_Init(BTN2_GPIO_Port, &GPIO_InitStruct);
  898. /**/
  899. GPIO_InitStruct.Pin = BTN3_Pin;
  900. GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
  901. GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
  902. LL_GPIO_Init(BTN3_GPIO_Port, &GPIO_InitStruct);
  903. /**/
  904. GPIO_InitStruct.Pin = BTN4_Pin;
  905. GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
  906. GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
  907. LL_GPIO_Init(BTN4_GPIO_Port, &GPIO_InitStruct);
  908. /**/
  909. GPIO_InitStruct.Pin = LL_GPIO_PIN_12;
  910. GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
  911. GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  912. LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  913. /**/
  914. GPIO_InitStruct.Pin = Latch_Pin;
  915. GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
  916. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  917. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN;
  918. GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  919. LL_GPIO_Init(Latch_GPIO_Port, &GPIO_InitStruct);
  920. /**/
  921. GPIO_InitStruct.Pin = UART_EN_Pin;
  922. GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
  923. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
  924. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  925. GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  926. LL_GPIO_Init(UART_EN_GPIO_Port, &GPIO_InitStruct);
  927. /**/
  928. GPIO_InitStruct.Pin = UART_ST_Pin;
  929. GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
  930. GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  931. LL_GPIO_Init(UART_ST_GPIO_Port, &GPIO_InitStruct);
  932. /**/
  933. LL_EXTI_SetEXTISource(LL_EXTI_CONFIG_PORTC, LL_EXTI_CONFIG_LINE14);
  934. /**/
  935. EXTI_InitStruct.Line_0_31 = LL_EXTI_LINE_14;
  936. EXTI_InitStruct.LineCommand = ENABLE;
  937. EXTI_InitStruct.Mode = LL_EXTI_MODE_IT;
  938. EXTI_InitStruct.Trigger = LL_EXTI_TRIGGER_RISING;
  939. LL_EXTI_Init(&EXTI_InitStruct);
  940. /**/
  941. LL_GPIO_SetPinPull(IRQ_GPIO_Port, IRQ_Pin, LL_GPIO_PULL_UP);
  942. /**/
  943. LL_GPIO_SetPinMode(IRQ_GPIO_Port, IRQ_Pin, LL_GPIO_MODE_INPUT);
  944. /* EXTI interrupt init*/
  945. NVIC_SetPriority(EXTI4_15_IRQn, 0);
  946. NVIC_EnableIRQ(EXTI4_15_IRQn);
  947. }
  948. /* USER CODE BEGIN 4 */
  949. /**
  950. * S U B R O U T I N E S
  951. */
  952. /* Feel byte with tube position by digit.
  953. * If digit == 0xf, then tube is off -- clear all bits.
  954. */
  955. static void showDigit(tube_pos_t pos, uint8_t dig)
  956. {
  957. if (dig > 9) {
  958. if (dig != 0xf) {
  959. dig = 0;
  960. }
  961. }
  962. switch (pos) {
  963. case Tube_E:
  964. tubesBuffer[0] = 0;
  965. tubesBuffer[1] &= nixieCathodeMask[Tube_E][1];
  966. if (Tube_E != 0xf) {
  967. tubesBuffer[0] = (uint8_t)(nixieCathodeMap[Tube_E][dig] >> 8);
  968. tubesBuffer[1] |= (uint8_t)(nixieCathodeMap[Tube_E][dig]);
  969. }
  970. break;
  971. case Tube_D:
  972. tubesBuffer[1] &= nixieCathodeMask[Tube_D][0];
  973. tubesBuffer[2] &= nixieCathodeMask[Tube_D][1];
  974. if (Tube_D != 0xf) {
  975. tubesBuffer[1] |= (uint8_t)(nixieCathodeMap[Tube_D][dig] >> 8);
  976. tubesBuffer[2] |= (uint8_t)(nixieCathodeMap[Tube_D][dig]);
  977. }
  978. break;
  979. case Tube_B:
  980. tubesBuffer[2] &= nixieCathodeMask[Tube_B][0];
  981. tubesBuffer[3] &= nixieCathodeMask[Tube_B][1];
  982. if (Tube_B != 0xf) {
  983. tubesBuffer[2] |= (uint8_t)(nixieCathodeMap[Tube_B][dig] >> 8);
  984. tubesBuffer[3] |= (uint8_t)(nixieCathodeMap[Tube_B][dig]);
  985. }
  986. break;
  987. case Tube_A:
  988. tubesBuffer[3] &= nixieCathodeMask[Tube_A][0];
  989. tubesBuffer[4] = 0;
  990. if (Tube_A != 0xf) {
  991. tubesBuffer[3] |= (uint8_t)(nixieCathodeMap[Tube_A][dig] >> 8);
  992. tubesBuffer[4] = (uint8_t)(nixieCathodeMap[Tube_A][dig]);
  993. }
  994. break;
  995. default:
  996. break;
  997. }
  998. }
  999. /**
  1000. * @brief Îáðàáîòêà êíîïîê.
  1001. * @param : None
  1002. * @retval : None
  1003. */
  1004. static void btnProcess(void) {
  1005. /* get pin state */
  1006. uint32_t pins = BTN_PORT->IDR & BTN_PINS;
  1007. int i;
  1008. for (i=0; i<BTN_NUM; i++) {
  1009. if ((pins & Button[i].pin) == 0) {
  1010. /* button pressed */
  1011. Button[i].time ++;
  1012. if (Button[i].time >= (BTN_TIME_HOLDED/BTN_SCAN_PERIOD)) {
  1013. Button[i].time -= (BTN_TIME_REPEATED/BTN_SCAN_PERIOD);
  1014. if (Button[i].holded == Button[i].pressed) {
  1015. /* if pressed and holded - same function, then button pressed auto repeat */
  1016. ES_PlaceEvent(Button[i].pressed);
  1017. }
  1018. }
  1019. } else if (Button[i].time != 0) {
  1020. /* button released */
  1021. if (Button[i].time >= ((BTN_TIME_HOLDED - BTN_TIME_REPEATED)/BTN_SCAN_PERIOD)) {
  1022. /* process long press */
  1023. ES_PlaceEvent(Button[i].holded);
  1024. } else if (Button[i].time >= (BTN_TIME_PRESSED/BTN_SCAN_PERIOD)) {
  1025. /* process short press */
  1026. ES_PlaceEvent(Button[i].pressed);
  1027. }
  1028. Button[i].time = 0;
  1029. RTOS_SetTask(btnProcess, BTN_SCAN_PAUSE, BTN_SCAN_PERIOD);
  1030. }
  1031. } /* end FOR */
  1032. }
  1033. void in15Off(void) {
  1034. IN15_OFF;
  1035. }
  1036. void in15Minus(void) {
  1037. IN15_OFF;
  1038. IN15_Minus;
  1039. }
  1040. void in15Plus(void) {
  1041. IN15_OFF;
  1042. IN15_Plus;
  1043. }
  1044. void in15Percent(void) {
  1045. IN15_OFF;
  1046. IN15_Percent;
  1047. }
  1048. void in15P(void) {
  1049. IN15_OFF;
  1050. IN15_P;
  1051. }
  1052. void showTime(void) {
  1053. in15Minus();
  1054. RTOS_SetTask(in15Off, 500, 0);
  1055. showDigit(Tube_A, Clock.Hr >> 4);
  1056. showDigit(Tube_B, Clock.Hr & 0xf);
  1057. showDigit(Tube_D, Clock.Min >> 4);
  1058. showDigit(Tube_E, Clock.Min & 0xf);
  1059. tubes_Refresh();
  1060. }
  1061. void showWD(void) {
  1062. dispWDT = DISP_WDT_TIME;
  1063. IN15_OFF;
  1064. showDigit(Tube_A, 0xf);
  1065. showDigit(Tube_B, Clock.WD & 0xf);
  1066. showDigit(Tube_D, 0xf);
  1067. showDigit(Tube_E, 0xf);
  1068. tubes_Refresh();
  1069. }
  1070. void showDay(void) {
  1071. dispWDT = DISP_WDT_TIME;
  1072. IN15_OFF;
  1073. showDigit(Tube_A, Clock.Day >> 4);
  1074. showDigit(Tube_B, Clock.Day & 0xf);
  1075. showDigit(Tube_D, 0xf);
  1076. showDigit(Tube_E, 0xf);
  1077. tubes_Refresh();
  1078. }
  1079. void showMonth(void) {
  1080. dispWDT = DISP_WDT_TIME;
  1081. IN15_OFF;
  1082. showDigit(Tube_A, 0xf);
  1083. showDigit(Tube_B, 0xf);
  1084. showDigit(Tube_D, Clock.Mon >> 4);
  1085. showDigit(Tube_E, Clock.Mon & 0xf);
  1086. tubes_Refresh();
  1087. }
  1088. void showDayMon(void) {
  1089. dispWDT = DISP_WDT_TIME;
  1090. IN15_OFF;
  1091. showDigit(Tube_A, Clock.Day >> 4);
  1092. showDigit(Tube_B, Clock.Day & 0xf);
  1093. showDigit(Tube_D, Clock.Mon >> 4);
  1094. showDigit(Tube_E, Clock.Mon & 0xf);
  1095. tubes_Refresh();
  1096. }
  1097. void showYear(void) {
  1098. dispWDT = DISP_WDT_TIME;
  1099. IN15_OFF;
  1100. showDigit(Tube_A, 2);
  1101. showDigit(Tube_B, 0);
  1102. showDigit(Tube_D, Clock.Year >> 4);
  1103. showDigit(Tube_E, Clock.Year & 0xf);
  1104. tubes_Refresh();
  1105. }
  1106. void showHumidity(void) {
  1107. dispWDT = DISP_WDT_TIME;
  1108. in15Percent();
  1109. showDigit(Tube_A, Humidity >> 4);
  1110. showDigit(Tube_B, Humidity & 0xf);
  1111. showDigit(Tube_D, 0xf);
  1112. showDigit(Tube_E, 0xf);
  1113. tubes_Refresh();
  1114. }
  1115. void showTemperature(void) {
  1116. dispWDT = DISP_WDT_TIME;
  1117. in15Plus();
  1118. showDigit(Tube_A, 0xf);
  1119. showDigit(Tube_B, 0xf);
  1120. showDigit(Tube_D, Temperature >> 4);
  1121. showDigit(Tube_E, Temperature & 0xf);
  1122. tubes_Refresh();
  1123. }
  1124. void showPressure(void) {
  1125. dispWDT = DISP_WDT_TIME;
  1126. in15P();
  1127. showDigit(Tube_A, 0xf);
  1128. showDigit(Tube_B, Pressure.s16.u8H & 0xf);
  1129. showDigit(Tube_D, Pressure.s16.u8L >> 4);
  1130. showDigit(Tube_E, Pressure.s16.u8L & 0xf);
  1131. tubes_Refresh();
  1132. }
  1133. /* Simple function for cyclic show all sensor data */
  1134. void showSensorData(void) {
  1135. ES_SetState(stShowSensorData);
  1136. showTemperature();
  1137. tdelay_ms(3000);
  1138. showHumidity();
  1139. tdelay_ms(3000);
  1140. showPressure();
  1141. tdelay_ms(3000);
  1142. ES_SetState(stShowTime);
  1143. showTime();
  1144. }
  1145. /* USER CODE END 4 */
  1146. /**
  1147. * @brief This function is executed in case of error occurrence.
  1148. * @retval None
  1149. */
  1150. void Error_Handler(void)
  1151. {
  1152. /* USER CODE BEGIN Error_Handler_Debug */
  1153. /* User can add his own implementation to report the HAL error return state */
  1154. __disable_irq();
  1155. while (1)
  1156. {
  1157. }
  1158. /* USER CODE END Error_Handler_Debug */
  1159. }
  1160. #ifdef USE_FULL_ASSERT
  1161. /**
  1162. * @brief Reports the name of the source file and the source line number
  1163. * where the assert_param error has occurred.
  1164. * @param file: pointer to the source file name
  1165. * @param line: assert_param error line source number
  1166. * @retval None
  1167. */
  1168. void assert_failed(uint8_t *file, uint32_t line)
  1169. {
  1170. /* USER CODE BEGIN 6 */
  1171. /* User can add his own implementation to report the file name and line number,
  1172. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  1173. /* USER CODE END 6 */
  1174. }
  1175. #endif /* USE_FULL_ASSERT */
  1176. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/