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

spi: shell: rework command to use SPI devices #73962

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

liambeguin
Copy link
Contributor

Rework the shell interface to work on SPI devices. This will create a
build-time list of all spi device nodes based on the devicetree.

At runtime, the shell will autocomplete device names and use
spi_transceive_dt() to leverage the devicetree configuration of each
node. This removes the need for a conf command, and will ensure that all
chip select modes are properly supported (i.e. cs-gpios).

Copy link

github-actions bot commented Jun 8, 2024

Hello @liambeguin, and thank you very much for your first pull request to the Zephyr project!
Our Continuous Integration pipeline will execute a series of checks on your Pull Request commit messages and code, and you are expected to address any failures by updating the PR. Please take a look at our commit message guidelines to find out how to format your commit messages, and at our contribution workflow to understand how to update your Pull Request. If you haven't already, please make sure to review the project's Contributor Expectations and update (by amending and force-pushing the commits) your pull request if necessary.
If you are stuck or need help please join us on Discord and ask your question there. Additionally, you can escalate the review when applicable. 😊

@@ -74,82 +91,12 @@ static int cmd_spi_transceive(const struct shell *ctx, size_t argc, char **argv)
return ret;
}

static int cmd_spi_conf(const struct shell *ctx, size_t argc, char **argv)
Copy link
Collaborator

Choose a reason for hiding this comment

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

The idea with this command was to test things at run-time without any DTS pre-configuration made. An on-the-fly configuration command then.

Note that, however, having something like you propose co-existing with this spi_conf, would be nice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea with this command was to test things at run-time without any DTS pre-configuration made. An on-the-fly configuration command then.

I originally had this as an extra command, but thought it doesn't really take much effort to add the node to an existing devicetree.

Note that, however, having something like you propose co-existing with this spi_conf, would be nice.

Agreed, to me this is very useful for device driver development, and also ensures proper CS handling.

I don't mind adding back the conf command though, but I think we should be explicit about the CS handling.

We could also have a build CONFIG_ to switch between both modes, one interacting with SPI controllers, and another with SPI devices?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I originally had this as an extra command, but thought it doesn't really take much effort to add the node to an existing devicetree.

True, and I wouldn't see myself doing otherwise.

@benner any input on this one?

Copy link
Contributor

Choose a reason for hiding this comment

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

I like this approach because it allows to use different chip selects. During development I did knew how to do something like IS_SPIDEV_NODE and I was lucky that in my case it was the only one device on SPI bus.

We could also have a build CONFIG_ to switch between both modes, one interacting with SPI controllers, and another with SPI devices?

I agree this is better option

@benner
Copy link
Contributor

benner commented Jun 20, 2024

I also found one retrogression (at least for me). I'm getting

bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: zephyr/drivers/spi/libdrivers__spi.a(spi_shell.c.obj):(.data.spidev_list+0x54): undefined reference to `__device_dts_ord_191'
collect2: error: ld returned 1 exit status

After some digging I found one SPI bus device with fake compatible (I was too lazy to create proper bindings).

	x: x_0@0 {
		compatible = "vnd,spi-device";
		reg = <0>;
		spi-max-frequency = <DT_FREQ_K(2500)>;
	};

If I'm disabling it (ant ton of code accessing it) - everything is OK.

Not sure how it can be related because I'm using it with same const struct spi_dt_spec/SPI_DT_SPEC_GET API.

@liambeguin
Copy link
Contributor Author

I also found one retrogression (at least for me). I'm getting

bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: zephyr/drivers/spi/libdrivers__spi.a(spi_shell.c.obj):(.data.spidev_list+0x54): undefined reference to `__device_dts_ord_191'
collect2: error: ld returned 1 exit status

After some digging I found one SPI bus device with fake compatible (I was too lazy to create proper bindings).

	x: x_0@0 {
		compatible = "vnd,spi-device";
		reg = <0>;
		spi-max-frequency = <DT_FREQ_K(2500)>;
	};

If I'm disabling it (ant ton of code accessing it) - everything is OK.

Not sure how it can be related because I'm using it with same const struct spi_dt_spec/SPI_DT_SPEC_GET API.

I think this comes from the fact that I add the device to a list but because you don't have a valid compatible it gets deleted later on. I'm not entirely sure, but I noticed something similar with a valid compatible and its config disabled.

@benner
Copy link
Contributor

benner commented Jun 20, 2024

@liambeguin, this my assumption too. I quickly described simple dts:

% cat dts/bindings/spi/astro,spi.yaml  
description: foo
compatible: "astro,spi"
include:
  - spi-device.yaml

and changed compatable string inside overlay - problem persist.

So please ignore this regression for now. I will play more.

Problem - I'm on PTO, so not much time I have ATM.

Overall code and idea - looks good.

tbursztyka
tbursztyka previously approved these changes Jun 27, 2024
@benner
Copy link
Contributor

benner commented Jul 3, 2024

I know it's rc2 now. Can f451e54 be extracted to separate PR and merged (it's kind fix and fits current stage)?

@liambeguin
Copy link
Contributor Author

I know it's rc2 now. Can f451e54 be extracted to separate PR and merged (it's kind fix and fits current stage)?

sure, I don't mind separating it if someone is ready to take it

@benner
Copy link
Contributor

benner commented Jul 9, 2024

I made PR with just first commit (commit author preserved): #75685

@kartben
Copy link
Collaborator

kartben commented Jul 9, 2024

@liambeguin would #71912 be useful/applicable for—at least some of—what you're trying to accomplish here?

@liambeguin
Copy link
Contributor Author

@kartben if I understand correctly that MR is related to node labels no? For the SPI shell, I'm looking at all devices that have a required spi property so I don't think it would apply directly.

Copy link

github-actions bot commented Sep 9, 2024

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 Sep 9, 2024
@tbursztyka
Copy link
Collaborator

@liambeguin Could you rebase against the main branch?

@teburd any input? lgtm at least here

@liambeguin
Copy link
Contributor Author

@liambeguin Could you rebase against the main branch?

Will do!

Rework the shell interface to work on SPI devices. This will create a
build-time list of all spi device nodes based on the devicetree.

At runtime, the shell will autocomplete device names and use
spi_transceive_dt() to leverage the devicetree configuration of each
node. This removes the need for a conf command, and will ensure that all
chip select modes are properly supported (i.e. cs-gpios).

Signed-off-by: Liam Beguin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: SPI SPI bus
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants