Skip to content

Commit f923bda

Browse files
mif1-nordicmasz-nordic
authored andcommitted
applications: sdp: mspi: Fixed additional clock edge in modes 1-3
Added workarounds to hardware issue causing, additional clock edge in spi modes 1-3. Signed-off-by: Michal Frankiewicz <[email protected]>
1 parent 308c55e commit f923bda

File tree

4 files changed

+113
-61
lines changed

4 files changed

+113
-61
lines changed

applications/sdp/mspi/src/hrt/hrt-nrf54l15.s

Lines changed: 69 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ hrt_write:
289289
beq a3,a2,.L40
290290
li a5,32
291291
div a5,a5,a4
292-
j .L57
292+
j .L56
293293
.L36:
294294
lbu a4,81(s0)
295295
j .L38
@@ -298,14 +298,14 @@ hrt_write:
298298
j .L38
299299
.L39:
300300
lbu a5,8(a5)
301-
.L57:
301+
.L56:
302302
#APP
303303
csrw 3022, a5
304304
#NO_APP
305-
lbu a4,86(s0)
305+
lbu a4,87(s0)
306306
li a5,1
307307
sll a5,a5,a4
308-
lbu a4,88(s0)
308+
lbu a4,89(s0)
309309
slli a5,a5,16
310310
srli a5,a5,16
311311
bne a4,zero,.L43
@@ -333,34 +333,28 @@ hrt_write:
333333
addi a2,sp,3
334334
addi a0,s0,60
335335
call hrt_tx
336-
lbu a5,89(s0)
337-
beq a5,zero,.L45
338-
.L46:
339-
#APP
340-
csrr a5, 3022
341-
#NO_APP
342-
andi a5,a5,0xff
343-
bne a5,zero,.L46
344-
#APP
345-
csrw 2010, 0
346-
#NO_APP
347-
.L45:
336+
lbu a5,94(s0)
337+
bne a5,zero,.L45
348338
li a5,16384
349339
addi a5,a5,1
350340
#APP
351341
csrw 3019, a5
352342
csrw 3017, 0
353343
csrw 2000, 0
354344
#NO_APP
355-
lbu a5,87(s0)
345+
.L46:
346+
#APP
347+
csrw 2005, 0
348+
#NO_APP
349+
lbu a5,88(s0)
356350
bne a5,zero,.L33
357-
lbu a4,86(s0)
351+
lbu a4,87(s0)
358352
li a5,1
359353
sll a5,a5,a4
360-
lbu a4,88(s0)
354+
lbu a4,89(s0)
361355
slli a5,a5,16
362356
srli a5,a5,16
363-
bne a4,zero,.L48
357+
bne a4,zero,.L49
364358
#APP
365359
csrs 3008, a5
366360
#NO_APP
@@ -371,13 +365,49 @@ hrt_write:
371365
jr ra
372366
.L40:
373367
lbu a5,9(a5)
374-
j .L57
368+
j .L56
375369
.L43:
376370
#APP
377371
csrs 3008, a5
378372
#NO_APP
379373
j .L44
380-
.L48:
374+
.L45:
375+
#APP
376+
csrr a5, 3022
377+
#NO_APP
378+
andi a5,a5,0xff
379+
bne a5,zero,.L45
380+
#APP
381+
csrw 2000, 0
382+
#NO_APP
383+
li a5,16384
384+
addi a5,a5,1
385+
#APP
386+
csrw 3019, a5
387+
#NO_APP
388+
lbu a5,94(s0)
389+
li a4,1
390+
bne a5,a4,.L47
391+
lbu a4,86(s0)
392+
sll a5,a5,a4
393+
slli a5,a5,16
394+
srli a5,a5,16
395+
#APP
396+
csrc 3008, a5
397+
#NO_APP
398+
j .L46
399+
.L47:
400+
li a3,3
401+
bne a5,a3,.L46
402+
lbu a5,86(s0)
403+
sll a4,a4,a5
404+
slli a4,a4,16
405+
srli a4,a4,16
406+
#APP
407+
csrs 3008, a4
408+
#NO_APP
409+
j .L46
410+
.L49:
381411
#APP
382412
csrc 3008, a5
383413
#NO_APP
@@ -391,18 +421,18 @@ hrt_read:
391421
addi sp,sp,-12
392422
sw s0,4(sp)
393423
sw ra,8(sp)
394-
lbu a5,88(a0)
395-
lbu a4,86(a0)
424+
lbu a5,89(a0)
425+
lbu a4,87(a0)
396426
mv s0,a0
397-
bne a5,zero,.L59
427+
bne a5,zero,.L58
398428
li a5,1
399429
sll a5,a5,a4
400430
slli a5,a5,16
401431
srli a5,a5,16
402432
#APP
403433
csrc 3008, a5
404434
#NO_APP
405-
.L60:
435+
.L59:
406436
lhu a5,90(s0)
407437
slli a5,a5,16
408438
srli a5,a5,16
@@ -461,27 +491,27 @@ hrt_read:
461491
addi a0,s0,20
462492
call hrt_tx_rx.constprop.0
463493
li a5,0
464-
.L61:
494+
.L60:
465495
lw a4,64(s0)
466-
bltu a5,a4,.L62
496+
bltu a5,a4,.L61
467497
#APP
468498
csrw 2000, 0
469499
csrw 2001, 0
470500
csrw 3019, 0
471501
#NO_APP
472-
lbu a5,87(s0)
473-
bne a5,zero,.L63
474502
lbu a5,88(s0)
475-
lbu a4,86(s0)
476-
bne a5,zero,.L64
503+
bne a5,zero,.L62
504+
lbu a5,89(s0)
505+
lbu a4,87(s0)
506+
bne a5,zero,.L63
477507
li a5,1
478508
sll a5,a5,a4
479509
slli a5,a5,16
480510
srli a5,a5,16
481511
#APP
482512
csrs 3008, a5
483513
#NO_APP
484-
.L63:
514+
.L62:
485515
lhu a5,90(s0)
486516
ori a5,a5,4
487517
sh a5,90(s0)
@@ -493,16 +523,16 @@ hrt_read:
493523
lw s0,4(sp)
494524
addi sp,sp,12
495525
jr ra
496-
.L59:
526+
.L58:
497527
li a5,1
498528
sll a5,a5,a4
499529
slli a5,a5,16
500530
srli a5,a5,16
501531
#APP
502532
csrs 3008, a5
503533
#NO_APP
504-
j .L60
505-
.L62:
534+
j .L59
535+
.L61:
506536
#APP
507537
csrr a3, 3018
508538
#NO_APP
@@ -512,16 +542,16 @@ hrt_read:
512542
addi a5,a5,1
513543
sb a3,0(a4)
514544
andi a5,a5,0xff
515-
j .L61
516-
.L64:
545+
j .L60
546+
.L63:
517547
li a5,1
518548
sll a5,a5,a4
519549
slli a5,a5,16
520550
srli a5,a5,16
521551
#APP
522552
csrc 3008, a5
523553
#NO_APP
524-
j .L63
554+
j .L62
525555
.size hrt_read, .-hrt_read
526556
.section .sdata.xfer_shift_ctrl,"aw"
527557
.align 2

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

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -213,24 +213,32 @@ void hrt_write(hrt_xfer_t *hrt_xfer_params)
213213
hrt_tx(&hrt_xfer_params->xfer_data[HRT_FE_DATA], hrt_xfer_params->bus_widths.data,
214214
&counter_running, hrt_xfer_params->counter_value);
215215

216-
if (hrt_xfer_params->eliminate_last_pulse) {
217-
218-
/* Wait until the last word is sent */
216+
/* Hardware issue workaround,
217+
* additional clock edge when transmitting in modes other than MSPI_CPP_MODE_0.
218+
* modes 1 and 3: Disable clock before the last pulse and perform last clock edge manualy.
219+
* mode 2: Add one pulse more to the last word in message, and disable clock before the last
220+
* pulse.
221+
*/
222+
if (hrt_xfer_params->cpp_mode == MSPI_CPP_MODE_0) {
223+
nrf_vpr_csr_vio_shift_ctrl_buffered_set(&write_final_shift_ctrl_cfg);
224+
nrf_vpr_csr_vio_out_buffered_reversed_word_set(0x00);
225+
nrf_vpr_csr_vtim_count_mode_set(0, NRF_VPR_CSR_VTIM_COUNT_STOP);
226+
} else {
219227
while (nrf_vpr_csr_vio_shift_cnt_out_get() != 0) {
220228
}
229+
nrf_vpr_csr_vtim_count_mode_set(0, NRF_VPR_CSR_VTIM_COUNT_STOP);
221230

222-
/* This is a partial solution to surplus clock edge problem in modes 1 and 3.
223-
* This solution works only for counter values above 20.
224-
*/
225-
nrf_vpr_csr_vtim_simple_wait_set(0, false, 0);
226-
}
231+
nrf_vpr_csr_vio_shift_ctrl_buffered_set(&write_final_shift_ctrl_cfg);
227232

228-
/* Final configuration */
229-
nrf_vpr_csr_vio_shift_ctrl_buffered_set(&write_final_shift_ctrl_cfg);
230-
nrf_vpr_csr_vio_out_buffered_reversed_word_set(0x00);
233+
if (hrt_xfer_params->cpp_mode == MSPI_CPP_MODE_1) {
234+
nrf_vpr_csr_vio_out_clear_set(BIT(hrt_xfer_params->clk_vio));
235+
} else if (hrt_xfer_params->cpp_mode == MSPI_CPP_MODE_3) {
236+
nrf_vpr_csr_vio_out_or_set(BIT(hrt_xfer_params->clk_vio));
237+
}
238+
}
231239

232-
/* Stop counter */
233-
nrf_vpr_csr_vtim_count_mode_set(0, NRF_VPR_CSR_VTIM_COUNT_STOP);
240+
/* Reset counter 0, Next message may be sent incorrectly if counter is not reset here. */
241+
nrf_vpr_csr_vtim_simple_counter_set(0, 0);
234242

235243
/* Disable CE */
236244
if (!hrt_xfer_params->ce_hold) {

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ typedef struct {
8989
*/
9090
uint16_t counter_value;
9191

92+
/** @brief Index of clock VIO pin */
93+
uint8_t clk_vio;
94+
9295
/** @brief Index of CE VIO pin */
9396
uint8_t ce_vio;
9497

@@ -98,17 +101,15 @@ typedef struct {
98101
/** @brief Chip enable pin polarity in enabled state. */
99102
enum mspi_ce_polarity ce_polarity;
100103

101-
/** @brief When true clock signal makes 1 transition less.
102-
* It is required for spi modes 1 and 3 due to hardware issue.
103-
*/
104-
bool eliminate_last_pulse;
105-
106104
/** @brief Tx mode mask for csr dir register */
107105
uint16_t tx_direction_mask;
108106

109107
/** @brief Rx mode mask for csr dir register */
110108
uint16_t rx_direction_mask;
111109

110+
/** @brief Due to hardware issues hrt module needs to know about selected spi mode */
111+
enum mspi_cpp_mode cpp_mode;
112+
112113
} hrt_xfer_t;
113114

114115
/** @brief Write.

applications/sdp/mspi/src/main.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,25 +152,21 @@ static void configure_clock(enum mspi_cpp_mode cpp_mode)
152152
case MSPI_CPP_MODE_0: {
153153
vio_config.clk_polarity = 0;
154154
WRITE_BIT(out, pin_to_vio_map[NRFE_MSPI_SCK_PIN_NUMBER], VPRCSR_NORDIC_OUT_LOW);
155-
xfer_params.eliminate_last_pulse = false;
156155
break;
157156
}
158157
case MSPI_CPP_MODE_1: {
159158
vio_config.clk_polarity = 1;
160159
WRITE_BIT(out, pin_to_vio_map[NRFE_MSPI_SCK_PIN_NUMBER], VPRCSR_NORDIC_OUT_LOW);
161-
xfer_params.eliminate_last_pulse = true;
162160
break;
163161
}
164162
case MSPI_CPP_MODE_2: {
165163
vio_config.clk_polarity = 1;
166164
WRITE_BIT(out, pin_to_vio_map[NRFE_MSPI_SCK_PIN_NUMBER], VPRCSR_NORDIC_OUT_HIGH);
167-
xfer_params.eliminate_last_pulse = false;
168165
break;
169166
}
170167
case MSPI_CPP_MODE_3: {
171168
vio_config.clk_polarity = 0;
172169
WRITE_BIT(out, pin_to_vio_map[NRFE_MSPI_SCK_PIN_NUMBER], VPRCSR_NORDIC_OUT_HIGH);
173-
xfer_params.eliminate_last_pulse = true;
174170
break;
175171
}
176172
}
@@ -190,8 +186,10 @@ static void xfer_execute(nrfe_mspi_xfer_packet_msg_t *xfer_packet)
190186
xfer_params.counter_value = 4;
191187
xfer_params.ce_vio = ce_vios[device->ce_index];
192188
xfer_params.ce_hold = nrfe_mspi_xfer_config.hold_ce;
189+
xfer_params.cpp_mode = device->cpp;
193190
xfer_params.ce_polarity = device->ce_polarity;
194191
xfer_params.bus_widths = io_modes[device->io_mode];
192+
xfer_params.clk_vio = pin_to_vio_map[NRFE_MSPI_SCK_PIN_NUMBER];
195193

196194
/* Fix position of command and address if command/address length is < BITS_IN_WORD,
197195
* so that leading zeros would not be printed instead of data bits.
@@ -248,6 +246,21 @@ static void xfer_execute(nrfe_mspi_xfer_packet_msg_t *xfer_packet)
248246
adjust_tail(&xfer_params.xfer_data[HRT_FE_DATA], xfer_params.bus_widths.data,
249247
xfer_packet->num_bytes * BITS_IN_BYTE);
250248

249+
/* Hardware issue: Additional clock edge when transmitting in modes other
250+
* than MSPI_CPP_MODE_0.
251+
* Here is first part workaround of that issue only for MSPI_CPP_MODE_2.
252+
* Workaround: Add one pulse more to the last word in message,
253+
* and disable clock before the last pulse.
254+
*/
255+
if (device->cpp == MSPI_CPP_MODE_2) {
256+
for (uint8_t i = 0; i < HRT_FE_MAX; i++) {
257+
if (xfer_params.xfer_data[HRT_FE_MAX - 1 - i].word_count != 0) {
258+
xfer_params.xfer_data[HRT_FE_MAX - 1 - i].last_word_clocks++;
259+
break;
260+
}
261+
}
262+
}
263+
251264
nrf_vpr_clic_int_pending_set(NRF_VPRCLIC, VEVIF_IRQN(HRT_VEVIF_IDX_WRITE));
252265
}
253266

0 commit comments

Comments
 (0)