[TM4C123] SPI instances, machine_hard_spi and root pointers

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.
Post Reply
ExXec
Posts: 72
Joined: Sat Oct 20, 2018 4:02 pm

[TM4C123] SPI instances, machine_hard_spi and root pointers

Post by ExXec » Sun Apr 21, 2019 3:56 pm

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

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

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

Post by dhylands » Sun Apr 21, 2019 6:22 pm

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.

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

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

Post by ExXec » Mon Apr 22, 2019 1:02 pm

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

Post Reply