Skip to content

Commit 9f94311

Browse files
committed
applications: sdp: mspi: add SPI RX path
Add path for receiving data on SPI. Signed-off-by: Magdalena Pastula <[email protected]>
1 parent b265df8 commit 9f94311

File tree

7 files changed

+556
-58
lines changed

7 files changed

+556
-58
lines changed

applications/sdp/mspi/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ sdp_assembly_check("${CMAKE_SOURCE_DIR}/src/hrt/hrt.c")
1414
sdp_assembly_prepare_install("${CMAKE_SOURCE_DIR}/src/hrt/hrt.c")
1515

1616
target_sources(app PRIVATE src/main.c)
17-
target_sources(app PRIVATE src/hrt/hrt.s)
17+
target_sources(app PRIVATE src/hrt/hrt.c)
1818

1919
add_dependencies(app asm_check)

applications/sdp/mspi/boards/nrf54l15dk_nrf54l15_cpuflpr.conf

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ CONFIG_LOG=n
77
CONFIG_I2C=n
88
CONFIG_WATCHDOG=n
99
CONFIG_GPIO=n
10-
CONFIG_PINCTRL=n
10+
CONFIG_PINCTRL=y
1111
CONFIG_SPI=n
12-
CONFIG_SERIAL=n
12+
CONFIG_SERIAL=y
1313
CONFIG_FLASH=n
1414

1515
# Power management
@@ -18,23 +18,23 @@ CONFIG_PM=n
1818
# Interrupts
1919
CONFIG_DYNAMIC_INTERRUPTS=n
2020
CONFIG_IRQ_OFFLOAD=n
21-
CONFIG_GEN_SW_ISR_TABLE=n
21+
CONFIG_GEN_SW_ISR_TABLE=y
2222

2323
# Memory protection
2424
CONFIG_THREAD_STACK_INFO=n
2525
CONFIG_THREAD_CUSTOM_DATA=n
2626
CONFIG_FPU=n
2727

2828
# Boot
29-
CONFIG_BOOT_BANNER=n
29+
CONFIG_BOOT_BANNER=y
3030
CONFIG_NCS_BOOT_BANNER=n
3131

3232
# Console
33-
CONFIG_CONSOLE=n
34-
CONFIG_UART_CONSOLE=n
35-
CONFIG_STDOUT_CONSOLE=n
36-
CONFIG_PRINTK=n
37-
CONFIG_EARLY_CONSOLE=n
33+
CONFIG_CONSOLE=y
34+
CONFIG_UART_CONSOLE=y
35+
CONFIG_STDOUT_CONSOLE=y
36+
CONFIG_PRINTK=y
37+
CONFIG_EARLY_CONSOLE=y
3838

3939
# Build
4040
CONFIG_SIZE_OPTIMIZATIONS=y

applications/sdp/mspi/boards/nrf54l15dk_nrf54l15_cpuflpr.overlay

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
#address-cells = <1>;
1111
#size-cells = <1>;
1212

13-
sram_tx: memory@2003c000 {
14-
reg = <0x2003c000 0x0800>;
13+
sram_tx: memory@2003a000 {
14+
reg = <0x2003a000 0x0800>;
1515
};
1616

17-
sram_rx: memory@2003c800 {
18-
reg = <0x2003c800 0x0800>;
17+
sram_rx: memory@2003a800 {
18+
reg = <0x2003a800 0x0800>;
1919
};
2020
};
2121
};
@@ -33,16 +33,16 @@
3333
};
3434

3535
&cpuflpr_rram {
36-
reg = <0x17a000 DT_SIZE_K(12)>;
36+
reg = <0x178000 DT_SIZE_K(20)>;
3737
};
3838

3939
&cpuflpr_code_partition {
40-
reg = <0x0 DT_SIZE_K(12)>;
40+
reg = <0x0 DT_SIZE_K(20)>;
4141
};
4242

4343
&cpuflpr_sram {
44-
reg = <0x2003d000 DT_SIZE_K(12)>;
45-
ranges = <0x0 0x2003d000 0x3000>;
44+
reg = <0x2003b000 DT_SIZE_K(20)>;
45+
ranges = <0x0 0x2003b000 0x5000>;
4646
};
4747

4848
&cpuflpr_vevif_rx {
@@ -85,7 +85,7 @@
8585
};
8686

8787
&uart30 {
88-
status = "disabled";
88+
status = "okay";
8989
};
9090

9191
&pwm20 {

applications/sdp/mspi/src/hrt/hrt.c

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
/* Hardware requirement, to get n shifts SHIFTCNTB register has to be set to n-1*/
1111
#define SHIFTCNTB_VALUE(shift_count) (shift_count - 1)
1212

13+
#define SPI_INPUT_PIN_NUM 2
14+
#define CNT1_INIT_VALUE 1
15+
16+
#define INPUT_SHIFT_COUNT (BITS_IN_WORD - BITS_IN_BYTE)
17+
18+
#define CNT1_TOP_CALCULATE(cnt0_top) (2 * ((cnt0_top) + 1) - 1)
19+
1320
/** @brief Shift control configuration. */
1421
typedef struct {
1522
uint8_t shift_count;
@@ -189,3 +196,121 @@ void hrt_write(hrt_xfer_t *hrt_xfer_params)
189196
}
190197
}
191198
}
199+
200+
static void hrt_tx_rx(volatile hrt_xfer_data_t *xfer_data, uint8_t frame_width, uint16_t cnt0_val, uint16_t cnt1_val, bool *counter_running)
201+
{
202+
if(xfer_data->word_count == 0)
203+
{
204+
return;
205+
}
206+
207+
nrf_vpr_csr_vio_shift_ctrl_t shift_ctrl = {
208+
.shift_count = BITS_IN_BYTE - 1,
209+
.out_mode = NRF_VPR_CSR_VIO_SHIFT_OUTB_TOGGLE,
210+
.frame_width = frame_width,
211+
.in_mode = NRF_VPR_CSR_VIO_MODE_IN_SHIFT,
212+
};
213+
214+
for (uint32_t i = 0; i < xfer_data->word_count; i++) {
215+
216+
switch (xfer_data->word_count - i) {
217+
case 1: /* Last transfer */
218+
shift_ctrl.shift_count = xfer_data->last_word_clocks - 1;
219+
nrf_vpr_csr_vio_shift_ctrl_buffered_set(&shift_ctrl);
220+
221+
xfer_data->vio_out_set(xfer_data->last_word);
222+
break;
223+
case 2: /* Last but one transfer.*/
224+
shift_ctrl.shift_count =
225+
xfer_data->penultimate_word_clocks - 1;
226+
nrf_vpr_csr_vio_shift_ctrl_buffered_set(&shift_ctrl);
227+
xfer_data->vio_out_set(((uint32_t *)xfer_data->data)[i]);
228+
break;
229+
default:
230+
nrf_vpr_csr_vio_shift_ctrl_buffered_set(&shift_ctrl);
231+
xfer_data->vio_out_set(((uint32_t *)xfer_data->data)[i]);
232+
}
233+
234+
if ((i == 0) && (!*counter_running)) {
235+
/* Start both counters */
236+
nrf_vpr_csr_vtim_combined_counter_set(
237+
(cnt0_val << VPRCSR_NORDIC_CNT_CNT0_Pos) +
238+
(cnt1_val << VPRCSR_NORDIC_CNT_CNT1_Pos));
239+
*counter_running = true;
240+
}
241+
}
242+
}
243+
244+
void hrt_read(volatile hrt_xfer_t *hrt_xfer_params)
245+
{
246+
uint16_t out;
247+
bool counter_running = false;
248+
nrf_vpr_csr_vio_shift_ctrl_t shift_ctrl = {
249+
.out_mode = NRF_VPR_CSR_VIO_SHIFT_NONE,
250+
.in_mode = NRF_VPR_CSR_VIO_MODE_IN_CONTINUOUS,
251+
};
252+
nrf_vpr_csr_vio_mode_out_t out_mode = {
253+
.mode = NRF_VPR_CSR_VIO_SHIFT_OUTB_TOGGLE,
254+
.frame_width = 1,
255+
};
256+
257+
/* Enable CS */
258+
out = nrf_vpr_csr_vio_out_get();
259+
if (hrt_xfer_params->ce_polarity == MSPI_CE_ACTIVE_LOW) {
260+
WRITE_BIT(out, hrt_xfer_params->ce_vio, VPRCSR_NORDIC_OUT_LOW);
261+
} else {
262+
WRITE_BIT(out, hrt_xfer_params->ce_vio, VPRCSR_NORDIC_OUT_HIGH);
263+
}
264+
nrf_vpr_csr_vio_out_set(out);
265+
266+
/* Configure clock and pins */
267+
/* Set DQ1 as input */
268+
WRITE_BIT(hrt_xfer_params->tx_direction_mask, SPI_INPUT_PIN_NUM, VPRCSR_NORDIC_DIR_INPUT);
269+
nrf_vpr_csr_vio_dir_set(hrt_xfer_params->tx_direction_mask);
270+
271+
/* Initial configuration */
272+
nrf_vpr_csr_vio_mode_in_set(NRF_VPR_CSR_VIO_MODE_IN_SHIFT);
273+
nrf_vpr_csr_vio_mode_out_set(&out_mode);
274+
nrf_vpr_csr_vio_shift_cnt_out_set(hrt_xfer_params->xfer_data[HRT_FE_COMMAND].word_count * BITS_IN_BYTE);
275+
276+
/* Counter settings */
277+
nrf_vpr_csr_vtim_count_mode_set(0, NRF_VPR_CSR_VTIM_COUNT_RELOAD);
278+
nrf_vpr_csr_vtim_count_mode_set(1, NRF_VPR_CSR_VTIM_COUNT_RELOAD);
279+
280+
/* Set top counters value. Trigger data capture every two clock cycles */
281+
nrf_vpr_csr_vtim_simple_counter_top_set(0, hrt_xfer_params->counter_value);
282+
nrf_vpr_csr_vtim_simple_counter_top_set(1, CNT1_TOP_CALCULATE(hrt_xfer_params->counter_value));
283+
284+
/* Transfer command */
285+
hrt_tx_rx(&hrt_xfer_params->xfer_data[HRT_FE_COMMAND], hrt_xfer_params->bus_widths.command, hrt_xfer_params->counter_value,
286+
CNT1_INIT_VALUE, &counter_running);
287+
288+
for (uint8_t i = 0; i < hrt_xfer_params->xfer_data[HRT_FE_DATA].word_count; i++)
289+
{
290+
hrt_xfer_params->xfer_data[HRT_FE_DATA].rx_data[i] = hrt_xfer_params->xfer_data[HRT_FE_DATA].vio_inb_get() >> INPUT_SHIFT_COUNT;
291+
}
292+
293+
/* Final configuration */
294+
nrf_vpr_csr_vio_shift_ctrl_buffered_set(&shift_ctrl);
295+
nrf_vpr_csr_vio_out_buffered_reversed_word_set(0);
296+
297+
/* Stop counters */
298+
nrf_vpr_csr_vtim_count_mode_set(0, NRF_VPR_CSR_VTIM_COUNT_STOP);
299+
nrf_vpr_csr_vtim_count_mode_set(1, NRF_VPR_CSR_VTIM_COUNT_STOP);
300+
301+
/* Disable CS */
302+
if (!hrt_xfer_params->ce_hold) {
303+
out = nrf_vpr_csr_vio_out_get();
304+
305+
if (hrt_xfer_params->ce_polarity == MSPI_CE_ACTIVE_LOW) {
306+
WRITE_BIT(out, hrt_xfer_params->ce_vio, VPRCSR_NORDIC_OUT_HIGH);
307+
} else {
308+
WRITE_BIT(out, hrt_xfer_params->ce_vio, VPRCSR_NORDIC_OUT_LOW);
309+
}
310+
nrf_vpr_csr_vio_out_set(out);
311+
}
312+
313+
/* Set DQ1 back as output. */
314+
WRITE_BIT(hrt_xfer_params->tx_direction_mask, SPI_INPUT_PIN_NUM, VPRCSR_NORDIC_DIR_OUTPUT);
315+
nrf_vpr_csr_vio_dir_set(hrt_xfer_params->tx_direction_mask);
316+
}

applications/sdp/mspi/src/hrt/hrt.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ typedef struct {
3737

3838
typedef struct {
3939
/** @brief Buffer for RX/TX data */
40-
volatile uint8_t *data;
40+
uint8_t *data;
41+
uint8_t *rx_data;
4142

4243
/** @brief Data length in 4 byte words,
4344
* calculated as CEIL(buffer_length_bits/32).
@@ -70,6 +71,10 @@ typedef struct {
7071

7172
/** @brief Function for writing to buffered out register. */
7273
void (*vio_out_set)(uint32_t value);
74+
75+
/** @brief Function for reading from buffered in register. */
76+
uint32_t (*vio_inb_get)(void);
77+
7378
} hrt_xfer_data_t;
7479

7580
/** @brief Hrt transfer parameters. */
@@ -115,4 +120,12 @@ typedef struct {
115120
*/
116121
void hrt_write(hrt_xfer_t *hrt_xfer_params);
117122

123+
/** @brief Read.
124+
*
125+
* Function to be used to read data from MSPI.
126+
*
127+
* @param[in] hrt_xfer_params Hrt transfer parameters.
128+
*/
129+
void hrt_read(volatile hrt_xfer_t *hrt_xfer_params);
130+
118131
#endif /* _HRT_H__ */

0 commit comments

Comments
 (0)