Skip to main content
Visitor II
May 3, 2023
Question

EEPRMA2 M95 writedata bug?

  • May 3, 2023
  • 1 reply
  • 1220 views

Hi,

I'm using the latest EEPRMA2 drivers for the M95M04 EEPROM.

I'm trying to store data in EEPROM on a specific address.

In the following example, I expect one byte to be written to address 5.

uint8_t a = 10;

uint32_t targetAddr = 5;

EEPRMA2_M95_WriteData(EEPRMA2_M95M04_0, &a, targetAddr , sizeof(a));

Stepping into EEPRMA2_M95_WriteData, we go into M95_spi_WriteData which still has the size of 1, but moving to the step where EEPRMA2_SPI_SendBuffer is called, the size has changed to 6 bytes to be written. It looks like the size is defined from the remainder, which is based on the following equation: ( targetAddress + Size ) % PageSize

I don't see how this can be correct implementation?

Edit: I seems like this person has the same problem https://github.com/STMicroelectronics/X-CUBE-EEPRMA1/issues/4

    This topic has been closed for replies.

    1 reply

    Explorer II
    March 14, 2024
    int32_t M95_spi_WriteData(M95_Object_t *pObj, uint8_t * pData, const uint32_t TarAddr ,
     const uint16_t PageSize, const uint16_t Size )
    {
     int32_t status = M95_OK;
     
     uint32_t targetAddress = TarAddr;
     uint16_t remainingSize = Size;
     
     // Calculate the starting page and offset
     uint16_t startOffset = TarAddr % PageSize;
     uint16_t offset = startOffset;
     
     
     // Check for invalid inputs
     if (pObj == NULL || pData == NULL || PageSize == 0 || remainingSize == 0) {
     return M95_ERROR; // Return an error code indicating invalid inputs
     } 
     
     if (pObj->IO.IsReady( pObj->IO.Address ) !=M95_OK)
     {
     return M95_ERROR;
     } 
     
     // Iterate over the pages and write the data
     while (remainingSize > 0) 
     {
     uint16_t bytesToWrite = (remainingSize < PageSize - offset) ? remainingSize : (PageSize - offset);
     
     /* Condition Matters only for 4Kb SPI ie M95040, for others EEPROMEX_WRITE & EEPROMEX_UPWRITE are same */
     if (pObj->IO.Address == 0xC6) 
     { 
     if (targetAddress < 256)
     {
     status = pObj->IO.WriteBuffer( pData, targetAddress, pObj->IO.Address, bytesToWrite ,EEPROMEX_WRITE);
     }
     else
     {
     status = pObj->IO.WriteBuffer( pData, targetAddress, pObj->IO.Address, bytesToWrite ,EEPROMEX_UPWRITE);
     }
     }
     else
     {
     status = pObj->IO.WriteBuffer( pData, targetAddress, pObj->IO.Address, bytesToWrite ,EEPROMEX_WRITE);
     }
     
     pObj->IO.Delay(6);
     
     // Update the pointers and sizes for the next page
     pData += bytesToWrite;
     targetAddress += bytesToWrite;
     remainingSize -= bytesToWrite;
     offset = targetAddress % PageSize;
     
     // Wait for the SPI interface to be ready before proceeding to the next page
     while( pObj->IO.IsReady( pObj->IO.Address ) != M95_OK ) {};
     }
     return status; 
    }