diff --git a/components/testing/COMPONENT_FPGA_CI_TEST_SHIELD/test_utils.h b/components/testing/COMPONENT_FPGA_CI_TEST_SHIELD/test_utils.h index e439a45064a..efd5472b235 100644 --- a/components/testing/COMPONENT_FPGA_CI_TEST_SHIELD/test_utils.h +++ b/components/testing/COMPONENT_FPGA_CI_TEST_SHIELD/test_utils.h @@ -115,6 +115,11 @@ void find_ports(std::list &matched_ports, std::list ¬_mat FormFactorType::pin_to_string(port.pins[i]), port.pins[i]); continue; } + if (pinmap_list_has_peripheral(pinmap_restricted_peripherals(), port.peripheral)) { + utest_printf("Skipping %s peripheral %i with pin %s (%i)\r\n", pin_type, + port.peripheral, FormFactorType::pin_to_string(port.pins[i]), port.pins[i]); + continue; + } // skipp pin searching if single pin port type if (PortType::pin_count > 1) { find_port_pins(port); diff --git a/hal/mbed_pinmap_common.c b/hal/mbed_pinmap_common.c index aff140ea4d9..2c2643e0312 100644 --- a/hal/mbed_pinmap_common.c +++ b/hal/mbed_pinmap_common.c @@ -178,3 +178,12 @@ bool pinmap_list_has_pin(const PinList *list, PinName pin) return false; } +bool pinmap_list_has_peripheral(const PeripheralList *list, int peripheral) +{ + for (uint32_t i = 0; i < list->count; i++) { + if (list->peripheral[i] == peripheral) { + return true; + } + } + return false; +} diff --git a/hal/mbed_pinmap_default.c b/hal/mbed_pinmap_default.c index 780bb682520..dabfabc0caf 100644 --- a/hal/mbed_pinmap_default.c +++ b/hal/mbed_pinmap_default.c @@ -77,3 +77,12 @@ MBED_WEAK const PinList *pinmap_restricted_pins() return &pin_list; } +//*** Default restricted peripherals *** +MBED_WEAK const PeripheralList *pinmap_restricted_peripherals() +{ + static const PeripheralList peripheral_list = { + 0, + 0 + }; + return &peripheral_list; +} diff --git a/hal/pinmap.h b/hal/pinmap.h index b61183a169e..b2a8d560f07 100644 --- a/hal/pinmap.h +++ b/hal/pinmap.h @@ -38,6 +38,11 @@ typedef struct { const PinName *pins; } PinList; +typedef struct { + uint32_t count; + const int *peripheral; +} PeripheralList; + void pin_function(PinName pin, int function); void pin_mode(PinName pin, PinMode mode); @@ -123,6 +128,15 @@ bool pinmap_find_peripheral_pins(const PinList *whitelist, const PinList *blackl */ bool pinmap_list_has_pin(const PinList *list, PinName pin); +/** + * Check if the peripheral is in the list + * + * @param list peripheral list to check + * @param peripheral peripheral to check for in the list + * @return true if the peripheral is in the list, false otherwise + */ +bool pinmap_list_has_peripheral(const PeripheralList *list, int peripheral); + /** * Get the pin list of pins to avoid during testing * @@ -139,6 +153,31 @@ bool pinmap_list_has_pin(const PinList *list, PinName pin); */ const PinList *pinmap_restricted_pins(void); +/** + * Get the pin list of peripherals to avoid during testing + * + * The restricted peripheral list is used to indicate to testing + * that a peripheral should be skipped due to some caveat about it. + * For example, using the USB serial port during tests will interfere + * with the test runner and should be avoided. + * + * Targets should override the weak implementation of this + * function if they have peripherals which should be + * skipped during testing. + * + * @note Some targets use the same value for multiple + * different types of peripherals. For example SPI 0 + * and UART 0 may both be identified by the peripheral + * value 0. If your target does this then do not + * use this function to skip peripherals, as this will + * unintentionally cause all peripherals with that value + * to be skipped. Instead these entries should be removed + * from the peripheral PinMap itself. + * + * @return Pointer to a peripheral list of peripheral to avoid + */ +const PeripheralList *pinmap_restricted_peripherals(void); + #ifdef TARGET_FF_ARDUINO /**