How can canvas use with lv_mem_alloc()?

i developing smartwatch for my graduation project, developed a analog clock for the sleeping mode but, i have a problem on memory, i wrote before to the forum but, lv_mem_alloc() function give a error, how can i solve my problem ?

i saw this method at a websites;
lv_color_t *cbuf = (lv_color_t*)lv_mem_alloc(LV_CANVAS_BUF_SIZE_TRUE_COLOR(272, 272));

but console give this errors;

Warn: Couldn’t allocate memory (c:\users\nesat\documents\github\lv_sim_visual_studio_sdl\visual_studio_2017_sdl\lvgl\src\lv_misc\lv_mem.c #167)
Error: lv_canvas_set_buffer (c:\users\nesat\documents\github\lv_sim_visual_studio_sdl\visual_studio_2017_sdl\lvgl\src\lv_objx\lv_canvas.c #117)
Error: NULL pointer (0x00000000) (c:\users\nesat\documents\github\lv_sim_visual_studio_sdl\visual_studio_2017_sdl\lvgl\src\lv_core\lv_debug.c #167)

canvas docs so not descriptive for new start developer;

Hi, you can use several methods like this
1.modify more large size => LV_MEM_SIZE (@lv_conf.h)
2.use static buffer => static lv_color_t color_buffer[…]
3.use malloc(…) (system memory is large enough, usually apply in simulation mode)

Thank you, i tried to first method. LV_MEM_SIZE changed and similation work now. But i have a question, how can i calculate the alloc memory? can you give a advice?
# define LV_MEM_SIZE (32U * 32768U)

I suggest using lv_mem_monitor and determining how much memory is used. Increase that value a bit (for safety) and you have what you actually need for your application.

İ tried to compiling for stm32f7 disco on cube ide but ide again giving this error; .bss' will not fit in regionRAM’,
please can you answer on a video tutorial?

c:\st\stm32cubeide_1.0.1\stm32cubeide\plugins\\tools\arm-none-eabi\bin\ld.exe: stm32f746_disco_no_os.elf section .bss' will not fit in regionRAM’
c:\st\stm32cubeide_1.0.1\stm32cubeide\plugins\\tools\arm-none-eabi\bin\ld.exe: region `RAM’ overflowed by 81856 bytes

This my memory size;
# define LV_MEM_SIZE (32U * 12000U)
and this my code for canvas buffer;
lv_color_t *cbuf = (lv_color_t*)lv_mem_alloc(LV_CANVAS_BUF_SIZE_ALPHA_2BIT(272, 272));

i thinked change from LV_CANVAS_BUF_SIZE_TRUE_COLOR to LV_CANVAS_BUF_SIZE_ALPHA_2BIT, but my problem isnt solved, please help me !
i m working on this problem for 4 weeks and i dont get an answer to a great solution.

LV_MEM_SIZE is now so big that it doesn’t fit in internal RAM anymore. You’ll have to shrink it to something smaller.

i tested simulation on visual studio, if memory size small from 32U * 12000U, returned error code, but memory alloc is bigger from 32U * 12000 then simulation working. i tried on cube ide and i debuged if memory alloc is smaller, ide can doing debug but send program to stm32f7 disco, drawing does not appear on the screen.İf memory alloc is bigger 32U * 12000U then cube ide dosnt compile, return error code.

This is completely normal, because the DISCO board has a lot less RAM than the simulator does.

Do you need to use the canvas to draw the watch face, or can you just create one or more custom objects? The canvas is very inefficient for this use case because you have to store the whole rendered object as a bitmap in memory, whereas a true LittlevGL object requires far less RAM.

I 'll examine, and return. Thank you

I gave up the canvas, now i m developing a object for analogue dial, i get lmeter for reference object. Now i draw my dial on Visual studio simulation;
but take errors to lvgl objects in now on cube ide.
This is page create module;

This is Analog Dial module;

/only draw static dial for now/
This is compiler error outputs;

i defined at lv_conf.h

/tos_Analog Clock/

and i added at lv_theme.h

lv_style_t * tos_anologClock;

I suggest you look at the line numbers referenced in the errors and try to find what the issue is. There’s probably a typo somewhere in lv_conf.h.

but the errors doesnt come from lv_conf.h , the errors come annother objx for example;

expected declaration specifiers or ‘…’ before numeric constant also errors.

This means that there’s a typo in one of the header files being included by lv_bar.h. The C compiler doesn’t always give you exact error readings so you need to do some investigation yourself.

hmm do you think there is an error in tos_anologClock.c

I don’t know. I suggest tracing through the recent changes you made to see what caused the issue. I can’t really help you with that.

i finded the real problem, i wasn’t think before, so visual studio definitions is different to cube ide definitions. And another problem i import lvgl in my object, but i include in screen library at same time.
the picture from my static clock dial

We won against to cubeide :slight_smile:

1 Like

I have a working watch now :), but dont understand, why pixels gets broken in image? and why the screen feels slow? so, lvgl demo application was so fast. How can solution for pixels and speed?

this is test video;

Please post your design_cb code.

Header file;

.C file;

i havent any problem for static draw;

but there are so errors in dynamic draw;

you didn’t feedback. i wait a solution formula for dynamic draw problem, please send a answer for solution. :slight_smile: