Skip to content

Commit b228a69

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 787b64a commit b228a69

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 UARTMAPS_NAME "UART"
24+
#define UARTNOFCMAPS_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, UARTMAPS_NAME) || !strcmp(PortType::PinMap::name, UARTNOFCMAPS_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);
@@ -462,7 +475,7 @@ struct SPIMaps {
462475
};
463476
const PinMap *SPIMaps::maps[] = { spi_master_mosi_pinmap(), spi_master_miso_pinmap(), spi_master_clk_pinmap(), spi_master_cs_pinmap() };
464477
const char *const SPIMaps::pin_type_names[] = { "MOSI", "MISO", "SCLK", "SSEL" };
465-
const char *const SPIMaps::name = "SPI";
478+
const char *const SPIMaps::name = SPI_NAME;
466479
typedef Port<4, SPIMaps, DefaultFormFactor, TF4> SPIPort;
467480

468481
struct SPINoCSMaps {
@@ -472,7 +485,7 @@ struct SPINoCSMaps {
472485
};
473486
const PinMap *SPINoCSMaps::maps[] = { spi_master_mosi_pinmap(), spi_master_miso_pinmap(), spi_master_clk_pinmap()};
474487
const char *const SPINoCSMaps::pin_type_names[] = { "MOSI", "MISO", "SCLK" };
475-
const char *const SPINoCSMaps::name = "SPI";
488+
const char *const SPINoCSMaps::name = SPI_NAME;
476489
typedef Port<3, SPINoCSMaps, DefaultFormFactor, TF3> SPINoCSPort;
477490

478491
struct SPISlaveMaps {
@@ -482,7 +495,7 @@ struct SPISlaveMaps {
482495
};
483496
const PinMap *SPISlaveMaps::maps[] = { spi_slave_mosi_pinmap(), spi_slave_miso_pinmap(), spi_slave_clk_pinmap(), spi_slave_cs_pinmap() };
484497
const char *const SPISlaveMaps::pin_type_names[] = { "MOSI", "MISO", "SCLK", "SSEL" };
485-
const char *const SPISlaveMaps::name = "SPISlave";
498+
const char *const SPISlaveMaps::name = SPISLAVE_NAME;
486499
typedef Port<4, SPISlaveMaps, DefaultFormFactor, TF4> SPISlavePort;
487500
#endif
488501

@@ -495,7 +508,7 @@ struct I2CMaps {
495508
};
496509
const PinMap *I2CMaps::maps[] = { i2c_master_sda_pinmap(), i2c_master_scl_pinmap() };
497510
const char *const I2CMaps::pin_type_names[] = { "SDA", "SCL" };
498-
const char *const I2CMaps::name = "I2C";
511+
const char *const I2CMaps::name = I2C_NAME;
499512
typedef Port<2, I2CMaps, DefaultFormFactor, TF2> I2CPort;
500513
#endif
501514

@@ -508,7 +521,7 @@ struct PWMMaps {
508521
};
509522
const PinMap *PWMMaps::maps[] = { pwmout_pinmap() };
510523
const char *const PWMMaps::pin_type_names[] = { "PWM_OUT" };
511-
const char *const PWMMaps::name = "PWM";
524+
const char *const PWMMaps::name = PWM_NAME;
512525
typedef Port<1, PWMMaps, DefaultFormFactor, TF1> PWMPort;
513526
#endif
514527

@@ -521,7 +534,7 @@ struct AnaloginMaps {
521534
};
522535
const PinMap *AnaloginMaps::maps[] = { analogin_pinmap() };
523536
const char *const AnaloginMaps::pin_type_names[] = { "ADC_IN" };
524-
const char *const AnaloginMaps::name = "ADC";
537+
const char *const AnaloginMaps::name = ANALOGIN_NAME;
525538
typedef Port<1, AnaloginMaps, DefaultFormFactor, TF1> AnaloginPort;
526539
#endif
527540

@@ -534,7 +547,7 @@ struct AnalogoutMaps {
534547
};
535548
const PinMap *AnalogoutMaps::maps[] = { analogout_pinmap() };
536549
const char *const AnalogoutMaps::pin_type_names[] = { "DAC_OUT" };
537-
const char *const AnalogoutMaps::name = "DAC";
550+
const char *const AnalogoutMaps::name = ANALOGOUT_NAME;
538551
typedef Port<1, AnalogoutMaps, DefaultFormFactor, TF1> AnalogoutPort;
539552
#endif
540553

@@ -548,7 +561,7 @@ struct UARTMaps {
548561
};
549562
const PinMap *UARTMaps::maps[] = { serial_tx_pinmap(), serial_rx_pinmap(), serial_cts_pinmap(), serial_rts_pinmap() };
550563
const char *const UARTMaps::pin_type_names[] = { "TX", "RX", "CLS", "RTS" };
551-
const char *const UARTMaps::name = "UART";
564+
const char *const UARTMaps::name = UARTMAPS_NAME;
552565
typedef Port<4, UARTMaps, DefaultFormFactor, TF4> UARTPort;
553566
#endif
554567

@@ -559,8 +572,7 @@ struct UARTNoFCMaps {
559572
};
560573
const PinMap *UARTNoFCMaps::maps[] = { serial_tx_pinmap(), serial_rx_pinmap() };
561574
const char *const UARTNoFCMaps::pin_type_names[] = { "TX", "RX" };
562-
const char *const UARTNoFCMaps::name = "UART-no-FC";
575+
const char *const UARTNoFCMaps::name = UARTNOFCMAPS_NAME;
563576
typedef Port<2, UARTNoFCMaps, DefaultFormFactor, TF2> UARTNoFCPort;
564577
#endif
565-
566578
#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)