[Solved]Error when running the same code on Linux and IDE

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
ndhuy
Posts: 32
Joined: Mon Nov 04, 2019 8:01 am

[Solved]Error when running the same code on Linux and IDE

Post by ndhuy » Fri Feb 28, 2020 4:50 am

Hello everyone,

I am Huy. Currently, I am working on a project of writing a display module in C language and then translate it into MicroPython modules. On both platform (IDE and Linux), I already compiled and included HAL library as well as BSP Discovery library.

The problem is: with the same .c file, on STM32CubeIDE, I can build and run it smoothly without error. The display on the screen was also the same as expected. However, with that piece of code I cannot run on Linux. To be specific, on the REPL, after i refresh the screen, i cannot type anything and the following lines of code cannot be executed and after a minute, it automatically turns back to the terminal. On IDE, the code is runnable and the following lines can run. My doubt is on the BSP_LCD_Refresh() function because after that, the error appears.

In the BSP_LCD_Refresh(), I can see that the FrameBuffer is set to 0 and DSI will trigger the pin TearOn to 1.

Code: Select all

extern LTDC_HandleTypeDef hltdc_discovery;
extern DSI_HandleTypeDef hdsi_discovery;


static uint32_t *my_fb = (uint32_t*)(0x30000000UL); //GFXMMU_VIRTUALBUFFER0_BASE;

static volatile bool display_inited = false;

bool display_active(void)
{
return display_inited;
}

void LCD_init(void)
{
FMC_Bank1_R->BTCR[0] = 0x000030D2;

//Hardware initialization
BSP_PSRAM_Init();
BSP_LCD_Init();
BSP_LCD_SelectLayer(0);

HAL_DSI_ShortWrite(&hdsi_discovery, 0, DSI_DCS_SHORT_PKT_WRITE_P0, DSI_SET_DISPLAY_ON, 0x0);

BSP_LCD_Clear(0xFFFFFFFF);
display_inited = true; // to check the screen is working 
}

void LCD_refresh(void)
{
BSP_LCD_Refresh();
}

void LCD_deinit(void)
{
BSP_PSRAM_DeInit();
BSP_LCD_DeInit();
}

void my_flush_cb(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_p)
{
CopyBuffer((uint32_t*)color_p, my_fb, area->x1, area->y1, lv_area_get_width(area), lv_area_get_height(area));
BSP_LCD_Refresh();
lv_disp_flush_ready(drv);
}
I separate the refresh function to be a different module to test the BSP_LCD_Refresh().

I have no idea Why this happens? My doubt is on the way IDE and Linux run the same code differently.
Last edited by ndhuy on Wed Mar 04, 2020 1:05 am, edited 1 time in total.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Error when running the same code on Linux and IDE

Post by jimmo » Fri Feb 28, 2020 7:50 am

I'm not quite sure what you mean by running the code in your IDE or on Linux? Surely you're running this on a stm32 dev board?

ndhuy
Posts: 32
Joined: Mon Nov 04, 2019 8:01 am

Re: Error when running the same code on Linux and IDE

Post by ndhuy » Fri Feb 28, 2020 7:59 am

Hi Jimmo,
Yes surely i run the code on STM32L4R9I Discovery.

With IDE i mean that I compiled and build the code, then load it to the board and run. And by Linux, I mean that i build LCD module in C language, translate it into MicroPython modules, compile the code. An then I write MicroPython command to control the board.

What might the cause of this issue be?

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Error when running the same code on Linux and IDE

Post by jimmo » Fri Feb 28, 2020 8:03 am

So when you're compiling the code in the IDE, there's no MicroPython involved?

My guess is still what I suggested on the previous thread -- that the LCD driver is using a particular region of memory that MicroPython is also using.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Error when running the same code on Linux and IDE

Post by jimmo » Fri Feb 28, 2020 8:06 am

Remember that MicroPython will use all available RAM for heap+stack. Many of those ST libraries will do things like assuming they can use a particular region directly for a framebuffer.

The way to fix this is either make the ST library use MicroPython's gc_malloc, or to modify MicroPython's linker script to not use those regions.

ndhuy
Posts: 32
Joined: Mon Nov 04, 2019 8:01 am

Re: Error when running the same code on Linux and IDE

Post by ndhuy » Sat Feb 29, 2020 2:32 pm

Hi Jimmo,
jimmo wrote:
Fri Feb 28, 2020 8:06 am
Remember that MicroPython will use all available RAM for heap+stack. Many of those ST libraries will do things like assuming they can use a particular region directly for a framebuffer.
I've read the memory map in STM32L4R9xx datasheet DS12023
https://drive.google.com/file/d/1SXgBwg ... sp=sharing
There are 2 distinct regions, RAM(SRAM1+SRAM2+SRAM3) and GFXMMU Virtual Buffer, so I dont think they use the same region.
jimmo wrote:
Fri Feb 28, 2020 8:06 am
The way to fix this is either make the ST library use MicroPython's gc_malloc
About the using gc_malloc, can you more specific?
jimmo wrote:
Fri Feb 28, 2020 8:06 am
to modify MicroPython's linker script to not use those regions.
How can i identify which region is used by the ST library?. I tried to make the MicroPython used less RAM but it did not work as this error occurred:
https://drive.google.com/file/d/1LqMnfF ... sp=sharing

ndhuy
Posts: 32
Joined: Mon Nov 04, 2019 8:01 am

Re: Error when running the same code on Linux and IDE

Post by ndhuy » Mon Mar 02, 2020 3:25 am

Also, according to this material: https://github.com/micropython/micropyt ... ry-Manager

On startup, Garbage Collector is initialised by MicroPython via the function gc_init()

ndhuy
Posts: 32
Joined: Mon Nov 04, 2019 8:01 am

Re: [Solved]Error when running the same code on Linux and IDE

Post by ndhuy » Wed Mar 04, 2020 1:08 am

Hi Jimmo,

I solved the issue already. The issue is the function BSP_LCD_Refresh() needs an interrupt to end its "setting tear on". But in uPython, that interrupt cannot be called. therefore, the issue occurred. The interrupt is EndofRefreshCallBack in stm32l4r9i_discovery_lcd.c

Anyway, thanks for your response. It helped me in this issue.

Post Reply