Skip to content

Commit

Permalink
Merge pull request #4 from DynamicDevices/shreya/nRF5340Tag_overlay
Browse files Browse the repository at this point in the history
modified:   boards/nrf5340tag_nrf5340_cpuapp.overlay
  • Loading branch information
ajlennon authored May 8, 2024
2 parents 392a1da + 448b905 commit a30a37e
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 5 deletions.
2 changes: 1 addition & 1 deletion boards/nrf5340tag_nrf5340_cpuapp.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
# Default PRNG entropy for nRF53 Series devices is CSPRNG CC312
# which for that purpose is too slow yet
# Use Xoroshiro128+ as PRNG
CONFIG_XOROSHIRO_RANDOM_GENERATOR=y
CONFIG_XOSHIRO_RANDOM_GENERATOR=y
98 changes: 96 additions & 2 deletions boards/nrf5340tag_nrf5340_cpuapp.overlay
Original file line number Diff line number Diff line change
@@ -1,9 +1,103 @@
/* Copyright (c) 2020 Nordic Semiconductor ASA
/* Copyright (c) 2021 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#include <zephyr/dt-bindings/lora/sx126x.h>

//&temp {
// status = "okay";
//};

/ {
/*
* In some default configurations within the nRF Connect SDK,
* e.g. on nRF52840, the chosen zephyr,entropy node is &cryptocell.
* This devicetree overlay ensures that default is overridden wherever it
* is set, as this application uses the RNG node for entropy exclusively.
*/
// chosen {
// zephyr,entropy = &rng;
// };

aliases {
lora0 = &lora;
};

GNSS: zephyr,user {
gnss_vbckp_on-gpios = <&gpio0 5 0>;
gnss_vcc_on-gpios = <&gpio1 0 0>;
gnss_reset-gpios = <&gpio1 6 0>;
};
};

&pinctrl {

uart0_default: uart0_default {
group1 {
psels = <NRF_PSEL(UART_TX, 0, 25)>, <NRF_PSEL(UART_RTS, 0, 19)>;
};
group2 {
psels = <NRF_PSEL(UART_RX, 0, 24)>, <NRF_PSEL(UART_CTS, 0, 21)>;
};
};

uart0_sleep: uart0_sleep {
group1 {
psels = <NRF_PSEL(UART_TX, 0, 25)>,
<NRF_PSEL(UART_RX, 0, 24)>,
<NRF_PSEL(UART_RTS, 0, 19)>,
<NRF_PSEL(UART_CTS, 0, 21)>;
};
};

spi1_default: spi1_default {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 0, 20)>,
<NRF_PSEL(SPIM_MOSI, 0, 22)>,
<NRF_PSEL(SPIM_MISO, 0, 23)>;
};
};

spi1_sleep: spi1_sleep {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 0, 20)>,
<NRF_PSEL(SPIM_MOSI, 0, 22)>,
<NRF_PSEL(SPIM_MISO, 0, 23)>;
};
};
};

&uart0 {
status = "okay";
hw-flow-control;
current-speed = <9600>;
pinctrl-0 = <&uart0_default>;
pinctrl-1 = <&uart0_sleep>;
pinctrl-names = "default", "sleep";
};

&spi1 {
compatible = "nordic,nrf-spim";
status = "okay";
cs-gpios = <&gpio0 21 GPIO_ACTIVE_LOW>;

pinctrl-0 = <&spi1_default>;
pinctrl-1 = <&spi1_sleep>;
pinctrl-names = "default", "sleep";
lora: lora@0 {
compatible = "semtech,sx1262";
reg = <0>;
reset-gpios = <&gpio1 3 GPIO_ACTIVE_LOW>;
busy-gpios = <&gpio1 2 GPIO_ACTIVE_HIGH>;
// tx-enable-gpios = <&gpio0 25 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>;
// rx-enable-gpios = <&gpio0 24 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>;
dio1-gpios = <&gpio0 6 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH) >;
antenna-enable-gpios = <&gpio1 7 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH) >;
spi-max-frequency = <125000>;
};
};
&gpio_fwd {
uart {
gpios = <&gpio0 11 0>;
};
};
43 changes: 41 additions & 2 deletions src/gpsparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <zephyr/kernel.h>
#include <zephyr/drivers/uart.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/logging/log.h>

#include "gpsparser.h"
Expand All @@ -22,10 +23,21 @@ LOG_MODULE_REGISTER(gpsparser, CONFIG_GPS_PARSER_LOG_LEVEL);

#define INDENT_SPACES " "

const struct device *uart = DEVICE_DT_GET(DT_NODELABEL(uart1));
// 1000 msec = 1 sec
#define SLEEP_TIME_S 1000
#define SLEEP_TIME_MS 100
#define SLEEP_TIME_MMS 10

#define ZEPHYR_USER_NODE DT_PATH(zephyr_user)

const struct gpio_dt_spec gnss_vbckup = GPIO_DT_SPEC_GET(ZEPHYR_USER_NODE, gnss_vbckp_on_gpios);
const struct gpio_dt_spec gnss_vcc = GPIO_DT_SPEC_GET(ZEPHYR_USER_NODE, gnss_vcc_on_gpios);
const struct gpio_dt_spec gnss_reset = GPIO_DT_SPEC_GET(ZEPHYR_USER_NODE, gnss_reset_gpios);

const struct device *uart = DEVICE_DT_GET(DT_NODELABEL(uart0));

const struct uart_config uart_cfg = {
.baudrate = 9600,
.baudrate = 115200,
.parity = UART_CFG_PARITY_NONE,
.stop_bits = UART_CFG_STOP_BITS_1,
.data_bits = UART_CFG_DATA_BITS_8,
Expand Down Expand Up @@ -86,6 +98,33 @@ void set_callback_gga( GgaHandler handler)
void gpsparser(void)
{
char line[MINMEA_MAX_LENGTH];
int ret;

if (!gpio_is_ready_dt(&gnss_vbckup)) { return; }
if (!gpio_is_ready_dt(&gnss_vcc)) { return; }
if (!gpio_is_ready_dt(&gnss_reset)) { return; }
LOG_INF("pins are ready.");

// Configure the pins
ret = gpio_pin_configure_dt(&gnss_vbckup, GPIO_OUTPUT_INACTIVE);
if (ret < 0) { return; }
ret = gpio_pin_configure_dt(&gnss_vcc, GPIO_OUTPUT_INACTIVE);
if (ret < 0) { return; }
ret = gpio_pin_configure_dt(&gnss_reset, GPIO_OUTPUT_INACTIVE);
if (ret < 0) { return; }
LOG_INF("pins are configured.");

// GNSS start-up procedure
LOG_INF("GNSS start-up procedure...");
gpio_pin_set_dt(&gnss_vbckup, 0);
gpio_pin_set_dt(&gnss_vcc, 0);
gpio_pin_set_dt(&gnss_reset, 0);
k_msleep(SLEEP_TIME_MMS);
gpio_pin_set_dt(&gnss_vbckup, 1);
gpio_pin_set_dt(&gnss_vcc, 1);
k_msleep(SLEEP_TIME_MS);
gpio_pin_set_dt(&gnss_reset, 1);
LOG_INF("GNSS is set active.");

int err = uart_configure(uart, &uart_cfg);

Expand Down

0 comments on commit a30a37e

Please sign in to comment.