[TM4C123] Assertion failed

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
jickster
Posts: 574
Joined: Thu Sep 07, 2017 8:57 pm

Re: [TM4C123] Assertion failed

Post by jickster » Sat Dec 15, 2018 11:25 pm

Is your compiler producing 64-bit code?


Sent from my iPhone using Tapatalk Pro

ExXec
Posts: 23
Joined: Sat Oct 20, 2018 4:02 pm

Re: [TM4C123] Assertion failed

Post by ExXec » Sun Dec 16, 2018 1:33 am

Update: after insterting the changes into version 1.9.4 it looks like this:

Code: Select all

MicroPython v1.9.4-1-gea2acac46 on 2018-12-16; Tiva Launch Pad with TM4C123G6HPM
>>> a = 5
>>> a = 5
>>> a = 5
>>> a = 5
>>> a = 5
>>> a = 5
>>> a = 5
>>> a = 5
>>> a = 5
>>> a = 5
>>> a = 5
>>> a = 5
>>> a = 5
>>> a = 5
GC: total: 1984, used: 960, free: 1024
 No. of 1-blocks: 3, 2-blocks: 4, max blk sz: 32, max free sz: 42
>>> a = 5
>>> a = 5
>>> a = 5
>>> a = 5
>>> a = 5
>>> a = 5
>>> a = 5
>>> a = 5
>>> a = 5
>>> a = 5
>>> a = 5
>>> a = 5
>>> a = 5

and then the controller had a hard fault and stopped

ExXec
Posts: 23
Joined: Sat Oct 20, 2018 4:02 pm

Re: [TM4C123] Assertion failed

Post by ExXec » Sun Dec 16, 2018 1:38 am

jickster wrote:
Sat Dec 15, 2018 11:25 pm
Is your compiler producing 64-bit code?
I don't know

My compiler options are:

Code: Select all

CFLAGS_CORTEX_M4 = -mthumb -mtune=cortex-m4 -mabi=aapcs-linux -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -fsingle-precision-constant -Wdouble-promotion
CFLAGS = $(INC) -Wall -Werror -std=c99 -nostdlib $(CFLAGS_CORTEX_M4) $(COPT)
and im using the arm-none-eabi-gcc compiler

ExXec
Posts: 23
Joined: Sat Oct 20, 2018 4:02 pm

Re: [TM4C123] Assertion failed

Post by ExXec » Sun Dec 16, 2018 6:19 pm

And I just noticed, that my gc_collect() function is still the basic one from the minimal port.

Code: Select all

void gc_collect(void) {
    // WARNING: This gc_collect implementation doesn't try to get root
    // pointers from CPU registers, and thus may function incorrectly.
    void *dummy;
    gc_collect_start();
    gc_collect_root(&dummy, ((mp_uint_t)stack_top - (mp_uint_t)&dummy) / sizeof(mp_uint_t));
    gc_collect_end();
    gc_dump_info();
}
do I just replace the dummy pointer with something?

User avatar
dhylands
Posts: 2948
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: [TM4C123] Assertion failed

Post by dhylands » Sun Dec 16, 2018 6:33 pm

I always look at the stm32 port functions to decide what to do.

The intention is to look thru the active portion of the stack, which for most ports goes from the stack pointer to the end of RAM.

Note that the stm32 code stores the current registers into the stack:
https://github.com/micropython/micropyt ... lect.c#L48

which means that the contents of the registers are also scanned as a side-effect of that. The gc_helper_get_regs_and_sp function can be found in the gchelper.s

The TM4C123 is a Cortex-M4 which is the same as the STM32F4 series so you should be able to use the gchelper.s file as-is.

ExXec
Posts: 23
Joined: Sat Oct 20, 2018 4:02 pm

Re: [TM4C123] Assertion failed

Post by ExXec » Sun Dec 16, 2018 9:10 pm

Thank you for the advice.
I added the assembly source to my project, now I have a problem with this line:

Code: Select all

gc_collect_root((void**)sp, ((uint32_t)&_ram_end - sp) / sizeof(uint32_t));
It says, that _ram_end is not defined.
Do I replace that with the last address of ram ( 0x2000.7FFF ) or the address following that one (0x2000.8000) or something different?
(RAM: 0x2000.0000 - 0x2000.7FFF)
Like this:

Code: Select all

gc_collect_root((void**)sp, ((uint32_t)0x20007FFF - sp) / sizeof(uint32_t));
EDIT:
I tired 0x20008000 as replacement and it doesn't immedeately crash so i guess thats good.
It looks like the GC runs once and the second time it crashes before entering the gc_collect function.

jickster
Posts: 574
Joined: Thu Sep 07, 2017 8:57 pm

Re: [TM4C123] Assertion failed

Post by jickster » Mon Dec 17, 2018 12:20 am

That’s wrong.

You need to use MP_STATE_THREAD(stack_top) like in ports/stm32/gccollect.c

But to do that, you must call mp_stack_ctrl_init() before you run any micropython functions.


Sent from my iPhone using Tapatalk Pro

ExXec
Posts: 23
Joined: Sat Oct 20, 2018 4:02 pm

Re: [TM4C123] Assertion failed

Post by ExXec » Tue Dec 18, 2018 12:14 am

I added the mp_stack_ctrl_init() call to my main and defined _ram_end and other missing constants in the linker file and now it seems to work

in my main():

Code: Select all

    
    mp_stack_ctrl_init();
    mp_stack_set_top(&__StackTop);
    //mp_stack_set_limit((char*)&_estack - (char*)&_heap_end - 1024);
    #if MICROPY_ENABLE_GC
    gc_init(&_heap_start, &_heap_end);
    #endif
in the gccollect.c:

Code: Select all

gc_collect_root((void**)sp, ((uint32_t)&_ram_end - sp) / sizeof(uint32_t));
I didn't change the call of gc_collect_root, because I have not implemented the thread module, and it doesn't seem to impact the functionality.

Thanks for your help, I very much appreciate it :D

Post Reply