LMS7002Mr3 Calibration Using MCU

Introduction
This page provides a brief description of the main calibration procedures used to improve the RF performance of LMS7002M IC by using the built-in microcontroller (MCU). It also contains information needed to program and run LMS7002M IC internal MCU, which handles the calibration procedure execution routines, thus greatly simplifying the calibration porting procedure to other systems.

General MCU calibration description
This section focuses on a brief description of the calibration procedures themselves that are handled by the program stored in MCU image. The calibration procedures for the LMS7002M chip are listed below:
 * DC offset and LO Leakage, and Quadrature (IQ) chain imbalance calibration;
 * Analog filter -3 dB bandwidth calibration.

Calibration procedures are used for both transmitter (TX) and receiver (RX) chains, although the individual calibration setup and flow is different for each of them.

For the ideal TX case, if the continuous wave (CW) signal is up-converted to radio frequency (RF), the TX output ideal spectrum has no unwanted components, as shown in Figure 1 upper graph. In non-linear conditions, the TX output spectrum has unwanted tones as shown in Figure 1 lower graph. Descriptions of the tones are given below:


 * Wanted Signal (1) – wanted TX sideband, with an offset fwanted from the carrier frequency fcarier;


 * LO Leakage (2) – primarily caused by DC offsets in the TX baseband and LO leakage at the TX frequency mixing stage;


 * IQ Image (3) – unwanted TX sideband, with an offset -fwanted from the carrier frequency fcarier. Primary caused by gain and phase imbalances in different IQ signal blocks.



For the ideal RX case, the down-converted CW signal does not have unwanted tones at the input of the analog-digital-converter (ADC) as shown in the Figure 2 upper graph. However, under non-linear conditions the RX spectrum has unwanted signals as shown in the Figure 2 lower graph. Descriptions of the tones are given below:


 * Wanted Signal (4) – wanted RX sideband, with an offset fwanted from the DC;


 * DC Offset (5) – Unwanted RX DC offset. Primarily caused by DC offsets in the RX baseband and LO leakage at the RX frequency mixing stage;


 * IQ Image (6) – Unwanted RX sideband, with an offset -fwanted from the DC. Primary caused by gain and phase imbalances in different quadrature (IQ) signal blocks.

Calibration procedure 1 is used to calibrate unwanted tones. The goal of the MCU program executing the calibration procedure is to find suitable LMS7002M DC offset, gain or phase correction control values for TX and RX, at which the unwanted tones are reduced to levels close to ideal cases shown in Figure 1 and Figure 2.



Calibration procedure 2 is used for analog filter bandwidth calibration. The procedure can be used to tune the desired filter(s) to a new bandwidth setting or to perform re-calibration on an active setup. Figure 3 shows two cases of analog filter tuning:


 * Case 1 – General case. Filter -3dB bandwidth is tuned to a particular frequency or re-calibrated for a new setup;


 * Case 2 – Multiple filter stage tuning. On RX side, the transpimedance amplifier (TIA) acts as a 1st order low pass filter (LPF), while the baseband LPF provides a 2nd order Chebyshev response with a 3 dB peak. Combining both filters can yield a 3rd order LPF with a tunable in-band response. Both stages need to be calibrated separately to produce the desired filter response. A similar setup is used in the TX low band stage.

The MCU program automatically selects the appropriate analog filter bandwidth calibration case in respect to the wanted bandwidth. It also handles the appropriate power down (PD) or enable (EN) controls of the involved blocks (manual setup is not needed).



General MCU calibration limitations and options
The internal LMS7002M MCU has 16384 bytes of memory, thus the size of the calibration program is limited. Furthermore, it takes time (further elaborated in Section 2) to program the MCU, hence only the main (used most frequently) calibration procedures (see Section 1.1) are stored in the MCU image. Other calibration procedures, such as PLL frequency, TX gain tuning, should be implemented as separate baseband processor routines and should be ported separately using the latest source code found on LimeSuite GitHub webpage. Thus, time for MCU image upload is reduced and the overall calibration speed is increased.

By default, MCU calibration image uses internal LMS7002M RF loopback to perform the required test signal generation procedures, hence no external components or connections are required. Nonetheless, internal RF loopback has bandwidth and signal coupling limitations. It achieves the best calibration performance up to 2GHz, but can be effectively used up to 2.7GHz (where unwanted tone suppression will decrease down to <−35dBc). External RF loopback can be used to remove the RF limitation, but this requires a modification on the board level and the use of a separate MCU image (based around the particular board). Please note, that only DC offset, LO leakage, gain and phase mismatch calibration procedures are affected by the internal/external loopback selection, while other calibration routines do not depend on board connection modifications.

LMS7002M MCU image calibration procedures
MCU calibration image (see Section 2.1.2) has the following calibration routines that can be executed:


 * 1) Calibration of TX chain DC offset and LO leakage, phase, gain imbalances;
 * 2) Calibration of RX chain DC offset, phase, gain imbalances;
 * 3) Calibration of TX analog filter bandwidth;
 * 4) Calibration of RX analog filter bandwidth.

Other data handling procedures (for example certain variable input to the MCU) will be discussed in Section 2.2.

LMS7002M Setup Steps Needed for MCU Image Calibration Execution
LMS7002M IC must be properly set-up from the stand-point of analog and digital interface settings prior to main DC offset and LO, phase, gain calibration procedures handled by the MCU image for both TX and RX chains.

The recommended calibration/tuning priority list for TX chain is given below:


 * 1) TX and clock generator (CLKGEN) PLL frequency tuning (block order is irrelevant, baseband processor routine, see Section 1.2);
 * 2) TX analog filter bandwidth (handled by the MCU image);
 * 3) TX gain tuning (baseband processor routine, see Section 1.2);
 * 4) Settings of other TX chain controls (bias, power amplifier gain and etc.). Please note, that digital interface speed should also be configured at this or any of the earlier stages;
 * 5) TX DC offset and LO, phase gain calibration (handled by the MCU image).

The recommended calibration/tuning priority list for RX chain is given below:


 * 1) RX and clock generator (CLKGEN) PLL frequency tuning (block order is irrelevant, baseband processor routine, see Section 1.2);
 * 2) RX analog filter bandwidth (handled by the MCU image);
 * 3) Settings of other RX chain controls (bias, LNA, TIA, PGA gain and etc.). Please note, that digital interface speed should also be configured at this or any of the earlier stages;
 * 4) RX DC offset and LO, phase gain calibration (handled by the MCU image).

MCU calibration can handle a single procedure at a given time – calibrating both A and B channels or executing several calibrations procedures simultaneously at the same time is not possible. MCU calibrates only currently selected transceiver channel, which is selected by SPI 0x0020[1:0] bits. Baseband has to select channel and initiate calibration for each transceiver channel individually.

MCU Calibration Image Location
The latest MCU calibration image can always be found on LimeSuie GitHub webpage:


 * Hex format;
 * Binary format.

MCU Internal Memory Size
MCU internal memory size is 16384 bytes. It is required that all 16384 bytes have to be uploaded before the MCU becomes programmed. If program image size is less than 16384 bytes, image should be padded with zeros to meet the required size.

Programming the MCU

 * 1) Reset MCU, write to SPI address 0x0002 = 0;
 * 2) Set one of the programming modes:
 * 3) EEPROM and SRAM, write to SPI address 0x0002 = 1;
 * 4) SRAM, write to SPI address 0x0002 = 2;
 * 5) Wait until MCU programming buffer is empty, read from SPI address 0x0003[0]:
 * 6) 0x0003[0] == 0, buffer empty;
 * 7) 0x0003[0] == 1, buffer has data;
 * 8) Write 32 bytes of program image into MCU buffer, by SPI writing to address 0x0004;
 * 9) Go to step 3. until 16384 total bytes have been written;
 * 10) Wait until MCU becomes programmed, read from SPI address 0x0003[6]:
 * 11) 0x0003[6] == 0, MCU not programmed;
 * 12) 0x0003[6] == 1, MCU programmed.

Running MCU Image Calibration Procedure
The following steps are needed to run the MCU image calibration procedure:


 * 1) SPI write 0x0006[0] = 1, switch SPI controls to MCU;
 * 2) SPI write 0x0000 = procedure ID (see Table 1);
 * 3) SPI write 0x0002[3] = 0;
 * 4) SPI write 0x0002[3] = 1;
 * 5) SPI write 0x0002[3] = 0;
 * 6) SPI read address 0x0001;
 * 7) IF 0x0001== 0xFF, MCU procedure is in progress, repeat step 6;
 * 8) IF 0x0001== 0, MCU procedure finished successfully;
 * 9) IF 0x0001== Any Other Value, MCU encountered error;
 * 10) SPI write 0x0006[0]=0, switch SPI controls back to baseband.

Passing Parameters Into MCU Calibration Image
There are two main parameters that need to be passed to the MCU calibration program prior to executing any of the procedures mentioned in Section 2.1.1:


 * 1) Reference clock parameter;
 * 2) Bandwidth parameter.

Reference clock parameter specifies the reference clock frequency used by LMS7002M. It is passed to the MCU image with the following sequence:


 * 1) SPI write into address 0x0000 = byte0
 * 2) SPI write into address 0x0002[2] = 1
 * 3) SPI write into address 0x0002[2] = 0
 * 4) SPI write into address 0x0000 = byte1
 * 5) SPI write into address 0x0002[2] = 1
 * 6) SPI write into address 0x0002[2] = 0
 * 7) SPI write into address 0x0000 = byte2
 * 8) SPI write into address 0x0002[2] = 1
 * 9) SPI write into address 0x0002[2] = 0
 * 10) Run MCU procedure ID #4 (Update reference clock parameter, see Section 2.2.2)

Bytes have to be shifted in by triggering interrupt in MCU. Here, the reference clock parameter is passed into MCU as 3 bytes:


 * 1) byte0 – kHz LSB part;
 * 2) byte1 – kHz MSB part;
 * 3) byte2 – MHz integer.

For example, 30.72 MHz reference clock would be:


 * 1) byte0 = 208;
 * 2) byte1 = 2;
 * 3) byte2 = 30.

Valid reference clock values for different MCU calibration image procedure IDs are given in Table 2.

Bandwidth parameter specifies the reference clock frequency used by LMS7002M. It is passed to the MCU image with the following sequence:


 * 1) SPI write into address 0x0000 = byte0
 * 2) SPI write into address 0x0002[2] = 1
 * 3) SPI write into address 0x0002[2] = 0
 * 4) SPI write into address 0x0000 = byte1
 * 5) SPI write into address 0x0002[2] = 1
 * 6) SPI write into address 0x0002[2] = 0
 * 7) SPI write into address 0x0000 = byte2
 * 8) SPI write into address 0x0002[2] = 1
 * 9) SPI write into address 0x0002[2] = 0
 * 10) Run MCU procedure ID #3 (Update bandwidth parameter, see Section 2.2.2)

Bytes have to be shifted in by triggering interrupt in MCU. Here, the reference clock parameter is passed into MCU as 3 bytes:


 * 1) byte0 – kHz LSB part;
 * 2) byte1 – kHz MSB part;
 * 3) byte2 – MHz integer.

For example, 5 MHz bandwidth would be:


 * 1) byte0 = 0;
 * 2) byte1 = 0;
 * 3) byte2 = 5.

Valid bandwidth values for different MCU calibration image procedure IDs are given in Table 3.

Configuring MCU Calibration Image

 * 1) Program MCU calibration image (see Section 2.2.1);
 * 2) Configure transceiver to working condition (refer to Section 2.1.2);
 * 3) Set chip reference clock for the MCU (optional, default 30.72MHz, see Section 2.2.3);
 * 4) Set bandwidth parameter for to be used algorithm (optional, default 5MHz, see Section 2.2.3);
 * 5) Run algorithm procedure (see Section 2.2.2);
 * 6) Wait for algorithm completion (see Section 2.2.2, step 6).

Frequently Asked Question Regarding MCU Operations
A short check-up list is given below to quickly review several important steps needed for proper MCU work:
 * 1) Is the MCU programmed?
 * 2) Is LMS7002M configured into working state prior to executing calibration procedure?
 * 3) Does the reference clock parameter passed into MCU contain the correct and actual reference clock value supplied to the LMS7002M (see Table 2)?
 * 4) Does the bandwidth parameter passed into MCU is achievable by LMS7002M (see Table 3)?
 * 5) Was the SPI control enabled for the MCU before running calibration procedure (see Question/Answer 2 below)?

Q1: MCU programming fails or program is not running.

A1: MCU requires 16384 bytes to be uploaded to become programmed. If program image size is less than 16384 bytes, image should be padded with zeros to meet the required size.

Q2: MCU can’t control LMS7002M IC.

A2: Baseband has to give over SPI controls to the MCU by SPI write 0x0006[0] = 1:


 * 0x0006[0] == 0, transceiver controlled by Baseband;
 * 0x0006[0] == 1, transceiver controlled by MCU.

Q3: What do the MCU error codes mean?

A3: Unfortunately because of limited MCU resources the returned error codes are not very informative, to know exact meaning of each error code, source code has to be inspected according to which procedure was used.

Q4: How much time does the calibration procedure take?

A4: Calibration duration depends on several factors:
 * 1) MCU reference clock frequency (higher frequency executes faster);
 * 2) RF sampling frequency (higher frequency reduces time needed for measurements);
 * 3) Selected procedure, each procedure has different duration.

Q5: MCU is not running procedures or is acting unpredictably.

A5: MCU relies on SPI communications with the baseband to receive parameters and initiate procedures. It might be a case that baseband SPI operations are being performed faster than the MCU can react to them.

Q6: Can MCU calibrate both A and B channels of the transceiver at the same time?

A6: No, MCU calibrates only currently selected transceiver channel, which is selected by SPI 0x0020[1:0] bits. Baseband has to select channel and initiate calibration for each transceiver channel individually.

Q7: Do I need to reprogram MCU before each procedure launch?

A7: No, it is sufficient to program MCU once after reset, and then procedures can be executed multiple times.