grblHAL / RP2040

grblHAL driver for RP2040 (Pi Pico)
Other
103 stars 44 forks source link

Support for TMC5160 #73

Open fireup924 opened 10 months ago

fireup924 commented 10 months ago

I would like to add support for TMC5160 which uses SPI but not sure where to start?

Do I add a new file call tmc_spi.c and include the two functions:

tmc_spi_write() and tmc_spi_read() ?

terjeio commented 10 months ago

It is a little more involved than that, best is to start with code from another driver. There are two SPI modes for Trinamic drivers, either separate chip select lines for each drivers or a common one. The latter requires the SPI lines to be chained and the drivers appear as a single long register.

Part of the STM32F4xx driver code can be used as a starting point. To save pins you can use the existing SPI interface provided in spi.c.

fireup924 commented 1 month ago

I was able to get TMC5160 working on RP2040 but only one drive is working at the moment. There's a driver.cs_pin variable declared in trinamic_motor_t struct, but don't know where I can assign it so I can use it later in tmc_spi_write() and tmc_spi_read() ?

terjeio commented 1 month ago

The STM32F4xx driver code linked above has separate chip select lines for each driver, this board specific code has a shared line for chained drivers.

driver.c needs to be updated to handle the chip select(s), again see the STM32F4xx driver here and here. The latter code ensures the pin(s) are enabled as outputs with the level set high initially.

fireup924 commented 1 month ago

Thank you for the help. I got it working now! 👍

I'm using the output from HC595 shift register for CS pins and I didn't initialize them as high and was causing SPI bus collision