Skip to content

Commit dc26390

Browse files
committed
DISCO_L475VG_IOT01A: Add explicit pinmap support
1 parent 31f9941 commit dc26390

File tree

7 files changed

+533
-402
lines changed

7 files changed

+533
-402
lines changed

targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L475xG/TARGET_DISCO_L475VG_IOT01A/PeripheralPinMaps.h

Lines changed: 418 additions & 0 deletions
Large diffs are not rendered by default.

targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L475xG/TARGET_DISCO_L475VG_IOT01A/PeripheralPins.c

Lines changed: 1 addition & 361 deletions
Large diffs are not rendered by default.

targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L475xG/TARGET_DISCO_L475VG_IOT01A/PinNames.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
extern "C" {
3939
#endif
4040

41+
/* If this macro is defined, then constexpr utility functions for pin-map seach can be used. */
42+
#define EXPLICIT_PINMAP_READY 1
43+
4144
typedef enum {
4245
ALT0 = 0x100,
4346
ALT1 = 0x200,

targets/TARGET_STM/TARGET_STM32L4/analogin_device.c

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,28 @@
3636
#include "mbed_error.h"
3737
#include "PeripheralPins.h"
3838

39-
void analogin_init(analogin_t *obj, PinName pin)
39+
#if EXPLICIT_PINMAP_READY
40+
#define ANALOGIN_INIT_DIRECT analogin_init_direct
41+
void analogin_init_direct(analogin_t *obj, const PinMap *pinmap)
42+
#else
43+
#define ANALOGIN_INIT_DIRECT _analogin_init_direct
44+
static void _analogin_init_direct(analogin_t *obj, const PinMap *pinmap)
45+
#endif
4046
{
41-
uint32_t function = (uint32_t)NC;
47+
uint32_t function = (uint32_t)pinmap->function;
48+
49+
// Get the peripheral name from the pin and assign it to the object
50+
obj->handle.Instance = (ADC_TypeDef *)pinmap->peripheral;
4251

4352
// ADC Internal Channels "pins" (Temperature, Vref, Vbat, ...)
4453
// are described in PinNames.h and PeripheralPins.c
4554
// Pin value must be between 0xF0 and 0xFF
46-
if ((pin < 0xF0) || (pin >= 0x100)) {
47-
// Normal channels
48-
// Get the peripheral name from the pin and assign it to the object
49-
obj->handle.Instance = (ADC_TypeDef *)pinmap_peripheral(pin, PinMap_ADC);
50-
// Get the functions (adc channel) from the pin and assign it to the object
51-
function = pinmap_function(pin, PinMap_ADC);
55+
if ((pinmap->pin < 0xF0) || (pinmap->pin >= 0x100)) {
5256
// Configure GPIO
53-
pinmap_pinout(pin, PinMap_ADC);
57+
pin_function(pinmap->pin, pinmap->function);
58+
pin_mode(pinmap->pin, PullNone);
5459
} else {
5560
// Internal channels
56-
obj->handle.Instance = (ADC_TypeDef *)pinmap_peripheral(pin, PinMap_ADC_Internal);
57-
function = pinmap_function(pin, PinMap_ADC_Internal);
5861
// No GPIO configuration for internal channels
5962
}
6063
MBED_ASSERT(obj->handle.Instance != (ADC_TypeDef *)NC);
@@ -63,7 +66,7 @@ void analogin_init(analogin_t *obj, PinName pin)
6366
obj->channel = STM_PIN_CHANNEL(function);
6467

6568
// Save pin number for the read function
66-
obj->pin = pin;
69+
obj->pin = pinmap->pin;
6770

6871
// Configure ADC object structures
6972
obj->handle.State = HAL_ADC_STATE_RESET;
@@ -111,6 +114,25 @@ void analogin_init(analogin_t *obj, PinName pin)
111114
}
112115
}
113116

117+
void analogin_init(analogin_t *obj, PinName pin)
118+
{
119+
int peripheral;
120+
int function;
121+
122+
if ((pin < 0xF0) || (pin >= 0x100)) {
123+
peripheral = (int)pinmap_peripheral(pin, PinMap_ADC);
124+
function = (int)pinmap_find_function(pin, PinMap_ADC);
125+
} else {
126+
peripheral = (int)pinmap_peripheral(pin, PinMap_ADC_Internal);
127+
function = (int)pinmap_find_function(pin, PinMap_ADC_Internal);
128+
}
129+
130+
const PinMap explicit_pinmap = {pin, peripheral, function};
131+
132+
ANALOGIN_INIT_DIRECT(obj, &explicit_pinmap);
133+
}
134+
135+
114136
uint16_t adc_read(analogin_t *obj)
115137
{
116138
ADC_ChannelConfTypeDef sConfig = {0};

targets/TARGET_STM/TARGET_STM32L4/analogout_device.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,22 @@
3939
static int channel1_used = 0;
4040
static int channel2_used = 0;
4141

42-
void analogout_init(dac_t *obj, PinName pin)
42+
#if EXPLICIT_PINMAP_READY
43+
#define ANALOGOUT_INIT_DIRECT analogout_init_direct
44+
void analogout_init_direct(dac_t *obj, const PinMap *pinmap)
45+
#else
46+
#define ANALOGOUT_INIT_DIRECT _analogout_init_direct
47+
static void _analogout_init_direct(dac_t *obj, const PinMap *pinmap)
48+
#endif
4349
{
4450
DAC_ChannelConfTypeDef sConfig = {0};
4551

4652
// Get the peripheral name from the pin and assign it to the object
47-
obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC);
53+
obj->dac = (DACName)pinmap->peripheral;
4854
MBED_ASSERT(obj->dac != (DACName)NC);
4955

5056
// Get the pin function and assign the used channel to the object
51-
uint32_t function = pinmap_function(pin, PinMap_DAC);
57+
uint32_t function = (uint32_t)pinmap->function;
5258
MBED_ASSERT(function != (uint32_t)NC);
5359

5460
switch (STM_PIN_CHANNEL(function)) {
@@ -66,10 +72,11 @@ void analogout_init(dac_t *obj, PinName pin)
6672
}
6773

6874
// Configure GPIO
69-
pinmap_pinout(pin, PinMap_DAC);
75+
pin_function(pinmap->pin, pinmap->function);
76+
pin_mode(pinmap->pin, PullNone);
7077

7178
// Save the pin for future use
72-
obj->pin = pin;
79+
obj->pin = pinmap->pin;
7380

7481
// Enable DAC clock
7582
__HAL_RCC_DAC1_CLK_ENABLE();
@@ -101,6 +108,16 @@ void analogout_init(dac_t *obj, PinName pin)
101108
analogout_write_u16(obj, 0);
102109
}
103110

111+
void analogout_init(dac_t *obj, PinName pin)
112+
{
113+
int peripheral = (int)pinmap_peripheral(pin, PinMap_DAC);
114+
int function = (int)pinmap_find_function(pin, PinMap_DAC);
115+
116+
const PinMap explicit_pinmap = {pin, peripheral, function};
117+
118+
ANALOGOUT_INIT_DIRECT(obj, &explicit_pinmap);
119+
}
120+
104121
void analogout_free(dac_t *obj)
105122
{
106123
// Reset DAC and disable clock

targets/TARGET_STM/TARGET_STM32L4/common_objects.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ struct i2c_s {
9999
int hz;
100100
PinName sda;
101101
PinName scl;
102+
int sda_func;
103+
int scl_func;
102104
IRQn_Type event_i2cIRQ;
103105
IRQn_Type error_i2cIRQ;
104106
uint32_t XferOperation;

targets/TARGET_STM/TARGET_STM32L4/serial_device.c

Lines changed: 53 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -657,57 +657,86 @@ void serial_rx_abort_asynch(serial_t *obj)
657657
* Set HW Control Flow
658658
* @param obj The serial object
659659
* @param type The Control Flow type (FlowControlNone, FlowControlRTS, FlowControlCTS, FlowControlRTSCTS)
660-
* @param rxflow Pin for the rxflow
661-
* @param txflow Pin for the txflow
660+
* @param pinmap Pointer to structure which holds static pinmap
662661
*/
663-
void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, PinName txflow)
662+
#if EXPLICIT_PINMAP_READY
663+
#define SERIAL_SET_FC_DIRECT serial_set_flow_control_direct
664+
void serial_set_flow_control_direct(serial_t *obj, FlowControl type, const serial_fc_pinmap_t *pinmap)
665+
#else
666+
#define SERIAL_SET_FC_DIRECT _serial_set_flow_control_direct
667+
static void _serial_set_flow_control_direct(serial_t *obj, FlowControl type, const serial_fc_pinmap_t *pinmap)
668+
#endif
664669
{
665670
struct serial_s *obj_s = SERIAL_S(obj);
666671

667-
// Checked used UART name (UART_1, UART_2, ...)
668-
UARTName uart_rts = (UARTName)pinmap_peripheral(rxflow, PinMap_UART_RTS);
669-
UARTName uart_cts = (UARTName)pinmap_peripheral(txflow, PinMap_UART_CTS);
670-
if (((UARTName)pinmap_merge(uart_rts, obj_s->uart) == (UARTName)NC) || ((UARTName)pinmap_merge(uart_cts, obj_s->uart) == (UARTName)NC)) {
671-
MBED_ASSERT(0);
672-
return;
673-
}
674-
675672
if (type == FlowControlNone) {
676673
// Disable hardware flow control
677674
obj_s->hw_flow_ctl = UART_HWCONTROL_NONE;
678675
}
679676
if (type == FlowControlRTS) {
680677
// Enable RTS
681-
MBED_ASSERT(uart_rts != (UARTName)NC);
682-
obj_s->hw_flow_ctl = UART_HWCONTROL_RTS;
683-
obj_s->pin_rts = rxflow;
678+
MBED_ASSERT(pinmap->rx_flow_pin != (UARTName)NC);
679+
obj_s->pin_rts = pinmap->rx_flow_pin;
684680
// Enable the pin for RTS function
685-
pinmap_pinout(rxflow, PinMap_UART_RTS);
681+
pin_function(pinmap->rx_flow_pin, pinmap->rx_flow_function);
682+
pin_mode(pinmap->rx_flow_pin, PullNone);
686683
}
687684
if (type == FlowControlCTS) {
688685
// Enable CTS
689-
MBED_ASSERT(uart_cts != (UARTName)NC);
686+
MBED_ASSERT(pinmap->tx_flow_pin != (UARTName)NC);
690687
obj_s->hw_flow_ctl = UART_HWCONTROL_CTS;
691-
obj_s->pin_cts = txflow;
688+
obj_s->pin_cts = pinmap->tx_flow_pin;
692689
// Enable the pin for CTS function
693-
pinmap_pinout(txflow, PinMap_UART_CTS);
690+
pin_function(pinmap->tx_flow_pin, pinmap->tx_flow_function);
691+
pin_mode(pinmap->tx_flow_pin, PullNone);
694692
}
695693
if (type == FlowControlRTSCTS) {
696694
// Enable CTS & RTS
697-
MBED_ASSERT(uart_rts != (UARTName)NC);
698-
MBED_ASSERT(uart_cts != (UARTName)NC);
695+
MBED_ASSERT(pinmap->rx_flow_pin != (UARTName)NC);
696+
MBED_ASSERT(pinmap->tx_flow_pin != (UARTName)NC);
699697
obj_s->hw_flow_ctl = UART_HWCONTROL_RTS_CTS;
700-
obj_s->pin_rts = rxflow;
701-
obj_s->pin_cts = txflow;
698+
obj_s->pin_rts = pinmap->rx_flow_pin;;
699+
obj_s->pin_cts = pinmap->tx_flow_pin;;
702700
// Enable the pin for CTS function
703-
pinmap_pinout(txflow, PinMap_UART_CTS);
701+
pin_function(pinmap->tx_flow_pin, pinmap->tx_flow_function);
702+
pin_mode(pinmap->tx_flow_pin, PullNone);
704703
// Enable the pin for RTS function
705-
pinmap_pinout(rxflow, PinMap_UART_RTS);
704+
pin_function(pinmap->rx_flow_pin, pinmap->rx_flow_function);
705+
pin_mode(pinmap->rx_flow_pin, PullNone);
706706
}
707707

708708
init_uart(obj);
709709
}
710710

711+
/**
712+
* Set HW Control Flow
713+
* @param obj The serial object
714+
* @param type The Control Flow type (FlowControlNone, FlowControlRTS, FlowControlCTS, FlowControlRTSCTS)
715+
* @param rxflow Pin for the rxflow
716+
* @param txflow Pin for the txflow
717+
*/
718+
void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, PinName txflow)
719+
{
720+
struct serial_s *obj_s = SERIAL_S(obj);
721+
722+
UARTName uart_rts = (UARTName)pinmap_peripheral(rxflow, PinMap_UART_RTS);
723+
UARTName uart_cts = (UARTName)pinmap_peripheral(txflow, PinMap_UART_CTS);
724+
725+
if (((UARTName)pinmap_merge(uart_rts, obj_s->uart) == (UARTName)NC) || ((UARTName)pinmap_merge(uart_cts, obj_s->uart) == (UARTName)NC)) {
726+
MBED_ASSERT(0);
727+
return;
728+
}
729+
730+
int peripheral = (int)pinmap_merge(uart_rts, uart_cts);
731+
732+
int tx_flow_function = (int)pinmap_find_function(txflow, PinMap_UART_CTS);
733+
int rx_flow_function = (int)pinmap_find_function(rxflow, PinMap_UART_RTS);
734+
735+
const serial_fc_pinmap_t explicit_uart_fc_pinmap = {peripheral, txflow, tx_flow_function, rxflow, rx_flow_function};
736+
737+
SERIAL_SET_FC_DIRECT(obj, type, &explicit_uart_fc_pinmap);
738+
}
739+
711740
#endif /* DEVICE_SERIAL_FC */
712741

713742
#endif /* DEVICE_SERIAL */

0 commit comments

Comments
 (0)