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).
This commit is contained in:
parent
8b03d944e2
commit
bfa7b480a7
|
@ -153,7 +153,7 @@ void SpiOpen(gcSpiHandleRx pfRxHandler)
|
|||
SPI_HANDLE->Init.TIMode = SPI_TIMODE_DISABLED;
|
||||
SPI_HANDLE->Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
|
||||
SPI_HANDLE->Init.CRCPolynomial = 7;
|
||||
spi_init(SPI_HANDLE);
|
||||
spi_init(SPI_HANDLE, false);
|
||||
|
||||
// configure wlan CS and EN pins
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
|
|
@ -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
|
|||
init->CRCPolynomial = 0;
|
||||
|
||||
// init the SPI bus
|
||||
spi_init(lcd->spi);
|
||||
spi_init(lcd->spi, false);
|
||||
|
||||
// set the pins to default values
|
||||
lcd->pin_cs1->gpio->BSRRL = lcd->pin_cs1->pin_mask;
|
||||
|
|
|
@ -86,7 +86,7 @@ void spi_init0(void) {
|
|||
}
|
||||
|
||||
// TODO allow to take a list of pins to use
|
||||
void spi_init(SPI_HandleTypeDef *spi) {
|
||||
void spi_init(SPI_HandleTypeDef *spi, bool enable_nss_pin) {
|
||||
// init the GPIO lines
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
|
||||
|
@ -130,7 +130,7 @@ void spi_init(SPI_HandleTypeDef *spi) {
|
|||
return;
|
||||
}
|
||||
|
||||
for (uint i = 0; i < 4; i++) {
|
||||
for (uint i = (enable_nss_pin ? 0 : 1); i < 4; i++) {
|
||||
GPIO_InitStructure.Pin = pins[i]->pin_mask;
|
||||
HAL_GPIO_Init(pins[i]->gpio, &GPIO_InitStructure);
|
||||
}
|
||||
|
@ -297,7 +297,7 @@ STATIC mp_obj_t pyb_spi_init_helper(const pyb_spi_obj_t *self, mp_uint_t n_args,
|
|||
}
|
||||
|
||||
// init the SPI bus
|
||||
spi_init(self->spi);
|
||||
spi_init(self->spi, init->NSS != SPI_NSS_SOFT);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
|
|
@ -30,5 +30,5 @@ extern SPI_HandleTypeDef SPIHandle3;
|
|||
extern const mp_obj_type_t pyb_spi_type;
|
||||
|
||||
void spi_init0(void);
|
||||
void spi_init(SPI_HandleTypeDef *spi);
|
||||
void spi_init(SPI_HandleTypeDef *spi, bool enable_nss_pin);
|
||||
SPI_HandleTypeDef *spi_get_handle(mp_obj_t o);
|
||||
|
|
Loading…
Reference in New Issue