Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit 5a8f795

Browse files
authored
Merge pull request ARMmbed#10804 from VVESTM/vve_fix_10589
TARGET_STM: SPI: update pull up config depending on clk polarity
2 parents 1803561 + 82979f6 commit 5a8f795

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

targets/TARGET_STM/stm_spi_api.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,12 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
216216
handle->Init.FifoThreshold = SPI_FIFO_THRESHOLD_01DATA;
217217
#endif
218218

219+
/*
220+
* According the STM32 Datasheet for SPI peripheral we need to PULLDOWN
221+
* or PULLUP the SCK pin according the polarity used.
222+
*/
223+
pin_mode(spiobj->pin_sclk, (handle->Init.CLKPolarity == SPI_POLARITY_LOW) ? PullDown: PullUp);
224+
219225
init_spi(obj);
220226
}
221227

@@ -290,6 +296,7 @@ void spi_format(spi_t *obj, int bits, int mode, int slave)
290296
{
291297
struct spi_s *spiobj = SPI_S(obj);
292298
SPI_HandleTypeDef *handle = &(spiobj->handle);
299+
PinMode pull = 0;
293300

294301
DEBUG_PRINTF("spi_format, bits:%d, mode:%d, slave?:%d\r\n", bits, mode, slave);
295302

@@ -331,6 +338,13 @@ void spi_format(spi_t *obj, int bits, int mode, int slave)
331338
handle->Init.Direction = SPI_DIRECTION_2LINES;
332339
}
333340

341+
/*
342+
* According the STM32 Datasheet for SPI peripheral we need to PULLDOWN
343+
* or PULLUP the SCK pin according the polarity used.
344+
*/
345+
pull = (handle->Init.CLKPolarity == SPI_POLARITY_LOW) ? PullDown: PullUp;
346+
pin_mode(spiobj->pin_sclk, pull);
347+
334348
init_spi(obj);
335349
}
336350

0 commit comments

Comments
 (0)