Hard fault (STM32) with lv_chart_set_point_count

Hello,

when I set the count points to the maximum in a chart, I get a Hard Fault. Why is this?
In general, I don’t really understand the relationship between the count number/points and the pixel number and chart-size (X-axis)…

Thank you

lv_chart_set_point_count(screenchart1, 65535);

Hi @epikao

The LVGL documentation said the following respect to this variable.

The number of points in the series can be modified by

lv_chart_set_point_count(chart, point_num)

The default value is 10. Note: this also affects the number of points processed when an external buffer is assigned to a series, so you need to be sure the external array is large enough.

May be the problem of the hard fault is because the buffer provided is smaller than 65535 element, producing an overflow of memory.
Here there is an example how to use.

Hanes

Thank you, but I not use a buffer, I simply use screen_chart_1_0->y_points[count] = value;

I do not understand this here:
uint32_t pcnt = sizeof(ecg_sample) / sizeof(ecg_sample[0]);

Why using for the calculation of the number of points on the x-axis the sample[0], so a y value??

Maybe I should explain my code and my problem a little bit more.
Below is my code how I update the chart.

I want to update the chart every 18ms with a new point, I have about 900 points.
I want to show all these points on the chart, so data in a time range of about 15 to 16 seconds (900 x 18ms).
The chart has a width of 950 pixels… so the width of the chart should be big enough to show all the points.

Anyway, the chart is doing something completely different, in the code below the processor is at 100% capacity and everything is jerky…

uint32_t value;
...
lv_obj_set_size(ui.screen_chart_1, 950, 155);
lv_chart_set_point_count(ui.screen_chart_1, 900);
...
while(1){



	        if( ( millis()-lastMillis3 ) >= 18){

	    		countChart++;

			if(countChart > 898){countChart = 0;}

		        screen_chart_1_0->y_points[countChart] = value;

		        lv_chart_refresh(ui.screen_chart_1); /*Required after direct set*/

	        	lastMillis3 = millis();

	        }
}

Hi @epikao

The reason why it calculates the size as follows is because sizeof function give you the size of vector in bytes, for example:

uint32_t buffer[4] = {0};
uint32_t size = 0;

size = sizeof(buffer);

This size variable will be 16 because the variable has 4 element but every element has 4 bytes. Toobtain the real size is necessary divide to the size of one element.

Best regards
Hanes

ok, finally for me the solution was to change the function from:
screen_chart_1_0->y_points(
to
lv_chart_set_value_by_id(

with the id function it works without crash and without high processor load…

I just noticed that this function lv_chart_set_value_by_id takes ~30ms, is that normal? (STM32F7xx)…

EDIT:
interesting, if set X-axis as following the function above is very fast…
lv_chart_set_axis_tick(ui.screen_chart_1, LV_CHART_AXIS_PRIMARY_X, 10, 5, 15, 1, true, 30);

buf if set as following, it takes around 30ms:
lv_chart_set_axis_tick(ui.screen_chart_1, LV_CHART_AXIS_PRIMARY_X, 10, 5, 950, 1, true, 30);

Hi @epikao

I’m not a LVGL developer but I think that the timing is because in the first example you divide 5 (10 - 5) positions of your X axis into 15 position. In contrast, in the second example you divide the same 5 positions by 950 point. IThis demand more processing for the MCU. This is p just intuitive, I read the documentation to answer your question.

Best regards
Hanes

ok but for me this is not logically because the ticks of the X-axis should be drawn at the initialization, so only once…

There is another issue with the chart (ticks Y-axis), if set as following “1000”, 1000 is displayed as “000”
lv_chart_set_range(ui.screen_chart_1,LV_CHART_AXIS_PRIMARY_Y, 0, 1000);

if set as following “1001” is displayed correctly, so as “1001”… I don’t understand this behaviour…
lv_chart_set_range(ui.screen_chart_1,LV_CHART_AXIS_PRIMARY_Y, 0, 1001);