cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
jakubon2
Participant
Participant
9,780 Views
Registered: ‎04-02-2013

Zynq Standalone - Dynamic Memory Allocation malloc() Problem

Jump to solution

Hi there,

 

I cannot use malloc() under a standalone application for Zynq, it seems that the pointer keeps its value after its call. There is a simplified chuck of the program which returns the error: 

 

#include "stdlib.h"

 

typedef struct {
  u32_t *base; /** Base pointer of the buffer */
  u32_t *wr; /** Next memory location to write to */
  u32_t *rd; /** Next memory location to read from */
  u32_t size; /** Buffer size in 4*bytes, must be a power of 2 */
  u32_t items; /** Number of 4*byte words in the FIFO */
  u32_t mask; /** Mask of the buffer */
} fifo_t __attribute__ ((aligned (4)));

 

fifo_t *fifo;

fifo = (fifo_t *) malloc(sizeof(fifo_t));
if (fifo == NULL) return FIFO_ALLOC_FAILED;

 

I am using the SW architecture from AMP Linux and Baremetal reference desing for ZC702, adopted to ZC706. Everything else works fine. 

 

In some cases, the error message repeadly keeps printing on the terminal.  

 

Is there any restriction with using malloc() or anything else necessary to initialize? Should sbrk() function be used instead?

 

Thank you in advance!

Ondrej

 

Ondrej
0 Kudos
1 Solution

Accepted Solutions
ryserp
Xilinx Employee
Xilinx Employee
12,829 Views
Registered: ‎07-31-2008

Could it be that you are running out of heap space? How much heap have you allocated in the linker script?

 

View solution in original post

5 Replies
ryserp
Xilinx Employee
Xilinx Employee
12,830 Views
Registered: ‎07-31-2008

Could it be that you are running out of heap space? How much heap have you allocated in the linker script?

 

View solution in original post

jakubon2
Participant
Participant
9,764 Views
Registered: ‎04-02-2013

Hi,

 

I've got by default 2kB of heap space in the linker script, the FIFO module asks for 256 of u32 words so I guess this should be fine.  I've tried to run that allocation on an empty application, still having the problem.

 

Is there any reference design which uses malloc() on Zynq Standalone which I can take a look at?

 

Thank you for your quick response.

Ondrej

 

 

 

Ondrej
0 Kudos
jakubon2
Participant
Participant
9,760 Views
Registered: ‎04-02-2013

I found that a similar topic's been discussed here. It was redirected to AR# 23345. I will try to increase the heap size much more as suggested.

Ondrej
0 Kudos
jakubon2
Participant
Participant
9,749 Views
Registered: ‎04-02-2013

Hi there, 

 

Increasing the heap size helped, the problem is solved now. Thank you!

Ondrej
0 Kudos
Nitin_Kumar
Contributor
Contributor
298 Views
Registered: ‎07-28-2020

solved my issue too.. Thanks

0 Kudos