Skip to content

Conversation

@cooked
Copy link

@cooked cooked commented Nov 2, 2024

Add support for the ADI TMC5160 stepper driver, using the new stepper API

@jilaypandya
Copy link
Member

Hi @cooked,

Thanks for contributing to the project.

@jilaypandya
Copy link
Member

jilaypandya commented Nov 3, 2024

  • Rebase on main, drop the merge commit.
  • tmc5160 is highly similiar to tmc5130, you can rename the driver to tmc51xx
  • tmc5041 can support two steppers, this is not the case with tmc51xx, hence there is no need of child nodes. You can singularize the driver instantiation.
  • Check Commit Message

Copy link
Member

Choose a reason for hiding this comment

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

remove extra newline

@cooked
Copy link
Author

cooked commented Nov 3, 2024

Hi @jilaypandya,
while making the driver generalized for the 51xx in the code, shall I keep the kconfig explicit with both TMC5160 and TMC5130 (while the cmakefile will select the same .c)? or go 51xx in the kconfig as well?

@jilaypandya
Copy link
Member

Hi @jilaypandya, while making the driver generalized for the 51xx in the code, shall I keep the kconfig explicit with both TMC5160 and TMC5130 (while the cmakefile will select the same .c)? or go 51xx in the kconfig as well?

You can rename it tmc51xx in kconfig as well. tmc51xx as a driver shall serve both tmc5130 and tmc5160.

Copy link
Member

Choose a reason for hiding this comment

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

The set_ramp_parameters function is better off being within the respective drivers, i.e., tmc5041.c or tmc5160.c and then having a set_ramp_parametersfunction in stepper.h.

Copy link
Member

Choose a reason for hiding this comment

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

We are gathering all trinamic specific functions in this file stepper_trinamic.h. IFDEFs are not really required coz compiler will report an error anyhow :)

@zephyrbot
Copy link

zephyrbot commented Nov 6, 2024

The following west manifest projects have been modified in this Pull Request:

Name Old Revision New Revision Diff

Note: This message is automatically posted and updated by the Manifest GitHub Action.

@jilaypandya jilaypandya self-requested a review November 6, 2024 12:41
struct spi_dt_spec spi;
const uint32_t clock_frequency;
const uint16_t default_micro_step_res;
// StallGuard
Copy link
Member

Choose a reason for hiding this comment

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

Run python zephyr/scripts/ci/check_compliance.py locally before pushing, it will show you all the compliance errors. https://docs.zephyrproject.org/latest/contribute/guidelines.html

include:
- name: spi-device.yaml
- name: adi,trinamic-gconf.yaml
property-allowlist:
Copy link
Member

Choose a reason for hiding this comment

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

gconf in tmc51xx has few more registers. You can extend adi, trinamic-gconf.yaml with those extra registers. Initially i just took stuff from tmc5041 and tmc2209, but it can be extended.

}
if ((status_byte & BIT_MASK(1)) != 0) {
LOG_WRN("spi dataframe: driver_error(1) detected");
LOG_WRN("spi dataframe: driver_error/driver_error(1) detected");
Copy link
Member

Choose a reason for hiding this comment

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

drop driver_error(1)

#include "adi_tmc_spi.h"

#include <zephyr/logging/log.h>

Copy link
Member

Choose a reason for hiding this comment

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

drop the empty line over here. :)

Signed-off-by: Stefano Cottafavi <[email protected]>
@faxe1008
Copy link
Contributor

Since there are many more step-dir based drivers would it make sense to extract them to a device binding that can be used by multiple drivers internally? This would reduce the boilerplate for any other drivers. For inspiration what I mean you can look at the input-kdb-matrix where the same principle is applied.


def run(self):
exe = f"clang-format-diff.{'exe' if platform.system() == 'Windows' else 'py'}"
exe = f"clang-format-diff{'exe' if platform.system() == 'Windows' else ''}"
Copy link
Member

Choose a reason for hiding this comment

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

This change needs to be reverted

Comment on lines 58 to 59
const struct tmc5160_config *config = dev->config;
struct tmc5160_data *data = dev->data;
Copy link
Member

Choose a reason for hiding this comment

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

would it make sense to use the child device as argument to tmc5160_write, change these to dev->controller->config and dev->controller->data and just pass dev to this API? Make the code a bit more compact

}
reg_value &= TMC5160_CHOPCONF_MRES_MASK;
reg_value >>= TMC5160_CHOPCONF_MRES_SHIFT;
*res = (1 << (MICRO_STEP_RES_INDEX(STEPPER_MICRO_STEP_256) - reg_value));
Copy link
Member

Choose a reason for hiding this comment

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

can you do *res = BIT(MICRO_STEP_RES_INDEX(STEPPER_MICRO_STEP_256) - reg_value)?


err = tmc5160_write(config->controller, TMC5160_VSTART, ramp_data->vstart);
if (err != 0) {
return -EIO;
Copy link
Member

Choose a reason for hiding this comment

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

do you have a reason to discard err and return -EIO instead? It's usually a good idea to pass through the error code, than one can log it and it may give some more information of what's wrong in the lower layers

@github-actions
Copy link

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the Stale label Jan 14, 2025
@github-actions github-actions bot closed this Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants