AnsweredAssumed Answered

PE- SDHC Example Project

Question asked by Carl Kendrat on Nov 30, 2011
Latest reply on Dec 1, 2011 by Ladislav Vadkerti

I am running CW10.1 and the example SDHC project.  It seems to work fine as-is Reading/Writing single blocks.  I am trying to modify the project to read/write multiple blocks and made the following changes...

 

1.  ReadBuffer[1200UL];

2.  Change...

                            Error = SD_ReadBlockPart(&SD, 0x00000000U, 0, Length, ReadBuffer);

to...

                            Error = SD_Read2Blocks(&SD, 0x00000000U, 0, sizeof(ReadBuffer), ReadBuffer);

3.   Where the functions are declared...

 

bool SD_Read2Blocks(TSDData *SD, uint32_t Address, uint32_t Offset, uint32_t Size, uint8_t *Data)
{
  bool Error = FALSE;
  const uint16_t BlockCount = 2;
  const uint16_t BlockSize = 512;
  static uint8_t Buffer[BlockSize*BlockCount + 4]; /* Data buffer */
  uint8_t *AlignedBuffer = (uint8_t*)(((uint32_t)Buffer + 4) & ~0x03U); /* Align buffer to 4-byte boundary */

  /* Read block */
  Error = SD_TransferBlocks(SD, TRUE, Address, AlignedBuffer, BlockCount);
  /* Cut out block part */
  memcpy(Data, &AlignedBuffer[Offset], Size);
  return Error;
}

 

bool SD_TransferBlocks(TSDData *SD, bool Read, uint32_t Address, uint8_t *Buffer,  uint8_t BlockCount)
{
  bool Error = FALSE;
  const uint16_t BlockSize = 512;
//  const uint16_t BlockCount = 1;
  uint32_t CardAddr = SD_ByteToCardAddress(&SD->CardInfo, Address); /* Read block address */
  LDD_SDHC_TBufferDesc BufferDesc;
  uint32_t Index;

  /* Init read buffer descriptor */
  BufferDesc.DataPtr = Buffer;
  BufferDesc.Size = BlockSize;
  /* Read card data block */
  SDHC_TransferBlocks(SD->SDHCPtr, (Read ? LDD_SDHC_READ : LDD_SDHC_WRITE), CardAddr, &BufferDesc, BlockCount);
  SD_Wait(SD, &Error);
  return Error;
}

 

It is not working correctly, what am I missing??

Outcomes