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
}
`