[STD-PIN] ARDUINO_UNO pins

- hal/include/hal/ArduinoUnoAliases.h creation
- doc update
pull/14381/head
jeromecoutant 2020-11-17 09:02:38 +01:00 committed by George Psimenos
parent a4350f72bd
commit 9d453cce68
6 changed files with 165 additions and 61 deletions

View File

@ -61,9 +61,9 @@ The Arduino Uno (Rev3) form factor for Mbed boards must support and define both
The analog input signals in the Arduino Uno connector must be supported on at least the Ax pins.
// Arduino Uno (Rev3) connector pin connection naming
#ifdef TARGET_FF_ARDUINO_UNO
// Arduino Uno (Rev3) pins
// Px_xx relates to the processor pin connected to the Arduino Uno (Rev3) connector pin
ARDUINO_UNO_D0 = Px_xx,
ARDUINO_UNO_D1 = Px_xx,
ARDUINO_UNO_D2 = Px_xx,
@ -87,12 +87,13 @@ The analog input signals in the Arduino Uno connector must be supported on at le
ARDUINO_UNO_A3 = Px_xx,
ARDUINO_UNO_A4 = Px_xx,
ARDUINO_UNO_A5 = Px_xx,
#endif // TARGET_FF_ARDUINO_UNO
If the development board has the Arduino Uno connector in hardware, but does not comply with the Arduino Uno standard, whether it be with alternate functionality pins or non connected pins, the board should not be defined as Arduino Uno compliant and `ARDUINO_UNO` should not be added as a supported form factor in targets.json. Note this may result in a warning being generated at compile time to inform the user.
**I2C, SPI and UART definition**
All I2C, SPI and UART pin name alias definitions for the Arduino Uno (Rev3) connector pins should be defined in ArduinoUnoAliases.h in the Mbed OS HAL (common to all Arduino Uno compliant targets) as follows:
All I2C, SPI and UART pin name alias definitions for the Arduino Uno (Rev3) connector pins is defined in the Mbed OS HAL (hal/include/hal/ArduinoUnoAliases.h) and are common to all Arduino Uno compliant targets:
#ifdef TARGET_FF_ARDUINO_UNO
// Arduino Uno I2C signals aliases
@ -108,7 +109,6 @@ All I2C, SPI and UART pin name alias definitions for the Arduino Uno (Rev3) conn
// Arduino Uno UART signals aliases
#define ARDUINO_UNO_UART_TX ARDUINO_UNO_D1
#define ARDUINO_UNO_UART_RX ARDUINO_UNO_D0
#endif // TARGET_FF_ARDUINO_UNO
**Other pin functions**
@ -197,14 +197,14 @@ There should be both compile and run time checks to confirm whether a board has
- PWM compatibility on `ARDUINO_UNO_D3/D5/D6/D9/D10/D11`
- Analog compatibility on `ARDUINO_UNO_A0/A1/A2/A3/A4/A5`
There is a proposal [here](https://github.com/ARMmbed/mbed-os/compare/master...jeromecoutant:DEV_STANDARDIZATION) on how to perform tests on pins.
Additionally, there should be tests on each of the Arduino Uno pins to confirm whether the required funcionality is implemented correctly. This can be achieved by using the FPGA test shield and the existing [tests](https://github.com/ARMmbed/mbed-os/tree/master/hal/tests/TESTS/mbed_hal_fpga_ci_test_shield).
A python script could check, during CI process, whether a board has valid ARDUINO_UNO pins defined (none equal to NC, and no duplicated pin values).
The tests could be compiled and run unsing Greentea as shown here:
Additionally, a Greentea test checks each of the Arduino Uno pins to confirm whether the required funcionality is implemented correctly (only API call check, no hardware signals checks).
mbed test -t <toolchain> -m <target> -n *test_arduino_uno_pin_names* --compile
mbed test -t <toolchain> -m <target> -n *test_arduino_uno_pin_names* --run
mbed test -t <toolchain> -m <target> -v -n hal-tests-tests-pin_names-arduino_uno
Hardware signal testing on pins can be achieved by using the FPGA test shield and the existing [tests](https://github.com/ARMmbed/mbed-os/tree/master/hal/tests/TESTS/mbed_hal_fpga_ci_test_shield).
If the target claims to support the `ARDUINO_UNO` formfactor in targets.json but no valid Arduino Uno pinnames are detected, then an error should be generated.
@ -217,12 +217,16 @@ There are a number of changes and enhancements required to introduce support for
Mbed OS currently includes the `ARDUINO` form factor although it's not considered a standard as it's poorly defined and there are no checks on specific pin names. The configuration for this form factor should continue to be available, although should be marked as deprecated amd aimed to be removed in the next version of Mbed OS.
The following files should be created or updated with a Arduino Uno specific implementation:
In targets.json, "ARDUINO_UNO" has to be added in "supported_form_factors"
- https://github.com/ARMmbed/mbed-os/blob/master/hal/ArduinoUnoAliases.h (new)
- https://github.com/ARMmbed/mbed-os/blob/master/hal/mbed_pinmap_default.cpp
- https://github.com/ARMmbed/mbed-os/blob/master/hal/mbed_gpio.c
- https://github.com/ARMmbed/mbed-os/blob/master/targets/targets.json
- https://github.com/ARMmbed/mbed-os/blob/master/hal/pinmap.h
- https://github.com/ARMmbed/mbed-os/tree/master/TESTS/arduino_uno_pin_names (new)
- https://github.com/ARMmbed/mbed-os/tree/master/TESTS/mbed_hal_fpga_ci_test_shield
The following files has been created for Arduino Uno:
- hal/include/hal/ArduinoUnoAliases.h
- hal/tests/TESTS/pin_names/arduino_uno/main.cpp
The following files has been updated:
- hal/source/mbed_pinmap_default.cpp
- hal/source/mbed_gpio.c
- hal/include/hal/pinmap.h
- hal/tests/TESTS/mbed_hal_fpga_ci_test_shield/*/main.cpp

View File

@ -0,0 +1,97 @@
/** \addtogroup hal */
/** @{*/
/* mbed Microcontroller Library
* Copyright (c) 2020 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBED_ARDUINO_UNO_H
#define MBED_ARDUINO_UNO_H
#if defined (TARGET_FF_ARDUINO) || (TARGET_FF_ARDUINO_UNO)
#ifdef TARGET_FF_ARDUINO_UNO
#define A0 ARDUINO_UNO_A0
#define A1 ARDUINO_UNO_A1
#define A2 ARDUINO_UNO_A2
#define A3 ARDUINO_UNO_A3
#define A4 ARDUINO_UNO_A4
#define A5 ARDUINO_UNO_A5
#define D0 ARDUINO_UNO_D0
#define D1 ARDUINO_UNO_D1
#define D2 ARDUINO_UNO_D2
#define D3 ARDUINO_UNO_D3
#define D4 ARDUINO_UNO_D4
#define D5 ARDUINO_UNO_D5
#define D6 ARDUINO_UNO_D6
#define D7 ARDUINO_UNO_D7
#define D8 ARDUINO_UNO_D8
#define D9 ARDUINO_UNO_D9
#define D10 ARDUINO_UNO_D10
#define D11 ARDUINO_UNO_D11
#define D12 ARDUINO_UNO_D12
#define D13 ARDUINO_UNO_D13
#define D14 ARDUINO_UNO_D14
#define D15 ARDUINO_UNO_D15
#endif // TARGET_FF_ARDUINO_UNO
#ifdef TARGET_FF_ARDUINO
#define ARDUINO_UNO_A0 A0
#define ARDUINO_UNO_A1 A1
#define ARDUINO_UNO_A2 A2
#define ARDUINO_UNO_A3 A3
#define ARDUINO_UNO_A4 A4
#define ARDUINO_UNO_A5 A5
#define ARDUINO_UNO_D0 D0
#define ARDUINO_UNO_D1 D1
#define ARDUINO_UNO_D2 D2
#define ARDUINO_UNO_D3 D3
#define ARDUINO_UNO_D4 D4
#define ARDUINO_UNO_D5 D5
#define ARDUINO_UNO_D6 D6
#define ARDUINO_UNO_D7 D7
#define ARDUINO_UNO_D8 D8
#define ARDUINO_UNO_D9 D9
#define ARDUINO_UNO_D10 D10
#define ARDUINO_UNO_D11 D11
#define ARDUINO_UNO_D12 D12
#define ARDUINO_UNO_D13 D13
#define ARDUINO_UNO_D14 D14
#define ARDUINO_UNO_D15 D15
#endif // TARGET_FF_ARDUINO
// Arduino Uno I2C signals aliases
#define ARDUINO_UNO_I2C_SDA ARDUINO_UNO_D14
#define ARDUINO_UNO_I2C_SCL ARDUINO_UNO_D15
// Arduino Uno SPI signals aliases
#define ARDUINO_UNO_SPI_CS ARDUINO_UNO_D10
#define ARDUINO_UNO_SPI_MOSI ARDUINO_UNO_D11
#define ARDUINO_UNO_SPI_MISO ARDUINO_UNO_D12
#define ARDUINO_UNO_SPI_SCK ARDUINO_UNO_D13
// Arduino Uno UART signals aliases
#define ARDUINO_UNO_UART_TX ARDUINO_UNO_D1
#define ARDUINO_UNO_UART_RX ARDUINO_UNO_D0
#endif // (TARGET_FF_ARDUINO) || (TARGET_FF_ARDUINO_UNO)
#endif // MBED_ARDUINO_UNO_H
/** @}*/

View File

@ -195,14 +195,14 @@ const PeripheralList *pinmap_uart_restricted_peripherals(void);
*/
const PinList *pinmap_gpio_restricted_pins(void);
#ifdef TARGET_FF_ARDUINO
#if defined (TARGET_FF_ARDUINO) || (TARGET_FF_ARDUINO_UNO)
/**
* Get the pin list of the Arduino form factor
*
* @return Pointer to the Arduino pin list
*/
const PinList *pinmap_ff_arduino_pins(void);
const PinList *pinmap_ff_arduino_uno_pins(void);
/**
* Get the string representation of a form factor pin
@ -210,11 +210,11 @@ const PinList *pinmap_ff_arduino_pins(void);
* @param pin Pin to get a string for
* @return String representing the form factor pin
*/
const char *pinmap_ff_arduino_pin_to_string(PinName pin);
const char *pinmap_ff_arduino_uno_pin_to_string(PinName pin);
/* Default to arduino form factor if unspecified */
#ifndef MBED_CONF_TARGET_DEFAULT_FORM_FACTOR
#define MBED_CONF_TARGET_DEFAULT_FORM_FACTOR arduino
#define MBED_CONF_TARGET_DEFAULT_FORM_FACTOR arduino_uno
#endif
#endif

View File

@ -16,6 +16,7 @@
*/
#include "hal/gpio_api.h"
#include "platform/mbed_toolchain.h"
#include "hal/ArduinoUnoAliases.h"
static inline void _gpio_init_in(gpio_t *gpio, PinName pin, PinMode mode)
{
@ -77,7 +78,7 @@ MBED_WEAK void gpio_get_capabilities(gpio_t *gpio, gpio_capabilities_t *cap)
cap->pull_up = 1;
}
#ifdef TARGET_FF_ARDUINO
#if defined (TARGET_FF_ARDUINO) || (TARGET_FF_ARDUINO_UNO)
typedef enum {
DEFAULT_GPIO = 0,
@ -87,28 +88,28 @@ MBED_WEAK const PinMap *gpio_pinmap()
{
// Targets should override this weak implementation to provide correct data.
static const PinMap empty_gpio_pinmap[] = {
{D0, DEFAULT_GPIO, 0},
{D1, DEFAULT_GPIO, 0},
{D2, DEFAULT_GPIO, 0},
{D3, DEFAULT_GPIO, 0},
{D4, DEFAULT_GPIO, 0},
{D5, DEFAULT_GPIO, 0},
{D6, DEFAULT_GPIO, 0},
{D7, DEFAULT_GPIO, 0},
{D8, DEFAULT_GPIO, 0},
{D9, DEFAULT_GPIO, 0},
{D10, DEFAULT_GPIO, 0},
{D11, DEFAULT_GPIO, 0},
{D12, DEFAULT_GPIO, 0},
{D13, DEFAULT_GPIO, 0},
{D14, DEFAULT_GPIO, 0},
{D15, DEFAULT_GPIO, 0},
{A0, DEFAULT_GPIO, 0},
{A1, DEFAULT_GPIO, 0},
{A2, DEFAULT_GPIO, 0},
{A3, DEFAULT_GPIO, 0},
{A4, DEFAULT_GPIO, 0},
{A5, DEFAULT_GPIO, 0},
{ARDUINO_UNO_D0, DEFAULT_GPIO, 0},
{ARDUINO_UNO_D1, DEFAULT_GPIO, 0},
{ARDUINO_UNO_D2, DEFAULT_GPIO, 0},
{ARDUINO_UNO_D3, DEFAULT_GPIO, 0},
{ARDUINO_UNO_D4, DEFAULT_GPIO, 0},
{ARDUINO_UNO_D5, DEFAULT_GPIO, 0},
{ARDUINO_UNO_D6, DEFAULT_GPIO, 0},
{ARDUINO_UNO_D7, DEFAULT_GPIO, 0},
{ARDUINO_UNO_D8, DEFAULT_GPIO, 0},
{ARDUINO_UNO_D9, DEFAULT_GPIO, 0},
{ARDUINO_UNO_D10, DEFAULT_GPIO, 0},
{ARDUINO_UNO_D11, DEFAULT_GPIO, 0},
{ARDUINO_UNO_D12, DEFAULT_GPIO, 0},
{ARDUINO_UNO_D13, DEFAULT_GPIO, 0},
{ARDUINO_UNO_D14, DEFAULT_GPIO, 0},
{ARDUINO_UNO_D15, DEFAULT_GPIO, 0},
{ARDUINO_UNO_A0, DEFAULT_GPIO, 0},
{ARDUINO_UNO_A1, DEFAULT_GPIO, 0},
{ARDUINO_UNO_A2, DEFAULT_GPIO, 0},
{ARDUINO_UNO_A3, DEFAULT_GPIO, 0},
{ARDUINO_UNO_A4, DEFAULT_GPIO, 0},
{ARDUINO_UNO_A5, DEFAULT_GPIO, 0},
{NC, NC, 0},
};

View File

@ -21,49 +21,50 @@
#include "platform/mbed_assert.h"
#include "device.h"
#include "hal/serial_api.h"
#include "hal/ArduinoUnoAliases.h"
//*** Common form factors ***
#ifdef TARGET_FF_ARDUINO
#if defined (TARGET_FF_ARDUINO) || (TARGET_FF_ARDUINO_UNO)
static const PinName ff_arduino_pins[] = {
D0, D1, D2, D3, D4, D5, D6, D7,
D8, D9, D10, D11, D12, D13, D14, D15,
A0, A1, A2, A3, A4, A5
static const PinName ff_arduino_uno_pins[] = {
ARDUINO_UNO_D0, ARDUINO_UNO_D1, ARDUINO_UNO_D2, ARDUINO_UNO_D3, ARDUINO_UNO_D4, ARDUINO_UNO_D5, ARDUINO_UNO_D6, ARDUINO_UNO_D7,
ARDUINO_UNO_D8, ARDUINO_UNO_D9, ARDUINO_UNO_D10, ARDUINO_UNO_D11, ARDUINO_UNO_D12, ARDUINO_UNO_D13, ARDUINO_UNO_D14, ARDUINO_UNO_D15,
ARDUINO_UNO_A0, ARDUINO_UNO_A1, ARDUINO_UNO_A2, ARDUINO_UNO_A3, ARDUINO_UNO_A4, ARDUINO_UNO_A5
};
static const char *ff_arduino_names[] = {
static const char *ff_arduino_uno_names[] = {
"D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
"D8", "D9", "D10", "D11", "D12", "D13", "D14", "D15",
"A0", "A1", "A2", "A3", "A4", "A5"
};
static const PinList ff_arduino_list = {
sizeof(ff_arduino_pins) / sizeof(ff_arduino_pins[0]),
ff_arduino_pins
static const PinList ff_arduino_uno_list = {
sizeof(ff_arduino_uno_pins) / sizeof(ff_arduino_uno_pins[0]),
ff_arduino_uno_pins
};
static_assert(sizeof(ff_arduino_pins) / sizeof(ff_arduino_pins[0]) == sizeof(ff_arduino_names) / sizeof(ff_arduino_names[0]),
"Arrays must have the same length");
const PinList *pinmap_ff_arduino_pins()
const PinList *pinmap_ff_arduino_uno_pins()
{
return &ff_arduino_list;
return &ff_arduino_uno_list;
}
const char *pinmap_ff_arduino_pin_to_string(PinName pin)
const char *pinmap_ff_arduino_uno_pin_to_string(PinName pin)
{
if (pin == NC) {
if (pin == (PinName)NC) {
return "NC";
}
for (size_t i = 0; i < ff_arduino_list.count; i++) {
if (ff_arduino_list.pins[i] == pin) {
return ff_arduino_names[i];
for (size_t i = 0; i < ff_arduino_uno_list.count; i++) {
if (ff_arduino_uno_list.pins[i] == pin) {
return ff_arduino_uno_names[i];
}
}
return "Unknown";
}
#endif
#endif // defined (TARGET_FF_ARDUINO) || (TARGET_FF_ARDUINO_UNO)
//*** Default restricted pins ***
MBED_WEAK const PinList *pinmap_restricted_pins()

View File

@ -28,6 +28,7 @@
#include "device.h"
#include "PinNames.h"
#include "PeripheralNames.h"
#include "hal/ArduinoUnoAliases.h"
/** \defgroup platform-public-api Platform
* \ingroup mbed-os-public