Hi,
I have put all qspi related code in internal memory as you mentioned. But still application is waiting for qspi_mem_wait_for_write_en while erasing chip. It is never come out of while loop which is inside qspi_mem_wait_for_write_en function. Also Attached scatter file
int xt_nvm_write(TUNER* p)
{
char* aligned=NULL;
void* buf = (void*) &(p->savedState);
int nbytes = sizeof(p->savedState);
_int_disable();
/*Erasing flash 64K Sector before write*/
printf("Erasing NVM QSPI region.....\r\n");
qspi_mem_Sec_erase(p->qspifd,NVM_ADDR, SECTOR_64K);
_time_delay(500);
if ((uint_32)buf & 0x03) {
// sqi write needs word aligned buffer (malloc will give this)
printf("Re-align write buffer %p\r\n",buf);
aligned=malloc(nbytes);
if (!aligned) {
printf("allocate %d bytes failed\r\n",nbytes);
return -1;
}
memcpy(aligned,buf,nbytes);
buf = aligned;
}
//printf("Write %d bytes from %p\r\n",nbytes,buf);
qspi_mem_write_data (p->qspifd, NVM_ADDR, nbytes, buf);
if (aligned)
_mem_free(aligned);
_int_enable();
return 0;
}
int xt_nvm_read(TUNER* p)
{
void* buf = (void*) &(p->savedState);
int nbytes = sizeof(p->savedState);
_int_disable();
qspi_mem_read_data(p->qspifd, NVM_ADDR, nbytes, buf);
_int_enable();
return 0;
}
/*Below code sits in qspi_code internal memory*/
#pragma arm section code = "qspi_code"
_mqx_int qspi_mem_open(HTUNER h)
{
TUNER* p = (TUNER*)h;
_mqx_int errcode = 0;
printf ("\nQSPI Flash NVM Region Open\n");
/* Open the QSPI driver */
p->qspifd = fopen (QSPI_CHANNEL, NULL);
if (p->qspifd == NULL) {
printf ("Error opening QSPI Flash driver!\n");
_time_delay (200L);
errcode = MQX_ERROR;
}
return errcode;
}
void qspi_mem_wait_for_not_busy(MQX_FILE_PTR qspifd)
{
uint_8 status = 0x01;
while(status & 0x1) {
if (qspi_mem_read_status1(qspifd, &status) == FALSE)
status = 0x01;
}
}
void qspi_mem_wait_for_write_en(MQX_FILE_PTR qspifd)
{
uint_8 status = 0x0;
printf("Waiting for write enable bit\r\n");
while(!(status & 0x2)) {
if (qspi_mem_read_status1(qspifd, &status) == FALSE)
status = 0x0;
}
}
static void qspi_mem_set_write_en(MQX_FILE_PTR qspifd, uint_32 addr, boolean enable)
{
_mqx_int result;
uint_8 buffer[4+QuadSPI_ADDR_BYTES] = {0};
result = ioctl(qspifd, QuadSPI_IOCTL_SET_FLASH_ADDR, &addr);
if (result != MQX_OK) {
printf("memory_write_data: failed at ioctl set flash address!\n");
return;
}
if (enable) {
buffer[0] = QuadSPI_WRITE_EN & 0xFF;
buffer[1] = (QuadSPI_WRITE_EN >> 8) & 0xFF;
} else {
buffer[0] = QuadSPI_WRITE_DISABLE & 0xFF;
buffer[1] = (QuadSPI_WRITE_DISABLE >> 8) & 0xFF;
}
buffer[2] = QuadSPI_LOOKUP_STOP & 0xFF;
buffer[3] = (QuadSPI_LOOKUP_STOP >> 8) & 0xFF;
printf("Enabling QSPI write\r\n");
/* Write instruction */
result = fwrite (buffer, 1, 4 + QuadSPI_ADDR_BYTES, qspifd);
if (result < 0) {
printf ("ERROR\n");
return;
}
printf("flushing QSPI \r\n");
/* Wait till transfer end (and deactivate CS) */
fflush (qspifd);
qspi_mem_wait_for_write_en(qspifd);
}
int_32 qspi_mem_Sec_erase(MQX_FILE_PTR qspifd, uint_32 addr,uint_32 sectorFlag)
{
_mqx_int result;
uint_8 buffer[6+QuadSPI_ADDR_BYTES] = {0};
/* Enable flash memory write */
qspi_mem_set_write_en(qspifd, addr, TRUE);
/* Send erase command */
if(SECTOR_64K == sectorFlag)
{
printf("Erasing 64K Flash Sector at 0x%X\r\n",addr);
buffer[0] = QuadSPI_CHIP_64K_SEC_ERASE & 0xFF;
buffer[1] = (QuadSPI_CHIP_64K_SEC_ERASE >> 8) & 0xFF;
}
else if(SECTOR_4K == sectorFlag)
{
printf("Erasing 4K Flash Sector at 0x%X\r\n",addr);
buffer[0] = QuadSPI_CHIP_4K_SEC_ERASE & 0xFF;
buffer[1] = (QuadSPI_CHIP_4K_SEC_ERASE >> 8) & 0xFF;
}
else //SECTOR_8K == sectorFlag)
{
printf("Erasing 8K Flash Sector at 0x%X\r\n",addr);
buffer[0] = QuadSPI_CHIP_8K_SEC_ERASE & 0xFF;
buffer[1] = (QuadSPI_CHIP_8K_SEC_ERASE >> 8) & 0xFF;
}
buffer[2] = QuadSPI_SET_ADDR & 0xFF;
buffer[3] = (QuadSPI_SET_ADDR >> 8) & 0xFF;
buffer[4] = QuadSPI_LOOKUP_STOP & 0xFF;
buffer[5] = (QuadSPI_LOOKUP_STOP >> 8) & 0xFF;
/* Write instruction */
result = fwrite(buffer, 1, 6 + QuadSPI_ADDR_BYTES, qspifd);
printf("Waiting for not busy\r\n");
/* Wait till the flash is not busy at program */
qspi_mem_wait_for_not_busy(qspifd);
if (result < 0) {
printf("ERROR\n");
return -1;
}
printf("QuadSPI Successfully Erase Flash\n");
return 0;
}
boolean qspi_mem_read_status1(MQX_FILE_PTR qspifd, uint_8_ptr status)
{
}
uint_8 qspi_mem_read_byte(MQX_FILE_PTR qspifd, uint_32 addr)
{
}
int_32 qspi_mem_write_data (MQX_FILE_PTR qspifd, uint_32 addr, uint_32 size, uint_8_ptr data)
{
}
int_32 qspi_mem_read_data (MQX_FILE_PTR qspifd, uint_32 addr, uint_32 size, uint_8_ptr data)
{
}
#pragma arm section code