mirror of https://github.com/ARMmbed/mbed-os.git
[NUCLEO_L031K6] Update HAL API
parent
a58c1959c4
commit
39486f74a0
|
@ -48,7 +48,9 @@ I2C_HandleTypeDef I2cHandle;
|
|||
void i2c_init(i2c_t *obj, PinName sda, PinName scl)
|
||||
{
|
||||
static int i2c1_inited = 0;
|
||||
#if defined(I2C2_BASE)
|
||||
static int i2c2_inited = 0;
|
||||
#endif
|
||||
#if defined(I2C3_BASE)
|
||||
static int i2c3_inited = 0;
|
||||
#endif
|
||||
|
@ -72,6 +74,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl)
|
|||
pin_mode(scl, OpenDrain);
|
||||
}
|
||||
|
||||
#if defined(I2C2_BASE)
|
||||
// Enable I2C2 clock and pinout if not done
|
||||
if ((obj->i2c == I2C_2) && !i2c2_inited) {
|
||||
i2c2_inited = 1;
|
||||
|
@ -82,6 +85,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl)
|
|||
pin_mode(sda, OpenDrain);
|
||||
pin_mode(scl, OpenDrain);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(I2C3_BASE)
|
||||
// Enable I2C3 clock and pinout if not done
|
||||
|
@ -321,10 +325,12 @@ void i2c_reset(i2c_t *obj)
|
|||
__I2C1_FORCE_RESET();
|
||||
__I2C1_RELEASE_RESET();
|
||||
}
|
||||
#if defined(I2C2_BASE)
|
||||
if (obj->i2c == I2C_2) {
|
||||
__I2C2_FORCE_RESET();
|
||||
__I2C2_RELEASE_RESET();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if DEVICE_I2CSLAVE
|
||||
|
|
|
@ -91,10 +91,12 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
|
|||
MBED_ASSERT(obj->uart != (UARTName)NC);
|
||||
|
||||
// Enable UART clock
|
||||
#if defined(USART1_BASE)
|
||||
if (obj->uart == UART_1) {
|
||||
__HAL_RCC_USART1_CLK_ENABLE();
|
||||
obj->index = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (obj->uart == UART_2) {
|
||||
__HAL_RCC_USART2_CLK_ENABLE();
|
||||
|
@ -150,11 +152,13 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
|
|||
void serial_free(serial_t *obj)
|
||||
{
|
||||
// Reset UART and disable clock
|
||||
#if defined(USART1_BASE)
|
||||
if (obj->uart == UART_1) {
|
||||
__HAL_RCC_USART1_FORCE_RESET();
|
||||
__HAL_RCC_USART1_RELEASE_RESET();
|
||||
__HAL_RCC_USART1_CLK_DISABLE();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (obj->uart == UART_2) {
|
||||
__HAL_RCC_USART2_FORCE_RESET();
|
||||
|
@ -247,10 +251,12 @@ static void uart_irq(UARTName name, int id)
|
|||
}
|
||||
}
|
||||
|
||||
#if defined(USART1_BASE)
|
||||
static void uart1_irq(void)
|
||||
{
|
||||
uart_irq(UART_1, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void uart2_irq(void)
|
||||
{
|
||||
|
@ -289,10 +295,12 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
|
|||
|
||||
UartHandle.Instance = (USART_TypeDef *)(obj->uart);
|
||||
|
||||
#if defined(USART1_BASE)
|
||||
if (obj->uart == UART_1) {
|
||||
irq_n = USART1_IRQn;
|
||||
vector = (uint32_t)&uart1_irq;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (obj->uart == UART_2) {
|
||||
irq_n = USART2_IRQn;
|
||||
|
|
|
@ -83,9 +83,12 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
|
|||
if (obj->spi == SPI_1) {
|
||||
__SPI1_CLK_ENABLE();
|
||||
}
|
||||
|
||||
#if defined(SPI2_BASE)
|
||||
if (obj->spi == SPI_2) {
|
||||
__SPI2_CLK_ENABLE();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Configure the SPI pins
|
||||
pinmap_pinout(mosi, PinMap_SPI_MOSI);
|
||||
|
@ -121,11 +124,13 @@ void spi_free(spi_t *obj)
|
|||
__SPI1_CLK_DISABLE();
|
||||
}
|
||||
|
||||
#if defined(SPI2_BASE)
|
||||
if (obj->spi == SPI_2) {
|
||||
__SPI2_FORCE_RESET();
|
||||
__SPI2_RELEASE_RESET();
|
||||
__SPI2_CLK_DISABLE();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Configure GPIO
|
||||
pin_function(obj->pin_miso, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
|
||||
|
|
Loading…
Reference in New Issue