Skip to content

Commit fbf4856

Browse files
authored
bsp/nrf5x: nrf52840添加spim驱动 (#10576)
* 添加了spim的底层驱动和设备驱动 * 添加了nrf52840 的spim底层驱动和设备驱动 * 添加了spim的底层驱动和设备驱动 * 添加了spim的底层驱动和设备驱动 * 代码规范 * 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 e0243e8 commit fbf4856

23 files changed

+2126
-82
lines changed

bsp/nrf5x/libraries/drivers/drv_adc.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006-2022, RT-Thread Development Team
2+
* Copyright (c) 2006-2025, RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
@@ -221,13 +221,13 @@ INIT_BOARD_EXPORT(rt_hw_adc_init);
221221
/*test saadc*/
222222
#include <drv_adc.h>
223223

224-
#define SAMPLE_ADC_MODE_SINGLE_ENDED 0 //single-ended mode
225-
#define SAMPLE_ADC_MODE_DIFFERENTIAL 1 //differential mode
224+
#define SAMPLE_ADC_MODE_SINGLE_ENDED 0 /* single-ended mode */
225+
#define SAMPLE_ADC_MODE_DIFFERENTIAL 1 /* differential mode */
226226

227227
#define SAMPLE_ADC_AIN1 1
228228
#define SAMPLE_ADC_AIN2 2
229229
#define SAMPLE_ADC_AIN7 7
230-
#define SAMPLE_ADC_AIN_NC 0 //disable input of AINx
230+
#define SAMPLE_ADC_AIN_NC 0 /* disable input of AINx */
231231

232232
#define SAMPLE_ADC_CHANNEL_0 0
233233
#define SAMPLE_ADC_CHANNEL_1 1
@@ -242,19 +242,22 @@ void saadc_sample(void)
242242
adc_dev = (rt_adc_device_t)rt_device_find(ADC_NAME);
243243
adc_dev->parent.user_data = &channel_config;
244244

245-
channel_config = (drv_nrfx_saadc_channel_t){.mode = SAMPLE_ADC_MODE_SINGLE_ENDED,
245+
channel_config = (drv_nrfx_saadc_channel_t)
246+
{.mode = SAMPLE_ADC_MODE_SINGLE_ENDED,
246247
.pin_p = SAMPLE_ADC_AIN1,
247248
.pin_n = SAMPLE_ADC_AIN_NC,
248249
.channel_num = SAMPLE_ADC_CHANNEL_0};
249250
rt_adc_enable(adc_dev, channel_config.channel_num);
250251

251-
channel_config = (drv_nrfx_saadc_channel_t){.mode = SAMPLE_ADC_MODE_SINGLE_ENDED,
252+
channel_config = (drv_nrfx_saadc_channel_t)
253+
{.mode = SAMPLE_ADC_MODE_SINGLE_ENDED,
252254
.pin_p = SAMPLE_ADC_AIN2,
253255
.pin_n = SAMPLE_ADC_AIN_NC,
254256
.channel_num = SAMPLE_ADC_CHANNEL_1};
255257
rt_adc_enable(adc_dev, channel_config.channel_num);
256258

257-
channel_config = (drv_nrfx_saadc_channel_t){.mode = SAMPLE_ADC_MODE_SINGLE_ENDED,
259+
channel_config = (drv_nrfx_saadc_channel_t)
260+
{.mode = SAMPLE_ADC_MODE_SINGLE_ENDED,
258261
.pin_p = SAMPLE_ADC_AIN7,
259262
.pin_n = SAMPLE_ADC_AIN_NC,
260263
.channel_num = SAMPLE_ADC_CHANNEL_5};

bsp/nrf5x/libraries/drivers/drv_adc.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006-2022, RT-Thread Development Team
2+
* Copyright (c) 2006-2025, RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
@@ -31,10 +31,10 @@
3131
*/
3232
typedef struct
3333
{
34-
nrf_saadc_mode_t mode; ///< SAADC mode. Single-ended or differential.
35-
uint8_t pin_p; ///< Input positive pin selection.
36-
uint8_t pin_n; ///< Input negative pin selection.
37-
uint8_t channel_num; ///< Channel number.
34+
nrf_saadc_mode_t mode; /* /< SAADC mode. Single-ended or differential. */
35+
uint8_t pin_p; /* /< Input positive pin selection. */
36+
uint8_t pin_n; /* /< Input negative pin selection. */
37+
uint8_t channel_num; /* /< Channel number. */
3838
} drv_nrfx_saadc_channel_t;
3939

4040
typedef struct
@@ -46,3 +46,4 @@ typedef struct
4646
} drv_nrfx_saadc_result_t;
4747

4848
#endif /* __DRV_ADC_H__ */
49+

bsp/nrf5x/libraries/drivers/drv_flash.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006-2022, RT-Thread Development Team
2+
* Copyright (c) 2006-2025, RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
@@ -95,15 +95,16 @@ int mcu_flash_write(rt_uint32_t addr, const uint8_t *buf, size_t size)
9595
if (addr % 4 != 0)
9696
{
9797
LOG_E("write addr should be 4-byte alignment");
98-
//4byte write
99-
//else byts
98+
/* 4byte write */
99+
/* else byts */
100100
return -RT_EINVAL;
101101
}
102102

103103
if (size < 1)
104104
{
105105
return -RT_ERROR;
106106
}
107+
107108
if (size % 4 != 0)
108109
{
109110
nrfx_nvmc_bytes_write(addr, buf, size);
@@ -186,3 +187,4 @@ const struct fal_flash_dev mcu_onchip_flash =
186187
};
187188
#endif
188189
#endif /* BSP_USING_ON_CHIP_FLASH */
190+

bsp/nrf5x/libraries/drivers/drv_gpio.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006-2022, RT-Thread Development Team
2+
* Copyright (c) 2006-2025, RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
@@ -223,6 +223,7 @@ static rt_err_t nrf5x_pin_attach_irq(struct rt_device *device, rt_base_t pin,
223223
break;
224224
}
225225
}
226+
226227
if(irqindex == -1)
227228
{
228229
return -RT_ENOMEM;
@@ -298,6 +299,7 @@ static rt_err_t nrf5x_pin_dettach_irq(struct rt_device *device, rt_base_t pin)
298299
break;
299300
}
300301
}
302+
301303
if(i >= irq_quantity)
302304
{
303305
return -RT_ENOSYS;
@@ -414,6 +416,7 @@ void button_1_callback(void *args)
414416
rt_pin_write(DK_BOARD_LED_1, PIN_HIGH);
415417
}
416418
}
419+
417420
void button_2_callback(void *args)
418421
{
419422
static int flag2 = 0;
@@ -428,6 +431,7 @@ void button_2_callback(void *args)
428431
rt_pin_write(DK_BOARD_LED_2, PIN_HIGH);
429432
}
430433
}
434+
431435
void button_3_callback(void *args)
432436
{
433437
static int flag3 = 0;
@@ -442,6 +446,7 @@ void button_3_callback(void *args)
442446
rt_pin_write(DK_BOARD_LED_3, PIN_HIGH);
443447
}
444448
}
449+
445450
void button_4_callback(void *args)
446451
{
447452
static int flag4 = 0;
@@ -470,21 +475,22 @@ void gpio_sample(void)
470475
rt_pin_write(DK_BOARD_LED_4, PIN_HIGH);
471476

472477
rt_pin_attach_irq(DK_BOARD_BUTTON_1, PIN_IRQ_MODE_FALLING,
473-
button_1_callback, (void*) true); //true: hi_accuracy(IN_EVENT),false: lo_accuracy(PORT_EVENT)
478+
button_1_callback, (void*) true); /* true: hi_accuracy(IN_EVENT),false: lo_accuracy(PORT_EVENT) */
474479
rt_pin_irq_enable(DK_BOARD_BUTTON_1, PIN_IRQ_ENABLE);
475480

476481
rt_pin_attach_irq(DK_BOARD_BUTTON_2, PIN_IRQ_MODE_FALLING,
477-
button_2_callback, (void*) true); //true: hi_accuracy(IN_EVENT),false: lo_accuracy(PORT_EVENT)
482+
button_2_callback, (void*) true); /* true: hi_accuracy(IN_EVENT),false: lo_accuracy(PORT_EVENT) */
478483
rt_pin_irq_enable(DK_BOARD_BUTTON_2, PIN_IRQ_ENABLE);
479484

480485
rt_pin_attach_irq(DK_BOARD_BUTTON_3, PIN_IRQ_MODE_FALLING,
481-
button_3_callback, (void*) true); //true: hi_accuracy(IN_EVENT),false: lo_accuracy(PORT_EVENT)
486+
button_3_callback, (void*) true); /* true: hi_accuracy(IN_EVENT),false: lo_accuracy(PORT_EVENT) */
482487
rt_pin_irq_enable(DK_BOARD_BUTTON_3, PIN_IRQ_ENABLE);
483488

484489
rt_pin_attach_irq(DK_BOARD_BUTTON_4, PIN_IRQ_MODE_FALLING,
485-
button_4_callback, (void*) false); //true: hi_accuracy(IN_EVENT),false: lo_accuracy(PORT_EVENT)
490+
button_4_callback, (void*) false); /* true: hi_accuracy(IN_EVENT),false: lo_accuracy(PORT_EVENT) */
486491
rt_pin_irq_enable(DK_BOARD_BUTTON_4, PIN_IRQ_ENABLE);
487492
}
488493
MSH_CMD_EXPORT(gpio_sample, gpio sample);
489494

490495
#endif /* RT_USING_PIN */
496+

bsp/nrf5x/libraries/drivers/drv_gpio.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006-2022, RT-Thread Development Team
2+
* Copyright (c) 2006-2025, RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
@@ -34,7 +34,7 @@
3434
struct pin_index
3535
{
3636
int index;
37-
NRF_GPIO_Type *gpio;//NRF_P0 or NRF_P1
37+
NRF_GPIO_Type *gpio;/* NRF_P0 or NRF_P1 */
3838
rt_base_t pin;
3939
};
4040

bsp/nrf5x/libraries/drivers/drv_hwtimer.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006-2022, RT-Thread Development Team
2+
* Copyright (c) 2006-2025, RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
@@ -27,7 +27,7 @@
2727
#ifdef RT_USING_HWTIMER
2828

2929
#ifndef TIM_DEV_INFO_CONFIG
30-
// maxfreq and minfreq unit is HZ
30+
/* maxfreq and minfreq unit is HZ */
3131
#define TIM_DEV_INFO_CONFIG \
3232
{ \
3333
.maxfreq = 16000000, \
@@ -103,7 +103,7 @@ static void timer_callback(nrf_timer_event_t event_type, void* p_context)
103103
{
104104
rt_hwtimer_t *timer_device = (struct rt_hwtimer_device *)p_context;
105105

106-
// no matter what event_type is(NRF_TIMER_EVENT_COMPARE0 or others), call same function "rt_device_hwtimer_isr"
106+
/* no matter what event_type is(NRF_TIMER_EVENT_COMPARE0 or others), call same function "rt_device_hwtimer_isr" */
107107
LOG_D("timer_callback event_type = %d, inst_id = %d, cc conunt = %d\r\n",
108108
event_type, timer_info->timer_inst.instance_id, timer_info->timer_inst.cc_channel_count);
109109
rt_device_hwtimer_isr(timer_device);
@@ -137,12 +137,12 @@ static rt_err_t timer_start(rt_hwtimer_t *timer, rt_uint32_t t, rt_hwtimer_mode_
137137

138138
if (opmode == HWTIMER_MODE_ONESHOT)
139139
{
140-
// means TIMER_SHORTS_COMPARE0_STOP_Msk or TIMER_SHORTS_COMPARE1_STOP_Msk ..., according to cc_channel.
140+
/* means TIMER_SHORTS_COMPARE0_STOP_Msk or TIMER_SHORTS_COMPARE1_STOP_Msk ..., according to cc_channel. */
141141
mask = (nrf_timer_short_mask_t)(1 << (timer_info->cc_channel + 8));
142142
}
143143
else
144144
{
145-
// means TIMER_SHORTS_COMPARE0_CLEAR_Msk or TIMER_SHORTS_COMPARE1_CLEAR_Msk ..., according to cc_channel.
145+
/* means TIMER_SHORTS_COMPARE0_CLEAR_Msk or TIMER_SHORTS_COMPARE1_CLEAR_Msk ..., according to cc_channel. */
146146
mask = (nrf_timer_short_mask_t)(1 << timer_info->cc_channel);
147147
}
148148

@@ -276,8 +276,8 @@ static rt_uint32_t timer_counter_get(rt_hwtimer_t *timer)
276276

277277
timer_info = (nrf5x_timer_info_t *)timer->parent.user_data;
278278

279-
// capture method will copy the current counter register to the specified cc channel (here is NRF_TIMER_CC_CHANNEL5).
280-
// the specified cc channel cannot be same with the already used cc channels
279+
/* capture method will copy the current counter register to the specified cc channel (here is NRF_TIMER_CC_CHANNEL5). */
280+
/* the specified cc channel cannot be same with the already used cc channels */
281281
count = nrfx_timer_capture(&(timer_info->timer_inst), NRF_TIMER_CC_CHANNEL5);
282282
return count;
283283
}

bsp/nrf5x/libraries/drivers/drv_i2c.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006-2023, RT-Thread Development Team
2+
* Copyright (c) 2006-2025, RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
@@ -173,3 +173,4 @@ int rt_hw_i2c_init(void)
173173

174174
INIT_BOARD_EXPORT(rt_hw_i2c_init);
175175
#endif /* defined(BSP_USING_I2C0) || defined(BSP_USING_I2C1) */
176+

bsp/nrf5x/libraries/drivers/drv_i2c.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006-2022, RT-Thread Development Team
2+
* Copyright (c) 2006-2025, RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
@@ -21,3 +21,4 @@ extern "C" {
2121

2222

2323
#endif /* __DRV_I2C_H__ */
24+

bsp/nrf5x/libraries/drivers/drv_pwm.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006-2022, RT-Thread Development Team
2+
* Copyright (c) 2006-2025, RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
@@ -223,9 +223,9 @@ static rt_err_t mcu_hw_pwm_init(struct mcu_pwm *device)
223223
nrfx_pwm_config_t config0 =
224224
{
225225
.irq_priority = _PRIO_APP_LOWEST,
226-
.base_clock = NRF_PWM_CLK_1MHz, //default value
226+
.base_clock = NRF_PWM_CLK_1MHz, /* default value */
227227
.count_mode = NRF_PWM_MODE_UP,
228-
.top_value = 5000, //default vaule
228+
.top_value = 5000, /* default vaule */
229229
.load_mode = NRF_PWM_LOAD_INDIVIDUAL,
230230
.step_mode = NRF_PWM_STEP_AUTO
231231
};
@@ -414,10 +414,12 @@ static int pwm_led_sample(int argc, char *argv[])
414414
{
415415
pulse -= 500;
416416
}
417+
417418
if (pulse >= period)
418419
{
419420
dir = 0;
420421
}
422+
421423
if (0 == pulse)
422424
{
423425
dir = 1;
@@ -430,3 +432,4 @@ static int pwm_led_sample(int argc, char *argv[])
430432
MSH_CMD_EXPORT(pwm_led_sample, pwm sample);
431433

432434
#endif
435+

bsp/nrf5x/libraries/drivers/drv_qspi_flash.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006-2022, RT-Thread Development Team
2+
* Copyright (c) 2006-2025, RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
@@ -14,7 +14,7 @@
1414
#if defined(RT_USING_FAL)
1515
#include <fal.h>
1616

17-
//log
17+
/* log */
1818
#include <rtdbg.h>
1919
#define LOG_TAG "drv.qspiflash"
2020

@@ -47,14 +47,14 @@ static void configure_memory()
4747
.wren = true
4848
};
4949

50-
// Send reset enable
50+
/* Send reset enable */
5151
err_code = nrfx_qspi_cinstr_xfer(&cinstr_cfg, NULL, NULL);
5252
if (NRFX_SUCCESS != err_code)
5353
{
5454
LOG_E("\r\n ERROR: QSPI_STD_CMD_RSTEN:0x%x\n", err_code);
5555
return ;
5656
}
57-
// Send reset command
57+
/* Send reset command */
5858
cinstr_cfg.opcode = QSPI_STD_CMD_RST;
5959
err_code = nrfx_qspi_cinstr_xfer(&cinstr_cfg, NULL, NULL);
6060
if (NRFX_SUCCESS != err_code)
@@ -63,7 +63,7 @@ static void configure_memory()
6363
return ;
6464
}
6565

66-
// Switch to qspi mode
66+
/* Switch to qspi mode */
6767
cinstr_cfg.opcode = QSPI_STD_CMD_WRSR;
6868
cinstr_cfg.length = NRF_QSPI_CINSTR_LEN_2B;
6969
err_code = nrfx_qspi_cinstr_xfer(&cinstr_cfg, &temporary, NULL);
@@ -73,6 +73,7 @@ static void configure_memory()
7373
return;
7474
}
7575
}
76+
7677
static int init(void)
7778
{
7879
rt_uint32_t err_code;
@@ -151,3 +152,4 @@ struct fal_flash_dev nor_flash0 =
151152
};
152153

153154
#endif
155+

0 commit comments

Comments
 (0)