Skip to content

Add STDIO UART as restricted for FPGA testing for all targets and support for restricting GPIO #12379

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 41 additions & 16 deletions components/testing/COMPONENT_FPGA_CI_TEST_SHIELD/test_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@

#include <list>

#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);
Expand Down Expand Up @@ -115,11 +126,26 @@ void find_ports(std::list<PortType> &matched_ports, std::list<PortType> &not_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<PortType, FormFactorType>(port);
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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
26 changes: 23 additions & 3 deletions hal/mbed_pinmap_default.c → hal/mbed_pinmap_default.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
36 changes: 26 additions & 10 deletions hal/pinmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we've come full circle and come back to the idea from #10459. 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥇


#ifdef TARGET_FF_ARDUINO

Expand Down
23 changes: 4 additions & 19 deletions targets/TARGET_NUVOTON/TARGET_M2351/pinmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -81,38 +81,23 @@ 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)
{
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;
}
Expand Down
15 changes: 0 additions & 15 deletions targets/TARGET_NUVOTON/TARGET_M251/pinmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
23 changes: 4 additions & 19 deletions targets/TARGET_NUVOTON/TARGET_M261/pinmap.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright (c) 2019-2020 Nuvoton Technology Corporation
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -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;
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}
Loading