Burning hex image into on internal uC of LMS7002M

#1

Hello guys ,
I can communicate via SPI to the LMS7002M . What protocol do I follow to burn the calibration hex file into the microcontroller present in LMS7002M ?
Also what is the difference between Lime Suite library and LMS7002M driver ?

Regards,
Kishore Saldanha

#2

Hi kishores,

first, you need to set programming mode (regi 0x0002), then write image by byte into register 0x0004 while checking FIFO status in register (0x0003)

In LimeSuite, MCU programming code can be found:

and related SPI register description in section “2.22 mSPI Configuration Memory” of:
https://github.com/myriadrf/LMS7002M-docs/blob/master/LMS7002M_Programming_and_Calibration_Guide_v31r05.pdf

I am not sure about exact functionality of LMS7002M driver but I think it is similar to LMS7002m class in LimeSuite (It only provides functions for configuring LMS7 chip). LimeSuite library provides support for different boards so it also deals with different connection types, FPGA configuration, sample streaming, controlling other on-board component (e.g RF switches, GPIOs …).

#3

Hello @IgnasJ ,
I was able to reset the MCU ,set the SRAM mode ,check whether the program buffer is empty(only once) but I am not able to program it .It is stuck in a while loop. Can you have a look at my code . `#include <LMS7002M/LMS7002M.h>
#include <LMS7002M/LMS7002M_logger.h>
#include “spidev_interface.h”
#include <wiringPi.h>
#include <unistd.h>
#include <stdlib.h>
#include <LMS7002M_filter_cal.h>
#include “mcu_dc_iq_calibration.h”

#define REF_FREQ (50e6)
#define PROGRAM_BUFF_MASK 1<<0
#define PROGRAM_COMP_MASK 1<<6
//set the time interval of delay in seconds
int LMS_GPIO_LOW=2;
int LMS_GPIO_HIGH=2;
int LMS_CONFIGURABLE=1000;
int DELAY=30000;

int main(){
LMS7_set_log_level(LMS7_DEBUG);
//initialize wiring pi
wiringPiSetup();
pinMode(6,OUTPUT);
//create an SPI handle
void *handle=spidev_interface_open("/dev/spidev0.0");
if (handle==NULL){
printf("\nUnable to create the handle . Exiting . ");
return -1;
}
//create an object
LMS7002M_t *lms=LMS7002M_create(spidev_interface_transact,handle);
if(lms==NULL){
printf("Unable to create the LMS7002M interface . ");
return -1;
}

// LMS7002M_reset(lms);
//read from the SPI device
digitalWrite(6,LOW);
delay(LMS_GPIO_LOW);
digitalWrite(6,HIGH);
//delay(LMS_GPIO_HIGH);
//delay(LMS_CONFIGURABLE);
//usleep(DELAY);
LMS7002M_reset(lms);
usleep(DELAY);
LMS7002M_set_spi_mode(lms,4);
usleep(DELAY);
LMS7002M_regs_spi_read(lms,0x002f);
usleep(DELAY);
printf(“rev. 0x%x\n”,LMS7002M_regs(lms)->reg_0x002f_rev);
printf(“ver. 0x%x\n”,LMS7002M_regs(lms)->reg_0x002f_ver);

LMS7002M_spi_write(lms,0x0002,0x0000);//reset the MCU 
usleep(DELAY);
LMS7002M_spi_write(lms,0x0002,0x0001);//select EEPROM/SRAM Mode
int value=LMS7002M_spi_read(lms,0x0003);//read programming buffer register
uint32_t *fp=(uint32_t *)calib_bin;
//TODO:ADD timeout here
while( (value & PROGRAM_BUFF_MASK)==  1 ){//loop if program buffer is not empty
	value=LMS7002M_spi_read(lms,0x0003);
	printf("Program buffer not empty\n");
}
//printf("Out of while loop");
printf("================Ready to flash the image======================\n");
int size=16384/32;
//write the binary into the MCU 
//NOTE:The size of binary is 16384,so total writes in steps of 32 are 16384/32=4096
for(int i=0;i<size;i++){
	LMS7002M_spi_write(lms,0x0004,fp[i]);
	value=LMS7002M_spi_read(lms,0x0003);
	 //TODO:ADD timeout here
	while( (value & PROGRAM_BUFF_MASK)==  1 ){//loop if program buffer is not empty
            	value=LMS7002M_spi_read(lms,0x0003);//read programming buffer register
		printf("Waiting for the Program buffer\n");//PROGRAM STUCK HERE
        }
}
value=LMS7002M_spi_read(lms,0x0003);
//TODO:Add timeout here
while( (value & PROGRAM_COMP_MASK)== 0 ){
	value=LMS7002M_spi_read(lms,0x003);
	printf("Programming not complete\n");
}
spidev_interface_close(handle);//close the handle
    }

`

#4

@kishores

It looks like you are trying to write 32bits (4 bytes) to register 0x4 at once. You should write only 1 byte at a time to 0x4.

#5

Hey @IgnasJ ,
I realized the LMS7002M_write function writes 16 bits at a time . So I modified my code . However, the issue is still not fixed . Maybe I am writing 16 bit MSB first instead of LSB .But the worst thing that will do is program a wrong image . If I program a wrong image into the MCU will the PROGRAMMING COMPLETE(0x0003[6]) flag be set ? Also how do I write 8 bit data ? Is the spi packet of the form (1<<31)|(addr<<16)|value& 0xff ?