Skip to content

Commit 05302b9

Browse files
nomo-nordicmasz-nordic
authored andcommitted
[nrf fromlist] soc: nordic: remove nRF52 Series anomaly 58 workaround
The anomaly will be handled as part of nrfx 4.0 Upstream PR #: 96467 Signed-off-by: Norbert Morawski <[email protected]>
1 parent cb5dcb6 commit 05302b9

File tree

7 files changed

+14
-169
lines changed

7 files changed

+14
-169
lines changed

drivers/spi/Kconfig.nrfx

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,24 +72,6 @@ config SPI_NRFX_SPIS
7272
select NRFX_SPIS136 if HAS_HW_NRF_SPIS136
7373
select NRFX_SPIS137 if HAS_HW_NRF_SPIS137
7474

75-
config SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58
76-
depends on SOC_NRF52832
77-
select NRFX_PPI
78-
bool "Allow enabling the SPIM driver despite PAN 58"
79-
help
80-
Allow enabling the nRF SPI Master with EasyDMA, despite
81-
Product Anomaly Notice 58 (SPIM: An additional byte is
82-
clocked out when RXD.MAXCNT == 1 and TXD.MAXCNT <= 1).
83-
Without this override, the SPI Master is only available
84-
without EasyDMA. Note that the 'SPIM' and 'SPIS' drivers
85-
use EasyDMA, while the 'SPI' driver does not.
86-
When used in conjunction with nRF SPIM Devicetree property
87-
'anomaly-58-workaround' a workaround can be enabled per SPIM
88-
instance. If you are certain that transactions with
89-
RXD.MAXCNT == 1 and TXD.MAXCNT <= 1 will NOT be executed
90-
then nRF52832 PPI and GPIOTE resources can be saved by not
91-
enabling 'anomaly-58-workaround' via the Devicetree.
92-
9375
config SPI_NRFX_RAM_BUFFER_SIZE
9476
int "Size of RAM buffers for SPIM peripherals"
9577
default 8

drivers/spi/spi_nrfx_spim.c

Lines changed: 3 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
#include <zephyr/mem_mgmt/mem_attr.h>
1515
#include <soc.h>
1616
#include <dmm.h>
17-
#ifdef CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58
18-
#include <nrfx_ppi.h>
19-
#endif
2017
#ifdef CONFIG_SOC_NRF5340_CPUAPP
2118
#include <hal/nrf_clock.h>
2219
#endif
@@ -31,12 +28,6 @@ LOG_MODULE_REGISTER(spi_nrfx_spim, CONFIG_SPI_LOG_LEVEL);
3128
#include "spi_context.h"
3229
#include "spi_nrfx_common.h"
3330

34-
#if defined(CONFIG_SOC_NRF52832) && !defined(CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58)
35-
#error This driver is not available by default for nRF52832 because of Product Anomaly 58 \
36-
(SPIM: An additional byte is clocked out when RXD.MAXCNT == 1 and TXD.MAXCNT <= 1). \
37-
Use CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58=y to override this limitation.
38-
#endif
39-
4031
#if (CONFIG_SPI_NRFX_RAM_BUFFER_SIZE > 0)
4132
#define SPI_BUFFER_IN_RAM 1
4233
#endif
@@ -112,11 +103,6 @@ struct spi_nrfx_data {
112103
uint8_t *tx_buffer;
113104
uint8_t *rx_buffer;
114105
#endif
115-
#ifdef CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58
116-
bool anomaly_58_workaround_active;
117-
uint8_t ppi_ch;
118-
uint8_t gpiote_ch;
119-
#endif
120106
#ifdef SPIM_ANY_FAST
121107
bool clock_requested;
122108
#endif
@@ -129,9 +115,6 @@ struct spi_nrfx_config {
129115
void (*irq_connect)(void);
130116
uint16_t max_chunk_len;
131117
const struct pinctrl_dev_config *pcfg;
132-
#ifdef CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58
133-
bool anomaly_58_workaround;
134-
#endif
135118
uint32_t wake_pin;
136119
nrfx_gpiote_t wake_gpiote;
137120
#ifdef SPIM_ANY_FAST
@@ -384,89 +367,6 @@ static int configure(const struct device *dev,
384367
return 0;
385368
}
386369

387-
#ifdef CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58
388-
static const nrfx_gpiote_t gpiote = NRFX_GPIOTE_INSTANCE(0);
389-
390-
/*
391-
* Brief Workaround for transmitting 1 byte with SPIM.
392-
*
393-
* Derived from the setup_workaround_for_ftpan_58() function from
394-
* the nRF52832 Rev 1 Errata v1.6 document anomaly 58 workaround.
395-
*
396-
* Warning Must not be used when transmitting multiple bytes.
397-
*
398-
* Warning After this workaround is used, the user must reset the PPI
399-
* channel and the GPIOTE channel before attempting to transmit multiple
400-
* bytes.
401-
*/
402-
static void anomaly_58_workaround_setup(const struct device *dev)
403-
{
404-
struct spi_nrfx_data *dev_data = dev->data;
405-
const struct spi_nrfx_config *dev_config = dev->config;
406-
NRF_SPIM_Type *spim = dev_config->spim.p_reg;
407-
uint32_t ppi_ch = dev_data->ppi_ch;
408-
uint32_t gpiote_ch = dev_data->gpiote_ch;
409-
uint32_t eep = (uint32_t)&gpiote.p_reg->EVENTS_IN[gpiote_ch];
410-
uint32_t tep = (uint32_t)&spim->TASKS_STOP;
411-
412-
dev_data->anomaly_58_workaround_active = true;
413-
414-
/* Create an event when SCK toggles */
415-
nrf_gpiote_event_configure(gpiote.p_reg, gpiote_ch, spim->PSEL.SCK,
416-
GPIOTE_CONFIG_POLARITY_Toggle);
417-
nrf_gpiote_event_enable(gpiote.p_reg, gpiote_ch);
418-
419-
/* Stop the spim instance when SCK toggles */
420-
nrf_ppi_channel_endpoint_setup(NRF_PPI, ppi_ch, eep, tep);
421-
nrf_ppi_channel_enable(NRF_PPI, ppi_ch);
422-
423-
/* The spim instance cannot be stopped mid-byte, so it will finish
424-
* transmitting the first byte and then stop. Effectively ensuring
425-
* that only 1 byte is transmitted.
426-
*/
427-
}
428-
429-
static void anomaly_58_workaround_clear(struct spi_nrfx_data *dev_data)
430-
{
431-
uint32_t ppi_ch = dev_data->ppi_ch;
432-
uint32_t gpiote_ch = dev_data->gpiote_ch;
433-
434-
if (dev_data->anomaly_58_workaround_active) {
435-
nrf_ppi_channel_disable(NRF_PPI, ppi_ch);
436-
nrf_gpiote_task_disable(gpiote.p_reg, gpiote_ch);
437-
438-
dev_data->anomaly_58_workaround_active = false;
439-
}
440-
}
441-
442-
static int anomaly_58_workaround_init(const struct device *dev)
443-
{
444-
struct spi_nrfx_data *dev_data = dev->data;
445-
const struct spi_nrfx_config *dev_config = dev->config;
446-
nrfx_err_t err_code;
447-
448-
dev_data->anomaly_58_workaround_active = false;
449-
450-
if (dev_config->anomaly_58_workaround) {
451-
err_code = nrfx_ppi_channel_alloc(&dev_data->ppi_ch);
452-
if (err_code != NRFX_SUCCESS) {
453-
LOG_ERR("Failed to allocate PPI channel");
454-
return -ENODEV;
455-
}
456-
457-
err_code = nrfx_gpiote_channel_alloc(&gpiote, &dev_data->gpiote_ch);
458-
if (err_code != NRFX_SUCCESS) {
459-
LOG_ERR("Failed to allocate GPIOTE channel");
460-
return -ENODEV;
461-
}
462-
LOG_DBG("PAN 58 workaround enabled for %s: ppi %u, gpiote %u",
463-
dev->name, dev_data->ppi_ch, dev_data->gpiote_ch);
464-
}
465-
466-
return 0;
467-
}
468-
#endif
469-
470370
static void finish_transaction(const struct device *dev, int error)
471371
{
472372
struct spi_nrfx_data *dev_data = dev->data;
@@ -544,26 +444,9 @@ static void transfer_next_chunk(const struct device *dev)
544444
goto in_alloc_failed;
545445
}
546446

547-
#ifdef CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58
548-
if (xfer.rx_length == 1 && xfer.tx_length <= 1) {
549-
if (dev_config->anomaly_58_workaround) {
550-
anomaly_58_workaround_setup(dev);
551-
} else {
552-
LOG_WRN("Transaction aborted since it would trigger "
553-
"nRF52832 PAN 58");
554-
error = -EIO;
555-
}
556-
}
557-
#endif
558-
if (error == 0) {
559-
result = nrfx_spim_xfer(&dev_config->spim, &xfer, 0);
560-
if (result == NRFX_SUCCESS) {
561-
return;
562-
}
563-
error = -EIO;
564-
#ifdef CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58
565-
anomaly_58_workaround_clear(dev_data);
566-
#endif
447+
result = nrfx_spim_xfer(&dev_config->spim, &xfer, 0);
448+
if (result == NRFX_SUCCESS) {
449+
return;
567450
}
568451

569452
/* On nrfx_spim_xfer() error */
@@ -592,10 +475,6 @@ static void event_handler(const nrfx_spim_evt_t *p_event, void *p_context)
592475
return;
593476
}
594477

595-
#ifdef CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58
596-
anomaly_58_workaround_clear(dev_data);
597-
#endif
598-
599478
if (spi_context_tx_buf_on(&dev_data->ctx)) {
600479
dmm_buffer_out_release(dev_config->mem_reg,
601480
(void **)p_event->xfer_desc.p_tx_buffer);
@@ -693,9 +572,6 @@ static int transceive(const struct device *dev,
693572
#else
694573
dev_data->ctx.ready = 0;
695574
#endif /* CONFIG_MULTITHREADING */
696-
#ifdef CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58
697-
anomaly_58_workaround_clear(dev_data);
698-
#endif
699575
} else if (error) {
700576
finalize_spi_transaction(dev, true);
701577
}
@@ -867,12 +743,6 @@ static int spi_nrfx_init(const struct device *dev)
867743

868744
spi_context_unlock_unconditionally(&dev_data->ctx);
869745

870-
#ifdef CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58
871-
err = anomaly_58_workaround_init(dev);
872-
if (err < 0) {
873-
return err;
874-
}
875-
#endif
876746
return pm_device_driver_init(dev, spim_nrfx_pm_action);
877747
}
878748

@@ -957,10 +827,6 @@ static int spi_nrfx_deinit(const struct device *dev)
957827
.irq_connect = irq_connect##idx, \
958828
.pcfg = PINCTRL_DT_DEV_CONFIG_GET(SPIM(idx)), \
959829
.max_chunk_len = BIT_MASK(SPIM_PROP(idx, easydma_maxcnt_bits)),\
960-
COND_CODE_1(CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58, \
961-
(.anomaly_58_workaround = \
962-
SPIM_PROP(idx, anomaly_58_workaround),), \
963-
()) \
964830
.wake_pin = NRF_DT_GPIOS_TO_PSEL_OR(SPIM(idx), wake_gpios, \
965831
WAKE_PIN_NOT_USED), \
966832
.wake_gpiote = WAKE_GPIOTE_INSTANCE(SPIM(idx)), \

dts/bindings/spi/nordic,nrf-spim.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@ compatible: "nordic,nrf-spim"
88
include: ["nordic,nrf-spi-common.yaml", "memory-region.yaml"]
99

1010
properties:
11-
anomaly-58-workaround:
12-
type: boolean
13-
description: |
14-
Enables the workaround for the nRF52832 SoC SPIM PAN 58 anomaly.
15-
Must be used in conjunction with
16-
CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58=y
17-
1811
rx-delay-supported:
1912
type: boolean
2013
description: |

modules/hal_nordic/nrfx/nrfx_kconfig.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,9 @@
504504
#ifdef CONFIG_NRFX_SPIM4
505505
#define NRFX_SPIM4_ENABLED 1
506506
#endif
507+
#ifdef CONFIG_NRF52_ANOMALY_58_WORKAROUND
508+
#define NRF52_ERRATA_58_ENABLE_WORKAROUND 1
509+
#endif
507510

508511
#define NRFX_SPIM_DT_HAS_RX_DELAY(node) DT_PROP(node, rx_delay_supported) +
509512

samples/drivers/led/led_strip/boards/nrf52dk_nrf52832.conf

Lines changed: 0 additions & 3 deletions
This file was deleted.

soc/nordic/nrf52/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
zephyr_library_sources(soc.c)
44
zephyr_include_directories(.)
55

6-
if(CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58 AND CONFIG_SPI_NRFX_SPIM)
7-
message(WARNING "Both SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58 and an NRF SPIM driver are enabled, therefore PAN 58 will apply if RXD.MAXCNT == 1 and TXD.MAXCNT <= 1")
8-
endif()
9-
106
if(CONFIG_SOC_NRF52832)
117
if(NOT CONFIG_NRF52_ANOMALY_109_WORKAROUND)
128
if (CONFIG_NRFX_SPIS OR CONFIG_NRFX_SPIM OR CONFIG_NRFX_TWIM OR CONFIG_NRFX_PWM)

soc/nordic/nrf52/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ config NRF52_ANOMALY_132_DELAY_US
9292
Additional drivers initialization increases initialization time and delay
9393
may be shortened. Workaround is disabled by setting delay to 0.
9494

95+
config NRF52_ANOMALY_58_WORKAROUND
96+
bool "Anomaly 58 workaround"
97+
default y
98+
depends on SOC_NRF52832
99+
depends on NRFX_SPIM
100+
help
101+
This anomaly causes SPIM to clock out 2 bytes when 1 byte transfer was requested.
102+
95103
config NRF52_ANOMALY_198_WORKAROUND
96104
bool "Anomaly 198 workaround"
97105
default y

0 commit comments

Comments
 (0)