Skip to content

Commit e577fae

Browse files
committed
[NUCLEO_L152RE] Add analog out api
and add macros for GPIOs, change master timer for ticker.
1 parent e3e5180 commit e577fae

File tree

7 files changed

+27
-19
lines changed

7 files changed

+27
-19
lines changed

libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/PeripheralNames.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ typedef enum {
4141
ADC_2 = (int)ADC_BASE
4242
} ADCName;
4343

44+
typedef enum {
45+
DAC_1 = (int)DAC_BASE
46+
} DACName;
47+
4448
typedef enum {
4549
UART_1 = (int)USART1_BASE,
4650
UART_2 = (int)USART2_BASE

libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/PinNames.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,17 @@ extern "C" {
4646
#define STM_PIN_PUPD(X) (((X)>>4) & 0x3)
4747
#define STM_PIN_AFNUM(X) (((X)>>8) & 0xF)
4848

49+
// High nibble = port number (0=A, 1=B, 2=C, 3=D, 4=E, 5=F, 6=G, 7=H)
50+
// Low nibble = pin number
51+
#define STM_PORT(X) (((uint32_t)(X) >> 4) & 0xF)
52+
#define STM_PIN(X) ((uint32_t)(X) & 0xF)
53+
4954
typedef enum {
5055
PIN_INPUT,
5156
PIN_OUTPUT
5257
} PinDirection;
5358

5459
typedef enum {
55-
56-
// high nibble = port number (0=A, 1=B, 2=C, 3=D, 4=E, 5=F, 6=G, 7=H)
57-
// low nibble = pin number
5860
PA_0 = 0x00,
5961
PA_1 = 0x01,
6062
PA_2 = 0x02,

libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/device.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636

3737
#define DEVICE_INTERRUPTIN 0
3838

39-
#define DEVICE_ANALOGIN 0
40-
#define DEVICE_ANALOGOUT 0
39+
#define DEVICE_ANALOGIN 1
40+
#define DEVICE_ANALOGOUT 1
4141

4242
#define DEVICE_SERIAL 1
4343

libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/gpio_api.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
4444

4545
if (pin == NC) return;
4646

47-
uint32_t pin_number = (uint32_t)pin;
48-
uint32_t port_index = (pin_number >> 4);
47+
uint32_t port_index = STM_PORT(pin);
4948

5049
// Get GPIO structure base address
5150
switch (port_index) {

libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/objects.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ struct analogin_s {
5858
PinName pin;
5959
};
6060

61+
struct dac_s {
62+
DACName dac;
63+
PinName channel;
64+
};
65+
6166
struct serial_s {
6267
UARTName uart;
6368
int index; // Used by irq

libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/pinmap.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,9 @@ void pin_function(PinName pin, int data) {
4545
uint32_t pupd = STM_PIN_PUPD(data);
4646
uint32_t afnum = STM_PIN_AFNUM(data);
4747

48-
uint32_t pin_number = (uint32_t)pin;
49-
uint32_t pin_index = (pin_number & 0xF);
50-
uint32_t port_index = (pin_number >> 4);
51-
48+
uint32_t port_index = STM_PORT(pin);
49+
uint32_t pin_index = STM_PIN(pin);
50+
5251
// Get GPIO structure base address and enable clock
5352
switch (port_index) {
5453
case PortA:
@@ -108,9 +107,8 @@ void pin_mode(PinName pin, PinMode mode) {
108107

109108
if (pin == NC) return;
110109

111-
uint32_t pin_number = (uint32_t)pin;
112-
uint32_t pin_index = (pin_number & 0xF);
113-
uint32_t port_index = (pin_number >> 4);
110+
uint32_t port_index = STM_PORT(pin);
111+
uint32_t pin_index = STM_PIN(pin);
114112

115113
// Get GPIO structure base address and enable clock
116114
switch (port_index) {

libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/us_ticker.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@
3232
// Timers selection:
3333
// The Master timer clocks the Slave timer
3434

35-
#define TIM_MST TIM3
36-
#define TIM_MST_IRQ TIM3_IRQn
37-
#define TIM_MST_RCC RCC_APB1Periph_TIM3
35+
#define TIM_MST TIM9
36+
#define TIM_MST_IRQ TIM9_IRQn
37+
#define TIM_MST_RCC RCC_APB2Periph_TIM9
3838

3939
#define TIM_SLV TIM4
4040
#define TIM_SLV_IRQ TIM4_IRQn
4141
#define TIM_SLV_RCC RCC_APB1Periph_TIM4
4242

43-
#define MST_SLV_ITR TIM_TS_ITR2
43+
#define MST_SLV_ITR TIM_TS_ITR3
4444

4545
int us_ticker_inited = 0;
4646

@@ -53,7 +53,7 @@ void us_ticker_init(void) {
5353
us_ticker_inited = 1;
5454

5555
// Enable Timers clock
56-
RCC_APB1PeriphClockCmd(TIM_MST_RCC, ENABLE);
56+
RCC_APB2PeriphClockCmd(TIM_MST_RCC, ENABLE);
5757
RCC_APB1PeriphClockCmd(TIM_SLV_RCC, ENABLE);
5858

5959
// Master and Slave timers time base configuration

0 commit comments

Comments
 (0)