Skip to content

Commit bfa7b48

Browse files
committed
stmhal: For spi_init, add argument to select if NSS pin is enabled.
Most of the time you don't use the NSS pin of the SPI bus, and so it shouldn't be enabled by default (this gave some bugs in the past).
1 parent 8b03d94 commit bfa7b48

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

drivers/cc3000/src/ccspi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ void SpiOpen(gcSpiHandleRx pfRxHandler)
153153
SPI_HANDLE->Init.TIMode = SPI_TIMODE_DISABLED;
154154
SPI_HANDLE->Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
155155
SPI_HANDLE->Init.CRCPolynomial = 7;
156-
spi_init(SPI_HANDLE);
156+
spi_init(SPI_HANDLE, false);
157157

158158
// configure wlan CS and EN pins
159159
GPIO_InitTypeDef GPIO_InitStructure;

stmhal/lcd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ STATIC mp_obj_t pyb_lcd_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n
263263
init->CRCPolynomial = 0;
264264

265265
// init the SPI bus
266-
spi_init(lcd->spi);
266+
spi_init(lcd->spi, false);
267267

268268
// set the pins to default values
269269
lcd->pin_cs1->gpio->BSRRL = lcd->pin_cs1->pin_mask;

stmhal/spi.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void spi_init0(void) {
8686
}
8787

8888
// TODO allow to take a list of pins to use
89-
void spi_init(SPI_HandleTypeDef *spi) {
89+
void spi_init(SPI_HandleTypeDef *spi, bool enable_nss_pin) {
9090
// init the GPIO lines
9191
GPIO_InitTypeDef GPIO_InitStructure;
9292
GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
@@ -130,7 +130,7 @@ void spi_init(SPI_HandleTypeDef *spi) {
130130
return;
131131
}
132132

133-
for (uint i = 0; i < 4; i++) {
133+
for (uint i = (enable_nss_pin ? 0 : 1); i < 4; i++) {
134134
GPIO_InitStructure.Pin = pins[i]->pin_mask;
135135
HAL_GPIO_Init(pins[i]->gpio, &GPIO_InitStructure);
136136
}
@@ -297,7 +297,7 @@ STATIC mp_obj_t pyb_spi_init_helper(const pyb_spi_obj_t *self, mp_uint_t n_args,
297297
}
298298

299299
// init the SPI bus
300-
spi_init(self->spi);
300+
spi_init(self->spi, init->NSS != SPI_NSS_SOFT);
301301

302302
return mp_const_none;
303303
}

stmhal/spi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ extern SPI_HandleTypeDef SPIHandle3;
3030
extern const mp_obj_type_t pyb_spi_type;
3131

3232
void spi_init0(void);
33-
void spi_init(SPI_HandleTypeDef *spi);
33+
void spi_init(SPI_HandleTypeDef *spi, bool enable_nss_pin);
3434
SPI_HandleTypeDef *spi_get_handle(mp_obj_t o);

0 commit comments

Comments
 (0)