RPI3B 1G IMX519 focus not working with libcamera

Hi,

I’ve received my IMX519 cameras and having problems using them.

  1. First of all, I have 1Gb version of rpi3. I cannot find any info that 1GB is not enough to capture image greater than 1024x1024 px. This info should be told in compability charts.
  2. I cannot get the camera module to focus at all. I always get this warning: “Could not set AF_MODE - no AF algorithm”.
  3. No guide mentions the red lens cover. I removed it thinking that the focusing issues was caused by it.

I have been installing everything by this guide:
https://docs.arducam.com/Raspberry-Pi-Camera/Native-camera/16MP-IMX519/

I get the still image using this command, but the image is always out of focus:
libcamera-still -t 1 -o test.jpg --autofocus-mode auto --width 1024 --height 1024

I have also tried the manual focus option, but there is no change in focus with any value of lens position:
libcamera-still -t 1 --width 1024 --height 1024 -n -o test.jpg --autofocus-mode manual --lens-position 1024000000

/mika

I am unable to edit my post to include this info (getting 403):

More info:
mimyllyv@rpi:~ $ dpkg -l | grep libcamera
ii libcamera-dev:arm64 0.3.1+rpt20240906-1 arm64 complex camera support library (development files)
ii libcamera-ipa:arm64 0.3.1+rpt20240906-1 arm64 complex camera support library (IPA modules)
ii libcamera-tools 0.3.1+rpt20240906-1 arm64 complex camera support library (tools)
ii libcamera0.3:arm64 0.3.1+rpt20240906-1 arm64 complex camera support library
ii pipewire-libcamera:arm64 0.3.65-3+rpt8+deb12u1 arm64 PipeWire libcamera plugin
ii python3-libcamera:arm64 0.3.1+rpt20240906-1 arm64 complex camera support library (Python bindings)

mimyllyv@rpi:~ $ uname -a
Linux rpi 6.6.47+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.6.47-1+rpt1 (2024-09-02) aarch64 GNU/Linux

Where did you get the camera module(s)?
Directly from arducam.

Model number of the product(s).
B0371

What hardware/platform were you working on?
Hardware name: Raspberry Pi 3 Model B Plus Rev 1.3 (DT)

Instructions you have followed. (link/manual/etc.)
https://docs.arducam.com/Raspberry-Pi-Camera/Native-camera/16MP-IMX519/

Problems you were having.
Specified above.

The dmesg log from your hardware.
No errors found, will include it if you really want.

Troubleshooting attempts you’ve made.
Many from the forum.

What help do you need?
I would like my camera to focus.

/mika

Hi,
Please follow the steps in the link below to update arducam libcamera.

Hi Dion,

The update works great! Now the focus is working. Thank you.

Could you help with the other problem? I am not able to capture photos in full 16M resolution. For what I have read, the problem lies to cma memory is low. For me it is 64M. I’ve was able to increase it to 128M, but now I cannot capture even 1024x1024 pixel image. What can I do to increase captured image size?

/mika

Hi Mika,
How did you increase the CMA size?
Can you attach the output of the command below?

cat /proc/meminfo

Hi Dion,

Here is the meminfo, when I change no config:
mimyllyv@rpi:~ $ cat /proc/meminfo
MemTotal: 929028 kB
MemFree: 626152 kB
MemAvailable: 763620 kB
Buffers: 16996 kB
Cached: 160092 kB
SwapCached: 0 kB
Active: 197164 kB
Inactive: 38628 kB
Active(anon): 59960 kB
Inactive(anon): 0 kB
Active(file): 137204 kB
Inactive(file): 38628 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 787452 kB
SwapFree: 787452 kB
Zswap: 0 kB
Zswapped: 0 kB
Dirty: 4292 kB
Writeback: 0 kB
AnonPages: 58744 kB
Mapped: 79552 kB
Shmem: 1256 kB
KReclaimable: 13636 kB
Slab: 36968 kB
SReclaimable: 13636 kB
SUnreclaim: 23332 kB
KernelStack: 3172 kB
PageTables: 2812 kB
SecPageTables: 0 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 1251964 kB
Committed_AS: 519216 kB
VmallocTotal: 257687552 kB
VmallocUsed: 10144 kB
VmallocChunk: 0 kB
Percpu: 672 kB
CmaTotal: 65536 kB
CmaFree: 59944 kB

To increase cma, I alter /boot/firmware/cmdline.txt. At the end of first line I add cma=128M:
console=serial0,115200 console=tty1 root=PARTUUID=c5b9660b-02 rootfstype=ext4 fsck.repair=yes rootwait cfg80211.ieee80211_regdom=FI cma=128M

Reboot rpi. Here is the new meminfo:
mimyllyv@rpi:~ $ cat /proc/meminfo
MemTotal: 929028 kB
MemFree: 631880 kB
MemAvailable: 763396 kB
Buffers: 16216 kB
Cached: 155008 kB
SwapCached: 0 kB
Active: 196152 kB
Inactive: 33848 kB
Active(anon): 60048 kB
Inactive(anon): 0 kB
Active(file): 136104 kB
Inactive(file): 33848 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 783356 kB
SwapFree: 783356 kB
Zswap: 0 kB
Zswapped: 0 kB
Dirty: 1964 kB
Writeback: 0 kB
AnonPages: 58828 kB
Mapped: 79792 kB
Shmem: 1252 kB
KReclaimable: 13496 kB
Slab: 36892 kB
SReclaimable: 13496 kB
SUnreclaim: 23396 kB
KernelStack: 3216 kB
PageTables: 2796 kB
SecPageTables: 0 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 1247868 kB
Committed_AS: 519180 kB
VmallocTotal: 257687552 kB
VmallocUsed: 10188 kB
VmallocChunk: 0 kB
Percpu: 672 kB
CmaTotal: 131072 kB
CmaFree: 125480 kB

/mika

Again (http?) 403 when trying to edit my last post.

Now with more cma available I get error:
dmaHeap allocation failure for rpicam-apps0
ERROR: *** failed to allocate capture buffers for stream ***

/mika

Hi Mika,
The CMA size maybe not be enough to store 16mp images. Can you increase it to a higher size like 128MB or 256MB?

Hi Dion,

If I try to change the size of cma memory (64M, 192M, 256M, 384M, 512M), I am not able to capture any image. The error message is always:

dmaHeap allocation failure for rpicam-apps0
ERROR: *** failed to allocate capture buffers for stream ***

Even if I set the cmdline.txt’s last parameter to be cma=64M, which is the default value, I cannot capture image.

If I remove the cma param from cmdline.txt alltogether, I am able to capture images, but not in full res.

Here is info from dmesg when I try to capture image without --width and --height parameters to libcamera-still (full resolution?). I have no cma parameter in cmdline.txt:

[ 60.683716] cma: cma_alloc: linux,cma: alloc failed, req-size: 1243 pages, ret: -12
[ 60.683775] ------------[ cut here ]------------
[ 60.683781] WARNING: CPU: 1 PID: 936 at mm/page_alloc.c:4437 __alloc_pages+0x6ac/0xe68
[ 60.683802] Modules linked in: rfcomm snd_seq_dummy snd_hrtimer snd_seq snd_seq_device cmac algif_hash aes_arm64 aes_generic algif_skcipher af_alg bnep brcmfmac_wcc brcmfmac brcmutil cfg80211 raspberrypi_hwmon hci_uart ak7375 btbcm imx519 bluetooth bcm2835_unicam v4l2_dv_timings bcm2835_isp(C) bcm2835_codec(C) v4l2_fwnode bcm2835_v4l2(C) v4l2_async bcm2835_mmal_vchiq(C) v4l2_mem2mem videobuf2_dma_contig videobuf2_vmalloc videobuf2_memops snd_bcm2835(C) videobuf2_v4l2 videodev snd_pcm binfmt_misc ecdh_generic ecc snd_timer rfkill videobuf2_common libaes snd mc vc_sm_cma(C) raspberrypi_gpiomem joydev uio_pdrv_genirq uio i2c_dev drm fuse dm_mod drm_panel_orientation_quirks backlight ip_tables x_tables ipv6 i2c_mux_pinctrl i2c_mux i2c_bcm2835
[ 60.684005] CPU: 1 PID: 936 Comm: libcamera-still Tainted: G C 6.6.47+rpt-rpi-v8 #1 Debian 1:6.6.47-1+rpt1
[ 60.684015] Hardware name: Raspberry Pi 3 Model B Plus Rev 1.3 (DT)
[ 60.684019] pstate: 20000005 (nzCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=–)
[ 60.684027] pc : __alloc_pages+0x6ac/0xe68
[ 60.684035] lr : __dma_direct_alloc_pages.constprop.0+0x15c/0x238
[ 60.684046] sp : ffffffc080d5b7c0
[ 60.684049] x29: ffffffc080d5b7c0 x28: 000000000000000b x27: ffffff80055ba508
[ 60.684061] x26: ffffff80067ea000 x25: ffffffd40dd3622c x24: 0000000000000000
[ 60.684072] x23: 0000000000000cc1 x22: ffffff8002479410 x21: 00000000000004da
[ 60.684084] x20: 00000000004dafff x19: 0000000000000000 x18: 00000000fffffffe
[ 60.684095] x17: 72202c7365676170 x16: 2033343231203a65 x15: 7a69732d71657220
[ 60.684106] x14: 2c64656c69616620 x13: 32312d203a746572 x12: 202c736567617020
[ 60.684117] x11: 33343231203a657a x10: ffffffd40f2b3710 x9 : ffffffd40dd3774c
[ 60.684128] x8 : 00000000ffffefff x7 : ffffffd40f2b3710 x6 : 80000000fffff000
[ 60.684139] x5 : 0000000000000001 x4 : 0000000000000000 x3 : 0000000000000000
[ 60.684150] x2 : ffffff80037cdc40 x1 : 0000000000000001 x0 : ffffffd40f41c000
[ 60.684163] Call trace:
[ 60.684168] __alloc_pages+0x6ac/0xe68
[ 60.684176] __dma_direct_alloc_pages.constprop.0+0x15c/0x238
[ 60.684183] dma_direct_alloc+0x78/0x310
[ 60.684189] dma_alloc_attrs+0x8c/0x108
[ 60.684202] vb2_dc_alloc+0xa8/0x188 [videobuf2_dma_contig]
[ 60.684220] __vb2_queue_alloc+0x1cc/0x4a8 [videobuf2_common]
[ 60.684255] vb2_core_reqbufs+0x244/0x470 [videobuf2_common]
[ 60.684279] vb2_ioctl_reqbufs+0xc0/0x108 [videobuf2_v4l2]
[ 60.684303] v4l_reqbufs+0x58/0x78 [videodev]
[ 60.684409] __video_do_ioctl+0x170/0x3e0 [videodev]
[ 60.684480] video_usercopy+0x208/0x770 [videodev]
[ 60.684547] video_ioctl2+0x20/0x40 [videodev]
[ 60.684615] v4l2_ioctl+0x48/0x70 [videodev]
[ 60.684683] __arm64_sys_ioctl+0xb4/0x100
[ 60.684693] invoke_syscall+0x50/0x128
[ 60.684705] el0_svc_common.constprop.0+0x48/0xf0
[ 60.684715] do_el0_svc+0x24/0x38
[ 60.684724] el0_svc+0x40/0xe8
[ 60.684735] el0t_64_sync_handler+0x100/0x130
[ 60.684742] el0t_64_sync+0x190/0x198
[ 60.684750] —[ end trace 0000000000000000 ]—
[ 60.685905] unicam 3f801000.csi: dma alloc of size 5091328 failed

And when I set the cma=256M, dmesg has no errors, but I get on terminal the same error:

dmaHeap allocation failure for rpicam-apps0
ERROR: *** failed to allocate capture buffers for stream ***

/mika