STM32WB55 development (5)----Adjusting RF power

Overview

As wireless communication technology continues to advance, it is becoming increasingly important to be able to precisely control the power of radio frequency (RF) signals. Adjusting RF power can not only affect the communication distance and coverage of the device, but also optimize battery life and reduce possible RF interference. The ACI_HAL_SET_TX_POWER_LEVEL instruction provides a method that enables engineers and developers to dynamically adjust the RF transmit power on ST's Bluetooth devices. This article will describe in detail how to use this command, as well as the possible impacts and application scenarios of adjusting the power level.
I am currently taking ST courses. If you need samples, you can join the group and apply: 615061293.

Hardware preparation

First, you need to prepare a development board. What I prepared here is the WB55RG development board:
Insert image description here

Video teaching

https://www.bilibili.com/video/BV1XF411D7bC/

STM32WB55 development (5)----Adjusting RF power

sample application

https://www.wjx.top/vm/OhcKxJk.aspx#

Source code download

https://download.csdn.net/download/qq_24312945/88351255

Select chip model

Insert image description here

Configure clock source

HSE and LSE are external high-speed clock and low-speed clock respectively. In this article, an external clock source is used, so the Crystal/Ceramic Resonator option is selected, as shown below:
Insert image description here

Configure clock tree

Insert image description here

RTC clock configuration

Insert image description here
RFWKP clock configuration

Insert image description here

Check the conditions for enabling STM32_WPAN

As you can see, RF, RTC, RCC, IPCC, and HSEM need to be turned on.
Insert image description here

Configure HSEM

The Hardware Semaphore (HSEM) module is used to manage shared access rights and resource synchronization between multiple processes.
Turn on HSEM as follows.
Insert image description here

Configure IPCC

The communication controller (IPCC) module is mainly used for signal message exchange between CPUs.
Turn it on as shown below.

Insert image description here

Configure RTC

Insert image description here

Start RF

Insert image description here

Turn on Bluetooth

Insert image description here

Enable serial port debugging

CFG_HW_USART1_ENABLED allows developers to choose whether to use USART1 as the trace output channel, and this configuration is only available under specific settings. Such a configuration is usually used for debugging embedded systems, allowing developers to view the status and output information of the device in real time.
Insert image description here

CFG_HW_USART1_ENABLED This is a configuration flag. When set to enabled, USART1 will be used as the channel for output tracking. When disabled, USART1 will not be used for this purpose.
This specific hardware configuration is only available when USART1 is configured by the CubeMX user interface: this means that the specific configuration option CFG_HW_USART1_ENABLED is only available when USART1 is configured using ST's CubeMX tools.

Looking at the schematic diagram, PA9 and PA10 are linked together with CH340 and are serial printing ports.

Insert image description here
The serial port configuration is as follows.
Insert image description here

Turn on CFG_HW_USART1_ENABLED.
Insert image description here

Turn off the generation of MX_USART1_UART_Init function.
Insert image description here

CFG_HW_USART1_DMA_TX_SUPPORTED allows developers to enable the DMA sending function of USART1. Enabling this feature can improve the efficiency of USART1 when sending data, but it may require more steps and considerations in configuration.
When set to enabled, USART1 will use DMA for data transmission (TX). DMA allows data to be sent directly from memory to a peripheral (USART1 in this case) without intervention from the CPU, thereby increasing efficiency and data transfer speeds.
Insert image description here

Turn on DMA.
Insert image description here

Turn on interrupts.

Insert image description here

Enable DMA of tx of serial port 1.

Insert image description here

If it cannot be turned on, you can reopen the BLE configuration.

Insert image description here

Start serial port 1 debugging trace.

Insert image description here

Enable tracking in the application.

Insert image description here

Configure Bluetooth parameters

Configure as a custom template.
Insert image description here

Name the device

Insert image description here

Configure BLE GATT

Insert image description here

Configure SVC
Insert image description here

Set project information

Insert image description here

Project file settings

Insert image description here

Keil project configuration

Insert image description here

Code configuration

Add the following header file to main.c.

/* USER CODE BEGIN Includes */
#include "stm32_seq.h"
/* USER CODE END Includes */

The UTIL_SEQ_Run(UTIL_SEQ_DEFAULT) function should start task scheduling in the while loop of the application.

  /* USER CODE BEGIN WHILE */
  while (1)
  {
    
    
    /* USER CODE END WHILE */
    MX_APPE_Process();

    /* USER CODE BEGIN 3 */
		UTIL_SEQ_Run(UTIL_SEQ_DEFAULT);
  }
  /* USER CODE END 3 */
}

Add initialization APPD_Init() in app_entry.c.

void MX_APPE_Init( void )
{
    
    
  System_Init( );       /**< System initialization */

  SystemPower_Config(); /**< Configure the system Power Mode */

  HW_TS_Init(hw_ts_InitMode_Full, &hrtc); /**< Initialize the TimerServer */

/* USER CODE BEGIN APPE_Init_1 */
    APPD_Init();
/* USER CODE END APPE_Init_1 */
  appe_Tl_Init();	/* Initialize all transport layers */

  /**
   * From now, the application is waiting for the ready event ( VS_HCI_C2_Ready )
   * received on the system channel before starting the Stack
   * This system event is received with APPE_SysUserEvtRx()
   */
/* USER CODE BEGIN APPE_Init_2 */

/* USER CODE END APPE_Init_2 */
   return;
}

RF power

dBm is a unit of measure of power used specifically to describe the power of radio frequency (RF) and microwave signals. dBm represents the power level relative to 1 milliwatt. So, 0 dBm represents 1 milliwatt of power; negative values ​​represent power less than 1 milliwatt, and positive values ​​represent power greater than 1 milliwatt.

Why do we use a logarithmic unit like dBm to express power instead of directly using linear units such as watts or milliwatts? The reason is that signal strength in wireless communications can vary over a very wide range, and using logarithmic units allows for a clearer and simpler description of these variations.

Here's a simplified explanation:
If a device emits 1 milliwatt of power, this is expressed as 0 dBm.
If the power is 10 times 1 milliwatt, which is 10 milliwatts, then it is 10 dBm.
If the power is 1/10 of 1 milliwatt, which is 0.1 milliwatts, then it is -10 dBm.
So in the list you provided, a negative dBm value means power less than 1 milliwatt, while a positive dBm value means power greater than 1 milliwatt. Such a representation allows engineers to easily compare and deal with various power levels, especially when it comes to RF design and analysis.

ACI_HAL_SET_TX_POWER_LEVEL

This command is used to set the TX power level of the device. PA_LEVEL is controlled to determine the output power level (dBm) of the IC pin. When the system starts
or restarts, the default transmit power level is used, with a maximum value of 6 dBm. Once this command is issued, the output power will be changed immediately regardless of whether
Bluetooth communication is in progress. For example, for debugging purposes, you can set the device to broadcast all the time and use this command to listen for changes in signal strength. The system retains
the latest transmit power level received from the command, i.e. the second command overwrites the previous transmit power level.
The new transmit power level will be maintained until another command to set the transmit power is received or the system is restarted.
Insert image description here

In STM32CUBEMX, the power can be modified first.

Insert image description here

We check that the app_ble.c file also has this initialization operation.
Serial port printing also has the configuration of this command.

Insert image description here

There is CFG_TX_POWER power definition in app_conf.h.

Insert image description here

In the main.c file, add the header file.

/* USER CODE BEGIN Includes */
#include "stm32_seq.h"

#include "ble_hal_aci.h"
/* USER CODE END Includes */

Define variables.

  /* USER CODE BEGIN 2 */
	tBleStatus ret = BLE_STATUS_INVALID_PARAMS;
	uint32_t a=0;
  /* USER CODE END 2 */

Perform the following operations in the while loop, and modify the antenna power after waiting for 5 seconds.

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    
    
    /* USER CODE END WHILE */
    MX_APPE_Process();

    /* USER CODE BEGIN 3 */
		UTIL_SEQ_Run(UTIL_SEQ_DEFAULT);
		if(a<5000)
		{
    
    
				a++;
			if(a==5000)
			{
    
    
					/**
					 * Set TX Power.
					 */
					ret = aci_hal_set_tx_power_level(1, 0x1F);
					if (ret != BLE_STATUS_SUCCESS)
					{
    
    
						printf("Fail   : aci_hal_set_tx_power_level 重新设置, result: 0x%x \n", ret);
					}
					else
					{
    
    
						printf("Success: aci_hal_set_tx_power_level 重新设置\n");
					}			
			}
			HAL_Delay(1);		
		}	
  }
  /* USER CODE END 3 */

Results demonstration

The Bluetooth signal at low power looks like this.
Insert image description here

Modify the bits for high power as shown below.

Insert image description here

Guess you like

Origin blog.csdn.net/qq_24312945/article/details/132953965