Acconeer A121 User manual

A121 Integration using STM32CubeIDE
User Guide

A121 Integration using STM32CubeIDE
Contents
1 Introduction 3
2 Getting Started with STM32CubeIDE 4
2.1 MCU/BoardSelection ............................................ 4
2.2 ProjectSetup ................................................. 5
2.3 PinConfiguration............................................... 6
2.3.1 PinConfigurationwithXE121.................................... 9
2.4 InterruptConfiguration ............................................ 10
2.5 GPIOConfiguration.............................................. 10
2.6 XE121SensorSelection ........................................... 11
2.7 XE121SingleSensorSetup.......................................... 11
2.8 SPIConfiguration............................................... 12
2.9 CodeGeneration ............................................... 12
3 Configuring Project for Acconeer Software 14
3.1 AddingAcconeerSoftware.......................................... 14
3.1.1 Source-files.............................................. 14
3.1.2 Header-files.............................................. 14
3.1.3 Libraries ............................................... 14
3.2 ProjectSettings ................................................ 14
3.3 Adding Print Functionality with UART/USART . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.3.1 FindSTM32BoardCOMport.................................... 15
3.3.2 StartandConfigurePuTTY ..................................... 15
4 HAL Integration File 18
4.1 Selecting the Appropriate HAL-integration File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
4.2 A121_SPI_HANDLE............................................. 18
4.3 SensorCrystalFrequency........................................... 18
5 Running a Radar Sensor Example 19
6 Troubleshooting and FAQ 20
6.1 ExampleFails................................................. 20
6.1.1 Sensor Creation Returns NULL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
6.1.2 ConfigCreationHardfaults...................................... 20
6.2 The Program is Stuck in HAL_Delay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
6.3 Troubleshooting SPI Communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
6.4 UARTProblems................................................ 21
6.5 LinkErrors .................................................. 21
6.6 HeapMemoryCorruption........................................... 21
7 Disclaimer 23
© 2022 by Acconeer AB - All rights reserved Page 2 of 23

A121 Integration using STM32CubeIDE
1 Introduction
In this document there will be a short guide with example on how to generate a project and setup the Acconeer software
in STM32CubeIDE.
The MCU board used as an example in this guide is a Nucleo-L476RG. We will show how to connect an XE121, including
the A121 radar sensor. There is some extra logic on the XE121 board to support multiple sensors that typically is not
present on boards with only one sensor. To show how a typical single sensor integration can be done, we have also
included some notes on how to use the XE121 in a single sensor setup.
STM32CubeIDE can be downloaded from the ST website at:
https://www.st.com/en/development-tools/stm32cubeide.html
This guide has been verified in both Ubuntu 20.04 and Windows with STM32CubeIDE 1.9.0
© 2022 by Acconeer AB - All rights reserved Page 3 of 23

A121 Integration using STM32CubeIDE
2 Getting Started with STM32CubeIDE
This section will cover how to setup a project in STM32CubeIDE, and make sure that the code works with the Acconeer
software.
Start STM32CubeIDE and click “Start new STM32 project”. The option is also available under “File →New →
STM32Project”.
Figure 1: Start new STM32CubeIDE project
When running on Linux/Ubuntu you might be asked about Connection Parameters, generally, you can skip this part by
selecting “No proxy”.
2.1 MCU/Board Selection
Search for the MCU or Board you are working with in the MCU Selector/Board Selector tab. In the example in this
document we use the board “NUCLEO-L476RG”. Start off by searching for “NUCLEO-L47” in the “Part Number
Search”-option at the top left in the Board Selector tab.
The board will show up in the “Boards list” at the bottom of the page. Click it. When clicking the board or MCU, you
will be given some information about it.
Make sure the “Nucleo-L476RG” board is selected and press the “Next”-button at the bottom of the page.
© 2022 by Acconeer AB - All rights reserved Page 4 of 23

A121 Integration using STM32CubeIDE
Figure 2: Target Selection
2.2 Project Setup
Select a name and location for your project and select the following options:
• Target language: C
• Target Binary type: Executable
• Target Project Type: STM32Cube
Finally, press the “Finish”-button at the bottom of the page.
© 2022 by Acconeer AB - All rights reserved Page 5 of 23

A121 Integration using STM32CubeIDE
Figure 3: Project Setup
Press “Yes” when you are asked if you want to initialize peripherals to their default mode.
Figure 4: Initialize Peripherals
Press “Yes” when you are asked if you want to open the STM32CubeMx perspective.
Figure 5: Open STM32CubeMX perspective
2.3 Pin Configuration
The Pinout is flexible – however it is important that the pins communicating with the radar have the right user labels and
that SPI is configured with “Full-Duplex Master”-mode.
In order to perform pin configuration you need to have the “.ioc”-file open that is named after your project.
© 2022 by Acconeer AB - All rights reserved Page 6 of 23

A121 Integration using STM32CubeIDE
The “LD2 [green Led]“ on the Nucleo board shares functionality with “SPI1_CLK“. Before we add SPI functionality we
need to remove the “LD2 [green Led]“ configuration from PA5. The pin configuration is removed by doing a left mouse
click on PA5 / “LD2 [green Led]“ and then selecting “Reset_State“.
Figure 6: Remove LD2 pin
The “B1 [Blue PushButton]“ on the Nucleo board is not used on our examples and can be removed. The pin configuration
is removed by doing a left mouse click on PC13 / “B1 [Blue PushButton]“ and then selecting “Reset_State“.
© 2022 by Acconeer AB - All rights reserved Page 7 of 23

A121 Integration using STM32CubeIDE
Figure 7: Remove B1 pin
In our example we activate SPI1 with “Full-Duplex Master”-mode by going into “Connectivity” in the “Pinout and
Configuration”-tab. Then by pressing “SPI1” the option of selecting mode is available, “Full-Duplex Master” is selected.
When doing this we get the SPI GPIOs:
© 2022 by Acconeer AB - All rights reserved Page 8 of 23

A121 Integration using STM32CubeIDE
Figure 8: SPI Setup
USER_LABEL NUCLEO PIN
SPI1_MOSI PA7
SPI1_MISO PA6
SPI1_SCK PA5
2.3.1 Pin Configuration with XE121
In order to set new GPIOs, you can left click the desired pin and selected the desired function of the pin.
The table below shows how the XE121 and the NUCLEO-board can be connected:
© 2022 by Acconeer AB - All rights reserved Page 9 of 23

A121 Integration using STM32CubeIDE
USER_LABEL NUCLEO PIN GPIO TYPE COMMENT
SEN_EN1 PB0 GPIO_Output
SEN_EN2 PB5 GPIO_Output Only needed for multi-sensor
SEN_EN3 PB3 GPIO_Output Only needed for multi-sensor
SEN_EN4 PA10 GPIO_Output Only needed for multi-sensor
SEN_EN5 PC1 GPIO_Output Only needed for multi-sensor
SPI1_MOSI PA7 SPI1_MOSI
SPI1_MISO PA6 SPI1_MISO
SPI1_SCK PA5 SPI1_SCK
A121_SPI_SS PB6 GPIO_Output
SPI_SEL0 PA4 GPIO_Output
SPI_SEL1 PA1 GPIO_Output
SPI_SEL2 PA0 GPIO_Output
SEN_INT1 PA9 GPIO_EXTI9
SEN_INT2 PA8 GPIO_EXTI8 Only needed for multi-sensor
SEN_INT3 PB10 GPIO_EXTI10 Only needed for multi-sensor
SEN_INT4 PB4 GPIO_EXTI4 Only needed for multi-sensor
SEN_INT5 PC0 GPIO_EXTI0 Only needed for multi-sensor
2.4 Interrupt Configuration
The NVIC interrupt for the SEN_INT1, SEN_INT2, SEN_INT3, SEN_INT4, SEN_INT5 pins should be enabled.
1. Select the GPIO item under the System Core.
2. Select the NVIC tab.
3. Tick the checkbox EXTI line0 interrupt.
4. Tick the checkbox EXTI line4 interrupt.
5. Tick the checkbox EXTI line[9:5] interrupt.
6. Tick the checkbox EXTI line[15:10] interrupt.
Figure 9: NVIC Configuration
2.5 GPIO Configuration
The GPIO signals from the processor to the sensor should be setup as outputs with very high drive strength.
1. Select the GPIO item under the System Core.
2. Select the GPIO tab.
3. Configure the GPIO pins accoring to the table below.
© 2022 by Acconeer AB - All rights reserved Page 10 of 23

A121 Integration using STM32CubeIDE
USER_LABEL NUCLEO PIN GPIO Output Level Maximum Output speed
SEN_EN1 PB0 Low Very High
SEN_EN2 PB5 Low Very High
SEN_EN3 PB3 Low Very High
SEN_EN4 PA10 Low Very High
SEN_EN5 PC1 Low Very High
A121_SPI_SS PB6 High Very High
SPI_SEL0 PA4 Low Very High
SPI_SEL1 PA1 Low Very High
SPI_SEL2 PA0 Low Very High
Figure 10: GPIO Configuration
2.6 XE121 Sensor Selection
The XE121 board has support for adding up to 4 extra A121 sensors by using FFC cables and XS121 boards. The selection
of which sensor to communicate with is done in the acc_hal_integration_xe121_multi_sensor.c file.
SPI_SEL2 SPI_SEL1 SPI_SEL0 Sensor Selection
LOW LOW LOW Sensor 1 (XE121)
LOW LOW HIGH Sensor 2 (XS121 S2)
LOW HIGH LOW Sensor 3 (XS121 S3)
LOW HIGH HIGH Sensor 4 (XS121 S4)
HIGH LOW LOW Sensor 5 (XS121 S5)
2.7 XE121 Single Sensor Setup
If the XE121 board is used in a single sensor setup there is no need to connect the following signals SEN_INT2,
SEN_INT3, SEN_INT4, SEN_INT5, SEN_EN2, SEN_EN3, SEN_EN4 and SEN_EN5.
Please note that SEN_SEL0, SEN_SEL1 and SEN_SEL2 need to be kept low to select the sensor onboard the
XE121.
The acc_hal_integration_xe121_multi_sensor.c should be replaced with the acc_hal_integration_xe121_single_sensor.c
file in the STM32CubeIDE project.
© 2022 by Acconeer AB - All rights reserved Page 11 of 23

A121 Integration using STM32CubeIDE
2.8 SPI Configuration
To make the SPI interface work properly with the Acconeer software you might need to set the Prescaler (for Baud Rate)
and Data Size.
Press the SPI you are using and under the Configuration menu you can change parameters. Under “Basic Parameters” you
can find that “Data Size” is set to 4 Bits by default, change this to 8 Bits.
Under “Clock Parameters” you will find “Prescaler”, this controls the frequency of the SPI bus. The higher the prescaler
value is, the lower the frequency will be. Depending on your setup, you might have to use different prescaler values
to fit your project. The A121 sensor supports SPI frequencies up to 50 MHz. In experimental configurations where the
sensor and MCU are not mounted on the same PCB, the maximum SPI frequency is often significantly lower and typically
around 10 MHz.
It is recommended to use the highest prescaler to begin with in order to make sure the SPI-communication is stable. Once
the communication works properly you can start trying lower prescalers in order to increase the frequency.
You might have to save the project and restart the program in order to access these settings.
Figure 11: SPI Master Config
2.9 Code Generation
Select Project/Generate Code to generate the driver and configuration MCU.
© 2022 by Acconeer AB - All rights reserved Page 12 of 23

A121 Integration using STM32CubeIDE
3 Configuring Project for Acconeer Software
3.1 Adding Acconeer Software
There are four different folders in the SDK zip:
• doc
• examples
• integration
• rss
In the “doc”-folder you can find reference documentation of the Acconeer software. The “examples”-folder contains
example programs and their header-files. The “rss”-folder contains two subfolders called “include” and “lib”. The “lib”-
folder contains the Radar System Software (RSS) and the “include”-folder contains the header-files needed to use RSS.
The “integration”-folder contains files which connect RSS with the drivers generated by STM32CubeIDE.
Start off by unpacking the zip-file into your project. Refresh the project by right clicking the project in the Project Explorer
and click “Refresh”. Make sure you can see the folder in your project before continuing.
3.1.1 Source-files
Now the integration-file which you want to use needs to be selected from the “cortex_m4_gcc/integration”-folder,
Copy/move the “acc_hal_integration_stm32cube_xe121_multi_sensor.c”-file you have selected into “Core/Src”-folder. If
you want any examples, copy them from “cortex_m4_gcc/examples” to “Core/Src”-folder.
Also move the "acc_integration_stm32.c" and the "acc_integration_log.c" files from the “cortex_m4_gcc/integration”-
folder to the “Core/Src”-folder.
For this guide we select “example_service.c” and move it to the “Core/Src”-folder.
3.1.2 Header-files
1. Select your project in the “Project Explorer”
2. Go into “Project →Properties →C/C++ General →Paths and Symbols →Includes”
3. Press “Add...” and then “Workspace...”
4. Select the “cortex_m4_gcc/rss/include”-folder in your project
Repeat this procedure for the “cortex_m4_gcc/integration”-folder and the “cortex_m4_gcc/examples”-folder.
3.1.3 Libraries
In order to set the path for the libraries, do the following:
1. Select your project in the “Project Explorer”
2. Go into “Project →Properties →C/C++ General →Paths and Symbols →Library Paths”
3. Press “Add...” and then “Workspace...”
4. Select the “cortex_m4_gcc/rss/lib”-folder in your project
Once the path is set, you can add the specific libraries by the following:
1. Go into “Project →Properties →C/C++ General →Paths and Symbols →Libraries”
2. Click “Add...”
3. Enter "acconeer_a121"
4. Click "OK"
3.2 Project Settings
Set the project to gnu99-compiler by going into “Project →Properties →C/C++ Build →Settings →Tool Settings →
MCU GCC Compiler →General”.
© 2022 by Acconeer AB - All rights reserved Page 14 of 23

A121 Integration using STM32CubeIDE
3.3 Adding Print Functionality with UART/USART
If an UART/USART has been added when setting up the project in the STM32CubeMX perspective and you want to use
it for prints then you can simply add the following code to your project:
int _write(int file , char *ptr , int len)
{(void)file;
HAL_UART_Transmit (& huart2 , ( uint8_t *)ptr , len , 0xFFFF );
return len;
}
A terminal emulator, for example PuTTY, can be used to view the UART prints from the board.
Download PuTTY from
https://putty.org
and install it on your computer.
3.3.1 Find STM32 Board COM port
If using Windows, go to Device Manager to locate the COM port used by your STM32 Board.
Figure 13: Windows Device Manager
3.3.2 Start and Configure PuTTY
1. Start the PuTTY application
2. Select Session in the Category window.
3. Set the Connection Type to Serial
4. Type the STM32 Board COM port in the Serial line text box.
5. Use the same Speed as used for the UART in the STM32CubeIDE project, default 115200.
6. Select Terminal in the Category window.
7. Tick the Implicit CR in every LF tickbox
8. Clock in Open to start the terminal
© 2022 by Acconeer AB - All rights reserved Page 15 of 23

A121 Integration using STM32CubeIDE
4 HAL Integration File
4.1 Selecting the Appropriate HAL-integration File
First off you need to pick what HAL integration file to use. The functions in the HAL integration file act as glue between
the RSS radar stack and the drivers generated by the device configuration tool (STM32CubeMX perspective). Your
hardware setup determines which HAL integration file to select as a starting point.
The files “acc_hal_integration_stm32cube_xe121_<single/multi>_sensor.c“ are HAL integrations prepared by Acconeer
to handle the XE121 EVK board together with an STM32 processor.
The file “acc_hal_integration_stm32cube_xe121_single_sensor.c“ will only handle the onboard sensor on the XE121. The
file “acc_hal_integration_stm32cube_xe121_multi_sensor.c“ will handle the onboard sensor on the XE121 aswell as the
possiblity to use XS121 sensors connected in slot S2, S3, S4, S5..
4.2 A121_SPI_HANDLE
Define "A121_SPI_HANDLE" as hspi1 between the comments “USER CODE BEGIN Private defines” and “USER
CODE END Private defines” in the file “Core/Inc/main.h”.
/* USER CODE BEGIN Private defines */
#define A121_SPI_HANDLE hspi1
/* USER CODE END Private defines */
4.3 Sensor Crystal Frequency
The ACC_BOARD_REF_FREQ define assumes 24MHz crystal on the XE121. This value needs to be changed if a crystal
with a different frequency is used with the A121 radar sensor.
© 2022 by Acconeer AB - All rights reserved Page 18 of 23

A121 Integration using STM32CubeIDE
5 Running a Radar Sensor Example
As a first radar example program to run, we selected the program "example_service.c".
To run the radar example program that we have chosen, simply include the header file “example_service.h” in the user
code includes field in your "main.c"-file in the following manner:
/* USER CODE BEGIN Includes */
#include " example_service.h''
/* USER CODE END Includes */
After including the header-file, you can call the function from the "main.c"-file in the user code 2 field by the following
call:
/* USER CODE BEGIN 2 */
acc_example_service (0, NULL);
/* USER CODE END 2 */
© 2022 by Acconeer AB - All rights reserved Page 19 of 23
Other manuals for A121
1
Table of contents
Other Acconeer Accessories manuals
Popular Accessories manuals by other brands

Lippert Components
Lippert Components Solera owner's manual

Adidas
Adidas miCoach Elite user manual

Tractel
Tractel Handifor 20 kg Operating and maintenance instructions

Vega
Vega VEGAPULS C 23 operating instructions

Eaton
Eaton Metalux installation instructions

LEGRAND
LEGRAND WT-600 installation instructions