Skip to content

Commit 7ab6adc

Browse files
Add INPUT_ANALOG to disconnect GPIO internally; fix qspi/uart/i2s/spi/sai to disconnect GPIO on *_disable()
1 parent 3af19ae commit 7ab6adc

15 files changed

+86
-11
lines changed

cores/stm32l4/Arduino.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ extern "C"{
5151
#define OUTPUT (0x1)
5252
#define INPUT_PULLUP (0x2)
5353
#define INPUT_PULLDOWN (0x3)
54+
#define INPUT_ANALOG (0x4)
5455

5556
#define PI 3.1415926535897932384626433832795
5657
#define HALF_PI 1.5707963267948966192313216916398

cores/stm32l4/stm32l4_wiring_digital.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ void pinMode( uint32_t ulPin, uint32_t ulMode )
5959
stm32l4_gpio_pin_configure(g_APinDescription[ulPin].pin, (GPIO_PUPD_PULLDOWN | GPIO_OSPEED_MEDIUM | GPIO_OTYPE_PUSHPULL | GPIO_MODE_INPUT));
6060
break ;
6161

62+
case INPUT_ANALOG:
63+
// Set pin to analog mode
64+
stm32l4_gpio_pin_configure(g_APinDescription[ulPin].pin, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));
65+
break ;
66+
6267
case OUTPUT:
6368
// Set pin to output mode
6469
stm32l4_gpio_pin_configure(g_APinDescription[ulPin].pin, (GPIO_PUPD_NONE | GPIO_OSPEED_MEDIUM | GPIO_OTYPE_PUSHPULL | GPIO_MODE_OUTPUT));

system/STM32L4xx/Lib/boot_stm32l432.o

48 Bytes
Binary file not shown.

system/STM32L4xx/Lib/boot_stm32l433.o

48 Bytes
Binary file not shown.

system/STM32L4xx/Lib/boot_stm32l476.o

48 Bytes
Binary file not shown.

system/STM32L4xx/Lib/boot_stm32l496.o

48 Bytes
Binary file not shown.

system/STM32L4xx/Lib/libstm32l432.a

1.04 KB
Binary file not shown.

system/STM32L4xx/Lib/libstm32l433.a

1.11 KB
Binary file not shown.

system/STM32L4xx/Lib/libstm32l476.a

1.11 KB
Binary file not shown.

system/STM32L4xx/Lib/libstm32l496.a

1.12 KB
Binary file not shown.

system/STM32L4xx/Source/stm32l4_i2c.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,8 @@ bool stm32l4_i2c_enable(stm32l4_i2c_t *i2c, uint32_t clock, uint32_t option, stm
868868

869869
bool stm32l4_i2c_disable(stm32l4_i2c_t *i2c)
870870
{
871+
uint32_t pin_scl, pin_sda;
872+
871873
if (i2c->state != I2C_STATE_READY)
872874
{
873875
return false;
@@ -880,6 +882,28 @@ bool stm32l4_i2c_disable(stm32l4_i2c_t *i2c)
880882

881883
stm32l4_system_hsi16_disable();
882884

885+
pin_scl = i2c->pins.scl;
886+
pin_sda = i2c->pins.sda;
887+
888+
#if defined(STM32L433xx)
889+
if ((i2c->option & I2C_OPTION_ALTERNATE) && (pin_scl == GPIO_PIN_PB6_I2C1_SCL) && (pin_sda == GPIO_PIN_PB7_I2C1_SDA))
890+
{
891+
pin_scl = GPIO_PIN_PB8_I2C1_SCL;
892+
pin_sda = GPIO_PIN_PB9_I2C1_SDA;
893+
}
894+
#endif /* defined(STM32L433xx) */
895+
896+
#if defined(STM32L476xx) || defined(STM32L496xx)
897+
if ((i2c->option & I2C_OPTION_ALTERNATE) && (pin_scl == GPIO_PIN_PB8_I2C1_SCL) && (pin_sda == GPIO_PIN_PB9_I2C1_SDA))
898+
{
899+
pin_scl = GPIO_PIN_PB6_I2C1_SCL;
900+
pin_sda = GPIO_PIN_PB7_I2C1_SDA;
901+
}
902+
#endif /* defined(STM32L476xx) || defined(STM32L496xx) */
903+
904+
stm32l4_gpio_pin_configure(pin_scl, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));
905+
stm32l4_gpio_pin_configure(pin_sda, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));
906+
883907
i2c->state = I2C_STATE_INIT;
884908

885909
return true;

system/STM32L4xx/Source/stm32l4_qspi.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,6 @@ static void stm32l4_qspi_stop(stm32l4_qspi_t *qspi)
150150
stm32l4_system_periph_disable(SYSTEM_PERIPH_QSPI);
151151
}
152152

153-
static void stm32l4_qspi_pins(stm32l4_qspi_t *qspi)
154-
{
155-
stm32l4_gpio_pin_configure(qspi->pins.clk, (GPIO_PUPD_NONE | GPIO_OSPEED_HIGH | GPIO_OTYPE_PUSHPULL | GPIO_MODE_ALTERNATE));
156-
stm32l4_gpio_pin_configure(qspi->pins.ncs, (GPIO_PUPD_NONE | GPIO_OSPEED_HIGH | GPIO_OTYPE_PUSHPULL | GPIO_MODE_ALTERNATE));
157-
stm32l4_gpio_pin_configure(qspi->pins.io0, (GPIO_PUPD_NONE | GPIO_OSPEED_HIGH | GPIO_OTYPE_PUSHPULL | GPIO_MODE_ALTERNATE));
158-
stm32l4_gpio_pin_configure(qspi->pins.io1, (GPIO_PUPD_NONE | GPIO_OSPEED_HIGH | GPIO_OTYPE_PUSHPULL | GPIO_MODE_ALTERNATE));
159-
stm32l4_gpio_pin_configure(qspi->pins.io2, (GPIO_PUPD_NONE | GPIO_OSPEED_HIGH | GPIO_OTYPE_PUSHPULL | GPIO_MODE_ALTERNATE));
160-
stm32l4_gpio_pin_configure(qspi->pins.io3, (GPIO_PUPD_NONE | GPIO_OSPEED_HIGH | GPIO_OTYPE_PUSHPULL | GPIO_MODE_ALTERNATE));
161-
}
162-
163153
static void stm32l4_qspi_dma_callback(stm32l4_qspi_t *qspi, uint32_t events)
164154
{
165155
QUADSPI->FCR = QUADSPI_FCR_CTCF;
@@ -323,6 +313,13 @@ bool stm32l4_qspi_disable(stm32l4_qspi_t *qspi)
323313
return false;
324314
}
325315

316+
stm32l4_gpio_pin_configure(qspi->pins.clk, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));
317+
stm32l4_gpio_pin_configure(qspi->pins.ncs, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));
318+
stm32l4_gpio_pin_configure(qspi->pins.io0, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));
319+
stm32l4_gpio_pin_configure(qspi->pins.io1, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));
320+
stm32l4_gpio_pin_configure(qspi->pins.io2, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));
321+
stm32l4_gpio_pin_configure(qspi->pins.io3, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));
322+
326323
qspi->state = QSPI_STATE_NONE;
327324

328325
return true;
@@ -361,7 +358,12 @@ bool stm32l4_qspi_configure(stm32l4_qspi_t *qspi, uint32_t clock, uint32_t optio
361358

362359
QUADSPI->DCR = QUADSPI_DCR_FSIZE | ((qspi->option & QSPI_OPTION_MODE_MASK) >> QSPI_OPTION_MODE_SHIFT);
363360

364-
stm32l4_qspi_pins(qspi);
361+
stm32l4_gpio_pin_configure(qspi->pins.clk, (GPIO_PUPD_NONE | GPIO_OSPEED_HIGH | GPIO_OTYPE_PUSHPULL | GPIO_MODE_ALTERNATE));
362+
stm32l4_gpio_pin_configure(qspi->pins.ncs, (GPIO_PUPD_NONE | GPIO_OSPEED_HIGH | GPIO_OTYPE_PUSHPULL | GPIO_MODE_ALTERNATE));
363+
stm32l4_gpio_pin_configure(qspi->pins.io0, (GPIO_PUPD_NONE | GPIO_OSPEED_HIGH | GPIO_OTYPE_PUSHPULL | GPIO_MODE_ALTERNATE));
364+
stm32l4_gpio_pin_configure(qspi->pins.io1, (GPIO_PUPD_NONE | GPIO_OSPEED_HIGH | GPIO_OTYPE_PUSHPULL | GPIO_MODE_ALTERNATE));
365+
stm32l4_gpio_pin_configure(qspi->pins.io2, (GPIO_PUPD_NONE | GPIO_OSPEED_HIGH | GPIO_OTYPE_PUSHPULL | GPIO_MODE_ALTERNATE));
366+
stm32l4_gpio_pin_configure(qspi->pins.io3, (GPIO_PUPD_NONE | GPIO_OSPEED_HIGH | GPIO_OTYPE_PUSHPULL | GPIO_MODE_ALTERNATE));
365367

366368
stm32l4_qspi_stop(qspi);
367369

system/STM32L4xx/Source/stm32l4_sai.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,15 @@ bool stm32l4_sai_disable(stm32l4_sai_t *sai)
693693

694694
stm32l4_system_saiclk_configure(SYSTEM_SAICLK_NONE);
695695

696+
stm32l4_gpio_pin_configure(sai->pins.sck, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));
697+
stm32l4_gpio_pin_configure(sai->pins.fs, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));
698+
stm32l4_gpio_pin_configure(sai->pins.sd, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));
699+
700+
if (sai->option & SAI_OPTION_MCK)
701+
{
702+
stm32l4_gpio_pin_configure(sai->pins.mck, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));
703+
}
704+
696705
sai->state = SAI_STATE_NONE;
697706

698707
return true;

system/STM32L4xx/Source/stm32l4_spi.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,20 @@ bool stm32l4_spi_disable(stm32l4_spi_t *spi)
946946

947947
spi->state = SPI_STATE_NONE;
948948

949+
stm32l4_gpio_pin_configure(spi->pins.mosi, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));
950+
951+
if (spi->pins.miso != GPIO_PIN_NONE)
952+
{
953+
stm32l4_gpio_pin_configure(spi->pins.miso, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));
954+
}
955+
956+
stm32l4_gpio_pin_configure(spi->pins.sck, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));
957+
958+
if (spi->pins.ss != GPIO_PIN_NONE)
959+
{
960+
stm32l4_gpio_pin_configure(spi->pins.ss, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));
961+
}
962+
949963
return true;
950964
}
951965

system/STM32L4xx/Source/stm32l4_uart.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,26 @@ bool stm32l4_uart_disable(stm32l4_uart_t *uart)
608608
stm32l4_system_hsi16_disable();
609609
}
610610

611+
if (uart->pins.rx != GPIO_PIN_NONE)
612+
{
613+
stm32l4_gpio_pin_configure(uart->pins.rx, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));
614+
}
615+
616+
if (uart->pins.tx != GPIO_PIN_NONE)
617+
{
618+
stm32l4_gpio_pin_configure(uart->pins.tx, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));
619+
}
620+
621+
if (uart->pins.cts != GPIO_PIN_NONE)
622+
{
623+
stm32l4_gpio_pin_configure(uart->pins.cts, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));
624+
}
625+
626+
if (uart->pins.rts_de != GPIO_PIN_NONE)
627+
{
628+
stm32l4_gpio_pin_configure(uart->pins.rts_de, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));
629+
}
630+
611631
uart->state = UART_STATE_INIT;
612632

613633
return true;

0 commit comments

Comments
 (0)