Skip to content

Commit 60f5c27

Browse files
committed
mimxrt: Allow a setting of -1 for cs in the constructor.
In that case, no Pin will be configured for the CS signal, even if it is internally still generated. That setting allows to use any pin for CS, which then must be controlled by the Python script.
1 parent 524c644 commit 60f5c27

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

docs/mimxrt/pinout.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,8 @@ Olimex RT1010Py - CS0/-/SDO/SDI/SCK SDCARD wi
322322
Seeed ARCH MIX J4_12/-/J4_14/J4_13/J4_15 J3_09/J3_05/J3_08_J3_11
323323
================= ========================= ======================= ===============
324324

325-
Pins denoted with (*) are by default not wired at the board.
325+
Pins denoted with (*) are by default not wired at the board. The CS0 and CS1 signals
326+
are enabled with the keyword option cs=0 or cs=1 of the SPI object constructor.
326327

327328
.. _mimxrt_i2c_pinout:
328329

docs/mimxrt/quickref.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,13 +301,16 @@ There are up to four hardware SPI channels that allow faster transmission
301301
rates (up to 30Mhz). Hardware SPI is accessed via the
302302
:ref:`machine.SPI <machine.SPI>` class and has the same methods as software SPI above::
303303

304-
from machine import SPI
304+
from machine import SPI, Pin
305305

306-
spi = SPI(0, 10000000)
306+
cs_pin = Pin(6, Pin.OUT, value=1)
307307
spi.write('Hello World')
308308

309309
For the assignment of Pins to SPI signals, refer to
310310
:ref:`Hardware SPI pinout <mimxrt_spi_pinout>`.
311+
The keyword option cs=n can be used to enable the cs pin 0 or 1 for an automatic cs signal. The
312+
default is cs=0. Using cs=-1 the automatic cs signal is not created.
313+
In that case, cs has to be set by the script. Clearing that assignment requires a power cycle.
311314

312315
Notes:
313316

ports/mimxrt/machine_spi.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static const iomux_table_t iomux_table[] = {
7777
IOMUX_TABLE_SPI
7878
};
7979

80-
bool lpspi_set_iomux(int8_t spi, uint8_t drive, uint8_t cs) {
80+
bool lpspi_set_iomux(int8_t spi, uint8_t drive, int8_t cs) {
8181
int index = (spi - 1) * 5;
8282

8383
if (SCK.muxRegister != 0) {
@@ -93,7 +93,7 @@ bool lpspi_set_iomux(int8_t spi, uint8_t drive, uint8_t cs) {
9393
IOMUXC_SetPinMux(CS1.muxRegister, CS1.muxMode, CS1.inputRegister, CS1.inputDaisy, CS1.configRegister, 0U);
9494
IOMUXC_SetPinConfig(CS1.muxRegister, CS1.muxMode, CS1.inputRegister, CS1.inputDaisy, CS1.configRegister,
9595
pin_generate_config(PIN_PULL_UP_100K, PIN_MODE_OUT, drive, CS1.configRegister));
96-
} else {
96+
} else if (cs != -1) {
9797
mp_raise_ValueError(MP_ERROR_TEXT("The chosen CS is not available"));
9898
}
9999

@@ -173,8 +173,9 @@ mp_obj_t machine_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
173173
}
174174
self->master_config->lastSckToPcsDelayInNanoSec = self->master_config->betweenTransferDelayInNanoSec;
175175
self->master_config->pcsToSckDelayInNanoSec = self->master_config->betweenTransferDelayInNanoSec;
176-
uint8_t cs = args[ARG_cs].u_int;
177-
if (cs <= 1) {
176+
int8_t cs = args[ARG_cs].u_int;
177+
// The default value 0 is set already, so only cs=1 has to be set.
178+
if (cs == 1) {
178179
self->master_config->whichPcs = cs;
179180
}
180181
LPSPI_MasterInit(self->spi_inst, self->master_config, BOARD_BOOTCLOCKRUN_LPSPI_CLK_ROOT);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy