Skip to content

Commit 6537e39

Browse files
committed
Add STDIO UART as restricted for FPGA testing for all targets
Substantiation for this is that the STDIO UART peripheral is used by Mbed, so it should never be tested. Also solve the potential problem with accidenty skipped peripherals in FPGA testing. Currently, we have a one `pinmap_restricted_peripherals()` function for all interfaces (UART, I2C, SPI, etc.). The problem can be encountered if different interfaces have the same peripheral ids (e.g. `UART_0` = 0, `SPI_0` = 0). In this case, if `UART_0` is on the restricted list, then SPI tests will be also skipped for `SPI_0`. The good news is that usually, the peripheral ids are the base addresses of the peripheral's register set, but we can't rely on this. It is also good that `pinmap_restricted_peripherals()` at this moment is only required for STDIO UART (Nuvoton and STM). To solve this issue we will change name of `pinmap_restricted_peripherals()` to `pinmap_uart_restricted_peripherals()`, make STDIO UART restricted by default for all targets and update FPGA test utilily functions to use `pinmap_uart_restricted_peripherals()` to skip only uart peripherals. In the future if needed we can consider to add support to restrict peripherals of other interfaces(SPI, I2C, etc).
1 parent 9eef833 commit 6537e39

File tree

3 files changed

+43
-27
lines changed

3 files changed

+43
-27
lines changed

components/testing/COMPONENT_FPGA_CI_TEST_SHIELD/test_utils.h

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@
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+
2332
// test function prototypes
2433
typedef void (*TF1)(PinName p0);
2534
typedef void (*TF2)(PinName p0, PinName p1);
@@ -115,11 +124,15 @@ void find_ports(std::list<PortType> &matched_ports, std::list<PortType> &not_mat
115124
FormFactorType::pin_to_string(port.pins[i]), port.pins[i]);
116125
continue;
117126
}
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;
127+
128+
if (!strcmp(PortType::PinMap::name, UART_NAME) || !strcmp(PortType::PinMap::name, UARTNOFC_NAME)) {
129+
if (pinmap_list_has_peripheral(pinmap_uart_restricted_peripherals(), port.peripheral)) {
130+
utest_printf("Skipping %s peripheral %i with pin %s (%i)\r\n", pin_type,
131+
port.peripheral, FormFactorType::pin_to_string(port.pins[i]), port.pins[i]);
132+
continue;
133+
}
122134
}
135+
123136
// skipp pin searching if single pin port type
124137
if (PortType::pin_count > 1) {
125138
find_port_pins<PortType, FormFactorType>(port);
@@ -467,7 +480,7 @@ struct SPIMaps {
467480
};
468481
const PinMap *SPIMaps::maps[] = { spi_master_mosi_pinmap(), spi_master_miso_pinmap(), spi_master_clk_pinmap(), spi_master_cs_pinmap() };
469482
const char *const SPIMaps::pin_type_names[] = { "MOSI", "MISO", "SCLK", "SSEL" };
470-
const char *const SPIMaps::name = "SPI";
483+
const char *const SPIMaps::name = SPI_NAME;
471484
typedef Port<4, SPIMaps, DefaultFormFactor, TF4> SPIPort;
472485

473486
struct SPINoCSMaps {
@@ -477,7 +490,7 @@ struct SPINoCSMaps {
477490
};
478491
const PinMap *SPINoCSMaps::maps[] = { spi_master_mosi_pinmap(), spi_master_miso_pinmap(), spi_master_clk_pinmap()};
479492
const char *const SPINoCSMaps::pin_type_names[] = { "MOSI", "MISO", "SCLK" };
480-
const char *const SPINoCSMaps::name = "SPI";
493+
const char *const SPINoCSMaps::name = SPI_NAME;
481494
typedef Port<3, SPINoCSMaps, DefaultFormFactor, TF3> SPINoCSPort;
482495

483496
struct SPISlaveMaps {
@@ -487,7 +500,7 @@ struct SPISlaveMaps {
487500
};
488501
const PinMap *SPISlaveMaps::maps[] = { spi_slave_mosi_pinmap(), spi_slave_miso_pinmap(), spi_slave_clk_pinmap(), spi_slave_cs_pinmap() };
489502
const char *const SPISlaveMaps::pin_type_names[] = { "MOSI", "MISO", "SCLK", "SSEL" };
490-
const char *const SPISlaveMaps::name = "SPISlave";
503+
const char *const SPISlaveMaps::name = SPISLAVE_NAME;
491504
typedef Port<4, SPISlaveMaps, DefaultFormFactor, TF4> SPISlavePort;
492505
#endif
493506

@@ -500,7 +513,7 @@ struct I2CMaps {
500513
};
501514
const PinMap *I2CMaps::maps[] = { i2c_master_sda_pinmap(), i2c_master_scl_pinmap() };
502515
const char *const I2CMaps::pin_type_names[] = { "SDA", "SCL" };
503-
const char *const I2CMaps::name = "I2C";
516+
const char *const I2CMaps::name = I2C_NAME;
504517
typedef Port<2, I2CMaps, DefaultFormFactor, TF2> I2CPort;
505518
#endif
506519

@@ -513,7 +526,7 @@ struct PWMMaps {
513526
};
514527
const PinMap *PWMMaps::maps[] = { pwmout_pinmap() };
515528
const char *const PWMMaps::pin_type_names[] = { "PWM_OUT" };
516-
const char *const PWMMaps::name = "PWM";
529+
const char *const PWMMaps::name = PWM_NAME;
517530
typedef Port<1, PWMMaps, DefaultFormFactor, TF1> PWMPort;
518531
#endif
519532

@@ -526,7 +539,7 @@ struct AnaloginMaps {
526539
};
527540
const PinMap *AnaloginMaps::maps[] = { analogin_pinmap() };
528541
const char *const AnaloginMaps::pin_type_names[] = { "ADC_IN" };
529-
const char *const AnaloginMaps::name = "ADC";
542+
const char *const AnaloginMaps::name = ANALOGIN_NAME;
530543
typedef Port<1, AnaloginMaps, DefaultFormFactor, TF1> AnaloginPort;
531544
#endif
532545

@@ -539,7 +552,7 @@ struct AnalogoutMaps {
539552
};
540553
const PinMap *AnalogoutMaps::maps[] = { analogout_pinmap() };
541554
const char *const AnalogoutMaps::pin_type_names[] = { "DAC_OUT" };
542-
const char *const AnalogoutMaps::name = "DAC";
555+
const char *const AnalogoutMaps::name = ANALOGOUT_NAME;
543556
typedef Port<1, AnalogoutMaps, DefaultFormFactor, TF1> AnalogoutPort;
544557
#endif
545558

@@ -553,7 +566,7 @@ struct UARTMaps {
553566
};
554567
const PinMap *UARTMaps::maps[] = { serial_tx_pinmap(), serial_rx_pinmap(), serial_cts_pinmap(), serial_rts_pinmap() };
555568
const char *const UARTMaps::pin_type_names[] = { "TX", "RX", "CLS", "RTS" };
556-
const char *const UARTMaps::name = "UART";
569+
const char *const UARTMaps::name = UART_NAME;
557570
typedef Port<4, UARTMaps, DefaultFormFactor, TF4> UARTPort;
558571
#endif
559572

@@ -564,8 +577,7 @@ struct UARTNoFCMaps {
564577
};
565578
const PinMap *UARTNoFCMaps::maps[] = { serial_tx_pinmap(), serial_rx_pinmap() };
566579
const char *const UARTNoFCMaps::pin_type_names[] = { "TX", "RX" };
567-
const char *const UARTNoFCMaps::name = "UART-no-FC";
580+
const char *const UARTNoFCMaps::name = UARTNOFC_NAME;
568581
typedef Port<2, UARTNoFCMaps, DefaultFormFactor, TF2> UARTNoFCPort;
569582
#endif
570-
571583
#endif

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

Lines changed: 10 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
@@ -78,11 +79,17 @@ MBED_WEAK const PinList *pinmap_restricted_pins()
7879
}
7980

8081
//*** Default restricted peripherals ***
81-
MBED_WEAK const PeripheralList *pinmap_restricted_peripherals()
82+
MBED_WEAK const PeripheralList *pinmap_uart_restricted_peripherals()
8283
{
84+
static const int stdio_uart = pinmap_peripheral(STDIO_UART_TX, serial_tx_pinmap());
85+
86+
static const int peripherals[] = {
87+
stdio_uart
88+
};
89+
8390
static const PeripheralList peripheral_list = {
84-
0,
85-
0
91+
sizeof peripherals / sizeof peripherals[0],
92+
peripherals
8693
};
8794
return &peripheral_list;
8895
}

hal/pinmap.h

Lines changed: 7 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,15 @@ 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+
const PeripheralList *pinmap_uart_restricted_peripherals(void);
181178

182179
#ifdef TARGET_FF_ARDUINO
183180

0 commit comments

Comments
 (0)