Unable to write and read uint32_t data to W25Q32 with stm32

In my project i am using winbond W25Q32 flash with stm32 i know this is not a forum for stm32 but i didn't get any support from stm community so please help me to write the uint32_t data to flash and read but as off now i have code for reading a uint8_t data and which is working properly.
so if i have 1000's of data like uint32_t spi_buf[1000];
and i want to write this data to flash but it takes only upto 0-255 after this write operation not working properly and even read aslo.
this is the code for write and read operation

void W25qxx_WritePage(char *pBuffer, uint32_t Page_Address, uint32_t OffsetInByte, uint32_t NumByteToWrite_up_to_PageSize)
{

	if (((NumByteToWrite_up_to_PageSize + OffsetInByte) > w25q32.PageSize) || (NumByteToWrite_up_to_PageSize == 0))
		NumByteToWrite_up_to_PageSize = w25q32.PageSize - OffsetInByte;
	if ((OffsetInByte + NumByteToWrite_up_to_PageSize) > w25q32.PageSize)
		NumByteToWrite_up_to_PageSize = w25q32.PageSize - OffsetInByte;
	W25q32_WaitForWriteEnd();
	W25q32_WriteEnable();
	HAL_GPIO_WritePin(GPIOB,GPIO_PIN_6,GPIO_PIN_RESET);
	Page_Address = (Page_Address * w25q32.PageSize) + OffsetInByte;
	W25q32_Spi(0x02);
	W25q32_Spi((Page_Address & 0xFF0000) >> 16);
	W25q32_Spi((Page_Address & 0xFF00) >> 8);
	W25q32_Spi(Page_Address & 0xFF);
	HAL_SPI_Transmit(&hspi1, pBuffer, NumByteToWrite_up_to_PageSize, 100);
	HAL_GPIO_WritePin(GPIOB,GPIO_PIN_6,GPIO_PIN_SET);
	W25q32_WaitForWriteEnd();
	printf("wrote data's are:\r\n");
	for (uint32_t i = 0; i < NumByteToWrite_up_to_PageSize; i++)
	{
		if ((i % 32 == 0) && (i > 2))
		{

			HAL_Delay(10);
		}
		printf("%d,", pBuffer[i]);
	}
	printf("\r\n");
	HAL_Delay(100);
}

void W25qxx_ReadPage(char *pBuffer, uint32_t Page_Address, uint32_t OffsetInByte, uint32_t NumByteToRead_up_to_PageSize)
{
	if ((NumByteToRead_up_to_PageSize > w25q32.PageSize) || (NumByteToRead_up_to_PageSize == 0))
		NumByteToRead_up_to_PageSize = w25q32.PageSize;
	if ((OffsetInByte + NumByteToRead_up_to_PageSize) > w25q32.PageSize)
		NumByteToRead_up_to_PageSize = w25q32.PageSize - OffsetInByte;
	Page_Address = Page_Address * w25q32.PageSize + OffsetInByte;
	HAL_GPIO_WritePin(GPIOB,GPIO_PIN_6,GPIO_PIN_RESET);
	W25q32_Spi(0x0B);
	W25q32_Spi((Page_Address & 0xFF0000) >> 16);
	W25q32_Spi((Page_Address & 0xFF00) >> 8);
	W25q32_Spi(Page_Address & 0xFF);
	W25q32_Spi(0);
	HAL_SPI_Receive(&hspi1, pBuffer, NumByteToRead_up_to_PageSize, 100);
	HAL_GPIO_WritePin(GPIOB,GPIO_PIN_6,GPIO_PIN_SET);
	printf("read data's are\r\n:");
	for (uint32_t i = 0; i < NumByteToRead_up_to_PageSize; i++)
	{
		if ((i % 32 == 0) && (i > 2))
		{
			HAL_Delay(10);
		}
		printf("%d,",pBuffer[i]);
	}
	printf("\r\n");
	HAL_Delay(100);
}
 

Welcome

Something like this maybe ?

W25qxx_WritePage( (char *)spi_buf, Page_Address, OffsetInByte, sizeof( spi_buf ) );

so you need first split your data to 255 bytes shunk and write one by one

Thanks for the reply guix, actually i tried in this way also but still it wrotes from 0-255 bytes after this i couldn't .So still i am blanked like how can i resolve this.

thanks for the reply, yes even i tried in that way also as you can see here,

void W25qxx_WritePage(uint16_t *pBuffer, uint32_t Page_Address, uint32_t OffsetInByte, uint32_t NumByteToWrite_up_to_PageSize)
{
	uint8_t *data;
	if (((NumByteToWrite_up_to_PageSize + OffsetInByte) > w25q32.PageSize) || (NumByteToWrite_up_to_PageSize == 0))
		NumByteToWrite_up_to_PageSize = w25q32.PageSize - OffsetInByte;
	if ((OffsetInByte + NumByteToWrite_up_to_PageSize) > w25q32.PageSize)
		NumByteToWrite_up_to_PageSize = w25q32.PageSize - OffsetInByte;
	W25q32_WaitForWriteEnd();
	W25q32_WriteEnable();
	HAL_GPIO_WritePin(GPIOB,GPIO_PIN_6,GPIO_PIN_RESET);
	Page_Address = (Page_Address * w25q32.PageSize) + OffsetInByte;
//	printf("\r\n in_write_size:%ld\r\n",NumByteToWrite_up_to_PageSize);
	data=(uint8_t *)pBuffer;
//	for(int i=0;i<10;i++)
//	{
//		printf("%d,", *(data++));
//	}
	for(uint8_t i=0;i<NumByteToWrite_up_to_PageSize;i++)
	{

		W25q32_Spi(0x02);
		W25q32_Spi((Page_Address & 0xFF0000) >> 16);
		W25q32_Spi((Page_Address & 0xFF00) >> 8);
		W25q32_Spi(Page_Address & 0xFF);
		HAL_SPI_Transmit(&hspi1, data++,1, 100);
		HAL_GPIO_WritePin(GPIOB,GPIO_PIN_6,GPIO_PIN_SET);
		W25q32_WaitForWriteEnd();
		HAL_Delay(100);
	}
	printf("\r\nwrote data's are:\r\n");
	for (uint32_t i = 0; i < NumByteToWrite_up_to_PageSize; i++)
	{
		if ((i % 32 == 0) && (i > 2))
		{

			HAL_Delay(10);
		}
		printf("%d,", data[i]);
	}
	printf("\n");
}




void W25qxx_ReadPage(uint16_t *qBuffer, uint32_t Page_Address, uint32_t OffsetInByte, uint32_t NumByteToRead_up_to_PageSize)
{
	uint8_t *data;
	if ((NumByteToRead_up_to_PageSize > w25q32.PageSize) || (NumByteToRead_up_to_PageSize == 0))
		NumByteToRead_up_to_PageSize = w25q32.PageSize;
	if ((OffsetInByte + NumByteToRead_up_to_PageSize) > w25q32.PageSize)
		NumByteToRead_up_to_PageSize = w25q32.PageSize - OffsetInByte;
	Page_Address = Page_Address * w25q32.PageSize + OffsetInByte;
//	printf("\r\n in_read_size:%ld\r\n",NumByteToRead_up_to_PageSize);
	for(uint32_t i=0;i<NumByteToRead_up_to_PageSize;i++)
	{
		data=(uint8_t *)qBuffer;
		HAL_GPIO_WritePin(GPIOB,GPIO_PIN_6,GPIO_PIN_RESET);
		W25q32_Spi(0x0B);
		W25q32_Spi((Page_Address & 0xFF0000) >> 16);
		W25q32_Spi((Page_Address & 0xFF00) >> 8);
		W25q32_Spi(Page_Address & 0xFF);
		W25q32_Spi(0);
		HAL_SPI_Receive(&hspi1, data++, 1, 100);
		HAL_GPIO_WritePin(GPIOB,GPIO_PIN_6,GPIO_PIN_SET);
		HAL_Delay(100);
	}
	printf("read data's are:\r\n");
	for (uint32_t i = 0; i < NumByteToRead_up_to_PageSize; i++)
	{
		if ((i % 32 == 0) && (i > 2))
		{
			HAL_Delay(10);
		}
		printf("%d,",data[i]);
	}
}

but no result as i expected so i don't know what to do, please anybody done this before help me to resolve the problem.

You have to send the array in small parts that fits in a page. If the page size is 256 bytes and your array is 4000 bytes then you have to send 16 parts (15 full pages and what remains)

Here is example demonstrating how to do it : woVhox - Online C++ Compiler & Debugging Tool - Ideone.com

sorry, but your code has nothing to do with "split data to 255 bytes parts and writing it one by one" as I recommended you. You send all data to the single page, as i see.

And I don't understand, what are you doing this:

If the HAL_Delay(10); is delay for page write - it should be used INSIDE the writing loop, but not after...

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.