Skip to content

Commit d3078a3

Browse files
authored
Merge pull request #12379 from mprse/STDIO_UART_restricted_all
Add STDIO UART as restricted for FPGA testing for all targets and support for restricting GPIO
2 parents 4ec6228 + 0d9a54f commit d3078a3

File tree

10 files changed

+107
-151
lines changed

10 files changed

+107
-151
lines changed

components/testing/COMPONENT_FPGA_CI_TEST_SHIELD/test_utils.h

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@
2020

2121
#include <list>
2222

23+
#define UART_NAME "UART"
24+
#define UARTNOFC_NAME "UART-no-FC"
25+
#define ANALOGOUT_NAME "DAC"
26+
#define ANALOGIN_NAME "ADC"
27+
#define PWM_NAME "PWM"
28+
#define I2C_NAME "I2C"
29+
#define SPI_NAME "SPI"
30+
#define SPISLAVE_NAME "SPISlave"
31+
#define GPIO_NAME "GPIO"
32+
#define GPIO_IRQ_NAME "GPIO_IRQ"
33+
2334
// test function prototypes
2435
typedef void (*TF1)(PinName p0);
2536
typedef void (*TF2)(PinName p0, PinName p1);
@@ -115,11 +126,26 @@ void find_ports(std::list<PortType> &matched_ports, std::list<PortType> &not_mat
115126
FormFactorType::pin_to_string(port.pins[i]), port.pins[i]);
116127
continue;
117128
}
118-
if (pinmap_list_has_peripheral(pinmap_restricted_peripherals(), port.peripheral)) {
119-
utest_printf("Skipping %s peripheral %i with pin %s (%i)\r\n", pin_type,
120-
port.peripheral, FormFactorType::pin_to_string(port.pins[i]), port.pins[i]);
121-
continue;
129+
130+
if (!strcmp(PortType::PinMap::name, GPIO_IRQ_NAME) || !strcmp(PortType::PinMap::name, GPIO_NAME)) {
131+
// Don't test restricted gpio pins
132+
if (pinmap_list_has_pin(pinmap_gpio_restricted_pins(), port.pins[i])) {
133+
utest_printf("Skipping %s pin %s (%i)\r\n", pin_type,
134+
FormFactorType::pin_to_string(port.pins[i]), port.pins[i]);
135+
continue;
136+
}
122137
}
138+
139+
#if DEVICE_SERIAL
140+
if (!strcmp(PortType::PinMap::name, UART_NAME) || !strcmp(PortType::PinMap::name, UARTNOFC_NAME)) {
141+
if (pinmap_list_has_peripheral(pinmap_uart_restricted_peripherals(), port.peripheral)) {
142+
utest_printf("Skipping %s peripheral %i with pin %s (%i)\r\n", pin_type,
143+
port.peripheral, FormFactorType::pin_to_string(port.pins[i]), port.pins[i]);
144+
continue;
145+
}
146+
}
147+
#endif
148+
123149
// skipp pin searching if single pin port type
124150
if (PortType::pin_count > 1) {
125151
find_port_pins<PortType, FormFactorType>(port);
@@ -442,7 +468,7 @@ struct GPIOMaps {
442468
};
443469
const PinMap *GPIOMaps::maps[] = { gpio_pinmap() };
444470
const char *const GPIOMaps::pin_type_names[] = { "IO" };
445-
const char *const GPIOMaps::name = "GPIO";
471+
const char *const GPIOMaps::name = GPIO_NAME;
446472
typedef Port<1, GPIOMaps, DefaultFormFactor, TF1> GPIOPort;
447473

448474
#if DEVICE_INTERRUPTIN
@@ -454,7 +480,7 @@ struct GPIOIRQMaps {
454480
};
455481
const PinMap *GPIOIRQMaps::maps[] = { gpio_irq_pinmap() };
456482
const char *const GPIOIRQMaps::pin_type_names[] = { "IRQ_IN" };
457-
const char *const GPIOIRQMaps::name = "GPIO_IRQ";
483+
const char *const GPIOIRQMaps::name = GPIO_IRQ_NAME;
458484
typedef Port<1, GPIOIRQMaps, DefaultFormFactor, TF1> GPIOIRQPort;
459485
#endif
460486

@@ -467,7 +493,7 @@ struct SPIMaps {
467493
};
468494
const PinMap *SPIMaps::maps[] = { spi_master_mosi_pinmap(), spi_master_miso_pinmap(), spi_master_clk_pinmap(), spi_master_cs_pinmap() };
469495
const char *const SPIMaps::pin_type_names[] = { "MOSI", "MISO", "SCLK", "SSEL" };
470-
const char *const SPIMaps::name = "SPI";
496+
const char *const SPIMaps::name = SPI_NAME;
471497
typedef Port<4, SPIMaps, DefaultFormFactor, TF4> SPIPort;
472498

473499
struct SPINoCSMaps {
@@ -477,7 +503,7 @@ struct SPINoCSMaps {
477503
};
478504
const PinMap *SPINoCSMaps::maps[] = { spi_master_mosi_pinmap(), spi_master_miso_pinmap(), spi_master_clk_pinmap()};
479505
const char *const SPINoCSMaps::pin_type_names[] = { "MOSI", "MISO", "SCLK" };
480-
const char *const SPINoCSMaps::name = "SPI";
506+
const char *const SPINoCSMaps::name = SPI_NAME;
481507
typedef Port<3, SPINoCSMaps, DefaultFormFactor, TF3> SPINoCSPort;
482508

483509
struct SPISlaveMaps {
@@ -487,7 +513,7 @@ struct SPISlaveMaps {
487513
};
488514
const PinMap *SPISlaveMaps::maps[] = { spi_slave_mosi_pinmap(), spi_slave_miso_pinmap(), spi_slave_clk_pinmap(), spi_slave_cs_pinmap() };
489515
const char *const SPISlaveMaps::pin_type_names[] = { "MOSI", "MISO", "SCLK", "SSEL" };
490-
const char *const SPISlaveMaps::name = "SPISlave";
516+
const char *const SPISlaveMaps::name = SPISLAVE_NAME;
491517
typedef Port<4, SPISlaveMaps, DefaultFormFactor, TF4> SPISlavePort;
492518
#endif
493519

@@ -500,7 +526,7 @@ struct I2CMaps {
500526
};
501527
const PinMap *I2CMaps::maps[] = { i2c_master_sda_pinmap(), i2c_master_scl_pinmap() };
502528
const char *const I2CMaps::pin_type_names[] = { "SDA", "SCL" };
503-
const char *const I2CMaps::name = "I2C";
529+
const char *const I2CMaps::name = I2C_NAME;
504530
typedef Port<2, I2CMaps, DefaultFormFactor, TF2> I2CPort;
505531
#endif
506532

@@ -513,7 +539,7 @@ struct PWMMaps {
513539
};
514540
const PinMap *PWMMaps::maps[] = { pwmout_pinmap() };
515541
const char *const PWMMaps::pin_type_names[] = { "PWM_OUT" };
516-
const char *const PWMMaps::name = "PWM";
542+
const char *const PWMMaps::name = PWM_NAME;
517543
typedef Port<1, PWMMaps, DefaultFormFactor, TF1> PWMPort;
518544
#endif
519545

@@ -526,7 +552,7 @@ struct AnaloginMaps {
526552
};
527553
const PinMap *AnaloginMaps::maps[] = { analogin_pinmap() };
528554
const char *const AnaloginMaps::pin_type_names[] = { "ADC_IN" };
529-
const char *const AnaloginMaps::name = "ADC";
555+
const char *const AnaloginMaps::name = ANALOGIN_NAME;
530556
typedef Port<1, AnaloginMaps, DefaultFormFactor, TF1> AnaloginPort;
531557
#endif
532558

@@ -539,7 +565,7 @@ struct AnalogoutMaps {
539565
};
540566
const PinMap *AnalogoutMaps::maps[] = { analogout_pinmap() };
541567
const char *const AnalogoutMaps::pin_type_names[] = { "DAC_OUT" };
542-
const char *const AnalogoutMaps::name = "DAC";
568+
const char *const AnalogoutMaps::name = ANALOGOUT_NAME;
543569
typedef Port<1, AnalogoutMaps, DefaultFormFactor, TF1> AnalogoutPort;
544570
#endif
545571

@@ -553,7 +579,7 @@ struct UARTMaps {
553579
};
554580
const PinMap *UARTMaps::maps[] = { serial_tx_pinmap(), serial_rx_pinmap(), serial_cts_pinmap(), serial_rts_pinmap() };
555581
const char *const UARTMaps::pin_type_names[] = { "TX", "RX", "CLS", "RTS" };
556-
const char *const UARTMaps::name = "UART";
582+
const char *const UARTMaps::name = UART_NAME;
557583
typedef Port<4, UARTMaps, DefaultFormFactor, TF4> UARTPort;
558584
#endif
559585

@@ -564,8 +590,7 @@ struct UARTNoFCMaps {
564590
};
565591
const PinMap *UARTNoFCMaps::maps[] = { serial_tx_pinmap(), serial_rx_pinmap() };
566592
const char *const UARTNoFCMaps::pin_type_names[] = { "TX", "RX" };
567-
const char *const UARTNoFCMaps::name = "UART-no-FC";
593+
const char *const UARTNoFCMaps::name = UARTNOFC_NAME;
568594
typedef Port<2, UARTNoFCMaps, DefaultFormFactor, TF2> UARTNoFCPort;
569595
#endif
570-
571596
#endif

hal/mbed_pinmap_default.c renamed to hal/mbed_pinmap_default.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "platform/mbed_toolchain.h"
2121
#include "platform/mbed_assert.h"
2222
#include "device.h"
23+
#include "hal/serial_api.h"
2324

2425
//*** Common form factors ***
2526
#ifdef TARGET_FF_ARDUINO
@@ -77,12 +78,31 @@ MBED_WEAK const PinList *pinmap_restricted_pins()
7778
return &pin_list;
7879
}
7980

80-
//*** Default restricted peripherals ***
81-
MBED_WEAK const PeripheralList *pinmap_restricted_peripherals()
81+
//*** Default restricted gpio pins ***
82+
// GPIO pins are special case because there are no pin-maps for GPIO
83+
MBED_WEAK const PinList *pinmap_gpio_restricted_pins()
8284
{
83-
static const PeripheralList peripheral_list = {
85+
static const PinList pin_list = {
8486
0,
8587
0
8688
};
89+
return &pin_list;
90+
}
91+
92+
//*** Default restricted peripherals ***
93+
#if DEVICE_SERIAL
94+
MBED_WEAK const PeripheralList *pinmap_uart_restricted_peripherals()
95+
{
96+
static const int stdio_uart = pinmap_peripheral(STDIO_UART_TX, serial_tx_pinmap());
97+
98+
static const int peripherals[] = {
99+
stdio_uart
100+
};
101+
102+
static const PeripheralList peripheral_list = {
103+
sizeof peripherals / sizeof peripherals[0],
104+
peripherals
105+
};
87106
return &peripheral_list;
88107
}
108+
#endif

hal/pinmap.h

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ bool pinmap_list_has_peripheral(const PeripheralList *list, int peripheral);
155155
const PinList *pinmap_restricted_pins(void);
156156

157157
/**
158-
* Get the pin list of peripherals to avoid during testing
158+
* Get the pin list of peripherals per interface to avoid during testing
159159
*
160160
* The restricted peripheral list is used to indicate to testing
161161
* that a peripheral should be skipped due to some caveat about it.
@@ -166,18 +166,34 @@ const PinList *pinmap_restricted_pins(void);
166166
* function if they have peripherals which should be
167167
* skipped during testing.
168168
*
169-
* @note Some targets use the same value for multiple
170-
* different types of peripherals. For example SPI 0
171-
* and UART 0 may both be identified by the peripheral
172-
* value 0. If your target does this then do not
173-
* use this function to skip peripherals, as this will
174-
* unintentionally cause all peripherals with that value
175-
* to be skipped. Instead these entries should be removed
176-
* from the peripheral PinMap itself.
169+
* @note Restricting peripheral is at the moment available for UART
170+
* interface only as only STDIO UART must be skipped because it is
171+
* used by Mbed.
172+
* Restricting peripherals for other interfaces should be added
173+
* in the future if required.
177174
*
178175
* @return Pointer to a peripheral list of peripheral to avoid
179176
*/
180-
const PeripheralList *pinmap_restricted_peripherals(void);
177+
#if DEVICE_SERIAL
178+
const PeripheralList *pinmap_uart_restricted_peripherals(void);
179+
#endif
180+
181+
/**
182+
* Get the pin list of pins to avoid during GPIO/GPIO_IRQ testing
183+
*
184+
* The GPIO restricted pin list is used to indicate to testing
185+
* that a pin should be skipped due to some caveat about it.
186+
*
187+
* Targets should override the weak implementation of this
188+
* function if they have peripherals which should be
189+
* skipped during testing.
190+
*
191+
* @note This is special case only for GPIO/GPIO_IRQ tests because
192+
* targets do not provide pin-maps for GPIO.
193+
*
194+
* @return Pointer to a peripheral list of peripheral to avoid
195+
*/
196+
const PinList *pinmap_gpio_restricted_pins(void);
181197

182198
#ifdef TARGET_FF_ARDUINO
183199

targets/TARGET_NUVOTON/TARGET_M2351/pinmap.c

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void pin_mode(PinName pin, PinMode mode)
4343
uint32_t pin_index = NU_PINNAME_TO_PIN(pin);
4444
uint32_t port_index = NU_PINNAME_TO_PORT(pin);
4545
GPIO_T *gpio_base = NU_PORT_BASE(port_index);
46-
46+
4747
uint32_t mode_intern = GPIO_MODE_INPUT;
4848

4949
switch (mode) {
@@ -81,38 +81,23 @@ void pin_mode(PinName pin, PinMode mode)
8181
*/
8282
}
8383

84-
/* List of peripherals excluded from testing */
85-
const PeripheralList *pinmap_restricted_peripherals()
86-
{
87-
static const int perifs[] = {
88-
STDIO_UART // Dedicated to USB VCOM
89-
};
90-
91-
static const PeripheralList peripheral_list = {
92-
sizeof(perifs) / sizeof(perifs[0]),
93-
perifs
94-
};
95-
96-
return &peripheral_list;
97-
}
98-
9984
#if defined(__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
10085

10186
static void pin_function_impl(int32_t pin, int32_t data, bool nonsecure_caller)
10287
{
10388
MBED_ASSERT(pin != (PinName)NC);
10489
uint32_t pin_index = NU_PINNAME_TO_PIN(pin);
10590
uint32_t port_index = NU_PINNAME_TO_PORT(pin);
106-
91+
10792
/* Guard access to secure GPIO from non-secure domain */
108-
if (nonsecure_caller &&
93+
if (nonsecure_caller &&
10994
(! (SCU_INIT_IONSSET_VAL & (1 << (port_index + 0))))) {
11095
error("Non-secure domain tries to control secure or undefined GPIO.");
11196
}
11297

11398
__IO uint32_t *GPx_MFPx = ((__IO uint32_t *) &SYS->GPA_MFPL) + port_index * 2 + (pin_index / 8);
11499
uint32_t MFP_Msk = NU_MFP_MSK(pin_index);
115-
100+
116101
// E.g.: SYS->GPA_MFPL = (SYS->GPA_MFPL & (~SYS_GPA_MFPL_PA0MFP_Msk) ) | SYS_GPA_MFPL_PA0MFP_SC0_CD ;
117102
*GPx_MFPx = (*GPx_MFPx & (~MFP_Msk)) | data;
118103
}

targets/TARGET_NUVOTON/TARGET_M251/pinmap.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,3 @@ void pin_mode(PinName pin, PinMode mode)
8383
* 2. PushPullOutput/PIN_INPUT
8484
*/
8585
}
86-
87-
/* List of peripherals excluded from testing */
88-
const PeripheralList *pinmap_restricted_peripherals()
89-
{
90-
static const int perifs[] = {
91-
STDIO_UART // Dedicated to USB VCOM
92-
};
93-
94-
static const PeripheralList peripheral_list = {
95-
sizeof(perifs) / sizeof(perifs[0]),
96-
perifs
97-
};
98-
99-
return &peripheral_list;
100-
}

targets/TARGET_NUVOTON/TARGET_M261/pinmap.c

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright (c) 2019-2020 Nuvoton Technology Corporation
33
* SPDX-License-Identifier: Apache-2.0
44
*
@@ -29,10 +29,10 @@ void pin_function(PinName pin, int data)
2929
MBED_ASSERT(pin != (PinName)NC);
3030
uint32_t pin_index = NU_PINNAME_TO_PIN(pin);
3131
uint32_t port_index = NU_PINNAME_TO_PORT(pin);
32-
32+
3333
__IO uint32_t *GPx_MFPx = ((__IO uint32_t *) &SYS->GPA_MFPL) + port_index * 2 + (pin_index / 8);
3434
uint32_t MFP_Msk = NU_MFP_MSK(pin_index);
35-
35+
3636
// E.g.: SYS->GPA_MFPL = (SYS->GPA_MFPL & (~SYS_GPA_MFPL_PA0MFP_Msk) ) | SYS_GPA_MFPL_PA0MFP_SC0_CD ;
3737
*GPx_MFPx = (*GPx_MFPx & (~MFP_Msk)) | data;
3838
}
@@ -46,7 +46,7 @@ void pin_mode(PinName pin, PinMode mode)
4646
uint32_t pin_index = NU_PINNAME_TO_PIN(pin);
4747
uint32_t port_index = NU_PINNAME_TO_PORT(pin);
4848
GPIO_T *gpio_base = NU_PORT_BASE(port_index);
49-
49+
5050
uint32_t mode_intern = GPIO_MODE_INPUT;
5151

5252
switch (mode) {
@@ -83,18 +83,3 @@ void pin_mode(PinName pin, PinMode mode)
8383
* 2. PushPullOutput/PIN_INPUT
8484
*/
8585
}
86-
87-
/* List of peripherals excluded from testing */
88-
const PeripheralList *pinmap_restricted_peripherals()
89-
{
90-
static const int perifs[] = {
91-
STDIO_UART // Dedicated to USB VCOM
92-
};
93-
94-
static const PeripheralList peripheral_list = {
95-
sizeof(perifs) / sizeof(perifs[0]),
96-
perifs
97-
};
98-
99-
return &peripheral_list;
100-
}

0 commit comments

Comments
 (0)