Skip to content

Commit 1d13e50

Browse files
committed
1. 在rt-thread\bsp\nrf5x\nrf52840\.ci\attachconfig\ci.attachconfig.yml中添加了spim的相关设置。
devices.spim: kconfig: - CONFIG_RT_USING_SPIM=y - CONFIG_BSP_USING_SPIM=y 2. nrfx_dpim.h 注释中纠正了错误的拼写 3. 多个文件中:nrfx_spim.c drv_spim.c drv_spim.h 删减了多余的宏定义:USING_SPI_DMA 4. nrfx_spim.c中删除了DMA_TRANS_MIN_LEN,该宏定义定义了spi+dma最小传输字节,直接定义20。
1 parent c8d0541 commit 1d13e50

File tree

6 files changed

+50
-93
lines changed

6 files changed

+50
-93
lines changed

bsp/nrf5x/libraries/drivers/drv_spim.c

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#include <string.h>
33
#include "board.h"
44
#include "drv_spim.h"
5-
#include "nrfx_spim.h"
65
#include "rtconfig.h"
76
#include <rtthread.h>
87
#include <rtdevice.h>
@@ -233,28 +232,24 @@ static rt_err_t spim_configure(struct rt_spi_device *device,
233232
void * context = RT_NULL;
234233
nrfx_spim_evt_handler_t handler = RT_NULL; /* spi send callback handler ,default NULL */
235234

236-
#if USING_SPI_DMA
237-
/* create and init completion */
238-
struct rt_completion *cpt = (struct rt_completion*)rt_malloc(sizeof(struct rt_completion));
239-
rt_completion_init(cpt);
240-
241-
/* create and init message about spim */
242-
struct spi_dma_message *mess = (struct spi_dma_message*)rt_malloc(sizeof(struct spi_dma_message));
243-
/* step 1 */
244-
mess->cs_pin = device->cs_pin;
245-
/* step 2 */
246-
mess->cs_take = 0;
247-
mess->cs_release = 0;
248-
/* step 3 */
249-
mess->use_hw_ss = config.use_hw_ss;
250-
/* step 4 */
251-
mess->ss_active_high = config.ss_active_high;
252-
/* step 6 */
253-
mess->cpt = cpt;
254-
255-
context = (void*)mess;
256-
handler = spim_handler[index];
257-
#endif
235+
/* create and init completion */
236+
struct rt_completion *cpt = (struct rt_completion*)rt_malloc(sizeof(struct rt_completion));
237+
rt_completion_init(cpt);
238+
/* create and init message about spim */
239+
struct spi_dma_message *mess = (struct spi_dma_message*)rt_malloc(sizeof(struct spi_dma_message));
240+
/* step 1: cs pin */
241+
mess->cs_pin = device->cs_pin;
242+
/* step 2: cs pin behavior */
243+
mess->cs_take = 0;
244+
mess->cs_release = 0;
245+
/* step 3 */
246+
mess->use_hw_ss = config.use_hw_ss;
247+
/* step 4: cs pin active */
248+
mess->ss_active_high = config.ss_active_high;
249+
/* step 6 */
250+
mess->cpt = cpt;
251+
context = (void*)mess;
252+
handler = spim_handler[index];
258253

259254
nrfx_err_t nrf_ret = nrfx_spim_init(&spim, &config, handler, context);
260255
if(NRFX_SUCCESS == nrf_ret)

bsp/nrf5x/libraries/drivers/drv_spim.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
#include "nrf_spi.h"
1212
#include "rtconfig.h"
1313

14-
#define USING_SPI_DMA 1
15-
16-
#if USING_SPI_DMA
17-
1814
struct spi_dma_message
1915
{
2016
rt_base_t cs_pin;
@@ -30,8 +26,6 @@ struct spi_dma_message
3026

3127
};
3228

33-
#endif
34-
3529
/**
3630
* @brief Attach the spi device to SPIM bus, this function must be used after initialization.
3731
* @param bus_name spim bus name "spim0"/"spim1"/"spim2"/"spim3"

bsp/nrf5x/libraries/drivers/nrfx_spim.c

Lines changed: 27 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -569,58 +569,32 @@ static void spim_int_enable(NRF_SPIM_Type * p_spim, bool enable);
569569

570570
static void finish_transfer(spim_control_block_t * p_cb)
571571
{
572-
573-
#if USING_SPI_DMA
574-
struct spi_dma_message *mess = (struct spi_dma_message*)(p_cb->p_context);
575-
if (mess->cs_pin != PIN_NONE && mess->cs_release)
572+
struct spi_dma_message *mess = (struct spi_dma_message*)(p_cb->p_context);
573+
if (mess->cs_pin != PIN_NONE && mess->cs_release)
574+
{
575+
#if NRFX_CHECK(NRFX_SPIM_EXTENDED_ENABLED)
576+
if (!mess->use_hw_ss)
577+
#endif
576578
{
577-
#if NRFX_CHECK(NRFX_SPIM_EXTENDED_ENABLED)
578-
if (!mess->use_hw_ss)
579-
#endif
579+
if (mess->ss_active_high)
580580
{
581-
if (mess->ss_active_high)
582-
{
583-
nrf_gpio_pin_clear(mess->cs_pin);
584-
}
585-
else
586-
{
587-
nrf_gpio_pin_set(mess->cs_pin);
588-
}
581+
nrf_gpio_pin_clear(mess->cs_pin);
589582
}
590-
}
591-
592-
#else
593-
/* If Slave Select signal is used, this is the time to deactivate it. */
594-
if (p_cb->ss_pin != NRFX_SPIM_PIN_NOT_USED)
595-
{
596-
#if NRFX_CHECK(NRFX_SPIM_EXTENDED_ENABLED)
597-
if (!p_cb->use_hw_ss)
598-
#endif
583+
else
599584
{
600-
if (p_cb->ss_active_high)
601-
{
602-
nrf_gpio_pin_clear(p_cb->ss_pin);
603-
}
604-
else
605-
{
606-
nrf_gpio_pin_set(p_cb->ss_pin);
607-
}
585+
nrf_gpio_pin_set(mess->cs_pin);
608586
}
609587
}
610-
#endif
611-
612-
588+
}
613589
/* By clearing this flag before calling the handler we allow subsequent */
614590
/* transfers to be started directly from the handler function. */
615591
p_cb->transfer_in_progress = false;
616592

617593
p_cb->evt.type = NRFX_SPIM_EVENT_DONE;
618594
p_cb->handler(&p_cb->evt, p_cb->p_context);
619595

620-
#if USING_SPI_DMA
621-
spim_int_enable(mess->spim, ((mess->flags) & NRFX_SPIM_FLAG_NO_XFER_EVT_HANDLER));
622-
rt_completion_done(mess->cpt);
623-
#endif
596+
spim_int_enable(mess->spim, ((mess->flags) & NRFX_SPIM_FLAG_NO_XFER_EVT_HANDLER));
597+
rt_completion_done(mess->cpt);
624598
}
625599

626600
static void spim_int_enable(NRF_SPIM_Type * p_spim, bool enable)
@@ -813,8 +787,6 @@ static nrfx_err_t rtt_spim_xfer(NRF_SPIM_Type * p_spim,
813787
struct rt_spi_message * message,
814788
struct rt_spi_device * dev)
815789
{
816-
#define DMA_TRANS_MIN_LEN (20) /* only buffer length >= DMA_TRANS_MIN_LEN will use DMA mode */
817-
818790
nrfx_err_t err_code;
819791
/* EasyDMA requires that transfer buffers are placed in Data RAM region; */
820792
/* signal error if they are not. */
@@ -829,13 +801,11 @@ static nrfx_err_t rtt_spim_xfer(NRF_SPIM_Type * p_spim,
829801
return err_code;
830802
}
831803

832-
#if USING_SPI_DMA
833-
struct spi_dma_message *mess = (struct spi_dma_message *)(p_cb->p_context);
834-
mess->cs_take = message->cs_take;
835-
mess->cs_release = message->cs_release;
836-
mess->flags = flags;
837-
mess->spim = p_spim;
838-
#endif
804+
struct spi_dma_message *mess = (struct spi_dma_message *)(p_cb->p_context);
805+
mess->cs_take = message->cs_take;
806+
mess->cs_release = message->cs_release;
807+
mess->flags = flags;
808+
mess->spim = p_spim;
839809

840810
nrf_spim_event_clear(p_spim, NRF_SPIM_EVENT_END);
841811

@@ -873,9 +843,9 @@ static nrfx_err_t rtt_spim_xfer(NRF_SPIM_Type * p_spim,
873843
}
874844
#endif
875845

876-
if (p_cb->handler == RT_NULL || (p_xfer_desc->rx_length<= DMA_TRANS_MIN_LEN && p_xfer_desc->tx_length<= DMA_TRANS_MIN_LEN))
846+
if (p_cb->handler == RT_NULL || (p_xfer_desc->rx_length<= 20 && p_xfer_desc->tx_length<= 20))
877847
{
878-
/* no cb func or lenth < DMA_TRANS_MIN_LEN, wait for transfer end */
848+
/* no cb func or lenth < 20, wait for transfer end */
879849
/* spim_int_enable(p_spim, ((mess->flags) & NRFX_SPIM_FLAG_NO_XFER_EVT_HANDLER)); */
880850
if (!(flags & NRFX_SPIM_FLAG_HOLD_XFER))
881851
{
@@ -909,17 +879,13 @@ static nrfx_err_t rtt_spim_xfer(NRF_SPIM_Type * p_spim,
909879
}
910880
else
911881
{
912-
#if USING_SPI_DMA
913-
spim_int_enable(p_spim, !(flags & NRFX_SPIM_FLAG_NO_XFER_EVT_HANDLER));
914-
p_cb->transfer_in_progress = false;
915-
if (rt_completion_wait(mess->cpt, 5000) != RT_EOK)
916-
{
917-
rt_kprintf("wait for DMA interrupt overtime!");
918-
return NRFX_ERROR_TIMEOUT;
919-
}
920-
#else
921-
spim_int_enable(p_spim, !(flags & NRFX_SPIM_FLAG_NO_XFER_EVT_HANDLER));
922-
#endif
882+
spim_int_enable(p_spim, !(flags & NRFX_SPIM_FLAG_NO_XFER_EVT_HANDLER));
883+
p_cb->transfer_in_progress = false;
884+
if (rt_completion_wait(mess->cpt, 5000) != RT_EOK)
885+
{
886+
rt_kprintf("wait for DMA interrupt overtime!");
887+
return NRFX_ERROR_TIMEOUT;
888+
}
923889
}
924890
err_code = NRFX_SUCCESS;
925891
NRFX_LOG_INFO("Function: %s, error code: %s.", __func__, NRFX_LOG_ERROR_STRING_GET(err_code));

bsp/nrf5x/libraries/drivers/nrfx_spim.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ typedef struct
160160
* - SS pin active low
161161
* - over-run character set to 0xFF
162162
* - clock frequency: 4 MHz
163-
* - mode: 0 (SCK active high, sample on leading edge of the clock signa;)
163+
* - mode: 0 (SCK active high, sample on leading edge of the clock signal;)
164164
* - MSB shifted out first
165165
* - MISO pull-up disabled
166166
*
@@ -334,7 +334,6 @@ nrfx_err_t nrfx_spim_xfer(nrfx_spim_t const * p_instance,
334334
nrfx_spim_xfer_desc_t const * p_xfer_desc,
335335
uint32_t flags);
336336

337-
338337
nrfx_err_t rtt_nrfx_spim_xfer(nrfx_spim_t const * p_instance,
339338
nrfx_spim_xfer_desc_t const * p_xfer_desc,
340339
uint32_t flags,

bsp/nrf5x/nrf52840/.ci/attachconfig/ci.attachconfig.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ devices.spi:
1919
kconfig:
2020
- CONFIG_RT_USING_SPI=y
2121
- CONFIG_BSP_USING_SPI=y
22+
devices.spim:
23+
kconfig:
24+
- CONFIG_RT_USING_SPIM=y
25+
- CONFIG_BSP_USING_SPIM=y
2226
devices.uart:
2327
kconfig:
2428
- CONFIG_BSP_USING_UART=y

bsp/nrf5x/nrf52840/board/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,6 @@ menu "On-chip Peripheral Drivers"
351351
range 0 47
352352
default 31
353353
endif
354-
355354

356355
config BSP_USING_SPIM3
357356
bool "Enable SPIM3 bus"

0 commit comments

Comments
 (0)