Flash write stalls

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Flash write stalls

Jump to solution
2,458 Views
Robert123
Contributor III

Hi, I am writing an application which downloads a new image (over-the-air update) from a HTTP server.

The size of the new image is a bit larger than 400 kbytes. After approximately 100-200 kbytes the write to the flash memory fails/stalls. I cannot get any useful information from the debugger.

I disable the interrupts and enable between each write to the flash as shown below:

 

unsigned char https_buf[1024];

int read_request()
{
	do
	{
		len = sizeof(https_buf);
		memset(https_buf, 0, sizeof(https_buf));
		ret = lwip_recv(tlsDataParams.fd, https_buf, len, 0);
		if (ret == 0)
		{
		PRINTF("\n\nEOF\r\n");
			goto exit;
		}

		uint32_t regPrimask = DisableGlobalIRQ();
		result = mflash_drv_write(chunk_addr, (uint8_t*)https_buf, len);
		EnableGlobalIRQ(regPrimask);
	} while (1);

 

I am using a Embedded Artists imx-rt1062-developers-kit with the following SDK: eaimxrt1062_sdk_2.9.3_freertos. The flash memory is a Adesto XIP.

Could you give any hints on why the write to flash stalls?

Labels (1)
0 Kudos
1 Solution
2,388 Views
Alexis_A
NXP TechSupport
NXP TechSupport

Hello @Robert123,

I think to ensure the communication in the ethernet side your workaround would be the best option. 

Best Regards,

Alexis Andalon

View solution in original post

7 Replies
2,430 Views
Robert123
Contributor III

double post

0 Kudos
2,438 Views
Robert123
Contributor III

Found a solution by ereasing the sector before writing to it, as described here: https://community.nxp.com/t5/NXP-Designs/Flash-Write-with-FreeRTos/m-p/1134245

result = mflash_drv_sector_erase(chunk_addr);
if (result != 0)
{
	PRINTF("\r\nCould not earase sector\r\n");
}

result = mflash_drv_write(chunk_addr, (uint8_t*)&https_buf[start_image_pos], len - start_image_pos);
if (result != 0)
{
	PRINTF("\r\nError during write\r\n");
}

 

0 Kudos
2,423 Views
Robert123
Contributor III

Actually, the problem still exists when I continued to work on my project today. I have tried to read and erase the flash memory before writing and also tried to reset the flex SPI but nothing works. The write to flash write still stalls/crashes.

0 Kudos
2,405 Views
Alexis_A
NXP TechSupport
NXP TechSupport

Hello @Robert123,

Is this a problem with writing at a certain sector? If you write at the sector that is stalling the operation does the same behavior is present?

Best Regards,
Alexis Andalon

0 Kudos
2,394 Views
Robert123
Contributor III

It stalls at different sectors from 100 to 300 kbytes (one sector is 10 kbyte). I am running FreeRTOS (for the lwip stack) and I think it may interfere when I am disabling the interrupts while I am writing to flash. Sometimes I am unable to fetch the entire binary and lwip_recv returns 0 indicating "end of file" premature.

I solved the OTA update by copying the entire binary to a temporary buffer. But the buffer is quite large so it would be nice to allow writing to flash while still enabling interrupts.

0 Kudos
2,389 Views
Alexis_A
NXP TechSupport
NXP TechSupport

Hello @Robert123,

I think to ensure the communication in the ethernet side your workaround would be the best option. 

Best Regards,

Alexis Andalon

2,374 Views
Robert123
Contributor III

Thanks, do you think a solution would be to replace lwip with the freertos TCP/IP stack? https://www.freertos.org/FreeRTOS_Support_Forum_Archive/November_2014/freertos_FreeRTOS_TCP_IP_stack...

It would be nice to avoid allocating a large buffer in RAM and write directly to flash.

0 Kudos