Skip to content

Commit

Permalink
samples: use zephyr spi for nrf52
Browse files Browse the repository at this point in the history
temporary fixes sughz communication issue
after the last upmerge

Signed-off-by: Krzysztof Taborowski <[email protected]>
  • Loading branch information
ktaborowski committed Oct 11, 2024
1 parent 4d57fc9 commit 09e6922
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 123 deletions.
32 changes: 0 additions & 32 deletions Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -243,38 +243,6 @@ config SIDEWALK_PAL_RADIO_SOURCE
bool "Build sub-GHz radio driver from sources [EXPERIMENTAL]"
select EXPERIMENTAL

if SIDEWALK_SPI_BUS

choice SIDEWALK_NRFX_SPI_INSTANCE_ID
prompt "Instance of the NRX SPI driver"
depends on SOC_NRF52840
default SIDEWALK_NRFX_SPI2
help
Select the NRFX SPI instance.
The same SPI instance must be disabled in the DTS.

config SIDEWALK_NRFX_SPI0
bool "SPI0"
select NRFX_SPI0

config SIDEWALK_NRFX_SPI1
bool "SPI1"
select NRFX_SPI1

config SIDEWALK_NRFX_SPI2
bool "SPI2"
select NRFX_SPI2

endchoice # SIDEWALK_NRFX_SPI_INSTANCE_ID

config SIDEWALK_NRFX_SPI_ID
int
depends on SOC_NRF52840
default 2
default 1 if SIDEWALK_NRFX_SPI1
default 0 if SIDEWALK_NRFX_SPI0

endif # SIDEWALK_SPI_BUS

rsource "Kconfig.dependencies"
rsource "utils/Kconfig"
Expand Down
51 changes: 25 additions & 26 deletions samples/sid_end_device/boards/nrf52840dk_nrf52840.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,17 @@
status = "disabled";
};

&spi2 {
status = "disabled";
sid_semtech: &spi2 {
compatible = "nordic,nrf-spim";
status = "okay";
cs-gpios = <&gpio1 0x8 GPIO_ACTIVE_LOW>;
pinctrl-0 = <&spi2_default>;
pinctrl-1 = <&spi2_sleep>;
pinctrl-names = "default", "sleep";
clock-frequency = <DT_FREQ_M(8)>;
};

/{
nrfx_spi_gpios{
compatible = "gpio-keys";
nrfx_spi_sck: sck {
gpios = <&gpio1 0xF GPIO_ACTIVE_LOW>;
label = "spi_sck";
};
nrfx_spi_miso: miso {
gpios = <&gpio1 0xE GPIO_ACTIVE_HIGH>;
label = "spi_miso";
};
nrfx_spi_mosi: mosi {
gpios = <&gpio1 0xD GPIO_ACTIVE_HIGH>;
label = "spi_mosi";
};
nrfx_spi_cs: cs {
gpios = <&gpio1 0x8 GPIO_ACTIVE_HIGH>;
label = "spi_cs";
};
};

state_notifier_gpios{
compatible = "gpio-keys";
state_notifier_error: error {
Expand Down Expand Up @@ -66,10 +52,6 @@

semtech_sx1262_gpios{
compatible = "gpio-keys";
semtech_sx1262_cs: cs {
gpios = <&gpio1 0x8 GPIO_ACTIVE_LOW>;
label = "semtech_sx1262 CS";
};
semtech_sx1262_reset_gpios: reset {
gpios = <&gpio0 0x3 GPIO_ACTIVE_LOW>;
label = "semtech_sx1262 Reset";
Expand All @@ -92,3 +74,20 @@
nordic,pm-ext-flash = &mx25r64;
};
};

&spi2_default {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 1, 15)>,
<NRF_PSEL(SPIM_MISO, 1, 14)>,
<NRF_PSEL(SPIM_MOSI, 1, 13)>;
};
};

&spi2_sleep {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 1, 15)>,
<NRF_PSEL(SPIM_MISO, 1, 14)>,
<NRF_PSEL(SPIM_MOSI, 1, 13)>;
low-power-enable;
};
};
107 changes: 46 additions & 61 deletions subsys/config/common/src/app_subGHz_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,33 @@
#include <sid_gpio_utils.h>
#include <sx126x_config.h>

#if CONFIG_SOC_NRF52840
#include <nrfx_spi.h>
#endif /* CONFIG_SOC_NRF52840 */

#include <app_subGHz_config.h>

#define REGION_US915

/* This product has no external PA and SX1262 can support max of 22dBm*/
#define RADIO_SX1262_MAX_TX_POWER 22
#define RADIO_SX1262_MIN_TX_POWER -9
#define RADIO_SX1262_MAX_TX_POWER 22
#define RADIO_SX1262_MIN_TX_POWER -9

#define RADIO_MAX_TX_POWER_NA 20
#define RADIO_MAX_TX_POWER_EU 14
#define RADIO_MAX_TX_POWER_NA 20
#define RADIO_MAX_TX_POWER_EU 14

#define RADIO_REGION RADIO_REGION_NA
#define RADIO_REGION RADIO_REGION_NA

#define RADIO_SX1262_SPI_BUFFER_SIZE 255
#define RADIO_SX1262_SPI_BUFFER_SIZE 255

#define RADIO_SX1262_PA_DUTY_CYCLE 0x04
#define RADIO_SX1262_HP_MAX 0x07
#define RADIO_SX1262_DEVICE_SEL 0x00
#define RADIO_SX1262_PA_LUT 0x01
#define RADIO_SX1262_PA_DUTY_CYCLE 0x04
#define RADIO_SX1262_HP_MAX 0x07
#define RADIO_SX1262_DEVICE_SEL 0x00
#define RADIO_SX1262_PA_LUT 0x01

#define RADIO_RX_LNA_GAIN 0
#define RADIO_MAX_CAD_SYMBOL SID_PAL_RADIO_LORA_CAD_04_SYMBOL
#define RADIO_ANT_GAIN(X) ((X) * 100)
#define RADIO_RX_LNA_GAIN 0
#define RADIO_MAX_CAD_SYMBOL SID_PAL_RADIO_LORA_CAD_04_SYMBOL
#define RADIO_ANT_GAIN(X) ((X) * 100)

#define NULL_STRUCT_INITIALIZER { 0 }
#define INVALID_DT_GPIO NULL_STRUCT_INITIALIZER
#define SPI_FREQUENCY_DEFAULT (DT_FREQ_M(8))
#define NULL_STRUCT_INITIALIZER { 0 }
#define INVALID_DT_GPIO NULL_STRUCT_INITIALIZER
#define SPI_FREQUENCY_DEFAULT (DT_FREQ_M(8))

static uint8_t radio_sx1262_buffer[RADIO_SX1262_SPI_BUFFER_SIZE] = { 0 };

Expand All @@ -77,38 +73,33 @@ static int32_t radio_sx1262_pa_cfg(int8_t tx_power, radio_sx126x_pa_cfg_t *pa_cf
pa_cfg->hp_max = RADIO_SX1262_HP_MAX;
pa_cfg->device_sel = RADIO_SX1262_DEVICE_SEL;
pa_cfg->pa_lut = RADIO_SX1262_PA_LUT;
pa_cfg->tx_power = pwr; // one to one mapping between tx params and tx power
pa_cfg->tx_power = pwr; // one to one mapping between tx params and tx power
pa_cfg->ramp_time = RADIO_SX126X_RAMP_40_US;

return 0;
}

static int32_t radio_sx1262_trim_val (uint16_t* trim_val)
static int32_t radio_sx1262_trim_val(uint16_t *trim_val)
{
*trim_val = CONFIG_SIDEWALK_SUBGHZ_TRIM_CAP_VAL;
return 0;
}

const radio_sx126x_regional_param_t radio_sx126x_regional_param[] =
{
#if defined (REGION_ALL) || defined (REGION_US915)
{
.param_region = RADIO_REGION_NA,
.max_tx_power = { RADIO_MAX_TX_POWER_NA, RADIO_MAX_TX_POWER_NA, RADIO_MAX_TX_POWER_NA,
RADIO_MAX_TX_POWER_NA, RADIO_MAX_TX_POWER_NA, RADIO_MAX_TX_POWER_NA },
.cca_level_adjust = { 0, 0, 0, 0, 0, 0 },
.ant_dbi = RADIO_ANT_GAIN(2.15)
},
#endif
#if defined (REGION_ALL) || defined (REGION_EU868)
{
.param_region = RADIO_REGION_EU,
.max_tx_power = { RADIO_MAX_TX_POWER_EU, RADIO_MAX_TX_POWER_EU, RADIO_MAX_TX_POWER_EU,
RADIO_MAX_TX_POWER_EU, RADIO_MAX_TX_POWER_EU, RADIO_MAX_TX_POWER_EU },
.cca_level_adjust = { 0, 0, 0, 0, 0, 0 },
.ant_dbi = RADIO_ANT_GAIN(2.15)
},
#endif
const radio_sx126x_regional_param_t radio_sx126x_regional_param[] = {
#if defined(REGION_ALL) || defined(REGION_US915)
{ .param_region = RADIO_REGION_NA,
.max_tx_power = { RADIO_MAX_TX_POWER_NA, RADIO_MAX_TX_POWER_NA, RADIO_MAX_TX_POWER_NA,
RADIO_MAX_TX_POWER_NA, RADIO_MAX_TX_POWER_NA, RADIO_MAX_TX_POWER_NA },
.cca_level_adjust = { 0, 0, 0, 0, 0, 0 },
.ant_dbi = RADIO_ANT_GAIN(2.15) },
#endif
#if defined(REGION_ALL) || defined(REGION_EU868)
{ .param_region = RADIO_REGION_EU,
.max_tx_power = { RADIO_MAX_TX_POWER_EU, RADIO_MAX_TX_POWER_EU, RADIO_MAX_TX_POWER_EU,
RADIO_MAX_TX_POWER_EU, RADIO_MAX_TX_POWER_EU, RADIO_MAX_TX_POWER_EU },
.cca_level_adjust = { 0, 0, 0, 0, 0, 0 },
.ant_dbi = RADIO_ANT_GAIN(2.15) },
#endif
};

static radio_sx126x_device_config_t radio_sx1262_cfg = {
Expand Down Expand Up @@ -149,31 +140,25 @@ static radio_sx126x_device_config_t radio_sx1262_cfg = {
const radio_sx126x_device_config_t *get_radio_cfg(void)
{
radio_sx1262_cfg.gpio_power =
sid_gpio_utils_register_gpio(
(struct gpio_dt_spec)GPIO_DT_SPEC_GET_OR(DT_NODELABEL(semtech_sx1262_reset_gpios), gpios, INVALID_DT_GPIO));
sid_gpio_utils_register_gpio((struct gpio_dt_spec)GPIO_DT_SPEC_GET_OR(
DT_NODELABEL(semtech_sx1262_reset_gpios), gpios, INVALID_DT_GPIO));
radio_sx1262_cfg.gpio_int1 =
sid_gpio_utils_register_gpio(
(struct gpio_dt_spec)GPIO_DT_SPEC_GET_OR(DT_NODELABEL(semtech_sx1262_dio1_gpios), gpios, INVALID_DT_GPIO));
sid_gpio_utils_register_gpio((struct gpio_dt_spec)GPIO_DT_SPEC_GET_OR(
DT_NODELABEL(semtech_sx1262_dio1_gpios), gpios, INVALID_DT_GPIO));
radio_sx1262_cfg.gpio_radio_busy =
sid_gpio_utils_register_gpio(
(struct gpio_dt_spec)GPIO_DT_SPEC_GET_OR(DT_NODELABEL(semtech_sx1262_busy_gpios), gpios, INVALID_DT_GPIO));
sid_gpio_utils_register_gpio((struct gpio_dt_spec)GPIO_DT_SPEC_GET_OR(
DT_NODELABEL(semtech_sx1262_busy_gpios), gpios, INVALID_DT_GPIO));
radio_sx1262_cfg.gpio_rf_sw_ena =
sid_gpio_utils_register_gpio(
(struct gpio_dt_spec)GPIO_DT_SPEC_GET_OR(DT_NODELABEL(semtech_sx1262_antenna_enable_gpios),
gpios, INVALID_DT_GPIO));
sid_gpio_utils_register_gpio((struct gpio_dt_spec)GPIO_DT_SPEC_GET_OR(
DT_NODELABEL(semtech_sx1262_antenna_enable_gpios), gpios, INVALID_DT_GPIO));
radio_sx1262_cfg.bus_selector.client_selector =
sid_gpio_utils_register_gpio((struct gpio_dt_spec)GPIO_DT_SPEC_GET_OR(
DT_NODELABEL(semtech_sx1262_cs), gpios, INVALID_DT_GPIO));
radio_sx1262_cfg.bus_selector.client_selector =
sid_gpio_utils_register_gpio(
(struct gpio_dt_spec)GPIO_DT_SPEC_GET_OR(DT_NODELABEL(semtech_sx1262_cs), gpios, INVALID_DT_GPIO));
radio_sx1262_cfg.bus_selector.client_selector =
sid_gpio_utils_register_gpio(
(struct gpio_dt_spec)GPIO_DT_SPEC_GET_OR(DT_NODELABEL(sid_semtech), cs_gpios, INVALID_DT_GPIO));
sid_gpio_utils_register_gpio((struct gpio_dt_spec)GPIO_DT_SPEC_GET_OR(
DT_NODELABEL(sid_semtech), cs_gpios, INVALID_DT_GPIO));
radio_sx1262_cfg.bus_selector.speed_hz =
#if CONFIG_SOC_NRF52840
NRF_SPI_FREQ_8M;
#else /* CONFIG_SOC_NRF52840 */
DT_PROP_OR(DT_NODELABEL(sid_semtech), clock_frequency, SPI_FREQUENCY_DEFAULT);
#endif /* CONFIG_SOC_NRF52840 */

radio_sx1262_cfg.gpio_tx_bypass =
sid_gpio_utils_register_gpio((struct gpio_dt_spec)GPIO_DT_SPEC_GET_OR(
DT_NODELABEL(semtech_sx1262_tx_bypass), gpios, INVALID_DT_GPIO));
Expand Down
4 changes: 0 additions & 4 deletions subsys/sal/sid_pal/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ zephyr_library_sources_ifdef(CONFIG_SIDEWALK_SW_INTERRUPTS sid_sw_interrupts.c)

zephyr_library_sources_ifdef(CONFIG_SIDEWALK_DELAY sid_delay.c)

if(CONFIG_SOC_NRF52840)
zephyr_library_sources_ifdef(CONFIG_SIDEWALK_SPI_BUS sid_pal_serial_bus_nrfx_spi.c)
else()
zephyr_library_sources_ifdef(CONFIG_SIDEWALK_SPI_BUS sid_pal_serial_bus_spi.c)
endif() # CONFIG_SOC_NRF52840

zephyr_library_sources_ifdef(CONFIG_SIDEWALK sid_common.c)

Expand Down

0 comments on commit 09e6922

Please sign in to comment.