Skip to content

Commit 1f30b62

Browse files
committed
NUCLEO_F303RE: Add explicit pinmap support
1 parent 10e8a79 commit 1f30b62

File tree

7 files changed

+458
-330
lines changed

7 files changed

+458
-330
lines changed

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

Lines changed: 342 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 & 289 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
@@ -652,57 +652,87 @@ void serial_rx_abort_asynch(serial_t *obj)
652652
* Set HW Control Flow
653653
* @param obj The serial object
654654
* @param type The Control Flow type (FlowControlNone, FlowControlRTS, FlowControlCTS, FlowControlRTSCTS)
655-
* @param rxflow Pin for the rxflow
656-
* @param txflow Pin for the txflow
655+
* @param pinmap Pointer to structure which holds static pinmap
657656
*/
658-
void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, PinName txflow)
657+
#if EXPLICIT_PINMAP_READY
658+
#define SERIAL_SET_FC_DIRECT serial_set_flow_control_direct
659+
void serial_set_flow_control_direct(serial_t *obj, FlowControl type, const serial_fc_pinmap_t *pinmap)
660+
#else
661+
#define SERIAL_SET_FC_DIRECT _serial_set_flow_control_direct
662+
static void _serial_set_flow_control_direct(serial_t *obj, FlowControl type, const serial_fc_pinmap_t *pinmap)
663+
#endif
659664
{
660665
struct serial_s *obj_s = SERIAL_S(obj);
661666

662-
// Checked used UART name (UART_1, UART_2, ...)
663-
UARTName uart_rts = (UARTName)pinmap_peripheral(rxflow, PinMap_UART_RTS);
664-
UARTName uart_cts = (UARTName)pinmap_peripheral(txflow, PinMap_UART_CTS);
665-
if (((UARTName)pinmap_merge(uart_rts, obj_s->uart) == (UARTName)NC) || ((UARTName)pinmap_merge(uart_cts, obj_s->uart) == (UARTName)NC)) {
666-
MBED_ASSERT(0);
667-
return;
668-
}
669-
670667
if (type == FlowControlNone) {
671668
// Disable hardware flow control
672669
obj_s->hw_flow_ctl = UART_HWCONTROL_NONE;
673670
}
674671
if (type == FlowControlRTS) {
675672
// Enable RTS
676-
MBED_ASSERT(uart_rts != (UARTName)NC);
673+
MBED_ASSERT(pinmap->rx_flow_pin != (UARTName)NC);
677674
obj_s->hw_flow_ctl = UART_HWCONTROL_RTS;
678-
obj_s->pin_rts = rxflow;
675+
obj_s->pin_rts = pinmap->rx_flow_pin;
679676
// Enable the pin for RTS function
680-
pinmap_pinout(rxflow, PinMap_UART_RTS);
677+
pin_function(pinmap->rx_flow_pin, pinmap->rx_flow_function);
678+
pin_mode(pinmap->rx_flow_pin, PullNone);
681679
}
682680
if (type == FlowControlCTS) {
683681
// Enable CTS
684-
MBED_ASSERT(uart_cts != (UARTName)NC);
682+
MBED_ASSERT(pinmap->tx_flow_pin != (UARTName)NC);
685683
obj_s->hw_flow_ctl = UART_HWCONTROL_CTS;
686-
obj_s->pin_cts = txflow;
684+
obj_s->pin_cts = pinmap->tx_flow_pin;
687685
// Enable the pin for CTS function
688-
pinmap_pinout(txflow, PinMap_UART_CTS);
686+
pin_function(pinmap->tx_flow_pin, pinmap->tx_flow_function);
687+
pin_mode(pinmap->tx_flow_pin, PullNone);
689688
}
690689
if (type == FlowControlRTSCTS) {
691690
// Enable CTS & RTS
692-
MBED_ASSERT(uart_rts != (UARTName)NC);
693-
MBED_ASSERT(uart_cts != (UARTName)NC);
691+
MBED_ASSERT(pinmap->rx_flow_pin != (UARTName)NC);
692+
MBED_ASSERT(pinmap->tx_flow_pin != (UARTName)NC);
694693
obj_s->hw_flow_ctl = UART_HWCONTROL_RTS_CTS;
695-
obj_s->pin_rts = rxflow;
696-
obj_s->pin_cts = txflow;
694+
obj_s->pin_rts = pinmap->rx_flow_pin;;
695+
obj_s->pin_cts = pinmap->tx_flow_pin;;
697696
// Enable the pin for CTS function
698-
pinmap_pinout(txflow, PinMap_UART_CTS);
697+
pin_function(pinmap->tx_flow_pin, pinmap->tx_flow_function);
698+
pin_mode(pinmap->tx_flow_pin, PullNone);
699699
// Enable the pin for RTS function
700-
pinmap_pinout(rxflow, PinMap_UART_RTS);
700+
pin_function(pinmap->rx_flow_pin, pinmap->rx_flow_function);
701+
pin_mode(pinmap->rx_flow_pin, PullNone);
701702
}
702703

703704
init_uart(obj);
704705
}
705706

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

708738
#endif /* DEVICE_SERIAL */

0 commit comments

Comments
 (0)