Skip to content

Commit 39486f7

Browse files
committed
[NUCLEO_L031K6] Update HAL API
1 parent a58c195 commit 39486f7

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32L0/i2c_api.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ I2C_HandleTypeDef I2cHandle;
4848
void i2c_init(i2c_t *obj, PinName sda, PinName scl)
4949
{
5050
static int i2c1_inited = 0;
51+
#if defined(I2C2_BASE)
5152
static int i2c2_inited = 0;
53+
#endif
5254
#if defined(I2C3_BASE)
5355
static int i2c3_inited = 0;
5456
#endif
@@ -72,6 +74,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl)
7274
pin_mode(scl, OpenDrain);
7375
}
7476

77+
#if defined(I2C2_BASE)
7578
// Enable I2C2 clock and pinout if not done
7679
if ((obj->i2c == I2C_2) && !i2c2_inited) {
7780
i2c2_inited = 1;
@@ -82,6 +85,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl)
8285
pin_mode(sda, OpenDrain);
8386
pin_mode(scl, OpenDrain);
8487
}
88+
#endif
8589

8690
#if defined(I2C3_BASE)
8791
// Enable I2C3 clock and pinout if not done
@@ -321,10 +325,12 @@ void i2c_reset(i2c_t *obj)
321325
__I2C1_FORCE_RESET();
322326
__I2C1_RELEASE_RESET();
323327
}
328+
#if defined(I2C2_BASE)
324329
if (obj->i2c == I2C_2) {
325330
__I2C2_FORCE_RESET();
326331
__I2C2_RELEASE_RESET();
327332
}
333+
#endif
328334
}
329335

330336
#if DEVICE_I2CSLAVE

libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32L0/serial_api.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,12 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
9191
MBED_ASSERT(obj->uart != (UARTName)NC);
9292

9393
// Enable UART clock
94+
#if defined(USART1_BASE)
9495
if (obj->uart == UART_1) {
9596
__HAL_RCC_USART1_CLK_ENABLE();
9697
obj->index = 0;
9798
}
99+
#endif
98100

99101
if (obj->uart == UART_2) {
100102
__HAL_RCC_USART2_CLK_ENABLE();
@@ -150,11 +152,13 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
150152
void serial_free(serial_t *obj)
151153
{
152154
// Reset UART and disable clock
155+
#if defined(USART1_BASE)
153156
if (obj->uart == UART_1) {
154157
__HAL_RCC_USART1_FORCE_RESET();
155158
__HAL_RCC_USART1_RELEASE_RESET();
156159
__HAL_RCC_USART1_CLK_DISABLE();
157160
}
161+
#endif
158162

159163
if (obj->uart == UART_2) {
160164
__HAL_RCC_USART2_FORCE_RESET();
@@ -247,10 +251,12 @@ static void uart_irq(UARTName name, int id)
247251
}
248252
}
249253

254+
#if defined(USART1_BASE)
250255
static void uart1_irq(void)
251256
{
252257
uart_irq(UART_1, 0);
253258
}
259+
#endif
254260

255261
static void uart2_irq(void)
256262
{
@@ -289,10 +295,12 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
289295

290296
UartHandle.Instance = (USART_TypeDef *)(obj->uart);
291297

298+
#if defined(USART1_BASE)
292299
if (obj->uart == UART_1) {
293300
irq_n = USART1_IRQn;
294301
vector = (uint32_t)&uart1_irq;
295302
}
303+
#endif
296304

297305
if (obj->uart == UART_2) {
298306
irq_n = USART2_IRQn;

libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32L0/spi_api.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,12 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
8383
if (obj->spi == SPI_1) {
8484
__SPI1_CLK_ENABLE();
8585
}
86+
87+
#if defined(SPI2_BASE)
8688
if (obj->spi == SPI_2) {
8789
__SPI2_CLK_ENABLE();
8890
}
91+
#endif
8992

9093
// Configure the SPI pins
9194
pinmap_pinout(mosi, PinMap_SPI_MOSI);
@@ -121,11 +124,13 @@ void spi_free(spi_t *obj)
121124
__SPI1_CLK_DISABLE();
122125
}
123126

127+
#if defined(SPI2_BASE)
124128
if (obj->spi == SPI_2) {
125129
__SPI2_FORCE_RESET();
126130
__SPI2_RELEASE_RESET();
127131
__SPI2_CLK_DISABLE();
128132
}
133+
#endif
129134

130135
// Configure GPIO
131136
pin_function(obj->pin_miso, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));

0 commit comments

Comments
 (0)