This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Linux/AM5728: Dual camera demo and CMEM

Part Number: AM5728


Tool/software: Linux

Hi, 

I recompile the dual-camera-demo in topdir of sdk4.2.0.9 with :make dual-camera-demo

I changed the "default_parameters" in loopback.c to our own device:

/* Main camera */
cap0_device.memory_mode = V4L2_MEMORY_DMABUF;
cap0_device.num_buffers = NBUF;
strcpy(cap0_device.dev_name,"/dev/video2");
strcpy(cap0_device.name,"Capture 0");
cap0_device.buffers = NULL;
cap0_device.fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
cap0_device.width = 1920;
cap0_device.height = 1080;

And I  uncomment "#define USE_CMEM_BUF" to capture frames to .jpeg .

It display fine.But when I tried to click Capture the app will be crash:

root@am57xx-evm:/opt# ./dual_camera -platform linuxfb
CRTCs size: 1920x1080

Capture 0: Opened Channel

Capture 0: Capable of streaming

Capture 0: Init done successfully


allocating cmem buffer of size 0x3f4800
allocating cmem buffer of size 0x3f4800

Capture 1: Opened Channel

Capture 1: Capable of streaming

VIDIOC_G_PARM: Inappropriate ioctl for device
allocating cmem buffer of size 0x3f4800Only one camera detected
Running the demo on am57xx processor
w=1920, h=1080
//click "Capture " here
Segmentation fault (core dumped)

There is a image0.jpg in /usr/share/camera-images/ ,but nothing can be stored.

And I tried to read the buf from the cmem pointer "buf->cmem".There is still nothing in cmem.

We are anxious to use cmem to read picture from V4L2 quickly and then display the proccessed picture. 

But we can't read the picture in this demo.Please help us.

Best Regards.

  • Hi,
    I found that issue occur at "alloc_cmem_buffer" in cmem_buf.c
    When excute :
    CMEM_export_dmabuf(cmem_buf);
    "cmem_buf" will be return to 0 .Why did that happened?
    the fuction:
    cmem_buf = CMEM_alloc2(CMEM_BLOCKID, size,&cmem_alloc_params);
    has already alloc a cmem_buf which I have checked.
  • int alloc_cmem_buffer(unsigned int size, unsigned int align, void *cmem_buf)
    {
    cmem_alloc_params.alignment = align;

    printf("\n allocating cmem buffer of size 0x%x", size);

    cmem_buf = CMEM_alloc2(CMEM_BLOCKID, size,
    &cmem_alloc_params);

    if(cmem_buf == NULL){
    printf("CMEM allocation failed");
    return -1;
    }

    return CMEM_export_dmabuf(cmem_buf); //cmem return to 0 ???
    }
  • Hi, There is known bug in dual_camera_demo cmem buffer allocation which will be taken care in next Processor SDK release.  The alloc_cmem_buffer() function call needs to pass pointer to the buffer address and inside that function, the value needs to be stored as  *cmem_buf.

    buf->fd[0]  = alloc_cmem_buffer(w*h*bytes_pp, 1, &buf->cmem_buf);

    *cmem_buf = CMEM_alloc2(CMEM_BLOCKID, size, &cmem_alloc_params);

  • Hi,
    Thanks,and another advice of alloc_cmem_buffer() "void *cmem_buf" need to be "unsigned int *cmem_buf"
  • CMEM_alloc2() API returns void *, so it's okay to return back as void * that application can assign to the type they want to consume the buffer as.
  • Hi,

    Thanks for your reply.

    There is another issue happened.

    I tried to creat a new cmem block in am57xx-evm-cmem.dtsi

    / {
    reserved-memory {
    #address-cells = <2>;
    #size-cells = <2>;
    ranges;

    cmem_block_mem_0: cmem_block_mem@a0000000 {
    reg = <0x0 0xa0000000 0x0 0xc000000>;
    no-map;
    status = "okay";
    };

    cmem_block_mem_1_ocmc3: cmem_block_mem@40500000 {
    reg = <0x0 0x40500000 0x0 0x100000>;
    no-map;
    status = "okay";
    };

    cmem_block_mem_2: cmem_block_mem@ac000000 {
    reg = <0x0 0xac000000 0x0 0xc000000>;
    no-map;
    status = "okay";
    };

    };

    cmem {
    compatible = "ti,cmem";
    #address-cells = <1>;
    #size-cells = <0>;

    #pool-size-cells = <2>;

    status = "okay";

    cmem_block_0: cmem_block@0 {
    reg = <0>;
    memory-region = <&cmem_block_mem_0>;
    cmem-buf-pools = <1 0x0 0xc000000>;
    };

    cmem_block_1: cmem_block@1 {
    reg = <1>;
    memory-region = <&cmem_block_mem_1_ocmc3>;
    };

    cmem_block_2: cmem_block@2 {
    reg = <2>;
    memory-region = <&cmem_block_mem_2>;
    cmem-buf-pools = <1 0x0 0xc000000>;
    };


    };
    };

    0xac000000 ~ 0xb7ffffff is my cmem to store buffer

    But when I tried to update the am57xx-beagle-x15.dtb :

    root@am57xx-evm:/opt# cat /proc/cmem

    Block 0: Pool 0: 1 bufs size 0xc000000 (0xc000000 requested)

    Pool 0 busy bufs:

    Pool 0 free bufs:
    id 0: phys addr 0xa0000000

    root@am57xx-evm:~# cat /proc/iomem | grep CMEM
    40500000-405fffff : CMEM
    a0000000-abffffff : CMEM
    ac000000-b7ffffff : CMEM

    still one default block?

  • Hi,

    Do u solve this cmem issue?I am facing the same issue,did that work to create a new block in am57xx-evm-cmem.dtsi?

    Any insight on this will be nice.

    Thanks and BR

  • Hi,

    I've solved it.

    If you use:

    CMEM_AllocParams cmem_alloc_params = {

    CMEM_HEAP, /* type */

    CMEM_CACHED, /* flags */

    1 /* alignment */

    };

    cmem_buf = CMEM_alloc2(CMEM_BLOCKID, size,

    &cmem_alloc_params);

    You will got a cmem in ddr automatically.

    If you set CMEM_POOL.

    You can choose a blockid in CMEM_alloc2()

  • Hi,
    Thanks for your reply.I have created a new block in am57xx-evm-cmem.dtsi,but when I run the dual_cam demo,the allocation still failed.Could u tell me how to set CMEM_POOL?Is there other change should i make in dts file or the demo?

    CMEM Error: allocHeap: ioctl CMEM_IOCALLOCHEAPCACHED failed: -1
    allocating cmem buffer of size 0x3f4800CMEM allocation failed
    CMEM Error: free: failed to free 0
    Cannot export CMEM buffer
    ERROR:get_vid_buffers_new:400: allocation failed
  • Hi,
    Below is my old thread about cmem:
    e2e.ti.com/.../660967
    Maybe that will help you .
  • Hi,
    Sorry to interrupt u again.I've checked your old thread and add a new block,now my question is how to choose this block in dual_cam demo,I found it used the old block not my new block.
    root@am57xx-evm:~# cat /proc/cmem

    Block 0: Pool 0: 1 bufs size 0xf000000 (0xf000000 requested)

    Pool 0 busy bufs:

    Pool 0 free bufs:
    id 0: phys addr 0xa0000000

    Block 1: Pool 0: 1 bufs size 0xf000000 (0xf000000 requested)

    Pool 0 busy bufs:

    Pool 0 free bufs:
    id 0: phys addr 0xaf000000
    Thanks sincerely and BR
  • I've tried ti-mctd too,and the same issue come,how did u solve it?
    root@am57xx-evm:~# ti-mctd
    [ 2040.531084] CMEMK Error: ioctl: no heap available in block 1
    CMEM Error: allocHeap: ioctl CMEM_IOCALLOCHEAPCACHED failed: -1
    TIOCL FATAL: Unable to allocate On-chip CMEM from 0xaf000000
  • Hi bulabula_yan,
    Problem solved,thanks for your help!