mirror of
https://github.com/aprochazka/ProfilometerProbe.git
synced 2025-06-30 17:47:20 +02:00
Push local changes for complete and functioning probe
This commit is contained in:
@ -3,15 +3,11 @@
|
||||
******************************************************************************
|
||||
* @file : main.c
|
||||
* @brief : Main program body
|
||||
* @author : Adam Prochazka <xproch0f>
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2023 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
* Code outside of "USER CODE" blocks was generated by STM32CubeMX by STMicroelectronics and was not written by the author.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@ -40,23 +36,22 @@
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
I2C_HandleTypeDef hi2c1;
|
||||
|
||||
SPI_HandleTypeDef hspi1;
|
||||
DMA_HandleTypeDef hdma_spi1_rx;
|
||||
DMA_HandleTypeDef hdma_spi1_tx;
|
||||
|
||||
UART_HandleTypeDef huart2;
|
||||
TIM_HandleTypeDef htim15;
|
||||
|
||||
PCD_HandleTypeDef hpcd_USB_FS;
|
||||
|
||||
uint16_t dev=0x52;
|
||||
/* USER CODE BEGIN PV */
|
||||
|
||||
uint16_t DistSensorAddr=0x52;
|
||||
int status=0;
|
||||
volatile int IntCount;
|
||||
#define isInterrupt 1 /* If isInterrupt = 1 then device working in interrupt mode, else device working in polling mode */
|
||||
|
||||
/* USER CODE BEGIN PV */
|
||||
//DAC_HandleTypeDef hdac1;
|
||||
|
||||
//TIM_HandleTypeDef htim15;
|
||||
#define isInterrupt 0 /* If isInterrupt = 1 then device working in interrupt mode, else device working in polling mode */
|
||||
|
||||
int SPI_Rx_Done_Flag = 0;
|
||||
/* USER CODE END PV */
|
||||
@ -65,14 +60,12 @@ int SPI_Rx_Done_Flag = 0;
|
||||
void SystemClock_Config(void);
|
||||
static void MX_GPIO_Init(void);
|
||||
static void MX_DMA_Init(void);
|
||||
static void MX_USART2_UART_Init(void);
|
||||
static void MX_SPI1_Init(void);
|
||||
static void MX_I2C1_Init(void);
|
||||
static void MX_USB_PCD_Init(void);
|
||||
static void MX_TIM15_Init(void);
|
||||
/* USER CODE BEGIN PFP */
|
||||
|
||||
//static void MX_DAC1_Init(void);
|
||||
//static void MX_TIM15_Init(void);
|
||||
/* USER CODE END PFP */
|
||||
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
@ -86,15 +79,12 @@ static void MX_USB_PCD_Init(void);
|
||||
int main(void)
|
||||
{
|
||||
/* USER CODE BEGIN 1 */
|
||||
//uint8_t byteData, sensorState=0;
|
||||
//uint16_t wordData;
|
||||
//uint8_t ToFSensor = 1; // 0=Left, 1=Center(default), 2=Right
|
||||
|
||||
uint16_t Distance = 0;
|
||||
uint16_t SignalRate;
|
||||
uint16_t AmbientRate;
|
||||
uint16_t SpadNum;
|
||||
uint8_t RangeStatus;
|
||||
//uint8_t dataReady;
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
@ -118,50 +108,58 @@ int main(void)
|
||||
/* Initialize all configured peripherals */
|
||||
MX_GPIO_Init();
|
||||
MX_DMA_Init();
|
||||
MX_USART2_UART_Init();
|
||||
MX_SPI1_Init();
|
||||
MX_I2C1_Init();
|
||||
MX_USB_PCD_Init();
|
||||
MX_TIM15_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
HAL_PWREx_EnableVddUSB();
|
||||
HAL_Delay(100);
|
||||
|
||||
//ToFSensor = 1; // Select ToFSensor: 0=Left, 1=Center, 2=Right
|
||||
|
||||
status = VL53L1X_SensorInit(dev);
|
||||
status = VL53L1X_SetDistanceMode(dev, 2);
|
||||
status = VL53L1X_SetTimingBudgetInMs(dev, 100);
|
||||
status = VL53L1X_SetInterMeasurementInMs(dev, 100);
|
||||
status = VL53L1X_StartRanging(dev);
|
||||
|
||||
HAL_Delay(1000);
|
||||
|
||||
status = VL53L1X_GetRangeStatus(dev, &RangeStatus);
|
||||
status = VL53L1X_GetDistance(dev, &Distance);
|
||||
status = VL53L1X_GetSignalRate(dev, &SignalRate);
|
||||
status = VL53L1X_GetAmbientRate(dev, &AmbientRate);
|
||||
status = VL53L1X_GetSpadNb(dev, &SpadNum);
|
||||
status = VL53L1X_ClearInterrupt(dev);
|
||||
|
||||
// Signalize user that device has started
|
||||
LED_On();
|
||||
|
||||
HAL_Delay(1);
|
||||
// Enable power to USB, without TinyUSB will not initialize
|
||||
HAL_PWREx_EnableVddUSB();
|
||||
// Wait for power to stabilize
|
||||
HAL_Delay(100);
|
||||
|
||||
// Initialize distance sensor
|
||||
status = VL53L1X_SensorInit(DistSensorAddr);
|
||||
|
||||
// Set distance mode of distance sensor for long distance (2)
|
||||
status = VL53L1X_SetDistanceMode(DistSensorAddr, 2);
|
||||
|
||||
// Set timing budget for each measurement
|
||||
status = VL53L1X_SetTimingBudgetInMs(DistSensorAddr, 100);
|
||||
status = VL53L1X_SetInterMeasurementInMs(DistSensorAddr, 100);
|
||||
|
||||
// Start first measurement to wake sensor up
|
||||
status = VL53L1X_StartRanging(DistSensorAddr);
|
||||
|
||||
|
||||
HAL_Delay(1000);
|
||||
|
||||
// Initialize TinyUSB
|
||||
tud_init(BOARD_DEVICE_RHPORT_NUM);
|
||||
|
||||
HAL_Delay(10);
|
||||
SPI_Init(&hspi1);
|
||||
|
||||
// USB utility function
|
||||
tud_task();
|
||||
|
||||
// Define variables for correct frame sending and capturing
|
||||
int last_sent_idx = 0;
|
||||
int buff_stop_idx = 0;
|
||||
uint16_t image_size = 0;
|
||||
uint8_t cdc_buff[CDC_BUFF_SIZE+CDC_FRAME_SIZE];
|
||||
for(int i = 0; i < (CDC_BUFF_SIZE+CDC_FRAME_SIZE); i++) cdc_buff[i] = 0x00;
|
||||
for(int i = 0; i < (CDC_BUFF_SIZE+CDC_FRAME_SIZE); i++) cdc_buff[i] = 0x00; // Clear frame buffer
|
||||
|
||||
//Distance_Sensor_Init(&hi2c1);
|
||||
int Laser_LED_Switch = 0; // Variable for switching between LASER and LED
|
||||
|
||||
// Initial states of LED and LASER (LED off, LASER on)
|
||||
HAL_GPIO_WritePin(VSET_LED_GPIO_Port, VSET_LED_Pin, GPIO_PIN_RESET);
|
||||
HAL_TIM_PWM_Start(&htim15, TIM_CHANNEL_1);
|
||||
|
||||
// Initialize camera module
|
||||
Cam_Init(&hi2c1, &hspi1);
|
||||
|
||||
/* USER CODE END 2 */
|
||||
@ -170,41 +168,53 @@ int main(void)
|
||||
/* USER CODE BEGIN WHILE */
|
||||
while (1)
|
||||
{
|
||||
// USB utility function
|
||||
tud_task();
|
||||
|
||||
// If there wasn't any image captured yet or the last one was sent out completely
|
||||
if(buff_stop_idx >= (int)image_size){
|
||||
|
||||
LED_Off();
|
||||
|
||||
// Reset variables responsible for sending correct amount of received image
|
||||
buff_stop_idx = 0;
|
||||
last_sent_idx = 0;
|
||||
|
||||
//for(int i = 0; i < CDC_BUFF_SIZE; i++) cdc_buff[i] = 0x00;
|
||||
|
||||
VL53L1X_GetDistance(dev, &Distance);
|
||||
HAL_Delay(2);
|
||||
VL53L1X_ClearInterrupt(dev);
|
||||
// Get current distance of probe inside the barrel
|
||||
VL53L1X_GetDistance(DistSensorAddr, &Distance);
|
||||
|
||||
CS_Off();
|
||||
CS_On();
|
||||
|
||||
// Start capturing frame and wait until it is done capturing
|
||||
Cam_Capture(&hspi1);
|
||||
|
||||
// Switch between LASER and LED, so the optical output power of diodes has time to stabilize until next capture
|
||||
if(Laser_LED_Switch == 1){
|
||||
Laser_LED_Switch = 0;
|
||||
__HAL_TIM_SET_COMPARE(&htim15, TIM_CHANNEL_1, 40);
|
||||
HAL_GPIO_WritePin(VSET_LED_GPIO_Port, VSET_LED_Pin, GPIO_PIN_RESET);
|
||||
}
|
||||
else{
|
||||
Laser_LED_Switch = 1;
|
||||
__HAL_TIM_SET_COMPARE(&htim15, TIM_CHANNEL_1, 0);
|
||||
HAL_GPIO_WritePin(VSET_LED_GPIO_Port, VSET_LED_Pin, GPIO_PIN_SET);
|
||||
}
|
||||
|
||||
// Get size of captured image, so that correct number of bytec can be read from camera and sent out
|
||||
image_size = Cam_FIFO_length(&hspi1);
|
||||
|
||||
// Activate burst read out mode of camera module (no need for requesting each byte individually)
|
||||
Cam_Start_Burst_Read(&hspi1);
|
||||
|
||||
//getDistance(&hi2c1);
|
||||
|
||||
LED_On();
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
else {
|
||||
LED_Off();
|
||||
|
||||
// Image has not been completely sent out
|
||||
else {
|
||||
|
||||
// Variable to save number of bytes that should be read from camera module
|
||||
int number_to_read = 0;
|
||||
//for(int i = 0; i < CDC_BUFF_SIZE; i++) cdc_buff[i] = 0x00;
|
||||
|
||||
// Determine how many bytes should be read from camera module - Is remaining image data to be read larger or smaller than framebuffer?
|
||||
if((buff_stop_idx + CDC_BUFF_SIZE) > (int) image_size){
|
||||
number_to_read = (int) image_size - buff_stop_idx;
|
||||
}
|
||||
@ -212,35 +222,58 @@ int main(void)
|
||||
number_to_read = CDC_BUFF_SIZE;
|
||||
}
|
||||
|
||||
// Read determined amount of bytes from camera in blocking mode
|
||||
HAL_SPI_Receive(&hspi1, cdc_buff, number_to_read, HAL_MAX_DELAY);
|
||||
|
||||
// Increment index of already read buffer data
|
||||
buff_stop_idx = buff_stop_idx + number_to_read;
|
||||
|
||||
LED_On();
|
||||
}
|
||||
|
||||
// Variable to store how many bytes were sent during this iteration
|
||||
int current_sending_idx = 0;
|
||||
|
||||
// Inform user that image data transfer started
|
||||
LED_On();
|
||||
|
||||
// Loop to send all image data inside cdc_buff in small CDC chunks
|
||||
do{
|
||||
|
||||
// USB utility function - has to be called between each cdc_write_flush()
|
||||
tud_task();
|
||||
|
||||
// How many bytes should be send in current CDC block
|
||||
int sendLen = CDC_FRAME_SIZE;
|
||||
if(last_sent_idx + CDC_FRAME_SIZE > buff_stop_idx){
|
||||
sendLen = buff_stop_idx - last_sent_idx;
|
||||
}
|
||||
|
||||
// Select bytes, that will be send during next CDC transfer
|
||||
tud_cdc_write(&cdc_buff[current_sending_idx], sendLen);
|
||||
|
||||
// Increment index of data to be sent for next loop iteration
|
||||
current_sending_idx = current_sending_idx + sendLen;
|
||||
last_sent_idx = last_sent_idx + sendLen;
|
||||
|
||||
// Transfer selected data through CDC
|
||||
tud_cdc_write_flush();
|
||||
//Delay between sends
|
||||
|
||||
//Delay between sends - necessary for USB synchronization
|
||||
int i = 0;
|
||||
for(;i<4000;i++);
|
||||
}
|
||||
// Repeat until all data from buffer has been sent
|
||||
while(last_sent_idx < buff_stop_idx);
|
||||
|
||||
|
||||
// If whole image has been sent, send distance data of where image was captured
|
||||
if(buff_stop_idx >= (int)image_size){
|
||||
HAL_Delay(100);
|
||||
|
||||
// Delay for synchronization
|
||||
HAL_Delay(20);
|
||||
|
||||
// USB utility function - has to be called, because it wasnt called after last tud_cdc_write_flush()
|
||||
tud_task();
|
||||
|
||||
// Format distance data between predefined header and footer, for clear decoding by receiver
|
||||
uint8_t distance_buff[12];
|
||||
distance_buff[0] = 0xff;
|
||||
distance_buff[1] = 0xff;
|
||||
@ -255,12 +288,26 @@ int main(void)
|
||||
distance_buff[10] = '\n';
|
||||
distance_buff[11] = '\r';
|
||||
|
||||
|
||||
// Prepare to send formatted distance data of image through CDC
|
||||
tud_cdc_write(&distance_buff[0], 12);
|
||||
|
||||
// Necessary delay for synchronization
|
||||
HAL_Delay(1);
|
||||
|
||||
// Transfer prepared Distance data through CDC
|
||||
tud_cdc_write_flush();
|
||||
|
||||
// Necessary delay for synchronization
|
||||
HAL_Delay(1);
|
||||
|
||||
// USB utility function - after write_flush()
|
||||
tud_task();
|
||||
}
|
||||
|
||||
// Inform user that transfer has been completed
|
||||
LED_Off();
|
||||
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
@ -407,37 +454,77 @@ static void MX_SPI1_Init(void)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USART2 Initialization Function
|
||||
* @brief TIM15 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_USART2_UART_Init(void)
|
||||
static void MX_TIM15_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN USART2_Init 0 */
|
||||
/* USER CODE BEGIN TIM15_Init 0 */
|
||||
|
||||
/* USER CODE END USART2_Init 0 */
|
||||
/* USER CODE END TIM15_Init 0 */
|
||||
|
||||
/* USER CODE BEGIN USART2_Init 1 */
|
||||
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
||||
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
||||
TIM_OC_InitTypeDef sConfigOC = {0};
|
||||
TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0};
|
||||
|
||||
/* 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)
|
||||
/* USER CODE BEGIN TIM15_Init 1 */
|
||||
|
||||
/* USER CODE END TIM15_Init 1 */
|
||||
htim15.Instance = TIM15;
|
||||
htim15.Init.Prescaler = 40;
|
||||
htim15.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim15.Init.Period = 1000;
|
||||
htim15.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
htim15.Init.RepetitionCounter = 0;
|
||||
htim15.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
if (HAL_TIM_Base_Init(&htim15) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN USART2_Init 2 */
|
||||
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||
if (HAL_TIM_ConfigClockSource(&htim15, &sClockSourceConfig) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
if (HAL_TIM_PWM_Init(&htim15) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||
if (HAL_TIMEx_MasterConfigSynchronization(&htim15, &sMasterConfig) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
||||
sConfigOC.Pulse = 500;
|
||||
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_PWM_ConfigChannel(&htim15, &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.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
|
||||
if (HAL_TIMEx_ConfigBreakDeadTime(&htim15, &sBreakDeadTimeConfig) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN TIM15_Init 2 */
|
||||
|
||||
/* USER CODE END USART2_Init 2 */
|
||||
/* USER CODE END TIM15_Init 2 */
|
||||
HAL_TIM_MspPostInit(&htim15);
|
||||
|
||||
}
|
||||
|
||||
@ -508,17 +595,17 @@ static void MX_GPIO_Init(void)
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(DEBUG_LED_GPIO_Port, DEBUG_LED_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(GPIOA, DEBUG_LED_Pin|VSET_LED_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOB, CHIP_SELECT_Pin|LD3_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin : DEBUG_LED_Pin */
|
||||
GPIO_InitStruct.Pin = DEBUG_LED_Pin;
|
||||
/*Configure GPIO pins : DEBUG_LED_Pin VSET_LED_Pin */
|
||||
GPIO_InitStruct.Pin = DEBUG_LED_Pin|VSET_LED_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(DEBUG_LED_GPIO_Port, &GPIO_InitStruct);
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : CHIP_SELECT_Pin LD3_Pin */
|
||||
GPIO_InitStruct.Pin = CHIP_SELECT_Pin|LD3_Pin;
|
||||
@ -535,11 +622,6 @@ void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi)
|
||||
SPI_Rx_Done_Flag = 1;
|
||||
}
|
||||
|
||||
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
|
||||
{
|
||||
// do nothing here
|
||||
}
|
||||
|
||||
/* USER CODE END 4 */
|
||||
|
||||
/**
|
||||
|
@ -60,7 +60,9 @@ extern DMA_HandleTypeDef hdma_spi1_tx;
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
/**
|
||||
|
||||
void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
|
||||
/**
|
||||
* Initializes the Global MSP.
|
||||
*/
|
||||
void HAL_MspInit(void)
|
||||
@ -268,89 +270,71 @@ void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief UART MSP Initialization
|
||||
* @brief TIM_Base MSP Initialization
|
||||
* This function configures the hardware resources used in this example
|
||||
* @param huart: UART handle pointer
|
||||
* @param htim_base: TIM_Base handle pointer
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_UART_MspInit(UART_HandleTypeDef* huart)
|
||||
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
|
||||
if(huart->Instance==USART2)
|
||||
if(htim_base->Instance==TIM15)
|
||||
{
|
||||
/* USER CODE BEGIN USART2_MspInit 0 */
|
||||
|
||||
/* USER CODE END USART2_MspInit 0 */
|
||||
|
||||
/** Initializes the peripherals clock
|
||||
*/
|
||||
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART2;
|
||||
PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;
|
||||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN TIM15_MspInit 0 */
|
||||
|
||||
/* USER CODE END TIM15_MspInit 0 */
|
||||
/* Peripheral clock enable */
|
||||
__HAL_RCC_USART2_CLK_ENABLE();
|
||||
__HAL_RCC_TIM15_CLK_ENABLE();
|
||||
/* USER CODE BEGIN TIM15_MspInit 1 */
|
||||
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
/**USART2 GPIO Configuration
|
||||
PA2 ------> USART2_TX
|
||||
PA15 (JTDI) ------> USART2_RX
|
||||
*/
|
||||
GPIO_InitStruct.Pin = VCP_TX_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
|
||||
HAL_GPIO_Init(VCP_TX_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = VCP_RX_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF3_USART2;
|
||||
HAL_GPIO_Init(VCP_RX_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/* USART2 interrupt Init */
|
||||
HAL_NVIC_SetPriority(USART2_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(USART2_IRQn);
|
||||
/* USER CODE BEGIN USART2_MspInit 1 */
|
||||
|
||||
/* USER CODE END USART2_MspInit 1 */
|
||||
/* USER CODE END TIM15_MspInit 1 */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
if(htim->Instance==TIM15)
|
||||
{
|
||||
/* USER CODE BEGIN TIM15_MspPostInit 0 */
|
||||
|
||||
/* USER CODE END TIM15_MspPostInit 0 */
|
||||
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
/**TIM15 GPIO Configuration
|
||||
PA2 ------> TIM15_CH1
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_2;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF14_TIM15;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/* USER CODE BEGIN TIM15_MspPostInit 1 */
|
||||
|
||||
/* USER CODE END TIM15_MspPostInit 1 */
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* @brief UART MSP De-Initialization
|
||||
* @brief TIM_Base MSP De-Initialization
|
||||
* This function freeze the hardware resources used in this example
|
||||
* @param huart: UART handle pointer
|
||||
* @param htim_base: TIM_Base handle pointer
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
|
||||
void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
|
||||
{
|
||||
if(huart->Instance==USART2)
|
||||
if(htim_base->Instance==TIM15)
|
||||
{
|
||||
/* USER CODE BEGIN USART2_MspDeInit 0 */
|
||||
/* USER CODE BEGIN TIM15_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END USART2_MspDeInit 0 */
|
||||
/* USER CODE END TIM15_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_USART2_CLK_DISABLE();
|
||||
__HAL_RCC_TIM15_CLK_DISABLE();
|
||||
/* USER CODE BEGIN TIM15_MspDeInit 1 */
|
||||
|
||||
/**USART2 GPIO Configuration
|
||||
PA2 ------> USART2_TX
|
||||
PA15 (JTDI) ------> USART2_RX
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOA, VCP_TX_Pin|VCP_RX_Pin);
|
||||
|
||||
/* USART2 interrupt DeInit */
|
||||
HAL_NVIC_DisableIRQ(USART2_IRQn);
|
||||
/* USER CODE BEGIN USART2_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END USART2_MspDeInit 1 */
|
||||
/* USER CODE END TIM15_MspDeInit 1 */
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -58,7 +58,6 @@
|
||||
extern DMA_HandleTypeDef hdma_spi1_rx;
|
||||
extern DMA_HandleTypeDef hdma_spi1_tx;
|
||||
extern SPI_HandleTypeDef hspi1;
|
||||
extern UART_HandleTypeDef huart2;
|
||||
extern PCD_HandleTypeDef hpcd_USB_FS;
|
||||
/* USER CODE BEGIN EV */
|
||||
|
||||
@ -244,20 +243,6 @@ void SPI1_IRQHandler(void)
|
||||
/* USER CODE END SPI1_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles USART2 global interrupt.
|
||||
*/
|
||||
void USART2_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN USART2_IRQn 0 */
|
||||
|
||||
/* USER CODE END USART2_IRQn 0 */
|
||||
HAL_UART_IRQHandler(&huart2);
|
||||
/* USER CODE BEGIN USART2_IRQn 1 */
|
||||
|
||||
/* USER CODE END USART2_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles USB event interrupt through EXTI line 17.
|
||||
*/
|
||||
|
@ -1,4 +1,15 @@
|
||||
/*
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : usb_descriptors.c
|
||||
* @brief : Descriptors of usb communication.
|
||||
* @author : Adam Prochazka <xproch0f>
|
||||
******************************************************************************
|
||||
|
||||
* @attention
|
||||
*
|
||||
* File was from the large part taken from the TinyUSB repository and just slightly configured for projects usecase.
|
||||
* Original file contains this disclaimer:
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Ha Thach (tinyusb.org)
|
||||
@ -216,11 +227,11 @@ uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
|
||||
// array of pointer to string descriptors
|
||||
char const* string_desc_arr [] =
|
||||
{
|
||||
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
|
||||
"TinyUSB", // 1: Manufacturer
|
||||
"TinyUSB test STM32L432", // 2: Product
|
||||
"123456", // 3: Serials, should use chip ID
|
||||
"TinyUSB CDC", // 4: CDC Interface
|
||||
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
|
||||
"Adam Prochazka", // 1: Manufacturer
|
||||
"Profilometer Probe", // 2: Product
|
||||
"2023", // 3: Serials, should use chip ID
|
||||
"TinyUSB CDC", // 4: CDC Interface
|
||||
};
|
||||
|
||||
static uint16_t _desc_str[32];
|
||||
|
@ -1,5 +1,15 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : vl53l1_platform.c
|
||||
* @brief : Platform specific configuration of distance sencor communication.
|
||||
* @author : Adam Prochazka <xproch0f>
|
||||
******************************************************************************
|
||||
|
||||
/*
|
||||
* @attention
|
||||
* File was partly taken from the VL53L1 Platform and configured for NucleoL432KC platform.
|
||||
* Configuration consisted mainly of implementing basic I2C communication functions, that were specific for this project.
|
||||
* Original file contains this disclaimer:
|
||||
*
|
||||
* This file is part of VL53L1 Platform
|
||||
*
|
||||
* Copyright (c) 2016, STMicroelectronics - All Rights Reserved
|
||||
@ -36,7 +46,6 @@
|
||||
|
||||
#include "vl53l1_platform.h"
|
||||
#include "vl53l1_platform_log.h"
|
||||
//#include "vl53l1_api.h"
|
||||
#include "vl53l1_platform_user_config.h"
|
||||
#include "stm32xxx_hal.h"
|
||||
#include "main.h"
|
||||
@ -44,7 +53,6 @@
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
#include "vl53l1_error_codes.h"
|
||||
//#include "X-NUCLEO-53L1A1.h"
|
||||
|
||||
|
||||
#define I2C_TIME_OUT_BASE 10
|
||||
@ -78,25 +86,16 @@ uint8_t _I2CBuffer[256];
|
||||
|
||||
int _I2CWrite(uint16_t Dev, uint8_t *pdata, uint32_t count) {
|
||||
int status;
|
||||
//int i2c_time_out = I2C_TIME_OUT_BASE+ count* I2C_TIME_OUT_BYTE;
|
||||
|
||||
status = HAL_I2C_Master_Transmit(&hi2c1, Dev, pdata, count, HAL_MAX_DELAY);
|
||||
if (status) {
|
||||
//VL6180x_ErrLog("I2C error 0x%x %d len", dev->I2cAddr, len);
|
||||
//XNUCLEO6180XA1_I2C1_Init(&hi2c1);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
int _I2CRead(uint16_t Dev, uint8_t *pdata, uint32_t count) {
|
||||
int status;
|
||||
//int i2c_time_out = I2C_TIME_OUT_BASE+ count* I2C_TIME_OUT_BYTE;
|
||||
|
||||
status = HAL_I2C_Master_Receive(&hi2c1, Dev|1, pdata, count, HAL_MAX_DELAY);
|
||||
if (status) {
|
||||
//VL6180x_ErrLog("I2C error 0x%x %d len", dev->I2cAddr, len);
|
||||
//XNUCLEO6180XA1_I2C1_Init(&hi2c1);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user