Skip to content

Commit

Permalink
Add INPUT_ANALOG to disconnect GPIO internally; fix qspi/uart/i2s/spi…
Browse files Browse the repository at this point in the history
…/sai to disconnect GPIO on *_disable()
  • Loading branch information
GrumpyOldPizza committed Oct 4, 2017
1 parent 3af19ae commit 7ab6adc
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 11 deletions.
1 change: 1 addition & 0 deletions cores/stm32l4/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ extern "C"{
#define OUTPUT (0x1)
#define INPUT_PULLUP (0x2)
#define INPUT_PULLDOWN (0x3)
#define INPUT_ANALOG (0x4)

#define PI 3.1415926535897932384626433832795
#define HALF_PI 1.5707963267948966192313216916398
Expand Down
5 changes: 5 additions & 0 deletions cores/stm32l4/stm32l4_wiring_digital.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ void pinMode( uint32_t ulPin, uint32_t ulMode )
stm32l4_gpio_pin_configure(g_APinDescription[ulPin].pin, (GPIO_PUPD_PULLDOWN | GPIO_OSPEED_MEDIUM | GPIO_OTYPE_PUSHPULL | GPIO_MODE_INPUT));
break ;

case INPUT_ANALOG:
// Set pin to analog mode
stm32l4_gpio_pin_configure(g_APinDescription[ulPin].pin, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));
break ;

case OUTPUT:
// Set pin to output mode
stm32l4_gpio_pin_configure(g_APinDescription[ulPin].pin, (GPIO_PUPD_NONE | GPIO_OSPEED_MEDIUM | GPIO_OTYPE_PUSHPULL | GPIO_MODE_OUTPUT));
Expand Down
Binary file modified system/STM32L4xx/Lib/boot_stm32l432.o
Binary file not shown.
Binary file modified system/STM32L4xx/Lib/boot_stm32l433.o
Binary file not shown.
Binary file modified system/STM32L4xx/Lib/boot_stm32l476.o
Binary file not shown.
Binary file modified system/STM32L4xx/Lib/boot_stm32l496.o
Binary file not shown.
Binary file modified system/STM32L4xx/Lib/libstm32l432.a
Binary file not shown.
Binary file modified system/STM32L4xx/Lib/libstm32l433.a
Binary file not shown.
Binary file modified system/STM32L4xx/Lib/libstm32l476.a
Binary file not shown.
Binary file modified system/STM32L4xx/Lib/libstm32l496.a
Binary file not shown.
24 changes: 24 additions & 0 deletions system/STM32L4xx/Source/stm32l4_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,8 @@ bool stm32l4_i2c_enable(stm32l4_i2c_t *i2c, uint32_t clock, uint32_t option, stm

bool stm32l4_i2c_disable(stm32l4_i2c_t *i2c)
{
uint32_t pin_scl, pin_sda;

if (i2c->state != I2C_STATE_READY)
{
return false;
Expand All @@ -880,6 +882,28 @@ bool stm32l4_i2c_disable(stm32l4_i2c_t *i2c)

stm32l4_system_hsi16_disable();

pin_scl = i2c->pins.scl;
pin_sda = i2c->pins.sda;

#if defined(STM32L433xx)
if ((i2c->option & I2C_OPTION_ALTERNATE) && (pin_scl == GPIO_PIN_PB6_I2C1_SCL) && (pin_sda == GPIO_PIN_PB7_I2C1_SDA))
{
pin_scl = GPIO_PIN_PB8_I2C1_SCL;
pin_sda = GPIO_PIN_PB9_I2C1_SDA;
}
#endif /* defined(STM32L433xx) */

#if defined(STM32L476xx) || defined(STM32L496xx)
if ((i2c->option & I2C_OPTION_ALTERNATE) && (pin_scl == GPIO_PIN_PB8_I2C1_SCL) && (pin_sda == GPIO_PIN_PB9_I2C1_SDA))
{
pin_scl = GPIO_PIN_PB6_I2C1_SCL;
pin_sda = GPIO_PIN_PB7_I2C1_SDA;
}
#endif /* defined(STM32L476xx) || defined(STM32L496xx) */

stm32l4_gpio_pin_configure(pin_scl, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));
stm32l4_gpio_pin_configure(pin_sda, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));

i2c->state = I2C_STATE_INIT;

return true;
Expand Down
24 changes: 13 additions & 11 deletions system/STM32L4xx/Source/stm32l4_qspi.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,6 @@ static void stm32l4_qspi_stop(stm32l4_qspi_t *qspi)
stm32l4_system_periph_disable(SYSTEM_PERIPH_QSPI);
}

static void stm32l4_qspi_pins(stm32l4_qspi_t *qspi)
{
stm32l4_gpio_pin_configure(qspi->pins.clk, (GPIO_PUPD_NONE | GPIO_OSPEED_HIGH | GPIO_OTYPE_PUSHPULL | GPIO_MODE_ALTERNATE));
stm32l4_gpio_pin_configure(qspi->pins.ncs, (GPIO_PUPD_NONE | GPIO_OSPEED_HIGH | GPIO_OTYPE_PUSHPULL | GPIO_MODE_ALTERNATE));
stm32l4_gpio_pin_configure(qspi->pins.io0, (GPIO_PUPD_NONE | GPIO_OSPEED_HIGH | GPIO_OTYPE_PUSHPULL | GPIO_MODE_ALTERNATE));
stm32l4_gpio_pin_configure(qspi->pins.io1, (GPIO_PUPD_NONE | GPIO_OSPEED_HIGH | GPIO_OTYPE_PUSHPULL | GPIO_MODE_ALTERNATE));
stm32l4_gpio_pin_configure(qspi->pins.io2, (GPIO_PUPD_NONE | GPIO_OSPEED_HIGH | GPIO_OTYPE_PUSHPULL | GPIO_MODE_ALTERNATE));
stm32l4_gpio_pin_configure(qspi->pins.io3, (GPIO_PUPD_NONE | GPIO_OSPEED_HIGH | GPIO_OTYPE_PUSHPULL | GPIO_MODE_ALTERNATE));
}

static void stm32l4_qspi_dma_callback(stm32l4_qspi_t *qspi, uint32_t events)
{
QUADSPI->FCR = QUADSPI_FCR_CTCF;
Expand Down Expand Up @@ -323,6 +313,13 @@ bool stm32l4_qspi_disable(stm32l4_qspi_t *qspi)
return false;
}

stm32l4_gpio_pin_configure(qspi->pins.clk, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));
stm32l4_gpio_pin_configure(qspi->pins.ncs, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));
stm32l4_gpio_pin_configure(qspi->pins.io0, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));
stm32l4_gpio_pin_configure(qspi->pins.io1, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));
stm32l4_gpio_pin_configure(qspi->pins.io2, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));
stm32l4_gpio_pin_configure(qspi->pins.io3, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));

qspi->state = QSPI_STATE_NONE;

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

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

stm32l4_qspi_pins(qspi);
stm32l4_gpio_pin_configure(qspi->pins.clk, (GPIO_PUPD_NONE | GPIO_OSPEED_HIGH | GPIO_OTYPE_PUSHPULL | GPIO_MODE_ALTERNATE));
stm32l4_gpio_pin_configure(qspi->pins.ncs, (GPIO_PUPD_NONE | GPIO_OSPEED_HIGH | GPIO_OTYPE_PUSHPULL | GPIO_MODE_ALTERNATE));
stm32l4_gpio_pin_configure(qspi->pins.io0, (GPIO_PUPD_NONE | GPIO_OSPEED_HIGH | GPIO_OTYPE_PUSHPULL | GPIO_MODE_ALTERNATE));
stm32l4_gpio_pin_configure(qspi->pins.io1, (GPIO_PUPD_NONE | GPIO_OSPEED_HIGH | GPIO_OTYPE_PUSHPULL | GPIO_MODE_ALTERNATE));
stm32l4_gpio_pin_configure(qspi->pins.io2, (GPIO_PUPD_NONE | GPIO_OSPEED_HIGH | GPIO_OTYPE_PUSHPULL | GPIO_MODE_ALTERNATE));
stm32l4_gpio_pin_configure(qspi->pins.io3, (GPIO_PUPD_NONE | GPIO_OSPEED_HIGH | GPIO_OTYPE_PUSHPULL | GPIO_MODE_ALTERNATE));

stm32l4_qspi_stop(qspi);

Expand Down
9 changes: 9 additions & 0 deletions system/STM32L4xx/Source/stm32l4_sai.c
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,15 @@ bool stm32l4_sai_disable(stm32l4_sai_t *sai)

stm32l4_system_saiclk_configure(SYSTEM_SAICLK_NONE);

stm32l4_gpio_pin_configure(sai->pins.sck, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));
stm32l4_gpio_pin_configure(sai->pins.fs, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));
stm32l4_gpio_pin_configure(sai->pins.sd, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));

if (sai->option & SAI_OPTION_MCK)
{
stm32l4_gpio_pin_configure(sai->pins.mck, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));
}

sai->state = SAI_STATE_NONE;

return true;
Expand Down
14 changes: 14 additions & 0 deletions system/STM32L4xx/Source/stm32l4_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,20 @@ bool stm32l4_spi_disable(stm32l4_spi_t *spi)

spi->state = SPI_STATE_NONE;

stm32l4_gpio_pin_configure(spi->pins.mosi, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));

if (spi->pins.miso != GPIO_PIN_NONE)
{
stm32l4_gpio_pin_configure(spi->pins.miso, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));
}

stm32l4_gpio_pin_configure(spi->pins.sck, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));

if (spi->pins.ss != GPIO_PIN_NONE)
{
stm32l4_gpio_pin_configure(spi->pins.ss, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));
}

return true;
}

Expand Down
20 changes: 20 additions & 0 deletions system/STM32L4xx/Source/stm32l4_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,26 @@ bool stm32l4_uart_disable(stm32l4_uart_t *uart)
stm32l4_system_hsi16_disable();
}

if (uart->pins.rx != GPIO_PIN_NONE)
{
stm32l4_gpio_pin_configure(uart->pins.rx, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));
}

if (uart->pins.tx != GPIO_PIN_NONE)
{
stm32l4_gpio_pin_configure(uart->pins.tx, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));
}

if (uart->pins.cts != GPIO_PIN_NONE)
{
stm32l4_gpio_pin_configure(uart->pins.cts, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));
}

if (uart->pins.rts_de != GPIO_PIN_NONE)
{
stm32l4_gpio_pin_configure(uart->pins.rts_de, (GPIO_PUPD_NONE | GPIO_MODE_ANALOG));
}

uart->state = UART_STATE_INIT;

return true;
Expand Down

0 comments on commit 7ab6adc

Please sign in to comment.