Skip to content

Commit b91c65e

Browse files
committed
[NUCLEO_L432KC] Update HAL API
1 parent 2198dcc commit b91c65e

File tree

6 files changed

+73
-11
lines changed

6 files changed

+73
-11
lines changed

hal/targets/hal/TARGET_STM/TARGET_STM32L4/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
__HAL_RCC_I2C1_FORCE_RESET();
322326
__HAL_RCC_I2C1_RELEASE_RESET();
323327
}
328+
#if defined(I2C2_BASE)
324329
if (obj->i2c == I2C_2) {
325330
__HAL_RCC_I2C2_FORCE_RESET();
326331
__HAL_RCC_I2C2_RELEASE_RESET();
327332
}
333+
#endif
328334
}
329335

330336
#if DEVICE_I2CSLAVE

hal/targets/hal/TARGET_STM/TARGET_STM32L4/pinmap.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,18 @@ uint32_t Set_GPIO_Clock(uint32_t port_idx)
6868
gpio_add = GPIOC_BASE;
6969
__HAL_RCC_GPIOC_CLK_ENABLE();
7070
break;
71+
#if defined(GPIOD_BASE)
7172
case PortD:
7273
gpio_add = GPIOD_BASE;
7374
__HAL_RCC_GPIOD_CLK_ENABLE();
7475
break;
76+
#endif
77+
#if defined(GPIOE_BASE)
7578
case PortE:
7679
gpio_add = GPIOE_BASE;
7780
__HAL_RCC_GPIOE_CLK_ENABLE();
7881
break;
82+
#endif
7983
case PortH:
8084
gpio_add = GPIOH_BASE;
8185
__HAL_RCC_GPIOH_CLK_ENABLE();

hal/targets/hal/TARGET_STM/TARGET_STM32L4/pwmout_api.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,23 @@ void pwmout_init(pwmout_t* obj, PinName pin)
5353
// Enable TIM clock
5454
if (obj->pwm == PWM_1) __HAL_RCC_TIM1_CLK_ENABLE();
5555
if (obj->pwm == PWM_2) __HAL_RCC_TIM2_CLK_ENABLE();
56+
#if defined(TIM3_BASE)
5657
if (obj->pwm == PWM_3) __HAL_RCC_TIM3_CLK_ENABLE();
58+
#endif
59+
#if defined(TIM4_BASE)
5760
if (obj->pwm == PWM_4) __HAL_RCC_TIM4_CLK_ENABLE();
61+
#endif
62+
#if defined(TIM5_BASE)
5863
if (obj->pwm == PWM_5) __HAL_RCC_TIM5_CLK_ENABLE();
64+
#endif
65+
#if defined(TIM8_BASE)
5966
if (obj->pwm == PWM_8) __HAL_RCC_TIM8_CLK_ENABLE();
67+
#endif
6068
if (obj->pwm == PWM_15) __HAL_RCC_TIM15_CLK_ENABLE();
6169
if (obj->pwm == PWM_16) __HAL_RCC_TIM16_CLK_ENABLE();
70+
#if defined(TIM17_BASE)
6271
if (obj->pwm == PWM_17) __HAL_RCC_TIM17_CLK_ENABLE();
72+
#endif
6373

6474
// Configure GPIO
6575
pinmap_pinout(pin, PinMap_PWM);

hal/targets/hal/TARGET_STM/TARGET_STM32L4/serial_api.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,34 +114,42 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
114114
obj->index = 1;
115115
}
116116

117+
#if defined(USART3_BASE)
117118
if (obj->uart == UART_3) {
118119
__HAL_RCC_USART3_FORCE_RESET();
119120
__HAL_RCC_USART3_RELEASE_RESET();
120121
__HAL_RCC_USART3_CLK_ENABLE();
121122
obj->index = 2;
122123
}
124+
#endif
123125

126+
#if defined(UART4_BASE)
124127
if (obj->uart == UART_4) {
125128
__HAL_RCC_UART4_FORCE_RESET();
126129
__HAL_RCC_UART4_RELEASE_RESET();
127130
__HAL_RCC_UART4_CLK_ENABLE();
128131
obj->index = 3;
129132
}
133+
#endif
130134

135+
#if defined(UART5_BASE)
131136
if (obj->uart == UART_5) {
132137
__HAL_RCC_UART5_FORCE_RESET();
133138
__HAL_RCC_UART5_RELEASE_RESET();
134139
__HAL_RCC_UART5_CLK_ENABLE();
135140
obj->index = 4;
136141
}
142+
#endif
137143

144+
#if defined(LPUART1_BASE)
138145
if (obj->uart == LPUART_1) {
139146
__HAL_RCC_LPUART1_FORCE_RESET();
140147
__HAL_RCC_LPUART1_RELEASE_RESET();
141148
__HAL_RCC_LPUART1_CLK_ENABLE();
142149
obj->baudrate = 38400; // Maximum peripheral clock is 4096 x BR -> This is the minimum BR with 80 MHz peripheral clock.
143150
obj->index = 5;
144151
}
152+
#endif
145153

146154
// Configure the UART pins
147155
pinmap_pinout(tx, PinMap_UART_TX);
@@ -184,29 +192,37 @@ void serial_free(serial_t *obj)
184192
__HAL_RCC_USART2_CLK_DISABLE();
185193
}
186194

195+
#if defined(USART3_BASE)
187196
if (obj->uart == UART_3) {
188197
__HAL_RCC_USART3_FORCE_RESET();
189198
__HAL_RCC_USART3_RELEASE_RESET();
190199
__HAL_RCC_USART3_CLK_DISABLE();
191200
}
201+
#endif
192202

203+
#if defined(UART4_BASE)
193204
if (obj->uart == UART_4) {
194205
__HAL_RCC_UART4_FORCE_RESET();
195206
__HAL_RCC_UART4_RELEASE_RESET();
196207
__HAL_RCC_UART4_CLK_DISABLE();
197208
}
209+
#endif
198210

211+
#if defined(UART5_BASE)
199212
if (obj->uart == UART_5) {
200213
__HAL_RCC_UART5_FORCE_RESET();
201214
__HAL_RCC_UART5_RELEASE_RESET();
202215
__HAL_RCC_UART5_CLK_DISABLE();
203216
}
217+
#endif
204218

219+
#if defined(LPUART1_BASE)
205220
if (obj->uart == LPUART_1) {
206221
__HAL_RCC_LPUART1_FORCE_RESET();
207222
__HAL_RCC_LPUART1_RELEASE_RESET();
208223
__HAL_RCC_LPUART1_CLK_DISABLE();
209224
}
225+
#endif
210226

211227
// Configure GPIOs
212228
pin_function(obj->pin_tx, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
@@ -341,25 +357,33 @@ static void uart2_irq(void)
341357
uart_irq(UART_2, 1);
342358
}
343359

360+
#if defined(USART3_BASE)
344361
static void uart3_irq(void)
345362
{
346363
uart_irq(UART_3, 2);
347364
}
365+
#endif
348366

367+
#if defined(UART4_BASE)
349368
static void uart4_irq(void)
350369
{
351370
uart_irq(UART_4, 3);
352371
}
372+
#endif
353373

374+
#if defined(UART5_BASE)
354375
static void uart5_irq(void)
355376
{
356377
uart_irq(UART_5, 4);
357378
}
379+
#endif
358380

381+
#if defined(LPUART1_BASE)
359382
static void lpuart1_irq(void)
360383
{
361384
uart_irq(LPUART_1, 5);
362385
}
386+
#endif
363387

364388
void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id)
365389
{
@@ -384,25 +408,33 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
384408
vector = (uint32_t)&uart2_irq;
385409
}
386410

411+
#if defined(USART3_BASE)
387412
if (obj->uart == UART_3) {
388413
irq_n = USART3_IRQn;
389414
vector = (uint32_t)&uart3_irq;
390415
}
416+
#endif
391417

418+
#if defined(UART4_BASE)
392419
if (obj->uart == UART_4) {
393420
irq_n = UART4_IRQn;
394421
vector = (uint32_t)&uart4_irq;
395422
}
423+
#endif
396424

425+
#if defined(UART5_BASE)
397426
if (obj->uart == UART_5) {
398427
irq_n = UART5_IRQn;
399428
vector = (uint32_t)&uart5_irq;
400429
}
430+
#endif
401431

432+
#if defined(LPUART1_BASE)
402433
if (obj->uart == LPUART_1) {
403434
irq_n = LPUART1_IRQn;
404435
vector = (uint32_t)&lpuart1_irq;
405436
}
437+
#endif
406438

407439
if (enable) {
408440

hal/targets/hal/TARGET_STM/TARGET_STM32L4/spi_api.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,11 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
8585
if (obj->spi == SPI_1) {
8686
__HAL_RCC_SPI1_CLK_ENABLE();
8787
}
88+
#if defined(SPI2_BASE)
8889
if (obj->spi == SPI_2) {
8990
__HAL_RCC_SPI2_CLK_ENABLE();
9091
}
92+
#endif
9193
if (obj->spi == SPI_3) {
9294
__HAL_RCC_SPI3_CLK_ENABLE();
9395
}
@@ -129,11 +131,13 @@ void spi_free(spi_t *obj)
129131
__HAL_RCC_SPI1_CLK_DISABLE();
130132
}
131133

134+
#if defined(SPI2_BASE)
132135
if (obj->spi == SPI_2) {
133136
__HAL_RCC_SPI2_FORCE_RESET();
134137
__HAL_RCC_SPI2_RELEASE_RESET();
135138
__HAL_RCC_SPI2_CLK_DISABLE();
136139
}
140+
#endif
137141

138142
if (obj->spi == SPI_3) {
139143
__HAL_RCC_SPI3_FORCE_RESET();
@@ -204,16 +208,18 @@ void spi_frequency(spi_t *obj, int hz)
204208
/* Get source clock depending on SPI instance */
205209
switch ((int)obj->spi) {
206210
case SPI_1:
207-
/* SPI_1. Source CLK is PCKL2 */
208-
spi_hz = HAL_RCC_GetPCLK2Freq();
209-
break;
210-
case SPI_2:
211-
case SPI_3:
212-
/* SPI_2, SPI_3. Source CLK is PCKL1 */
213-
spi_hz = HAL_RCC_GetPCLK1Freq();
214-
break;
215-
default:
216-
error("SPI instance not set");
211+
/* SPI_1. Source CLK is PCKL2 */
212+
spi_hz = HAL_RCC_GetPCLK2Freq();
213+
break;
214+
#if defined(SPI2_BASE)
215+
case SPI_2:
216+
#endif
217+
case SPI_3:
218+
/* SPI_2, SPI_3. Source CLK is PCKL1 */
219+
spi_hz = HAL_RCC_GetPCLK1Freq();
220+
break;
221+
default:
222+
error("SPI instance not set");
217223
}
218224

219225
/* Define pre-scaler in order to get highest available frequency below requested frequency */

hal/targets/hal/TARGET_STM/TARGET_STM32L4/us_ticker.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@
2929
#include "us_ticker_api.h"
3030
#include "PeripheralNames.h"
3131

32-
#define TIM_MST TIM5
32+
#if defined(TIM5_BASE)
33+
#define TIM_MST TIM5
34+
#else
35+
#define TIM_MST TIM2
36+
#endif
3337

3438
static TIM_HandleTypeDef TimMasterHandle;
3539
static int us_ticker_inited = 0;

0 commit comments

Comments
 (0)