Page 1 of 1

[TM4C123] SPI instances, machine_hard_spi and root pointers

Posted: Sun Apr 21, 2019 3:56 pm
by ExXec
Hey,

in the spi implementation for the pyboard, the program always references already existing instances, that are defined somewhere in the STM HAL I guess.

I have no such predefined spi instances, should I create some or should I rather create them when necessary as in the UART?
Because I'm really running out of flash at this point, so a dynamic approach would be better I think?

Another question: Whats the machine_hard_spi thing?
And can pyb_spi and machine_hard_spi control the same peripheral or only exclusive?

I'll need to create an array in the mpconfigport.h MICROPY_PORT_ROOT_POINTERS for the pyb_spi_obj and the machine_hard_spi_obj and a third one for the actual SPI instance?

A lot of questions, I'm sorry!

-ExXec

Re: [TM4C123] SPI instances, machine_hard_spi and root pointers

Posted: Sun Apr 21, 2019 6:22 pm
by dhylands
The SPI instances for the pyb_spi are allocated here: https://github.com/micropython/micropyt ... .c#L48-L98

These are also used by machine_hard_spi here: https://github.com/micropython/micropyt ... _spi.c#L34

Since both modules are using the same underlying objects, you should be able to mix and match calls from the 2 modules, but personally I wouldn't.

pyb.SPI was the original implementation. machine.SPI came along later when the machine API was added. For a new port, I would probably just use machine.SPI.

The spi_obj are declared const so they come from flash and don't need to be included in the root pointers. Only objects allocated from the heap need to be covered by root pointers.

Re: [TM4C123] SPI instances, machine_hard_spi and root pointers

Posted: Mon Apr 22, 2019 1:02 pm
by ExXec
Thanks for your response!

ok, I'll just focus on the machine spi then and without prebuilt spi objects, I think I'll go for the dynamic route and create them on the heap and use a root pointer. The root pointer itself is for GC i suppose, are there other places I need to register them to, or is the root enough?

In the original stm32 port, the machine.SPI only operates in MASTER mode, is that just because the other wasn't implemented or does this have a different reason behind it?

Also, why is it called machine_hard_spi, instead of just machine_spi? is it more "bare metal" than the other approach or just a name?

Thanks again for your time!

-ExXec