Skip to content

Commit 9d453cc

Browse files
jeromecoutantgpsimenos
authored andcommitted
[STD-PIN] ARDUINO_UNO pins
- hal/include/hal/ArduinoUnoAliases.h creation - doc update
1 parent a4350f7 commit 9d453cc

File tree

6 files changed

+165
-61
lines changed

6 files changed

+165
-61
lines changed

docs/design-documents/hal/0005-pin-names-Arduino-Uno-standard.md

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ The Arduino Uno (Rev3) form factor for Mbed boards must support and define both
6161

6262
The analog input signals in the Arduino Uno connector must be supported on at least the Ax pins.
6363

64-
// Arduino Uno (Rev3) connector pin connection naming
64+
#ifdef TARGET_FF_ARDUINO_UNO
65+
// Arduino Uno (Rev3) pins
6566
// Px_xx relates to the processor pin connected to the Arduino Uno (Rev3) connector pin
66-
6767
ARDUINO_UNO_D0 = Px_xx,
6868
ARDUINO_UNO_D1 = Px_xx,
6969
ARDUINO_UNO_D2 = Px_xx,
@@ -87,12 +87,13 @@ The analog input signals in the Arduino Uno connector must be supported on at le
8787
ARDUINO_UNO_A3 = Px_xx,
8888
ARDUINO_UNO_A4 = Px_xx,
8989
ARDUINO_UNO_A5 = Px_xx,
90+
#endif // TARGET_FF_ARDUINO_UNO
9091

9192
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.
9293

9394
**I2C, SPI and UART definition**
9495

95-
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:
96+
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:
9697

9798
#ifdef TARGET_FF_ARDUINO_UNO
9899
// Arduino Uno I2C signals aliases
@@ -108,7 +109,6 @@ All I2C, SPI and UART pin name alias definitions for the Arduino Uno (Rev3) conn
108109
// Arduino Uno UART signals aliases
109110
#define ARDUINO_UNO_UART_TX ARDUINO_UNO_D1
110111
#define ARDUINO_UNO_UART_RX ARDUINO_UNO_D0
111-
112112
#endif // TARGET_FF_ARDUINO_UNO
113113

114114
**Other pin functions**
@@ -197,14 +197,14 @@ There should be both compile and run time checks to confirm whether a board has
197197
- PWM compatibility on `ARDUINO_UNO_D3/D5/D6/D9/D10/D11`
198198
- Analog compatibility on `ARDUINO_UNO_A0/A1/A2/A3/A4/A5`
199199

200-
There is a proposal [here](https://github.com/ARMmbed/mbed-os/compare/master...jeromecoutant:DEV_STANDARDIZATION) on how to perform tests on pins.
201200

202-
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).
201+
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).
203202

204-
The tests could be compiled and run unsing Greentea as shown here:
203+
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).
205204

206-
mbed test -t <toolchain> -m <target> -n *test_arduino_uno_pin_names* --compile
207-
mbed test -t <toolchain> -m <target> -n *test_arduino_uno_pin_names* --run
205+
mbed test -t <toolchain> -m <target> -v -n hal-tests-tests-pin_names-arduino_uno
206+
207+
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).
208208

209209
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.
210210

@@ -217,12 +217,16 @@ There are a number of changes and enhancements required to introduce support for
217217

218218
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.
219219

220-
The following files should be created or updated with a Arduino Uno specific implementation:
220+
In targets.json, "ARDUINO_UNO" has to be added in "supported_form_factors"
221+
222+
The following files has been created for Arduino Uno:
223+
224+
- hal/include/hal/ArduinoUnoAliases.h
225+
- hal/tests/TESTS/pin_names/arduino_uno/main.cpp
226+
227+
The following files has been updated:
221228

222-
- https://github.com/ARMmbed/mbed-os/blob/master/hal/ArduinoUnoAliases.h (new)
223-
- https://github.com/ARMmbed/mbed-os/blob/master/hal/mbed_pinmap_default.cpp
224-
- https://github.com/ARMmbed/mbed-os/blob/master/hal/mbed_gpio.c
225-
- https://github.com/ARMmbed/mbed-os/blob/master/targets/targets.json
226-
- https://github.com/ARMmbed/mbed-os/blob/master/hal/pinmap.h
227-
- https://github.com/ARMmbed/mbed-os/tree/master/TESTS/arduino_uno_pin_names (new)
228-
- https://github.com/ARMmbed/mbed-os/tree/master/TESTS/mbed_hal_fpga_ci_test_shield
229+
- hal/source/mbed_pinmap_default.cpp
230+
- hal/source/mbed_gpio.c
231+
- hal/include/hal/pinmap.h
232+
- hal/tests/TESTS/mbed_hal_fpga_ci_test_shield/*/main.cpp

hal/include/hal/ArduinoUnoAliases.h

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
2+
/** \addtogroup hal */
3+
/** @{*/
4+
/* mbed Microcontroller Library
5+
* Copyright (c) 2020 ARM Limited
6+
* SPDX-License-Identifier: Apache-2.0
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
#ifndef MBED_ARDUINO_UNO_H
21+
#define MBED_ARDUINO_UNO_H
22+
23+
#if defined (TARGET_FF_ARDUINO) || (TARGET_FF_ARDUINO_UNO)
24+
25+
#ifdef TARGET_FF_ARDUINO_UNO
26+
27+
#define A0 ARDUINO_UNO_A0
28+
#define A1 ARDUINO_UNO_A1
29+
#define A2 ARDUINO_UNO_A2
30+
#define A3 ARDUINO_UNO_A3
31+
#define A4 ARDUINO_UNO_A4
32+
#define A5 ARDUINO_UNO_A5
33+
#define D0 ARDUINO_UNO_D0
34+
#define D1 ARDUINO_UNO_D1
35+
#define D2 ARDUINO_UNO_D2
36+
#define D3 ARDUINO_UNO_D3
37+
#define D4 ARDUINO_UNO_D4
38+
#define D5 ARDUINO_UNO_D5
39+
#define D6 ARDUINO_UNO_D6
40+
#define D7 ARDUINO_UNO_D7
41+
#define D8 ARDUINO_UNO_D8
42+
#define D9 ARDUINO_UNO_D9
43+
#define D10 ARDUINO_UNO_D10
44+
#define D11 ARDUINO_UNO_D11
45+
#define D12 ARDUINO_UNO_D12
46+
#define D13 ARDUINO_UNO_D13
47+
#define D14 ARDUINO_UNO_D14
48+
#define D15 ARDUINO_UNO_D15
49+
50+
#endif // TARGET_FF_ARDUINO_UNO
51+
52+
#ifdef TARGET_FF_ARDUINO
53+
54+
#define ARDUINO_UNO_A0 A0
55+
#define ARDUINO_UNO_A1 A1
56+
#define ARDUINO_UNO_A2 A2
57+
#define ARDUINO_UNO_A3 A3
58+
#define ARDUINO_UNO_A4 A4
59+
#define ARDUINO_UNO_A5 A5
60+
#define ARDUINO_UNO_D0 D0
61+
#define ARDUINO_UNO_D1 D1
62+
#define ARDUINO_UNO_D2 D2
63+
#define ARDUINO_UNO_D3 D3
64+
#define ARDUINO_UNO_D4 D4
65+
#define ARDUINO_UNO_D5 D5
66+
#define ARDUINO_UNO_D6 D6
67+
#define ARDUINO_UNO_D7 D7
68+
#define ARDUINO_UNO_D8 D8
69+
#define ARDUINO_UNO_D9 D9
70+
#define ARDUINO_UNO_D10 D10
71+
#define ARDUINO_UNO_D11 D11
72+
#define ARDUINO_UNO_D12 D12
73+
#define ARDUINO_UNO_D13 D13
74+
#define ARDUINO_UNO_D14 D14
75+
#define ARDUINO_UNO_D15 D15
76+
77+
#endif // TARGET_FF_ARDUINO
78+
79+
// Arduino Uno I2C signals aliases
80+
#define ARDUINO_UNO_I2C_SDA ARDUINO_UNO_D14
81+
#define ARDUINO_UNO_I2C_SCL ARDUINO_UNO_D15
82+
83+
// Arduino Uno SPI signals aliases
84+
#define ARDUINO_UNO_SPI_CS ARDUINO_UNO_D10
85+
#define ARDUINO_UNO_SPI_MOSI ARDUINO_UNO_D11
86+
#define ARDUINO_UNO_SPI_MISO ARDUINO_UNO_D12
87+
#define ARDUINO_UNO_SPI_SCK ARDUINO_UNO_D13
88+
89+
// Arduino Uno UART signals aliases
90+
#define ARDUINO_UNO_UART_TX ARDUINO_UNO_D1
91+
#define ARDUINO_UNO_UART_RX ARDUINO_UNO_D0
92+
93+
#endif // (TARGET_FF_ARDUINO) || (TARGET_FF_ARDUINO_UNO)
94+
95+
#endif // MBED_ARDUINO_UNO_H
96+
97+
/** @}*/

hal/include/hal/pinmap.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,26 +195,26 @@ const PeripheralList *pinmap_uart_restricted_peripherals(void);
195195
*/
196196
const PinList *pinmap_gpio_restricted_pins(void);
197197

198-
#ifdef TARGET_FF_ARDUINO
198+
#if defined (TARGET_FF_ARDUINO) || (TARGET_FF_ARDUINO_UNO)
199199

200200
/**
201201
* Get the pin list of the Arduino form factor
202202
*
203203
* @return Pointer to the Arduino pin list
204204
*/
205-
const PinList *pinmap_ff_arduino_pins(void);
205+
const PinList *pinmap_ff_arduino_uno_pins(void);
206206

207207
/**
208208
* Get the string representation of a form factor pin
209209
*
210210
* @param pin Pin to get a string for
211211
* @return String representing the form factor pin
212212
*/
213-
const char *pinmap_ff_arduino_pin_to_string(PinName pin);
213+
const char *pinmap_ff_arduino_uno_pin_to_string(PinName pin);
214214

215215
/* Default to arduino form factor if unspecified */
216216
#ifndef MBED_CONF_TARGET_DEFAULT_FORM_FACTOR
217-
#define MBED_CONF_TARGET_DEFAULT_FORM_FACTOR arduino
217+
#define MBED_CONF_TARGET_DEFAULT_FORM_FACTOR arduino_uno
218218
#endif
219219

220220
#endif

hal/source/mbed_gpio.c

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
#include "hal/gpio_api.h"
1818
#include "platform/mbed_toolchain.h"
19+
#include "hal/ArduinoUnoAliases.h"
1920

2021
static inline void _gpio_init_in(gpio_t *gpio, PinName pin, PinMode mode)
2122
{
@@ -77,7 +78,7 @@ MBED_WEAK void gpio_get_capabilities(gpio_t *gpio, gpio_capabilities_t *cap)
7778
cap->pull_up = 1;
7879
}
7980

80-
#ifdef TARGET_FF_ARDUINO
81+
#if defined (TARGET_FF_ARDUINO) || (TARGET_FF_ARDUINO_UNO)
8182

8283
typedef enum {
8384
DEFAULT_GPIO = 0,
@@ -87,28 +88,28 @@ MBED_WEAK const PinMap *gpio_pinmap()
8788
{
8889
// Targets should override this weak implementation to provide correct data.
8990
static const PinMap empty_gpio_pinmap[] = {
90-
{D0, DEFAULT_GPIO, 0},
91-
{D1, DEFAULT_GPIO, 0},
92-
{D2, DEFAULT_GPIO, 0},
93-
{D3, DEFAULT_GPIO, 0},
94-
{D4, DEFAULT_GPIO, 0},
95-
{D5, DEFAULT_GPIO, 0},
96-
{D6, DEFAULT_GPIO, 0},
97-
{D7, DEFAULT_GPIO, 0},
98-
{D8, DEFAULT_GPIO, 0},
99-
{D9, DEFAULT_GPIO, 0},
100-
{D10, DEFAULT_GPIO, 0},
101-
{D11, DEFAULT_GPIO, 0},
102-
{D12, DEFAULT_GPIO, 0},
103-
{D13, DEFAULT_GPIO, 0},
104-
{D14, DEFAULT_GPIO, 0},
105-
{D15, DEFAULT_GPIO, 0},
106-
{A0, DEFAULT_GPIO, 0},
107-
{A1, DEFAULT_GPIO, 0},
108-
{A2, DEFAULT_GPIO, 0},
109-
{A3, DEFAULT_GPIO, 0},
110-
{A4, DEFAULT_GPIO, 0},
111-
{A5, DEFAULT_GPIO, 0},
91+
{ARDUINO_UNO_D0, DEFAULT_GPIO, 0},
92+
{ARDUINO_UNO_D1, DEFAULT_GPIO, 0},
93+
{ARDUINO_UNO_D2, DEFAULT_GPIO, 0},
94+
{ARDUINO_UNO_D3, DEFAULT_GPIO, 0},
95+
{ARDUINO_UNO_D4, DEFAULT_GPIO, 0},
96+
{ARDUINO_UNO_D5, DEFAULT_GPIO, 0},
97+
{ARDUINO_UNO_D6, DEFAULT_GPIO, 0},
98+
{ARDUINO_UNO_D7, DEFAULT_GPIO, 0},
99+
{ARDUINO_UNO_D8, DEFAULT_GPIO, 0},
100+
{ARDUINO_UNO_D9, DEFAULT_GPIO, 0},
101+
{ARDUINO_UNO_D10, DEFAULT_GPIO, 0},
102+
{ARDUINO_UNO_D11, DEFAULT_GPIO, 0},
103+
{ARDUINO_UNO_D12, DEFAULT_GPIO, 0},
104+
{ARDUINO_UNO_D13, DEFAULT_GPIO, 0},
105+
{ARDUINO_UNO_D14, DEFAULT_GPIO, 0},
106+
{ARDUINO_UNO_D15, DEFAULT_GPIO, 0},
107+
{ARDUINO_UNO_A0, DEFAULT_GPIO, 0},
108+
{ARDUINO_UNO_A1, DEFAULT_GPIO, 0},
109+
{ARDUINO_UNO_A2, DEFAULT_GPIO, 0},
110+
{ARDUINO_UNO_A3, DEFAULT_GPIO, 0},
111+
{ARDUINO_UNO_A4, DEFAULT_GPIO, 0},
112+
{ARDUINO_UNO_A5, DEFAULT_GPIO, 0},
112113

113114
{NC, NC, 0},
114115
};

hal/source/mbed_pinmap_default.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,49 +21,50 @@
2121
#include "platform/mbed_assert.h"
2222
#include "device.h"
2323
#include "hal/serial_api.h"
24+
#include "hal/ArduinoUnoAliases.h"
2425

2526
//*** Common form factors ***
26-
#ifdef TARGET_FF_ARDUINO
27+
#if defined (TARGET_FF_ARDUINO) || (TARGET_FF_ARDUINO_UNO)
2728

28-
static const PinName ff_arduino_pins[] = {
29-
D0, D1, D2, D3, D4, D5, D6, D7,
30-
D8, D9, D10, D11, D12, D13, D14, D15,
31-
A0, A1, A2, A3, A4, A5
29+
static const PinName ff_arduino_uno_pins[] = {
30+
ARDUINO_UNO_D0, ARDUINO_UNO_D1, ARDUINO_UNO_D2, ARDUINO_UNO_D3, ARDUINO_UNO_D4, ARDUINO_UNO_D5, ARDUINO_UNO_D6, ARDUINO_UNO_D7,
31+
ARDUINO_UNO_D8, ARDUINO_UNO_D9, ARDUINO_UNO_D10, ARDUINO_UNO_D11, ARDUINO_UNO_D12, ARDUINO_UNO_D13, ARDUINO_UNO_D14, ARDUINO_UNO_D15,
32+
ARDUINO_UNO_A0, ARDUINO_UNO_A1, ARDUINO_UNO_A2, ARDUINO_UNO_A3, ARDUINO_UNO_A4, ARDUINO_UNO_A5
3233
};
3334

34-
static const char *ff_arduino_names[] = {
35+
static const char *ff_arduino_uno_names[] = {
3536
"D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
3637
"D8", "D9", "D10", "D11", "D12", "D13", "D14", "D15",
3738
"A0", "A1", "A2", "A3", "A4", "A5"
3839
};
3940

40-
static const PinList ff_arduino_list = {
41-
sizeof(ff_arduino_pins) / sizeof(ff_arduino_pins[0]),
42-
ff_arduino_pins
41+
static const PinList ff_arduino_uno_list = {
42+
sizeof(ff_arduino_uno_pins) / sizeof(ff_arduino_uno_pins[0]),
43+
ff_arduino_uno_pins
4344
};
4445

4546
static_assert(sizeof(ff_arduino_pins) / sizeof(ff_arduino_pins[0]) == sizeof(ff_arduino_names) / sizeof(ff_arduino_names[0]),
4647
"Arrays must have the same length");
4748

48-
const PinList *pinmap_ff_arduino_pins()
49+
const PinList *pinmap_ff_arduino_uno_pins()
4950
{
50-
return &ff_arduino_list;
51+
return &ff_arduino_uno_list;
5152
}
5253

53-
const char *pinmap_ff_arduino_pin_to_string(PinName pin)
54+
const char *pinmap_ff_arduino_uno_pin_to_string(PinName pin)
5455
{
55-
if (pin == NC) {
56+
if (pin == (PinName)NC) {
5657
return "NC";
5758
}
58-
for (size_t i = 0; i < ff_arduino_list.count; i++) {
59-
if (ff_arduino_list.pins[i] == pin) {
60-
return ff_arduino_names[i];
59+
for (size_t i = 0; i < ff_arduino_uno_list.count; i++) {
60+
if (ff_arduino_uno_list.pins[i] == pin) {
61+
return ff_arduino_uno_names[i];
6162
}
6263
}
6364
return "Unknown";
6465
}
6566

66-
#endif
67+
#endif // defined (TARGET_FF_ARDUINO) || (TARGET_FF_ARDUINO_UNO)
6768

6869
//*** Default restricted pins ***
6970
MBED_WEAK const PinList *pinmap_restricted_pins()

platform/include/platform/platform.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "device.h"
2929
#include "PinNames.h"
3030
#include "PeripheralNames.h"
31+
#include "hal/ArduinoUnoAliases.h"
3132

3233
/** \defgroup platform-public-api Platform
3334
* \ingroup mbed-os-public

0 commit comments

Comments
 (0)