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 f91152519b..f5f554eb15 100644 --- a/components/testing/COMPONENT_FPGA_CI_TEST_SHIELD/test_utils.h +++ b/components/testing/COMPONENT_FPGA_CI_TEST_SHIELD/test_utils.h @@ -20,6 +20,17 @@ #include +#define UART_NAME "UART" +#define UARTNOFC_NAME "UART-no-FC" +#define ANALOGOUT_NAME "DAC" +#define ANALOGIN_NAME "ADC" +#define PWM_NAME "PWM" +#define I2C_NAME "I2C" +#define SPI_NAME "SPI" +#define SPISLAVE_NAME "SPISlave" +#define GPIO_NAME "GPIO" +#define GPIO_IRQ_NAME "GPIO_IRQ" + // test function prototypes typedef void (*TF1)(PinName p0); typedef void (*TF2)(PinName p0, PinName p1); @@ -115,11 +126,26 @@ 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; + + if (!strcmp(PortType::PinMap::name, GPIO_IRQ_NAME) || !strcmp(PortType::PinMap::name, GPIO_NAME)) { + // Don't test restricted gpio pins + if (pinmap_list_has_pin(pinmap_gpio_restricted_pins(), port.pins[i])) { + utest_printf("Skipping %s pin %s (%i)\r\n", pin_type, + FormFactorType::pin_to_string(port.pins[i]), port.pins[i]); + continue; + } } + +#if DEVICE_SERIAL + if (!strcmp(PortType::PinMap::name, UART_NAME) || !strcmp(PortType::PinMap::name, UARTNOFC_NAME)) { + if (pinmap_list_has_peripheral(pinmap_uart_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; + } + } +#endif + // skipp pin searching if single pin port type if (PortType::pin_count > 1) { find_port_pins(port); @@ -442,7 +468,7 @@ struct GPIOMaps { }; const PinMap *GPIOMaps::maps[] = { gpio_pinmap() }; const char *const GPIOMaps::pin_type_names[] = { "IO" }; -const char *const GPIOMaps::name = "GPIO"; +const char *const GPIOMaps::name = GPIO_NAME; typedef Port<1, GPIOMaps, DefaultFormFactor, TF1> GPIOPort; #if DEVICE_INTERRUPTIN @@ -454,7 +480,7 @@ struct GPIOIRQMaps { }; const PinMap *GPIOIRQMaps::maps[] = { gpio_irq_pinmap() }; const char *const GPIOIRQMaps::pin_type_names[] = { "IRQ_IN" }; -const char *const GPIOIRQMaps::name = "GPIO_IRQ"; +const char *const GPIOIRQMaps::name = GPIO_IRQ_NAME; typedef Port<1, GPIOIRQMaps, DefaultFormFactor, TF1> GPIOIRQPort; #endif @@ -467,7 +493,7 @@ struct SPIMaps { }; const PinMap *SPIMaps::maps[] = { spi_master_mosi_pinmap(), spi_master_miso_pinmap(), spi_master_clk_pinmap(), spi_master_cs_pinmap() }; const char *const SPIMaps::pin_type_names[] = { "MOSI", "MISO", "SCLK", "SSEL" }; -const char *const SPIMaps::name = "SPI"; +const char *const SPIMaps::name = SPI_NAME; typedef Port<4, SPIMaps, DefaultFormFactor, TF4> SPIPort; struct SPINoCSMaps { @@ -477,7 +503,7 @@ struct SPINoCSMaps { }; const PinMap *SPINoCSMaps::maps[] = { spi_master_mosi_pinmap(), spi_master_miso_pinmap(), spi_master_clk_pinmap()}; const char *const SPINoCSMaps::pin_type_names[] = { "MOSI", "MISO", "SCLK" }; -const char *const SPINoCSMaps::name = "SPI"; +const char *const SPINoCSMaps::name = SPI_NAME; typedef Port<3, SPINoCSMaps, DefaultFormFactor, TF3> SPINoCSPort; struct SPISlaveMaps { @@ -487,7 +513,7 @@ struct SPISlaveMaps { }; const PinMap *SPISlaveMaps::maps[] = { spi_slave_mosi_pinmap(), spi_slave_miso_pinmap(), spi_slave_clk_pinmap(), spi_slave_cs_pinmap() }; const char *const SPISlaveMaps::pin_type_names[] = { "MOSI", "MISO", "SCLK", "SSEL" }; -const char *const SPISlaveMaps::name = "SPISlave"; +const char *const SPISlaveMaps::name = SPISLAVE_NAME; typedef Port<4, SPISlaveMaps, DefaultFormFactor, TF4> SPISlavePort; #endif @@ -500,7 +526,7 @@ struct I2CMaps { }; const PinMap *I2CMaps::maps[] = { i2c_master_sda_pinmap(), i2c_master_scl_pinmap() }; const char *const I2CMaps::pin_type_names[] = { "SDA", "SCL" }; -const char *const I2CMaps::name = "I2C"; +const char *const I2CMaps::name = I2C_NAME; typedef Port<2, I2CMaps, DefaultFormFactor, TF2> I2CPort; #endif @@ -513,7 +539,7 @@ struct PWMMaps { }; const PinMap *PWMMaps::maps[] = { pwmout_pinmap() }; const char *const PWMMaps::pin_type_names[] = { "PWM_OUT" }; -const char *const PWMMaps::name = "PWM"; +const char *const PWMMaps::name = PWM_NAME; typedef Port<1, PWMMaps, DefaultFormFactor, TF1> PWMPort; #endif @@ -526,7 +552,7 @@ struct AnaloginMaps { }; const PinMap *AnaloginMaps::maps[] = { analogin_pinmap() }; const char *const AnaloginMaps::pin_type_names[] = { "ADC_IN" }; -const char *const AnaloginMaps::name = "ADC"; +const char *const AnaloginMaps::name = ANALOGIN_NAME; typedef Port<1, AnaloginMaps, DefaultFormFactor, TF1> AnaloginPort; #endif @@ -539,7 +565,7 @@ struct AnalogoutMaps { }; const PinMap *AnalogoutMaps::maps[] = { analogout_pinmap() }; const char *const AnalogoutMaps::pin_type_names[] = { "DAC_OUT" }; -const char *const AnalogoutMaps::name = "DAC"; +const char *const AnalogoutMaps::name = ANALOGOUT_NAME; typedef Port<1, AnalogoutMaps, DefaultFormFactor, TF1> AnalogoutPort; #endif @@ -553,7 +579,7 @@ struct UARTMaps { }; const PinMap *UARTMaps::maps[] = { serial_tx_pinmap(), serial_rx_pinmap(), serial_cts_pinmap(), serial_rts_pinmap() }; const char *const UARTMaps::pin_type_names[] = { "TX", "RX", "CLS", "RTS" }; -const char *const UARTMaps::name = "UART"; +const char *const UARTMaps::name = UART_NAME; typedef Port<4, UARTMaps, DefaultFormFactor, TF4> UARTPort; #endif @@ -564,8 +590,7 @@ struct UARTNoFCMaps { }; const PinMap *UARTNoFCMaps::maps[] = { serial_tx_pinmap(), serial_rx_pinmap() }; const char *const UARTNoFCMaps::pin_type_names[] = { "TX", "RX" }; -const char *const UARTNoFCMaps::name = "UART-no-FC"; +const char *const UARTNoFCMaps::name = UARTNOFC_NAME; typedef Port<2, UARTNoFCMaps, DefaultFormFactor, TF2> UARTNoFCPort; #endif - #endif diff --git a/hal/mbed_pinmap_default.c b/hal/mbed_pinmap_default.cpp similarity index 79% rename from hal/mbed_pinmap_default.c rename to hal/mbed_pinmap_default.cpp index dabfabc0ca..45ac316691 100644 --- a/hal/mbed_pinmap_default.c +++ b/hal/mbed_pinmap_default.cpp @@ -20,6 +20,7 @@ #include "platform/mbed_toolchain.h" #include "platform/mbed_assert.h" #include "device.h" +#include "hal/serial_api.h" //*** Common form factors *** #ifdef TARGET_FF_ARDUINO @@ -77,12 +78,31 @@ MBED_WEAK const PinList *pinmap_restricted_pins() return &pin_list; } -//*** Default restricted peripherals *** -MBED_WEAK const PeripheralList *pinmap_restricted_peripherals() +//*** Default restricted gpio pins *** +// GPIO pins are special case because there are no pin-maps for GPIO +MBED_WEAK const PinList *pinmap_gpio_restricted_pins() { - static const PeripheralList peripheral_list = { + static const PinList pin_list = { 0, 0 }; + return &pin_list; +} + +//*** Default restricted peripherals *** +#if DEVICE_SERIAL +MBED_WEAK const PeripheralList *pinmap_uart_restricted_peripherals() +{ + static const int stdio_uart = pinmap_peripheral(STDIO_UART_TX, serial_tx_pinmap()); + + static const int peripherals[] = { + stdio_uart + }; + + static const PeripheralList peripheral_list = { + sizeof peripherals / sizeof peripherals[0], + peripherals + }; return &peripheral_list; } +#endif diff --git a/hal/pinmap.h b/hal/pinmap.h index 4fc0ec3740..f3af23b9d6 100644 --- a/hal/pinmap.h +++ b/hal/pinmap.h @@ -155,7 +155,7 @@ bool pinmap_list_has_peripheral(const PeripheralList *list, int peripheral); const PinList *pinmap_restricted_pins(void); /** - * Get the pin list of peripherals to avoid during testing + * Get the pin list of peripherals per interface 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. @@ -166,18 +166,34 @@ const PinList *pinmap_restricted_pins(void); * 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. + * @note Restricting peripheral is at the moment available for UART + * interface only as only STDIO UART must be skipped because it is + * used by Mbed. + * Restricting peripherals for other interfaces should be added + * in the future if required. * * @return Pointer to a peripheral list of peripheral to avoid */ -const PeripheralList *pinmap_restricted_peripherals(void); +#if DEVICE_SERIAL +const PeripheralList *pinmap_uart_restricted_peripherals(void); +#endif + +/** + * Get the pin list of pins to avoid during GPIO/GPIO_IRQ testing + * + * The GPIO restricted pin list is used to indicate to testing + * that a pin should be skipped due to some caveat about it. + * + * Targets should override the weak implementation of this + * function if they have peripherals which should be + * skipped during testing. + * + * @note This is special case only for GPIO/GPIO_IRQ tests because + * targets do not provide pin-maps for GPIO. + * + * @return Pointer to a peripheral list of peripheral to avoid + */ +const PinList *pinmap_gpio_restricted_pins(void); #ifdef TARGET_FF_ARDUINO diff --git a/targets/TARGET_NUVOTON/TARGET_M2351/pinmap.c b/targets/TARGET_NUVOTON/TARGET_M2351/pinmap.c index 0f8c9ccdca..7b630e7278 100644 --- a/targets/TARGET_NUVOTON/TARGET_M2351/pinmap.c +++ b/targets/TARGET_NUVOTON/TARGET_M2351/pinmap.c @@ -43,7 +43,7 @@ void pin_mode(PinName pin, PinMode mode) uint32_t pin_index = NU_PINNAME_TO_PIN(pin); uint32_t port_index = NU_PINNAME_TO_PORT(pin); GPIO_T *gpio_base = NU_PORT_BASE(port_index); - + uint32_t mode_intern = GPIO_MODE_INPUT; switch (mode) { @@ -81,21 +81,6 @@ void pin_mode(PinName pin, PinMode mode) */ } -/* List of peripherals excluded from testing */ -const PeripheralList *pinmap_restricted_peripherals() -{ - static const int perifs[] = { - STDIO_UART // Dedicated to USB VCOM - }; - - static const PeripheralList peripheral_list = { - sizeof(perifs) / sizeof(perifs[0]), - perifs - }; - - return &peripheral_list; -} - #if defined(__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) static void pin_function_impl(int32_t pin, int32_t data, bool nonsecure_caller) @@ -103,16 +88,16 @@ static void pin_function_impl(int32_t pin, int32_t data, bool nonsecure_caller) MBED_ASSERT(pin != (PinName)NC); uint32_t pin_index = NU_PINNAME_TO_PIN(pin); uint32_t port_index = NU_PINNAME_TO_PORT(pin); - + /* Guard access to secure GPIO from non-secure domain */ - if (nonsecure_caller && + if (nonsecure_caller && (! (SCU_INIT_IONSSET_VAL & (1 << (port_index + 0))))) { error("Non-secure domain tries to control secure or undefined GPIO."); } __IO uint32_t *GPx_MFPx = ((__IO uint32_t *) &SYS->GPA_MFPL) + port_index * 2 + (pin_index / 8); uint32_t MFP_Msk = NU_MFP_MSK(pin_index); - + // E.g.: SYS->GPA_MFPL = (SYS->GPA_MFPL & (~SYS_GPA_MFPL_PA0MFP_Msk) ) | SYS_GPA_MFPL_PA0MFP_SC0_CD ; *GPx_MFPx = (*GPx_MFPx & (~MFP_Msk)) | data; } diff --git a/targets/TARGET_NUVOTON/TARGET_M251/pinmap.c b/targets/TARGET_NUVOTON/TARGET_M251/pinmap.c index f18e3913a0..3fa6336a2b 100644 --- a/targets/TARGET_NUVOTON/TARGET_M251/pinmap.c +++ b/targets/TARGET_NUVOTON/TARGET_M251/pinmap.c @@ -83,18 +83,3 @@ void pin_mode(PinName pin, PinMode mode) * 2. PushPullOutput/PIN_INPUT */ } - -/* List of peripherals excluded from testing */ -const PeripheralList *pinmap_restricted_peripherals() -{ - static const int perifs[] = { - STDIO_UART // Dedicated to USB VCOM - }; - - static const PeripheralList peripheral_list = { - sizeof(perifs) / sizeof(perifs[0]), - perifs - }; - - return &peripheral_list; -} diff --git a/targets/TARGET_NUVOTON/TARGET_M261/pinmap.c b/targets/TARGET_NUVOTON/TARGET_M261/pinmap.c index 5c49354bb7..11dce0808e 100644 --- a/targets/TARGET_NUVOTON/TARGET_M261/pinmap.c +++ b/targets/TARGET_NUVOTON/TARGET_M261/pinmap.c @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2019-2020 Nuvoton Technology Corporation * SPDX-License-Identifier: Apache-2.0 * @@ -29,10 +29,10 @@ void pin_function(PinName pin, int data) MBED_ASSERT(pin != (PinName)NC); uint32_t pin_index = NU_PINNAME_TO_PIN(pin); uint32_t port_index = NU_PINNAME_TO_PORT(pin); - + __IO uint32_t *GPx_MFPx = ((__IO uint32_t *) &SYS->GPA_MFPL) + port_index * 2 + (pin_index / 8); uint32_t MFP_Msk = NU_MFP_MSK(pin_index); - + // E.g.: SYS->GPA_MFPL = (SYS->GPA_MFPL & (~SYS_GPA_MFPL_PA0MFP_Msk) ) | SYS_GPA_MFPL_PA0MFP_SC0_CD ; *GPx_MFPx = (*GPx_MFPx & (~MFP_Msk)) | data; } @@ -46,7 +46,7 @@ void pin_mode(PinName pin, PinMode mode) uint32_t pin_index = NU_PINNAME_TO_PIN(pin); uint32_t port_index = NU_PINNAME_TO_PORT(pin); GPIO_T *gpio_base = NU_PORT_BASE(port_index); - + uint32_t mode_intern = GPIO_MODE_INPUT; switch (mode) { @@ -83,18 +83,3 @@ void pin_mode(PinName pin, PinMode mode) * 2. PushPullOutput/PIN_INPUT */ } - -/* List of peripherals excluded from testing */ -const PeripheralList *pinmap_restricted_peripherals() -{ - static const int perifs[] = { - STDIO_UART // Dedicated to USB VCOM - }; - - static const PeripheralList peripheral_list = { - sizeof(perifs) / sizeof(perifs[0]), - perifs - }; - - return &peripheral_list; -} diff --git a/targets/TARGET_NUVOTON/TARGET_M451/pinmap.c b/targets/TARGET_NUVOTON/TARGET_M451/pinmap.c index 8da790154b..dcd10b6dc2 100644 --- a/targets/TARGET_NUVOTON/TARGET_M451/pinmap.c +++ b/targets/TARGET_NUVOTON/TARGET_M451/pinmap.c @@ -31,10 +31,10 @@ void pin_function(PinName pin, int data) __IO uint32_t *GPx_MFPx = ((__IO uint32_t *) &SYS->GPA_MFPL) + port_index * 2 + (pin_index / 8); //uint32_t MFP_Pos = NU_MFP_POS(pin_index); uint32_t MFP_Msk = NU_MFP_MSK(pin_index); - + // E.g.: SYS->GPA_MFPL = (SYS->GPA_MFPL & (~SYS_GPA_MFPL_PA0MFP_Msk) ) | SYS_GPA_MFPL_PA0MFP_SC0_CD ; *GPx_MFPx = (*GPx_MFPx & (~MFP_Msk)) | data; - + // [TODO] Disconnect JTAG-DP + SW-DP signals. // Warning: Need to reconnect under reset //if ((pin == PA_13) || (pin == PA_14)) { @@ -54,7 +54,7 @@ void pin_mode(PinName pin, PinMode mode) uint32_t pin_index = NU_PINNAME_TO_PIN(pin); uint32_t port_index = NU_PINNAME_TO_PORT(pin); GPIO_T *gpio_base = NU_PORT_BASE(port_index); - + uint32_t mode_intern = GPIO_MODE_INPUT; switch (mode) { @@ -91,18 +91,3 @@ void pin_mode(PinName pin, PinMode mode) * 2. PushPullOutput/PIN_INPUT */ } - -/* List of peripherals excluded from testing */ -const PeripheralList *pinmap_restricted_peripherals() -{ - static const int perifs[] = { - STDIO_UART // Dedicated to USB VCOM - }; - - static const PeripheralList peripheral_list = { - sizeof(perifs) / sizeof(perifs[0]), - perifs - }; - - return &peripheral_list; -} diff --git a/targets/TARGET_NUVOTON/TARGET_M480/pinmap.c b/targets/TARGET_NUVOTON/TARGET_M480/pinmap.c index 2a6c43cb3f..5101095474 100644 --- a/targets/TARGET_NUVOTON/TARGET_M480/pinmap.c +++ b/targets/TARGET_NUVOTON/TARGET_M480/pinmap.c @@ -97,18 +97,3 @@ const PinList *pinmap_restricted_pins() }; return &pin_list; } - -/* List of peripherals excluded from testing */ -const PeripheralList *pinmap_restricted_peripherals() -{ - static const int perifs[] = { - STDIO_UART // Dedicated to USB VCOM - }; - - static const PeripheralList peripheral_list = { - sizeof(perifs) / sizeof(perifs[0]), - perifs - }; - - return &peripheral_list; -} diff --git a/targets/TARGET_NUVOTON/TARGET_NANO100/pinmap.c b/targets/TARGET_NUVOTON/TARGET_NANO100/pinmap.c index 0fa193d741..c364c066af 100644 --- a/targets/TARGET_NUVOTON/TARGET_NANO100/pinmap.c +++ b/targets/TARGET_NUVOTON/TARGET_NANO100/pinmap.c @@ -30,7 +30,7 @@ void pin_function(PinName pin, int data) uint32_t port_index = NU_PINNAME_TO_PORT(pin); __IO uint32_t *Px_x_MFP = ((__IO uint32_t *) &SYS->PA_L_MFP) + port_index * 2 + (pin_index / 8); uint32_t MFP_Msk = NU_MFP_MSK(pin_index); - + // E.g.: SYS->PA_L_MFP = (SYS->PA_L_MFP & (~SYS_PA_L_MFP_PA0_MFP_Msk) ) | SYS_PA_L_MFP_PA0_MFP_SC0_CD ; *Px_x_MFP = (*Px_x_MFP & (~MFP_Msk)) | data; } @@ -44,7 +44,7 @@ void pin_mode(PinName pin, PinMode mode) uint32_t pin_index = NU_PINNAME_TO_PIN(pin); uint32_t port_index = NU_PINNAME_TO_PORT(pin); GPIO_T *gpio_base = NU_PORT_BASE(port_index); - + uint32_t mode_intern; switch (mode) { @@ -59,7 +59,7 @@ void pin_mode(PinName pin, PinMode mode) case OpenDrain: mode_intern = GPIO_PMD_OPEN_DRAIN; break; - + default: /* H/W doesn't support separate configuration for input pull mode/direction. * We expect upper layer would have translated input pull mode/direction @@ -77,18 +77,3 @@ void pin_mode(PinName pin, PinMode mode) * 2. PushPullOutput/PIN_INPUT */ } - -/* List of peripherals excluded from testing */ -const PeripheralList *pinmap_restricted_peripherals() -{ - static const int perifs[] = { - STDIO_UART // Dedicated to USB VCOM - }; - - static const PeripheralList peripheral_list = { - sizeof(perifs) / sizeof(perifs[0]), - perifs - }; - - return &peripheral_list; -} diff --git a/targets/TARGET_NUVOTON/TARGET_NUC472/pinmap.c b/targets/TARGET_NUVOTON/TARGET_NUC472/pinmap.c index f07ba20450..cd2cc107a0 100644 --- a/targets/TARGET_NUVOTON/TARGET_NUC472/pinmap.c +++ b/targets/TARGET_NUVOTON/TARGET_NUC472/pinmap.c @@ -31,10 +31,10 @@ void pin_function(PinName pin, int data) __IO uint32_t *GPx_MFPx = ((__IO uint32_t *) &SYS->GPA_MFPL) + port_index * 2 + (pin_index / 8); //uint32_t MFP_Pos = NU_MFP_POS(pin_index); uint32_t MFP_Msk = NU_MFP_MSK(pin_index); - + // E.g.: SYS->GPA_MFPL = (SYS->GPA_MFPL & (~SYS_GPA_MFPL_PA0MFP_Msk) ) | SYS_GPA_MFPL_PA0MFP_SC0_CD ; *GPx_MFPx = (*GPx_MFPx & (~MFP_Msk)) | data; - + // [TODO] Disconnect JTAG-DP + SW-DP signals. // Warning: Need to reconnect under reset //if ((pin == PA_13) || (pin == PA_14)) { @@ -54,7 +54,7 @@ void pin_mode(PinName pin, PinMode mode) uint32_t pin_index = NU_PINNAME_TO_PIN(pin); uint32_t port_index = NU_PINNAME_TO_PORT(pin); GPIO_T *gpio_base = NU_PORT_BASE(port_index); - + uint32_t mode_intern; switch (mode) { @@ -91,18 +91,3 @@ void pin_mode(PinName pin, PinMode mode) * 2. PushPullOutput/PIN_INPUT */ } - -/* List of peripherals excluded from testing */ -const PeripheralList *pinmap_restricted_peripherals() -{ - static const int perifs[] = { - STDIO_UART // Dedicated to USB VCOM - }; - - static const PeripheralList peripheral_list = { - sizeof(perifs) / sizeof(perifs[0]), - perifs - }; - - return &peripheral_list; -}