changeset 420:2174fb133dbe ImprovmentNVM_2

Optimize ef_write_block function: The function did single byte writing until a start of a page was detected. Only in that case a multi byte write was used. According to the manual page write is not limited to 256 byte. Multiple bytes may be written until the end of the page is reached => Changed implementation to always use multi byte writes which increases the performance of the write block function
author ideenmodellierer
date Mon, 10 Feb 2020 19:15:27 +0100
parents c2264ce139cb
children 3f7d80f37bfc
files Discovery/Src/externLogbookFlash.c
diffstat 1 files changed, 21 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/Discovery/Src/externLogbookFlash.c	Mon Feb 10 08:23:15 2020 +0000
+++ b/Discovery/Src/externLogbookFlash.c	Mon Feb 10 19:15:27 2020 +0100
@@ -1633,7 +1633,8 @@
 static void ef_write_block(uint8_t * sendByte, uint32_t length, uint8_t type, uint8_t do_not_erase)
 {
 	uint32_t remaining_page_size, remaining_length, remaining_space_to_ring_end;
-	
+	uint32_t i=0;
+
 	if(!length)
 		return;
 
@@ -1688,7 +1689,7 @@
 	if(do_not_erase == 0)
 		ext_flash_erase_if_on_page_start();
 	
-	for(uint32_t i=0;i<length;i++)
+	while( i<length)
 	{
 		ef_hw_rough_delay_us(5);
 		wait_chip_not_busy();
@@ -1697,12 +1698,24 @@
 		write_address(HOLDCS);
 		
 		remaining_length = length - i;
-		remaining_page_size = actualAddress & 0xFF;
+		remaining_page_size = 0xFF - (uint8_t)(actualAddress & 0xFF) +1;
 		remaining_space_to_ring_end = ringStop - actualAddress;
 		
-		if((remaining_page_size == 0) && (remaining_length >= 256) && (remaining_space_to_ring_end >= 256))
+		if(remaining_length >= 256)
+		{
+			remaining_length = 255;	/* up to 256 bytes may be written in one burst. Last byte is written with release */
+		}
+		else
 		{
-			for(int j=0; j<255; j++)
+			remaining_length--;		/* last byte needed for release */
+		}
+		if(remaining_length >= (remaining_page_size) ) /* use 256 byte page and calculate number of bytes left */
+		{
+			remaining_length = remaining_page_size - 1;
+		}
+		if( (remaining_space_to_ring_end >= 256)) 
+		{
+			for(int j=0; j<remaining_length; j++)
 			{
 				write_spi(sendByte[i],HOLDCS);/* write data */
 				actualAddress++;
@@ -1712,8 +1725,11 @@
 		/* byte with RELEASE */
 		write_spi(sendByte[i],RELEASE);/* write data */
 		actualAddress++;
+		i++;
+
 		if(actualAddress > ringStop)
 			actualAddress = ringStart;
+
 		if(do_not_erase == 0)
 			ext_flash_erase_if_on_page_start();
 	}