fsl_sdcard malloc return NULL pointer

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

fsl_sdcard malloc return NULL pointer

1,407 Views
mr_max
Contributor IV

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 ?

Labels (1)
0 Kudos
4 Replies

947 Views
ivadorazinova
NXP Employee
NXP Employee

Hi Maxime,

please, have you tried to increase stack size in MKL25Z128xxx4_flash.ld file?

HEAP_SIZE  = DEFINED(__heap_size__)  ? __heap_size__  : 0x0400;

STACK_SIZE = DEFINED(__stack_size__) ? __stack_size__ : 0x0400;

M_VECTOR_RAM_SIZE = DEFINED(__ram_vector_table__) ? 0x0100 : 0x0;

You will find it under C:\Freescale\KSDK_1.3.0\platform\devices\MKL25Z4\linker\gcc

Maybe this article also helps you. Tutorial: DIY Kinetis SDK Project with Eclipse – Startup | MCU on Eclipse

Best Regards,

Iva

0 Kudos

947 Views
mr_max
Contributor IV

Hello Iva,

Sorry for late response. No I didn't try to increase stack size. I checked the MKL25Z128 linker flash file and found exactly what you showed me. But I don't like the idea of editing these sources files because it's also using by many other projects (I guess ?).

I am using Processor Expert, so I have found that the heap size default value was 0x0000 into Cpu component -> Build option. So, I simply set it to the same value of stack size (0x0400) for a test and it solve my problem ! Calloc() function do not return a NULL pointer any more.

Capture d’écran 2016-03-31 à 14.32.41.png

Thank you for your response, you lead me to the good way :smileyhappy:.

Even I can't still use fsl_sdcard component correctly (didn't find any good code example)  but I can read/write to my sd card with fsl_spi component.

0 Kudos

947 Views
rimidhanjal
Contributor I

i am still facing the same issue ....i am trying to implement usb host hid(for keyboard) for k66 based on processor expert.

0 Kudos

947 Views
danielcaetano
Contributor III

I also found the same problem as Rimi trying to implement a USB MSD host. Did you manage to solve it yet?

0 Kudos