Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added TMC5160 support #725

Open
wants to merge 10 commits into
base: dev
Choose a base branch
from
Open

Added TMC5160 support #725

wants to merge 10 commits into from

Conversation

amken3d
Copy link

@amken3d amken3d commented Dec 9, 2024

Requesting review of the the PR to add support for TMC5160. The TMC5160 is a popular stepper driver and is feature packed. This implementation add support to using the TMC5160 using either the UART mode or the SPI mode. The code has been tested to work on rp2040. The smoke tests passed using "make test". The code is not fully tested for all available features of the TMC5160 as it is a pretty complicated piece of silicon.

@deadprogram deadprogram changed the base branch from release to dev December 10, 2024 11:05
go.mod Show resolved Hide resolved
@deadprogram
Copy link
Member

Hello @amken3d this is a very impressive PR! Thank you for working on it.

I changed the branch for it to dev as mentioned here:
https://github.com/tinygo-org/drivers/blob/release/CONTRIBUTING.md#how-to-use-our-github-repository

Also, I made a comment, although did not have time to look deeply in the new code.

Also, wondering if you could please add a smoketest/example?

Thanks!

@amken3d
Copy link
Author

amken3d commented Dec 11, 2024

@deadprogram, thank you for the kind words.
I have added example code and smoke test as per your suggestion. I hope this adds some value to users. Looking forward to many more adventures with Tinygo.
My go and tinygo journey started about a 2 months ago and I am loving it. My primary reason for switching to go/tinygo is because I am building a Pick and Place machine using go (gocv). I initially wrote the microcontroller code in c++(platformio), but I found it much more ergonomic to use tinygo instead. I do have a couple of gripes we can discuss offline, but overall, I feel like Tinygo is much easier alternative to Arduino/C/C++.

Regards
H Keni

go.mod Outdated
go 1.18
go 1.22.1

toolchain go1.23.3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here as above.

@amken3d
Copy link
Author

amken3d commented Dec 11, 2024

When i do go mod tidy, it automatically upgrades to
go 1.22.1

toolchain go1.23.1

Is there a way to pin it to 1.21? I've tried everything that google suggested and failed

@deadprogram
Copy link
Member

I think the toolchain here does not matter to user, so you were fine to run go mod tidy and commit the result. I was incorrect.

The toolchain directive only has an effect when the module is the main module and the default toolchain’s version is less than the suggested toolchain’s version.

via https://go.dev/ref/mod#go-mod-file-toolchain

@amken3d
Copy link
Author

amken3d commented Dec 11, 2024

@deadprogram : Updated

if !exists {
regName = "Unknown Register"
}
//println("Reading reg:", regName)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove commented out lines.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

if err != nil {
return 0, err
}
//println("Received", rx[0], rx[1], rx[2], rx[3], rx[4])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove commented out lines.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

// Step 1. Setup your protocol. SPI setup shown below
spi := machine.SPI1
spi.Configure(machine.SPIConfig{
SCK: machine.GPIO10,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not need to specify SCK, SDI, and SDO here since they are already the defaults for SPI1 on Pico. See https://github.com/tinygo-org/tinygo/blob/release/src/machine/board_pico.go#L60-L64 and https://github.com/tinygo-org/tinygo/blob/release/src/machine/machine_rp2040_spi.go#L176-L180

@deadprogram
Copy link
Member

The file named SPIcomm.go might better named spicomm.go to avoid capitals and also to match uartcomm.go naming.

@@ -0,0 +1,61 @@
//go:build test
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think due to this directive, the tests are in this file are not being run by the CI.

See https://github.com/tinygo-org/drivers/pull/725/checks#step:7:182

If you want to exclude these tests from being run by the GH action you should add it here https://github.com/tinygo-org/drivers/blob/dev/Makefile#L22

It would be better if the tests can run, however. 😸

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the file as it was not relevant.

byte(txData >> 8), // Next 8 bits of data
byte(txData), // Lower 8 bits of data
}
//println("Sending", tx[0], tx[1], tx[2], tx[3], tx[4])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove commented out line here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants