跳到主要内容

STM32 · configuration

TF 系列 LiDAR 接入 STM32 CAN / UART / TTL / UART · Nucleo-64 STM32F411:接入与配置指南

TF 系列 LiDAR 接入 STM32 的准备、连接、配置与代码要点。原始文件可在资料下载区获取。涉及接口:CAN、UART / TTL、UART。

接口
CAN, UART / TTL, UART
硬件目标
Nucleo-64 STM32F411
整理日期
2026-08-31
资料说明
资料版本日期:2026-08-31。

适用范围

TF 系列 LiDAR · STM32 · CAN、UART / TTL、UART · Nucleo-64 STM32F411

原始英文技术说明

Interfacing TF Series Single Point LiDARs with Nucleo-64 STM32F411 Development Board

Written by: Ibrahim (FAE)

Interfacing TF Series LiDAR with Nucleo-64 Benewake (Beijing) Co. Ltd.

This tutorial explains how to interface Benewake single point LiDARs with Nucleo-64 development boards carrying STM32F411RE series microcontrollers. The following assumptions are made while writing this tutorial:

1. The customer has Nucleo-F411RE development board and any of the single point

LiDARs (Luna, TFmini-Plus, mini-S, TF02-pro, TF03-UART) in hands 2. Have basic understanding of development environment (Keil-5, CubeMX) for compiling C code, and initial configurations of board and environment has already been set 3. All the necessary cables (USB cable, JST Socket (with 1.25mm pitch) to male dupont connector etc.) and 5V power supply is available 4. The LiDAR interface mode is TTL/UART 5. For code editing you could use CodeBlocks, VS Code or Keil but for compilation you need to use Keil, as it has everything set up

2|Page

Interfacing TF Series LiDAR with Nucleo-64 Benewake (Beijing) Co. Ltd.

Pin configuration of Nucleo-64:

For full documentation about Nucleo-F411RE you can refer to ST website, but here we will discuss briefly the pinouts for convenience and we will see which pins can be used for UART interfacing. The following image shows the pin details of Nucleo-F411RE:

Figure 1: Pin numbering

This development board has three USART interfaces. USART-2 is connected to ST-Link debugger for virtual com port which can be used to display the data on computer. Although it’s possible use this UART port for connecting peripherals or TTL-USB adapter but that’s beyond the scope of this tutorial. We will use only USART-1 and USART6 for connecting Benewake LiDAR. As you can see in above image that pins marked in red are connected to debugger, while pins marked in black are free and can be used to connect peripherals. The pin out-view taken from CubeMX is shown below, which are pin configuration:

3|Page

Interfacing TF Series LiDAR with Nucleo-64 Benewake (Beijing) Co. Ltd.

Figure 2: Pinout View

It should be noted that LiDAR needs 5V voltage for stable operation so connect LiDAR to any 5V output on Nucleo-64 board. If the voltage is not 5V, the accuracy will be affected and error will be more than rated accuracy, in some cases the error is non-linear and it increases with increase in distance. It may reach up to 40cm or even more.

4|Page

Interfacing TF Series LiDAR with Nucleo-64 Benewake (Beijing) Co. Ltd.

Schematic diagram:

The connection diagram for interfacing two LiDARs to Nucleo board and using a separate power supply is shown below:

Figure 3: Connection Diagram

For exact details about LiDAR current rating and your supply capacity, please refer to their respective data-sheets.

Default UART Communication Parameters of TF Series: According to the data-sheet of TF series LiDARs the parameters of UART communication:

Figure 4: UART Communication

5|Page

Interfacing TF Series LiDAR with Nucleo-64 Benewake (Beijing) Co. Ltd.

So the UART ports are configured in CubeMX and initial code is generated based on this information.

Cable Selection and Connector: All Benewake Single Points LiDARs have either 4-pin or 7pin (for TF03) Molex connector or JST with 1.25mm pitch, so the required mating connector is JST socket with 1.25mm. Please refer to the link1. In case if you are designing your own PCB so you can choose either 4-pin or 7- pin depending upon the LiDAR that you have. On the controller you may need Dupont male connector or female connector, I used female Dupont connector or you can choose any suitable connector based on your design. One of the sample cable is shown below:

Figure 4: JST 1.25 4P to DuPont male cable

Table III: Data format (for mid and small range LiDARs)

1 https://www.aliexpress.com/i/4000580232835.html

6|Page

Interfacing TF Series LiDAR with Nucleo-64 Benewake (Beijing) Co. Ltd.

Table IV: Data format (TF03 Series)

CubeMX related settings:

Following are the settings for all USART ports.

7|Page

Interfacing TF Series LiDAR with Nucleo-64 Benewake (Beijing) Co. Ltd.

Toolchain and firmware settings:

C code for Nucleo Board: After you generate the initial code using CubeMX, we will need to modify two files main.c and main.h to add our code for LiDAR interfacing and reading the data from sensors and then print it to virtual com port. So in this section we will discuss the main parts of C code that are necessary for communicating with Benewake LiDARs. Adding necessary libraries:

/* USER CODE BEGIN Includes */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/* USER CODE END Includes */

In the while loop of main function we will call two functions to read from sensor:

while (1)
{
/* USER CODE END WHILE */

8|Page

Interfacing TF Series LiDAR with Nucleo-64 Benewake (Beijing) Co. Ltd.

/* USER CODE BEGIN 3 */
read_data_uart1();
read_data_uart6();
}

These two functions are defined in main.c declared in main.h:

/* USER CODE BEGIN EFP */
void read_data_uart1(void);
void read_data_uart6(void);
/* USER CODE END EFP */
//***********Function for reading data from Sensor-1***************
void read_data_uart1(){
memset( usart_rx_buf, 0, sizeof( usart_rx_buf)); // Clear the data buffer.
HAL_UART_Receive(&huart1, usart_rx_buf, 9, HAL_MAX_DELAY);
uint16_t dist, strength=0;
uint8_t checksum, chip_temp=0;
if (usart_rx_buf[0]==HEADER && usart_rx_buf[1]==HEADER){
for (int i=0;i<8;i++){
checksum += usart_rx_buf[i];
}
if (usart_rx_buf[8] == (checksum&0xff)){
dist = usart_rx_buf[2] | (usart_rx_buf[3]<<8);
strength = usart_rx_buf[4] |(usart_rx_buf[5]<<8);
chip_temp = usart_rx_buf[6] | (usart_rx_buf[7]<<8);
chip_temp = chip_temp/8 - 256;
//printf("Distance: %d cm \t", dist);
//printf("Strength: %d \t", strength);
//printf("Chip temp: %d degree celcius\t\n", chip_temp);
printf("LiDAR-1: dist = %d cm; strength = %d; temp = %d.\r\n",
dist,strength,chip_temp); // Print everything in single line.
//HAL_UART_Transmit(&huart2,usart_rx_buf,sizeof(usart_rx_buf),
HAL_MAX_DELAY); // Print full Datapacket in HEX format.
for(int j=0; j<1000; j++){}; // This will create a short delay.
memset( usart_rx_buf, 0, sizeof( usart_rx_buf)); // Clear the data
buffer.
}
}
}

9|Page

Interfacing TF Series LiDAR with Nucleo-64 Benewake (Beijing) Co. Ltd.

//***********Function for reading data from Sensor-1***************
//***********Function for reading data from Sensor-2***************
void read_data_uart6(){
memset( usart_rx_buf, 0, sizeof( usart_rx_buf)); // Clear the data buffer.
HAL_UART_Receive(&huart6, usart_rx_buf, 9, HAL_MAX_DELAY);
uint16_t dist, strength=0;
uint8_t checksum, chip_temp=0;
if (usart_rx_buf[0]==HEADER && usart_rx_buf[1]==HEADER){
for (int i=0;i<8;i++){
checksum += usart_rx_buf[i];
}
if (usart_rx_buf[8] == (checksum&0xff)){
dist = usart_rx_buf[2] | (usart_rx_buf[3]<<8);
strength = usart_rx_buf[4] |(usart_rx_buf[5]<<8);
chip_temp = usart_rx_buf[6] | (usart_rx_buf[7]<<8);
chip_temp = chip_temp/8 - 256;
//printf("Distance: %d cm \t", dist);
//printf("Strength: %d \t", strength);
//printf("Chip temp: %d degree celcius\t\n", chip_temp);
printf("LiDAR-2: dist = %d cm; strength = %d; temp = %d.\r\n",
dist,strength,chip_temp); // Print everything in single line.
//HAL_UART_Transmit(&huart6,usart_rx_buf,sizeof(usart_rx_buf),
HAL_MAX_DELAY); // Print full DataPacket in HEX format.
for(int j=0; j<1000; j++){}; // This will create a short delay.
memset( usart_rx_buf, 0, sizeof( usart_rx_buf)); // Clear the data
buffer.
}
}
}
//***********Function for reading data from Sensor-2***************

In order to print data to the virtual com port which is connected to debugger we will need to add the following part of code:

//Function for printing data to virtual Com port #ifdef GNUC / With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf set to 'Yes') calls ioputchar() / #define PUTCHARPROTOTYPE int io_putchar(int ch)

10 | P a g e

Interfacing TF Series LiDAR with Nucleo-64 Benewake (Beijing) Co. Ltd.

#else #define PUTCHARPROTOTYPE int fputc(int ch, FILE f) #endif / GNUC / / @brief Retargets the C library printf function to the USART. @param None @retval None / PUTCHARPROTOTYPE { / Place your implementation of fputc here / / e.g. write a character to the EVALCOM1 and Loop until the end of transmission / HALUARTTransmit(&huart2, (uint8t )&ch, 1, HALMAXDELAY); // If you want to direct printf to some other ports let say uart1 or 6 then change the first param.

return ch;
}
//***********Function for printing data to virtual Com port***************

In the main function “while loop” runs continuously to monitor the data flow on serial ports and print it to the serial port tool through virtual com port. If your settings go successful and the code is compiled without any issue then you should be able to see the data being printed to serial port tool.

You can either get the code from Technical Support of Benewake or download from GitHub Link2.

2 https://github.com/ibrahimqazi/TF-Series-LiDAR-Interfacing-with-Nucleo-F411RE-using-UART-Interface

11 | P a g e

使用说明

按原始资料可读取的技术内容编排;具体的产品硬件版本、飞控/软件版本和现场安全边界仍应以原始资料及目标平台当前文档为准。

资料与下载

产品咨询

咨询产品方案

留下需求,我们会尽快与您联系。

产品咨询

提交成功

已收到您的询盘,我们会尽快与您联系。