Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* USER CODE BEGIN Header */
- /**
- ******************************************************************************
- * @file : main.c
- * @brief : Main program body
- ******************************************************************************
- * @attention
- *
- * <h2><center>© Copyright (c) 2021 STMicroelectronics.
- * All rights reserved.</center></h2>
- *
- * This software component is licensed by ST under BSD 3-Clause license,
- * the "License"; You may not use this file except in compliance with the
- * License. You may obtain a copy of the License at:
- * opensource.org/licenses/BSD-3-Clause
- *
- ******************************************************************************
- */
- /* USER CODE END Header */
- /* Includes ------------------------------------------------------------------*/
- #include "main.h"
- /* Private includes ----------------------------------------------------------*/
- /* USER CODE BEGIN Includes */
- //main ex
- #include "platform/port.h"
- app_t app;
- //end of main ex
- #include <stdio.h>
- #include <string.h>
- #include "decadriver/deca_device_api.h"
- #include "decadriver/deca_regs.h"
- #include "platform/stdio.h"
- #include "platform/deca_spi.h"
- #include "platform/port.h"
- /* USER CODE END Includes */
- /* Private typedef -----------------------------------------------------------*/
- /* USER CODE BEGIN PTD */
- /* USER CODE END PTD */
- /* Private define ------------------------------------------------------------*/
- /* USER CODE BEGIN PD */
- /* Example application name and version to display. */
- #define APP_NAME "SS TWR INIT v1.3\r\n"
- /* Inter-ranging delay period, in milliseconds. */
- #define RNG_DELAY_MS 1000
- /* Default antenna delay values for 64 MHz PRF. See NOTE 2 below. */
- #define TX_ANT_DLY 16505
- #define RX_ANT_DLY 16505
- /* UWB microsecond (uus) to device time unit (dtu, around 15.65 ps) conversion factor.
- * 1 uus = 512 / 499.2 µs and 1 µs = 499.2 * 128 dtu. */
- #define UUS_TO_DWT_TIME 65536
- /* Delay between frames, in UWB microseconds. See NOTE 1 below. */
- #define POLL_TX_TO_RESP_RX_DLY_UUS 140
- /* Receive response timeout. See NOTE 5 below. */
- #define RESP_RX_TIMEOUT_UUS 210
- /* Speed of light in air, in metres per second. */
- #define SPEED_OF_LIGHT 299702547
- /* USER CODE END PD */
- /* Private macro -------------------------------------------------------------*/
- /* USER CODE BEGIN PM */
- /* USER CODE END PM */
- /* Private variables ---------------------------------------------------------*/
- SPI_HandleTypeDef hspi1;
- TIM_HandleTypeDef htim1;
- UART_HandleTypeDef huart2;
- /* USER CODE BEGIN PV */
- /* Default communication configuration. We use here EVK1000's mode 4. See NOTE 1 below. */
- static dwt_config_t config = {
- 5, /* Channel number. */
- DWT_PRF_64M, /* Pulse repetition frequency. */
- DWT_PLEN_128, /* Preamble length. Used in TX only. */
- DWT_PAC8, /* Preamble acquisition chunk size. Used in RX only. */
- 9, /* TX preamble code. Used in TX only. */
- 9, /* RX preamble code. Used in RX only. */
- 0, /* 0 to use standard SFD, 1 to use non-standard SFD. */
- DWT_BR_6M8, /* Data rate. */
- DWT_PHRMODE_STD, /* PHY header mode. */
- (129 + 8 - 8) /* SFD timeout (preamble length + 1 + SFD length - PAC size). Used in RX only. */
- };
- /* Frames used in the ranging process. See NOTE 3 below. */
- static uint8 tx_poll_msg[] = {0x41, 0x88, 0, 0xCA, 0xDE, 'W', 'A', 'V', 'E', 0xE0, 0, 0};
- static uint8 rx_resp_msg[] = {0x41, 0x88, 0, 0xCA, 0xDE, 'V', 'E', 'W', 'A', 0xE1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- /* Length of the common part of the message (up to and including the function code, see NOTE 3 below). */
- #define ALL_MSG_COMMON_LEN 10
- /* Indexes to access some of the fields in the frames defined above. */
- #define ALL_MSG_SN_IDX 2
- #define RESP_MSG_POLL_RX_TS_IDX 10
- #define RESP_MSG_RESP_TX_TS_IDX 14
- #define RESP_MSG_TS_LEN 4
- /* Frame sequence number, incremented after each transmission. */
- static uint8 frame_seq_nb = 0;
- /* Buffer to store received response message.
- * Its size is adjusted to longest frame that this example code is supposed to handle. */
- #define RX_BUF_LEN 20
- static uint8 rx_buffer[RX_BUF_LEN];
- /* Hold copy of status register state here for reference so that it can be examined at a debug breakpoint. */
- static uint32 status_reg = 0;
- /* Hold copies of computed time of flight and distance here for reference so that it can be examined at a debug breakpoint. */
- static double tof;
- static double distance;
- /* String used to display measured distance over UART. */
- char dist_str[16] = {0};
- /* Declaration of static functions. */
- static void resp_msg_get_ts(uint8 *ts_field, uint32 *ts);
- uint8_t xtaltrim;
- /* USER CODE END PV */
- /* Private function prototypes -----------------------------------------------*/
- void SystemClock_Config(void);
- static void MX_GPIO_Init(void);
- static void MX_USART2_UART_Init(void);
- static void MX_SPI1_Init(void);
- static void MX_TIM1_Init(void);
- /* USER CODE BEGIN PFP */
- /* USER CODE END PFP */
- /* Private user code ---------------------------------------------------------*/
- /* USER CODE BEGIN 0 */
- /* USER CODE END 0 */
- /**
- * @brief The application entry point.
- * @retval int
- */
- int main(void)
- {
- /* USER CODE BEGIN 1 */
- /* USER CODE END 1 */
- /* MCU Configuration--------------------------------------------------------*/
- /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
- HAL_Init();
- /* USER CODE BEGIN Init */
- /* USER CODE END Init */
- /* Configure the system clock */
- SystemClock_Config();
- /* USER CODE BEGIN SysInit */
- /* USER CODE END SysInit */
- /* Initialize all configured peripherals */
- MX_GPIO_Init();
- MX_USART2_UART_Init();
- MX_SPI1_Init();
- MX_TIM1_Init();
- /* USER CODE BEGIN 2 */
- setup_DW1000RSTnIRQ(0);
- stdio_init(&huart2);
- HAL_TIM_Base_Init(&htim1);
- /* Display application name. */
- stdio_write(APP_NAME);
- stdio_write("\033[s"); // Save cursor position
- /* Reset and initialise DW1000.
- * For initialisation, DW1000 clocks must be temporarily set to crystal speed. After initialisation SPI rate can be increased for optimum
- * performance. */
- reset_DW1000(); /* Target specific drive of RSTn line into DW1000 low for a period. */
- port_set_dw1000_slowrate();
- if (dwt_initialise(DWT_LOADUCODE) == DWT_ERROR)
- {
- stdio_write("INIT FAILED");
- while (1)
- { };
- }
- port_set_dw1000_fastrate();
- /* Configure DW1000. See NOTE 6 below. */
- dwt_configure(&config);
- /* Apply default antenna delay value. See NOTE 2 below. */
- dwt_setrxantennadelay(RX_ANT_DLY);
- dwt_settxantennadelay(TX_ANT_DLY);
- /* Set expected response's delay and timeout. See NOTE 1 and 5 below.
- * As this example only handles one incoming frame with always the same delay and timeout, those values can be set here once for all. */
- dwt_setrxaftertxdelay(POLL_TX_TO_RESP_RX_DLY_UUS);
- dwt_setrxtimeout(RESP_RX_TIMEOUT_UUS);
- // xtaltrim = dwt_getxtaltrim();
- // dwt_setxtaltrim(31);
- /* USER CODE END 2 */
- /* Infinite loop */
- /* USER CODE BEGIN WHILE */
- while (1)
- {
- /* Write frame data to DW1000 and prepare transmission. See NOTE 7 below. */
- tx_poll_msg[ALL_MSG_SN_IDX] = frame_seq_nb;
- dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_TXFRS);
- dwt_writetxdata(sizeof(tx_poll_msg), tx_poll_msg, 0); /* Zero offset in TX buffer. */
- dwt_writetxfctrl(sizeof(tx_poll_msg), 0, 1); /* Zero offset in TX buffer, ranging. */
- /* Start transmission, indicating that a response is expected so that reception is enabled automatically after the frame is sent and the delay
- * set by dwt_setrxaftertxdelay() has elapsed. */
- dwt_starttx(DWT_START_TX_IMMEDIATE | DWT_RESPONSE_EXPECTED);
- /* We assume that the transmission is achieved correctly, poll for reception of a frame or error/timeout. See NOTE 8 below. */
- while (!((status_reg = dwt_read32bitreg(SYS_STATUS_ID)) & (SYS_STATUS_RXFCG | SYS_STATUS_ALL_RX_TO | SYS_STATUS_ALL_RX_ERR)))
- { };
- /* Increment frame sequence number after transmission of the poll message (modulo 256). */
- frame_seq_nb++;
- if (status_reg & SYS_STATUS_RXFCG)
- {
- uint32 frame_len;
- /* Clear good RX frame event in the DW1000 status register. */
- dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_RXFCG);
- /* A frame has been received, read it into the local buffer. */
- frame_len = dwt_read32bitreg(RX_FINFO_ID) & RX_FINFO_RXFLEN_MASK;
- if (frame_len <= RX_BUF_LEN)
- {
- dwt_readrxdata(rx_buffer, frame_len, 0);
- }
- /* Check that the frame is the expected response from the companion "SS TWR responder" example.
- * As the sequence number field of the frame is not relevant, it is cleared to simplify the validation of the frame. */
- rx_buffer[ALL_MSG_SN_IDX] = 0;
- if (memcmp(rx_buffer, rx_resp_msg, ALL_MSG_COMMON_LEN) == 0)
- {
- uint32 poll_tx_ts, resp_rx_ts, poll_rx_ts, resp_tx_ts;
- int32 rtd_init, rtd_resp;
- float clockOffsetRatio ;
- /* Retrieve poll transmission and response reception timestamps. See NOTE 9 below. */
- poll_tx_ts = dwt_readtxtimestamplo32();
- resp_rx_ts = dwt_readrxtimestamplo32();
- /* Read carrier integrator value and calculate clock offset ratio. See NOTE 11 below. */
- clockOffsetRatio = dwt_readcarrierintegrator() * (FREQ_OFFSET_MULTIPLIER * HERTZ_TO_PPM_MULTIPLIER_CHAN_2 / 1.0e6) ;
- /* Get timestamps embedded in response message. */
- resp_msg_get_ts(&rx_buffer[RESP_MSG_POLL_RX_TS_IDX], &poll_rx_ts);
- resp_msg_get_ts(&rx_buffer[RESP_MSG_RESP_TX_TS_IDX], &resp_tx_ts);
- /* Compute time of flight and distance, using clock offset ratio to correct for differing local and remote clock rates */
- rtd_init = resp_rx_ts - poll_tx_ts;
- rtd_resp = resp_tx_ts - poll_rx_ts;
- tof = ((rtd_init - rtd_resp * (1 - clockOffsetRatio)) / 2.0) * DWT_TIME_UNITS;
- distance = tof * SPEED_OF_LIGHT;
- /* Display computed distance. */
- sprintf(dist_str, "DIST: %3.2f m", distance);
- stdio_write(dist_str);
- stdio_write("\033[u"); // Restore last cursor position
- }
- }
- else
- {
- /* Clear RX error/timeout events in the DW1000 status register. */
- dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_ALL_RX_TO | SYS_STATUS_ALL_RX_ERR);
- /* Reset RX to properly reinitialise LDE operation. */
- dwt_rxreset();
- }
- /* Execute a delay between ranging exchanges. */
- Sleep(RNG_DELAY_MS);
- /* USER CODE END WHILE */
- /* USER CODE BEGIN 3 */
- }
- /* USER CODE END 3 */
- }
- /**
- * @brief System Clock Configuration
- * @retval None
- */
- void SystemClock_Config(void)
- {
- RCC_OscInitTypeDef RCC_OscInitStruct = {0};
- RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
- RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
- /** Initializes the RCC Oscillators according to the specified parameters
- * in the RCC_OscInitTypeDef structure.
- */
- RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
- RCC_OscInitStruct.HSIState = RCC_HSI_ON;
- RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
- RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
- RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
- RCC_OscInitStruct.PLL.PLLM = 1;
- RCC_OscInitStruct.PLL.PLLN = 10;
- RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV7;
- RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
- RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
- if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
- {
- Error_Handler();
- }
- /** Initializes the CPU, AHB and APB buses clocks
- */
- RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
- |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
- RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
- RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
- RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
- RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
- if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
- {
- Error_Handler();
- }
- PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART2;
- PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;
- if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
- {
- Error_Handler();
- }
- /** Configure the main internal regulator output voltage
- */
- if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)
- {
- Error_Handler();
- }
- }
- /**
- * @brief SPI1 Initialization Function
- * @param None
- * @retval None
- */
- static void MX_SPI1_Init(void)
- {
- /* USER CODE BEGIN SPI1_Init 0 */
- /* USER CODE END SPI1_Init 0 */
- /* USER CODE BEGIN SPI1_Init 1 */
- /* USER CODE END SPI1_Init 1 */
- /* SPI1 parameter configuration*/
- hspi1.Instance = SPI1;
- hspi1.Init.Mode = SPI_MODE_MASTER;
- hspi1.Init.Direction = SPI_DIRECTION_2LINES;
- hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
- hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
- hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
- hspi1.Init.NSS = SPI_NSS_SOFT;
- hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32;
- hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
- hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
- hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
- hspi1.Init.CRCPolynomial = 7;
- hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
- hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
- if (HAL_SPI_Init(&hspi1) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE BEGIN SPI1_Init 2 */
- /* USER CODE END SPI1_Init 2 */
- }
- /**
- * @brief TIM1 Initialization Function
- * @param None
- * @retval None
- */
- static void MX_TIM1_Init(void)
- {
- /* USER CODE BEGIN TIM1_Init 0 */
- /* USER CODE END TIM1_Init 0 */
- TIM_SlaveConfigTypeDef sSlaveConfig = {0};
- TIM_MasterConfigTypeDef sMasterConfig = {0};
- TIM_OC_InitTypeDef sConfigOC = {0};
- TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0};
- /* USER CODE BEGIN TIM1_Init 1 */
- /* USER CODE END TIM1_Init 1 */
- htim1.Instance = TIM1;
- htim1.Init.Prescaler = 0;
- htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
- htim1.Init.Period = 65535;
- htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
- htim1.Init.RepetitionCounter = 0;
- htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
- if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
- {
- Error_Handler();
- }
- if (HAL_TIM_OC_Init(&htim1) != HAL_OK)
- {
- Error_Handler();
- }
- sSlaveConfig.SlaveMode = TIM_SLAVEMODE_TRIGGER;
- sSlaveConfig.InputTrigger = TIM_TS_ITR0;
- if (HAL_TIM_SlaveConfigSynchro(&htim1, &sSlaveConfig) != HAL_OK)
- {
- Error_Handler();
- }
- sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
- sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET;
- sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
- if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
- {
- Error_Handler();
- }
- sConfigOC.OCMode = TIM_OCMODE_TIMING;
- sConfigOC.Pulse = 0;
- sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
- sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
- sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
- sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
- sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
- if (HAL_TIM_OC_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
- {
- Error_Handler();
- }
- sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;
- sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;
- sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;
- sBreakDeadTimeConfig.DeadTime = 0;
- sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;
- sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
- sBreakDeadTimeConfig.BreakFilter = 0;
- sBreakDeadTimeConfig.Break2State = TIM_BREAK2_DISABLE;
- sBreakDeadTimeConfig.Break2Polarity = TIM_BREAK2POLARITY_HIGH;
- sBreakDeadTimeConfig.Break2Filter = 0;
- sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
- if (HAL_TIMEx_ConfigBreakDeadTime(&htim1, &sBreakDeadTimeConfig) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE BEGIN TIM1_Init 2 */
- /* USER CODE END TIM1_Init 2 */
- HAL_TIM_MspPostInit(&htim1);
- }
- /**
- * @brief USART2 Initialization Function
- * @param None
- * @retval None
- */
- static void MX_USART2_UART_Init(void)
- {
- /* USER CODE BEGIN USART2_Init 0 */
- /* USER CODE END USART2_Init 0 */
- /* USER CODE BEGIN USART2_Init 1 */
- /* USER CODE END USART2_Init 1 */
- huart2.Instance = USART2;
- huart2.Init.BaudRate = 115200;
- huart2.Init.WordLength = UART_WORDLENGTH_8B;
- huart2.Init.StopBits = UART_STOPBITS_1;
- huart2.Init.Parity = UART_PARITY_NONE;
- huart2.Init.Mode = UART_MODE_TX_RX;
- huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
- huart2.Init.OverSampling = UART_OVERSAMPLING_16;
- huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
- huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
- if (HAL_UART_Init(&huart2) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE BEGIN USART2_Init 2 */
- /* USER CODE END USART2_Init 2 */
- }
- /**
- * @brief GPIO Initialization Function
- * @param None
- * @retval None
- */
- static void MX_GPIO_Init(void)
- {
- GPIO_InitTypeDef GPIO_InitStruct = {0};
- /* GPIO Ports Clock Enable */
- __HAL_RCC_GPIOC_CLK_ENABLE();
- __HAL_RCC_GPIOH_CLK_ENABLE();
- __HAL_RCC_GPIOA_CLK_ENABLE();
- __HAL_RCC_GPIOB_CLK_ENABLE();
- /*Configure GPIO pin Output Level */
- HAL_GPIO_WritePin(GPIOA, SMPS_EN_Pin|SMPS_V1_Pin|SMPS_SW_Pin|DW_RESET_Pin, GPIO_PIN_RESET);
- /*Configure GPIO pin Output Level */
- HAL_GPIO_WritePin(LD4_GPIO_Port, LD4_Pin, GPIO_PIN_RESET);
- /*Configure GPIO pin Output Level */
- HAL_GPIO_WritePin(DW_NSS_GPIO_Port, DW_NSS_Pin, GPIO_PIN_SET);
- /*Configure GPIO pin : B1_Pin */
- GPIO_InitStruct.Pin = B1_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct);
- /*Configure GPIO pins : SMPS_EN_Pin SMPS_V1_Pin SMPS_SW_Pin DW_NSS_Pin */
- GPIO_InitStruct.Pin = SMPS_EN_Pin|SMPS_V1_Pin|SMPS_SW_Pin|DW_NSS_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
- /*Configure GPIO pin : SMPS_PG_Pin */
- GPIO_InitStruct.Pin = SMPS_PG_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
- GPIO_InitStruct.Pull = GPIO_PULLUP;
- HAL_GPIO_Init(SMPS_PG_GPIO_Port, &GPIO_InitStruct);
- /*Configure GPIO pin : LD4_Pin */
- GPIO_InitStruct.Pin = LD4_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- HAL_GPIO_Init(LD4_GPIO_Port, &GPIO_InitStruct);
- /*Configure GPIO pin : DW_RESET_Pin */
- GPIO_InitStruct.Pin = DW_RESET_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- HAL_GPIO_Init(DW_RESET_GPIO_Port, &GPIO_InitStruct);
- /*Configure GPIO pin : DW_IRQn_Pin */
- GPIO_InitStruct.Pin = DW_IRQn_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
- GPIO_InitStruct.Pull = GPIO_PULLDOWN;
- HAL_GPIO_Init(DW_IRQn_GPIO_Port, &GPIO_InitStruct);
- /* EXTI interrupt init*/
- HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0);
- HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
- }
- /* USER CODE BEGIN 4 */
- static void resp_msg_get_ts(uint8 *ts_field, uint32 *ts)
- {
- int i;
- *ts = 0;
- for (i = 0; i < RESP_MSG_TS_LEN; i++)
- {
- *ts += ts_field[i] << (i * 8);
- }
- }
- /* USER CODE END 4 */
- /**
- * @brief This function is executed in case of error occurrence.
- * @retval None
- */
- void Error_Handler(void)
- {
- /* USER CODE BEGIN Error_Handler_Debug */
- /* User can add his own implementation to report the HAL error return state */
- __disable_irq();
- while (1)
- {
- }
- /* USER CODE END Error_Handler_Debug */
- }
- #ifdef USE_FULL_ASSERT
- /**
- * @brief Reports the name of the source file and the source line number
- * where the assert_param error has occurred.
- * @param file: pointer to the source file name
- * @param line: assert_param error line source number
- * @retval None
- */
- void assert_failed(uint8_t *file, uint32_t line)
- {
- /* USER CODE BEGIN 6 */
- /* User can add his own implementation to report the file name and line number,
- ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
- /* USER CODE END 6 */
- }
- #endif /* USE_FULL_ASSERT */
- /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement