AnsweredAssumed Answered

fsl_sdcard malloc return NULL pointer

Question asked by Maxime Dolberg on Mar 21, 2016
Latest reply on Oct 14, 2016 by Daniel Caetano

Hello,

 

I am face with a problem with fsl_sdcard component in KSDK v1.3 + PEx. I would like to read a block of my micro SDHC card with SDSPI_DRV_ReadBlocks() function driver. But it seem that it doesn't work because that function always returning kStatus_SDSPI_OutOfMemory.

 

Somewhere, SDSPI_DRV_ReadBlocks() call calloc()  function (see more bellow) and this is cause the problem.

 

I am using FRDM-KL25Z board.

 

My code :

void run_sdcard(void) {     uint8_t buffer[512] = {0};     SDSPI_DRV_ReadBlocks(&memoryCard1_spi_state,&memoryCard1_state,buffer,0,1);     while(1);  }

 

Source of fsl_sdcard_spi.c

sdspi_status_t SDSPI_DRV_ReadBlocks(sdspi_spi_t *spi, sdspi_card_t *card, uint8_t *buffer,                                     uint32_t startBlock, uint32_t blockCount) {     uint32_t offset, i;     sdspi_request_t *req;     assert(spi);     assert(card);     assert(buffer);     assert(blockCount);      req = (sdspi_request_t *)OSA_MemAllocZero(sizeof(sdspi_request_t));     if (req == NULL)     {         return kStatus_SDSPI_OutOfMemory;     }      offset = startBlock;     if (!IS_BLOCK_ACCESS(card))     { ....

 

Source of fsl_os_abstraction_bm.c. You can see the calloc()

/*FUNCTION**********************************************************************  *  * Function Name : OSA_MemAllocZero  * Description   : This function is used to allocate amount of memory in bytes  * and initializes it to 0.  * Return the pointer to the memory if success, otherwise return NULL;  *  *END**************************************************************************/ void * OSA_MemAllocZero(size_t size) {     return calloc(1, size); }

 

Why memories allocations failed like that ?

Outcomes