-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Samples: Introduce device_deinit()
sample
#89927
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
Open
bjarki-andreasen
wants to merge
6
commits into
zephyrproject-rtos:main
Choose a base branch
from
bjarki-andreasen:nrfx-spim-deinit
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+458
−16
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9e74cb8
drivers: spi: add DEINIT_ variants of SPI_DEVICE_ macros
bjarki-andreasen 7f4c083
drivers: spi: nrfx spim: implement device deinit
bjarki-andreasen fc663b9
drivers: spi: nrfx_spi: implement deinit
bjarki-andreasen 5d8497c
drivers: mfd: nxp_lp_flexcomm: introduce clearirqhandler
bjarki-andreasen cca0a10
drivers: spi: nxp_lpspi: implement deinit
bjarki-andreasen e34168b
samples: application_development: introduce deinit
bjarki-andreasen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
cmake_minimum_required(VERSION 3.20.0) | ||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
project(deinit) | ||
|
||
target_sources(app PRIVATE src/main.c) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,93 @@ | ||||||||||||||||||||
.. zephyr:code-sample:: deinit | ||||||||||||||||||||
:name: Device deinit | ||||||||||||||||||||
:relevant-api: gpio_interface spi_interface device_model | ||||||||||||||||||||
|
||||||||||||||||||||
Comment on lines
+1
to
+4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
Overview | ||||||||||||||||||||
******** | ||||||||||||||||||||
|
||||||||||||||||||||
This sample demonstrates how to initialize and deinitialize device | ||||||||||||||||||||
drivers at runtime, which allows switching between different devices | ||||||||||||||||||||
and device drivers which share pins or share hardware. | ||||||||||||||||||||
|
||||||||||||||||||||
Detailed description | ||||||||||||||||||||
******************** | ||||||||||||||||||||
|
||||||||||||||||||||
This sample demonstrates how to share a SPI CS (chip-select) pin | ||||||||||||||||||||
between a SPI peripheral and a GPIO port. The SPI CS pin chosen is | ||||||||||||||||||||
connected to an LED on the board used for the sample. This sample | ||||||||||||||||||||
blinks the LED, by either manually toggling the pin using the GPIO | ||||||||||||||||||||
port, or performing a mock SPI transaction with ``SPI_HOLD_ON_CS`` | ||||||||||||||||||||
set which keeps the SPI CS pin asserted from the start of the SPI | ||||||||||||||||||||
transaction until we call :c:func:`spi_release`. | ||||||||||||||||||||
|
||||||||||||||||||||
We use ``zephyr,deferred-init`` to prevent initializing the SPI | ||||||||||||||||||||
device driver during boot. The sample does the following after | ||||||||||||||||||||
booting: | ||||||||||||||||||||
|
||||||||||||||||||||
1. Configure the CS pin as an output in active state with | ||||||||||||||||||||
:c:func:`gpio_pin_configure_dt` | ||||||||||||||||||||
2. Wait | ||||||||||||||||||||
3. Configure the CS pin as an input with | ||||||||||||||||||||
:c:func:`gpio_pin_configure_dt` | ||||||||||||||||||||
|
||||||||||||||||||||
This is the first blink | ||||||||||||||||||||
|
||||||||||||||||||||
4. Initialize the SPI device driver with :c:func:`device_init` | ||||||||||||||||||||
5. Perform mock SPI transaction with :c:func:`spi_transceive` | ||||||||||||||||||||
6. Wait | ||||||||||||||||||||
7. Release SPI with :c:func:`spi_release` | ||||||||||||||||||||
|
||||||||||||||||||||
This is the second blink | ||||||||||||||||||||
|
||||||||||||||||||||
8. Deinitialize SPI device driver with :c:func:`device_deinit` | ||||||||||||||||||||
9. Configure the CS pin as an output in active state with | ||||||||||||||||||||
:c:func:`gpio_pin_configure_dt` | ||||||||||||||||||||
10. Wait | ||||||||||||||||||||
11. Configure the CS pin as an input | ||||||||||||||||||||
:c:func:`gpio_pin_configure_dt` | ||||||||||||||||||||
|
||||||||||||||||||||
This is the third blink | ||||||||||||||||||||
|
||||||||||||||||||||
12. Initialize the SPI device driver with :c:func:`device_init` | ||||||||||||||||||||
13. Perform mock SPI transaction with :c:func:`spi_transceive` | ||||||||||||||||||||
14. Wait | ||||||||||||||||||||
15. Release SPI with :c:func:`spi_release` | ||||||||||||||||||||
|
||||||||||||||||||||
This is the last blink. | ||||||||||||||||||||
|
||||||||||||||||||||
16. print ``sample complete`` to console | ||||||||||||||||||||
|
||||||||||||||||||||
If any errors occur during the sample, the error is printed to | ||||||||||||||||||||
the console and the sample is stopped. | ||||||||||||||||||||
|
||||||||||||||||||||
Porting guide | ||||||||||||||||||||
************* | ||||||||||||||||||||
|
||||||||||||||||||||
Use the following devicetree overlay example to create an | ||||||||||||||||||||
overlay for your board: | ||||||||||||||||||||
|
||||||||||||||||||||
.. code-block:: devicetree | ||||||||||||||||||||
|
||||||||||||||||||||
&port0 { | ||||||||||||||||||||
status = "okay"; | ||||||||||||||||||||
}; | ||||||||||||||||||||
|
||||||||||||||||||||
&spi0 { | ||||||||||||||||||||
status = "okay"; | ||||||||||||||||||||
zephyr,deferred-init; | ||||||||||||||||||||
cs-gpios = <&port0 0 GPIO_ACTIVE_LOW>; | ||||||||||||||||||||
}; | ||||||||||||||||||||
|
||||||||||||||||||||
/ { | ||||||||||||||||||||
zephyr,user { | ||||||||||||||||||||
spi = <&spi0>; | ||||||||||||||||||||
|
||||||||||||||||||||
/* | ||||||||||||||||||||
* Must match &spi0 cs-gpios and should | ||||||||||||||||||||
* preferably be a pin connected to an LED | ||||||||||||||||||||
* on the board, which illuminates when | ||||||||||||||||||||
* active. | ||||||||||||||||||||
*/ | ||||||||||||||||||||
cs-gpios = <&port0 0 GPIO_ACTIVE_LOW>; | ||||||||||||||||||||
}; | ||||||||||||||||||||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that when CONFIG_PM_DEVICE=n this function should actually call spim_suspend(dev);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kl-cruz FYI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
100% agree, this PR is a bit out of date, see
zephyr/drivers/spi/spi_nrfx_spim.c
Lines 769 to 788 in ad4c3e3