Skip to content

Commit 42b2eee

Browse files
committed
NUCLEO_F303RE: Add explicit pinmap support
1 parent a837565 commit 42b2eee

File tree

7 files changed

+465
-338
lines changed

7 files changed

+465
-338
lines changed

targets/TARGET_STM/TARGET_STM32F3/TARGET_STM32F303xE/TARGET_NUCLEO_F303RE/PeripheralPinMaps.h

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

targets/TARGET_STM/TARGET_STM32F3/TARGET_STM32F303xE/TARGET_NUCLEO_F303RE/PeripheralPins.c

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

targets/TARGET_STM/TARGET_STM32F3/TARGET_STM32F303xE/TARGET_NUCLEO_F303RE/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_STM32F3/analogin_device.c

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,29 @@
3737
#include "mbed_debug.h"
3838
#include "PeripheralPins.h"
3939

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

4453
// ADC Internal Channels "pins" (Temperature, Vref, Vbat, ...)
4554
// are described in PinNames.h and PeripheralPins.c
4655
// Pin value must be between 0xF0 and 0xFF
47-
if ((pin < 0xF0) || (pin >= 0x100)) {
56+
if ((pinmap->pin < 0xF0) || (pinmap->pin >= 0x100)) {
4857
// Normal channels
49-
// Get the peripheral name from the pin and assign it to the object
50-
obj->handle.Instance = (ADC_TypeDef *)pinmap_peripheral(pin, PinMap_ADC);
51-
// Get the functions (adc channel) from the pin and assign it to the object
52-
function = pinmap_function(pin, PinMap_ADC);
5358
// Configure GPIO
54-
pinmap_pinout(pin, PinMap_ADC);
59+
pin_function(pinmap->pin, pinmap->function);
60+
pin_mode(pinmap->pin, PullNone);
5561
} else {
5662
// Internal channels
57-
obj->handle.Instance = (ADC_TypeDef *)pinmap_peripheral(pin, PinMap_ADC_Internal);
58-
function = pinmap_function(pin, PinMap_ADC_Internal);
5963
// No GPIO configuration for internal channels
6064
}
6165
MBED_ASSERT(obj->handle.Instance != (ADC_TypeDef *)NC);
@@ -64,7 +68,7 @@ void analogin_init(analogin_t *obj, PinName pin)
6468
obj->channel = STM_PIN_CHANNEL(function);
6569

6670
// Save pin number for the read function
67-
obj->pin = pin;
71+
obj->pin = pinmap->pin;
6872

6973
// Configure ADC object structures
7074
obj->handle.State = HAL_ADC_STATE_RESET;
@@ -113,6 +117,24 @@ void analogin_init(analogin_t *obj, PinName pin)
113117
}
114118
}
115119

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

targets/TARGET_STM/TARGET_STM32F3/analogout_device.c

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,22 @@
3939
static int pa4_used = 0;
4040
static int pa5_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
// Save the channel for the write and read functions
@@ -67,10 +73,11 @@ void analogout_init(dac_t *obj, PinName pin)
6773
}
6874

6975
// Configure GPIO
70-
pinmap_pinout(pin, PinMap_DAC);
76+
pin_function(pinmap->pin, pinmap->function);
77+
pin_mode(pinmap->pin, PullNone);
7178

7279
// Save the pin for future use
73-
obj->pin = pin;
80+
obj->pin = pinmap->pin;
7481

7582
// Enable DAC clock
7683
if (obj->dac == DAC_1) {
@@ -101,11 +108,11 @@ void analogout_init(dac_t *obj, PinName pin)
101108
sConfig.DAC_OutputSwitch = DAC_OUTPUTSWITCH_ENABLE;
102109
#endif
103110

104-
if (pin == PA_4) {
111+
if (pinmap->pin == PA_4) {
105112
pa4_used = 1;
106113
}
107114

108-
if (pin == PA_5) {
115+
if (pinmap->pin == PA_5) {
109116
pa5_used = 1;
110117
}
111118

@@ -116,6 +123,16 @@ void analogout_init(dac_t *obj, PinName pin)
116123
analogout_write_u16(obj, 0);
117124
}
118125

126+
void analogout_init(dac_t *obj, PinName pin)
127+
{
128+
int peripheral = (int)pinmap_peripheral(pin, PinMap_DAC);
129+
int function = (int)pinmap_find_function(pin, PinMap_DAC);
130+
131+
const PinMap explicit_pinmap = {pin, peripheral, function};
132+
133+
ANALOGOUT_INIT_DIRECT(obj, &explicit_pinmap);
134+
}
135+
119136
void analogout_free(dac_t *obj)
120137
{
121138
// Reset DAC and disable clock

targets/TARGET_STM/TARGET_STM32F3/common_objects.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ struct i2c_s {
9696
int hz;
9797
PinName sda;
9898
PinName scl;
99+
int sda_func;
100+
int scl_func;
99101
IRQn_Type event_i2cIRQ;
100102
IRQn_Type error_i2cIRQ;
101103
uint32_t XferOperation;

targets/TARGET_STM/TARGET_STM32F3/serial_device.c

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -643,57 +643,87 @@ void serial_rx_abort_asynch(serial_t *obj)
643643
* Set HW Control Flow
644644
* @param obj The serial object
645645
* @param type The Control Flow type (FlowControlNone, FlowControlRTS, FlowControlCTS, FlowControlRTSCTS)
646-
* @param rxflow Pin for the rxflow
647-
* @param txflow Pin for the txflow
646+
* @param pinmap Pointer to structure which holds static pinmap
648647
*/
649-
void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, PinName txflow)
648+
#if EXPLICIT_PINMAP_READY
649+
#define SERIAL_SET_FC_DIRECT serial_set_flow_control_direct
650+
void serial_set_flow_control_direct(serial_t *obj, FlowControl type, const serial_fc_pinmap_t *pinmap)
651+
#else
652+
#define SERIAL_SET_FC_DIRECT _serial_set_flow_control_direct
653+
static void _serial_set_flow_control_direct(serial_t *obj, FlowControl type, const serial_fc_pinmap_t *pinmap)
654+
#endif
650655
{
651656
struct serial_s *obj_s = SERIAL_S(obj);
652657

653-
// Checked used UART name (UART_1, UART_2, ...)
654-
UARTName uart_rts = (UARTName)pinmap_peripheral(rxflow, PinMap_UART_RTS);
655-
UARTName uart_cts = (UARTName)pinmap_peripheral(txflow, PinMap_UART_CTS);
656-
if (((UARTName)pinmap_merge(uart_rts, obj_s->uart) == (UARTName)NC) || ((UARTName)pinmap_merge(uart_cts, obj_s->uart) == (UARTName)NC)) {
657-
MBED_ASSERT(0);
658-
return;
659-
}
660-
661658
if (type == FlowControlNone) {
662659
// Disable hardware flow control
663660
obj_s->hw_flow_ctl = UART_HWCONTROL_NONE;
664661
}
665662
if (type == FlowControlRTS) {
666663
// Enable RTS
667-
MBED_ASSERT(uart_rts != (UARTName)NC);
664+
MBED_ASSERT(pinmap->rx_flow_pin != (UARTName)NC);
668665
obj_s->hw_flow_ctl = UART_HWCONTROL_RTS;
669-
obj_s->pin_rts = rxflow;
666+
obj_s->pin_rts = pinmap->rx_flow_pin;
670667
// Enable the pin for RTS function
671-
pinmap_pinout(rxflow, PinMap_UART_RTS);
668+
pin_function(pinmap->rx_flow_pin, pinmap->rx_flow_function);
669+
pin_mode(pinmap->rx_flow_pin, PullNone);
672670
}
673671
if (type == FlowControlCTS) {
674672
// Enable CTS
675-
MBED_ASSERT(uart_cts != (UARTName)NC);
673+
MBED_ASSERT(pinmap->tx_flow_pin != (UARTName)NC);
676674
obj_s->hw_flow_ctl = UART_HWCONTROL_CTS;
677-
obj_s->pin_cts = txflow;
675+
obj_s->pin_cts = pinmap->tx_flow_pin;
678676
// Enable the pin for CTS function
679-
pinmap_pinout(txflow, PinMap_UART_CTS);
677+
pin_function(pinmap->tx_flow_pin, pinmap->tx_flow_function);
678+
pin_mode(pinmap->tx_flow_pin, PullNone);
680679
}
681680
if (type == FlowControlRTSCTS) {
682681
// Enable CTS & RTS
683-
MBED_ASSERT(uart_rts != (UARTName)NC);
684-
MBED_ASSERT(uart_cts != (UARTName)NC);
682+
MBED_ASSERT(pinmap->rx_flow_pin != (UARTName)NC);
683+
MBED_ASSERT(pinmap->tx_flow_pin != (UARTName)NC);
685684
obj_s->hw_flow_ctl = UART_HWCONTROL_RTS_CTS;
686-
obj_s->pin_rts = rxflow;
687-
obj_s->pin_cts = txflow;
685+
obj_s->pin_rts = pinmap->rx_flow_pin;;
686+
obj_s->pin_cts = pinmap->tx_flow_pin;;
688687
// Enable the pin for CTS function
689-
pinmap_pinout(txflow, PinMap_UART_CTS);
688+
pin_function(pinmap->tx_flow_pin, pinmap->tx_flow_function);
689+
pin_mode(pinmap->tx_flow_pin, PullNone);
690690
// Enable the pin for RTS function
691-
pinmap_pinout(rxflow, PinMap_UART_RTS);
691+
pin_function(pinmap->rx_flow_pin, pinmap->rx_flow_function);
692+
pin_mode(pinmap->rx_flow_pin, PullNone);
692693
}
693694

694695
init_uart(obj);
695696
}
696697

698+
/**
699+
* Set HW Control Flow
700+
* @param obj The serial object
701+
* @param type The Control Flow type (FlowControlNone, FlowControlRTS, FlowControlCTS, FlowControlRTSCTS)
702+
* @param rxflow Pin for the rxflow
703+
* @param txflow Pin for the txflow
704+
*/
705+
void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, PinName txflow)
706+
{
707+
struct serial_s *obj_s = SERIAL_S(obj);
708+
709+
UARTName uart_rts = (UARTName)pinmap_peripheral(rxflow, PinMap_UART_RTS);
710+
UARTName uart_cts = (UARTName)pinmap_peripheral(txflow, PinMap_UART_CTS);
711+
712+
if (((UARTName)pinmap_merge(uart_rts, obj_s->uart) == (UARTName)NC) || ((UARTName)pinmap_merge(uart_cts, obj_s->uart) == (UARTName)NC)) {
713+
MBED_ASSERT(0);
714+
return;
715+
}
716+
717+
int peripheral = (int)pinmap_merge(uart_rts, uart_cts);
718+
719+
int tx_flow_function = (int)pinmap_find_function(txflow, PinMap_UART_CTS);
720+
int rx_flow_function = (int)pinmap_find_function(rxflow, PinMap_UART_RTS);
721+
722+
const serial_fc_pinmap_t explicit_uart_fc_pinmap = {peripheral, txflow, tx_flow_function, rxflow, rx_flow_function};
723+
724+
SERIAL_SET_FC_DIRECT(obj, type, &explicit_uart_fc_pinmap);
725+
}
726+
697727
#endif /* DEVICE_SERIAL_FC */
698728

699729
#endif /* DEVICE_SERIAL */

0 commit comments

Comments
 (0)