-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
samples: boards: nxp: add sample for using psi5 driver
Add sample for using psi5 driver on s32z Signed-off-by: Cong Nguyen Huu <[email protected]>
- Loading branch information
1 parent
f046b4c
commit 05f2644
Showing
7 changed files
with
171 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,8 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
cmake_minimum_required(VERSION 3.20.0) | ||
|
||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
project(psi5) | ||
|
||
target_sources(app PRIVATE src/main.c) |
This file contains 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,33 @@ | ||
.. zephyr:code-sample:: nxp_s32_psi5 | ||
:name: NXP S32 Peripheral Sensor Interface (PSI5) | ||
|
||
Use NXP S32 Peripheral Sensor Interface (PSI5). | ||
|
||
Overview | ||
******** | ||
|
||
The sample application shows how to use NXP S32 Peripheral Sensor Interface (PSI5): | ||
|
||
* Receive data | ||
* Transmit data | ||
|
||
Requirements | ||
************ | ||
|
||
This sample requires connecting a wire between pin PA6 (data reception pin) and sensor. | ||
|
||
Building, Flashing and Running | ||
****************************** | ||
|
||
.. zephyr-app-commands:: | ||
:zephyr-app: samples/boards/nxp/s32/psi5 | ||
:board: s32z2xxdc2/s32z270/rtu0 | ||
:goals: build flash | ||
|
||
Sample Output: | ||
|
||
.. code-block:: console | ||
Rx channel 1 completed | ||
Tx channel 2 completed |
58 changes: 58 additions & 0 deletions
58
samples/boards/nxp/s32/psi5/boards/s32z2xxdc2_s32z270_rtu0.overlay
This file contains 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,58 @@ | ||
/* | ||
* Copyright 2025 NXP | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
&pinctrl { | ||
psi5_0_default: psi5_0_default { | ||
group1 { | ||
pinmux = <PA7_PSI5_0_SDOUT1>, <PB3_PSI5_0_SDOUT2>; | ||
output-enable; | ||
}; | ||
group2 { | ||
pinmux = <PA6_PSI5_0_SDIN1>, <PB2_PSI5_0_SDIN2>; | ||
input-enable; | ||
}; | ||
}; | ||
}; | ||
|
||
&psi5_0 { | ||
pinctrl-0 = <&psi5_0_default>; | ||
pinctrl-names = "default"; | ||
status = "okay"; | ||
}; | ||
|
||
&psi5_0_ch1 { | ||
period-sync-pulse-us = <500>; | ||
decoder-start-offset-us = <0>; | ||
sync-pulse-width-0-us = <100>; | ||
sync-pulse-width-1-us = <127>; | ||
tx-mode = "long-frame-31"; | ||
num-rx-buf = <32>; | ||
rx-bitrate-kbps = <189>; | ||
array-slot-duration-us = <150>; | ||
array-slot-start-offset-us = <110>; | ||
array-slot-data-length = <16>; | ||
array-slot-data-msb-first = <0>; | ||
array-slot-has-smc = <0>; | ||
array-slot-has-parity = <0>; | ||
status = "okay"; | ||
}; | ||
|
||
&psi5_0_ch2 { | ||
period-sync-pulse-us = <8>; | ||
decoder-start-offset-us = <0>; | ||
sync-pulse-width-0-us = <2>; | ||
sync-pulse-width-1-us = <6>; | ||
tx-mode = "long-frame-31"; | ||
num-rx-buf = <32>; | ||
rx-bitrate-kbps = <189>; | ||
array-slot-duration-us = <500>; | ||
array-slot-start-offset-us = <0>; | ||
array-slot-data-length = <16>; | ||
array-slot-data-msb-first = <0>; | ||
array-slot-has-smc = <0>; | ||
array-slot-has-parity = <0>; | ||
status = "okay"; | ||
}; |
7 changes: 7 additions & 0 deletions
7
samples/boards/nxp/s32/psi5/boards/s32z2xxdc2_s32z270_rtu1.overlay
This file contains 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 @@ | ||
/* | ||
* Copyright 2025 NXP | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "s32z2xxdc2_s32z270_rtu0.overlay" |
This file contains 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,3 @@ | ||
CONFIG_PSI5=y | ||
CONFIG_PSI5_LOG_LEVEL_DBG=y | ||
CONFIG_LOG=y |
This file contains 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,14 @@ | ||
sample: | ||
description: Sample for using PSI5 driver | ||
name: NXP S32 PSI5 sample | ||
|
||
tests: | ||
sample.boards.nxp_s32.psi5: | ||
platform_allow: | ||
- s32z2xxdc2/s32z270/rtu0 | ||
- s32z2xxdc2/s32z270/rtu1 | ||
- s32z2xxdc2@D/s32z270/rtu0 | ||
- s32z2xxdc2@D/s32z270/rtu1 | ||
depends_on: psi5 | ||
tags: psi5 | ||
harness: sensor |
This file contains 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,48 @@ | ||
/* | ||
* Copyright 2025 NXP | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <zephyr/logging/log.h> | ||
LOG_MODULE_REGISTER(nxp_s32_psi5_sample, LOG_LEVEL_DBG); | ||
|
||
#include <zephyr/kernel.h> | ||
|
||
#include <zephyr/drivers/psi5/psi5.h> | ||
|
||
#define PSI5_NODE DT_INST(0, nxp_s32_psi5) | ||
|
||
void tx_cb(const struct device *dev, uint8_t channel_id, enum psi5_status status, void *user_data) | ||
{ | ||
LOG_INF("Tx channel %d completed\n", channel_id); | ||
} | ||
|
||
void rx_cb(const struct device *dev, uint8_t channel_id, struct psi5_frame *frame, | ||
enum psi5_status status, void *user_data) | ||
{ | ||
|
||
LOG_INF("Rx channel %d completed\n", channel_id); | ||
} | ||
|
||
int main(void) | ||
{ | ||
const struct device *const dev = DEVICE_DT_GET(PSI5_NODE); | ||
uint64_t send_data = 0x1234; | ||
|
||
/* Test receive data */ | ||
psi5_add_rx_callback(dev, 1, rx_cb, NULL); | ||
|
||
psi5_start_sync(dev, 1); | ||
|
||
k_sleep(K_MSEC(100)); | ||
|
||
psi5_stop_sync(dev, 1); | ||
|
||
/* Test send data */ | ||
psi5_start_sync(dev, 2); | ||
|
||
psi5_send(dev, 2, send_data, K_MSEC(100), tx_cb, NULL); | ||
|
||
return 0; | ||
} |