Skip to content

Commit 05ea20c

Browse files
authored
Merge pull request #13681 from winneymj/nrf52840_SPIM3_Updates
Nrf52840 spim3 updates
2 parents aa9989f + d60af09 commit 05ea20c

File tree

4 files changed

+32
-32
lines changed

4 files changed

+32
-32
lines changed

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/object_owners.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,21 @@
1515
* limitations under the License.
1616
*/
1717

18+
#include "sdk_config.h"
1819
#include "object_owners.h"
1920

2021
#include "nrf.h"
2122
#include "nrf_peripherals.h"
2223

2324
#include <stdio.h>
2425

26+
#if NRFX_SPIM_ENABLED
27+
#define SPI2C_INSTANCES SPIM_COUNT
28+
#elif NRFX_SPI_ENABLED
2529
#define SPI2C_INSTANCES SPI_COUNT
30+
#endif
2631

27-
static void * nordic_spi2c_owners[SPI2C_INSTANCES] = { NULL, NULL, NULL };
32+
static void * nordic_spi2c_owners[SPI2C_INSTANCES] = { NULL };
2833

2934
/**
3035
* Brief Set instance owner for the SPI/I2C peripheral.

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/spi_api.c

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -480,11 +480,6 @@ void spi_frequency(spi_t *obj, int hz)
480480
int spi_master_write(spi_t *obj, int value)
481481
{
482482
nrfx_err_t ret;
483-
#if NRFX_CHECK(NRFX_SPIM_ENABLED)
484-
nrfx_spim_xfer_desc_t desc;
485-
#elif NRFX_CHECK(NRFX_SPI_ENABLED)
486-
nrfx_spi_xfer_desc_t desc;
487-
#endif
488483

489484
#if DEVICE_SPI_ASYNCH
490485
struct spi_s *spi_inst = &obj->spi;
@@ -507,18 +502,20 @@ int spi_master_write(spi_t *obj, int value)
507502
}
508503

509504
/* Transfer 1 byte. */
510-
desc.p_tx_buffer = &tx_buff;
511-
desc.p_rx_buffer = &rx_buff;
512-
desc.tx_length = 1;
513-
desc.rx_length = 1;
514-
#if NRFX_CHECK(NRFX_SPIM_ENABLED)
505+
#if NRFX_CHECK(NRFX_SPIM_ENABLED)
506+
nrfx_spim_xfer_desc_t desc = NRFX_SPIM_XFER_TRX(&tx_buff, 1, &rx_buff, 1);
507+
#elif NRFX_CHECK(NRFX_SPI_ENABLED)
508+
nrfx_spi_xfer_desc_t desc = NRFX_SPI_XFER_TRX(&tx_buff, 1, &rx_buff, 1);
509+
#endif
510+
511+
#if NRFX_CHECK(NRFX_SPIM_ENABLED)
515512
ret = nrfx_spim_xfer(&nordic_nrf5_spim_instance[instance], &desc, 0);
516-
#elif NRFX_CHECK(NRFX_SPI_ENABLED)
513+
#elif NRFX_CHECK(NRFX_SPI_ENABLED)
517514
ret = nrfx_spi_xfer(&nordic_nrf5_spi_instance[instance], &desc, 0);
518515
#endif
519516

520517
if (ret != NRFX_SUCCESS) {
521-
DEBUG_PRINTF("%d error returned from nrf_spi_xfer\n\r");
518+
DEBUG_PRINTF("%d error returned from nrf_spi_xfer\n\r", ret);
522519
}
523520

524521
/* Manually set chip select pin if defined. */
@@ -547,12 +544,6 @@ int spi_master_write(spi_t *obj, int value)
547544
*/
548545
int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length, char write_fill)
549546
{
550-
#if NRFX_CHECK(NRFX_SPIM_ENABLED)
551-
nrfx_spim_xfer_desc_t desc;
552-
#elif NRFX_CHECK(NRFX_SPI_ENABLED)
553-
nrfx_spi_xfer_desc_t desc;
554-
#endif
555-
556547
#if DEVICE_SPI_ASYNCH
557548
struct spi_s *spi_inst = &obj->spi;
558549
#else
@@ -586,6 +577,10 @@ int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, cha
586577

587578
ret_code_t result = NRFX_SUCCESS;
588579

580+
#if NRFX_CHECK(NRFX_SPIM_ENABLED)
581+
nrfx_spim_xfer_desc_t desc = NRFX_SPIM_XFER_TRX(tx_buffer, tx_length, rx_buffer, rx_length);
582+
result = nrfx_spim_xfer(&nordic_nrf5_spim_instance[instance], &desc, 0);
583+
#elif NRFX_CHECK(NRFX_SPI_ENABLED)
589584
/* Loop until all data is sent and received. */
590585
while (((tx_length > 0) || (rx_length > 0)) && (result == NRFX_SUCCESS)) {
591586

@@ -606,24 +601,17 @@ int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, cha
606601
NULL;
607602

608603
/* Blocking transfer. */
609-
desc.p_tx_buffer = tx_actual_buffer;
610-
desc.p_rx_buffer = rx_actual_buffer;
611-
desc.tx_length = tx_actual_length;
612-
desc.rx_length = rx_actual_length;
613-
#if NRFX_CHECK(NRFX_SPIM_ENABLED)
614-
result = nrfx_spim_xfer(&nordic_nrf5_spim_instance[instance],
615-
&desc, 0);
616-
#elif NRFX_CHECK(NRFX_SPI_ENABLED)
604+
nrfx_spi_xfer_desc_t desc = NRFX_SPI_XFER_TRX(tx_actual_buffer, tx_actual_length, rx_actual_buffer, rx_actual_length);
617605
result = nrfx_spi_xfer(&nordic_nrf5_spi_instance[instance],
618606
&desc, 0);
619-
#endif
620607
/* Update loop variables. */
621608
tx_length -= tx_actual_length;
622609
tx_offset += tx_actual_length;
623610

624611
rx_length -= rx_actual_length;
625612
rx_offset += rx_actual_length;
626613
}
614+
#endif
627615

628616
/* Manually set chip select pin if defined. */
629617
if (spi_inst->cs != NC) {

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/modules/nrfx/drivers/include/nrfx_spim.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ typedef struct
142142
#define NRFX_SPIM_DEFAULT_EXTENDED_CONFIG \
143143
.dcx_pin = NRFX_SPIM_PIN_NOT_USED, \
144144
.rx_delay = 0x00, \
145-
.ss_duration = 0x00, \
146-
.use_hw_ss = false,
145+
.use_hw_ss = false, \
146+
.ss_duration = 0x00,
147147
#else
148148
#define NRFX_SPIM_DEFAULT_EXTENDED_CONFIG
149149
#endif

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/modules/nrfx/drivers/src/nrfx_spim.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,21 @@ nrfx_err_t nrfx_spim_init(nrfx_spim_t const * const p_instance,
247247
NRF_GPIO_PIN_DIR_OUTPUT,
248248
NRF_GPIO_PIN_INPUT_CONNECT,
249249
NRF_GPIO_PIN_NOPULL,
250-
NRF_GPIO_PIN_S0S1,
250+
// Use High Drive if using SPIM3
251+
(p_instance->drv_inst_idx == NRFX_SPIM3_INST_IDX) ? NRF_GPIO_PIN_H0H1 : NRF_GPIO_PIN_S0S1,
251252
NRF_GPIO_PIN_NOSENSE);
252253
// - MOSI (optional) - output with initial value 0,
253254
if (p_config->mosi_pin != NRFX_SPIM_PIN_NOT_USED)
254255
{
255256
mosi_pin = p_config->mosi_pin;
256257
nrf_gpio_pin_clear(mosi_pin);
257-
nrf_gpio_cfg_output(mosi_pin);
258+
nrf_gpio_cfg(p_config->mosi_pin,
259+
NRF_GPIO_PIN_DIR_OUTPUT,
260+
NRF_GPIO_PIN_INPUT_DISCONNECT,
261+
NRF_GPIO_PIN_NOPULL,
262+
// Use High Drive if using SPIM3
263+
(p_instance->drv_inst_idx == NRFX_SPIM3_INST_IDX) ? NRF_GPIO_PIN_H0H1 : NRF_GPIO_PIN_S0S1,
264+
NRF_GPIO_PIN_NOSENSE);
258265
}
259266
else
260267
{

0 commit comments

Comments
 (0)