From 88210d454d739bdf8275e5399f6e15f35eb9cc29 Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Tue, 20 Aug 2019 12:23:25 +0200 Subject: [PATCH 01/36] Add spi_pinmap_t struct --- hal/spi_api.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/hal/spi_api.h b/hal/spi_api.h index a6ac1a3da42..942eb4c492a 100644 --- a/hal/spi_api.h +++ b/hal/spi_api.h @@ -51,6 +51,18 @@ typedef struct { */ typedef struct spi_s spi_t; +typedef struct { + const int peripheral; + const PinName mosi_pin; + const int mosi_function; + const PinName miso_pin; + const int miso_function; + const PinName sclk_pin; + const int sclk_function; + const PinName ssel_pin; + const int ssel_function; +} spi_pinmap_t; + #endif #ifdef __cplusplus From 4c1c27326a1942f2e7d7cac337f62fb73e793e8d Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Tue, 20 Aug 2019 13:11:18 +0200 Subject: [PATCH 02/36] Add spi_init_direct() function to HAL API --- hal/spi_api.h | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/hal/spi_api.h b/hal/spi_api.h index 942eb4c492a..a2ca9d2a836 100644 --- a/hal/spi_api.h +++ b/hal/spi_api.h @@ -51,20 +51,20 @@ typedef struct { */ typedef struct spi_s spi_t; +#endif + typedef struct { - const int peripheral; - const PinName mosi_pin; - const int mosi_function; - const PinName miso_pin; - const int miso_function; - const PinName sclk_pin; - const int sclk_function; - const PinName ssel_pin; - const int ssel_function; + int peripheral; + PinName mosi_pin; + int mosi_function; + PinName miso_pin; + int miso_function; + PinName sclk_pin; + int sclk_function; + PinName ssel_pin; + int ssel_function; } spi_pinmap_t; -#endif - #ifdef __cplusplus extern "C" { #endif @@ -85,6 +85,14 @@ extern "C" { SPIName spi_get_peripheral_name(PinName mosi, PinName miso, PinName mclk); #endif +/** Initialize the SPI peripheral + * + * Configures the pins used by SPI, sets a default format and frequency, and enables the peripheral + * @param[out] obj The SPI object to initialize + * @param[in] pinmap pointer to strucure which holds static pinmap + */ +void spi_init_direct(spi_t *obj, const spi_pinmap_t *pinmap); + /** Initialize the SPI peripheral * * Configures the pins used by SPI, sets a default format and frequency, and enables the peripheral From bd809916e8c8f395178824dde63d531a4f3787a2 Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Fri, 23 Aug 2019 10:00:37 +0200 Subject: [PATCH 03/36] Add default implementations of xxx_init_direct() functions for explicit pinmap. --- hal/explicit_pinmap.c | 83 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 hal/explicit_pinmap.c diff --git a/hal/explicit_pinmap.c b/hal/explicit_pinmap.c new file mode 100644 index 00000000000..d341de2efab --- /dev/null +++ b/hal/explicit_pinmap.c @@ -0,0 +1,83 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2019 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. + */ + +#include "mbed_error.h" +#include "spi_api.h" +#include "pwmout_api.h" +#include "analogin_api.h" +#include "analogout_api.h" +#include "i2c_api.h" +#include "serial_api.h" + + +/* + * This file provides default definitions of xxx_direct() functions for peripherals. + * in all cases standard init function is called, which won't give any ROM memory savings. + * + */ + +#if DEVICE_SPI +MBED_WEAK void spi_init_direct(spi_t *obj, const spi_pinmap_t *pinmap) +{ + spi_init(obj, pinmap->mosi_pin, pinmap->miso_pin, pinmap->sclk_pin, pinmap->ssel_pin); +} +#endif + +#if DEVICE_PWMOUT +MBED_WEAK void pwmout_init_direct(pwmout_t *obj, const PinMap *pinmap) +{ + pwmout_init(obj, pinmap->pin); +} +#endif + +#if DEVICE_ANALOGIN +MBED_WEAK void analogin_init_direct(analogin_t *obj, const PinMap *pinmap) +{ + printf("Pin: %d \r\n", pinmap->pin); + //wait_ns(5000); + + analogin_init(obj, pinmap->pin); +} +#endif + +#if DEVICE_ANALOGOUT +MBED_WEAK void analogout_init_direct(dac_t *obj, const PinMap *pinmap) +{ + analogout_init(obj, pinmap->pin); +} +#endif + +#if DEVICE_I2C +MBED_WEAK void i2c_init_direct(i2c_t *obj, const i2c_pinmap_t *pinmap) +{ + i2c_init(obj, pinmap->sda_pin, pinmap->scl_pin); +} +#endif + +#if DEVICE_SERIAL +MBED_WEAK void serial_init_direct(serial_t *obj, const serial_pinmap_t *pinmap) +{ + serial_init(obj, pinmap->tx_pin, pinmap->rx_pin); +} + +#if DEVICE_SERIAL_FC +MBED_WEAK void serial_set_flow_control_direct(serial_t *obj, FlowControl type, const serial_fc_pinmap_t *pinmap) +{ + serial_set_flow_control(obj, type, pinmap->rx_flow_pin, pinmap->tx_flow_pin); +} +#endif +#endif From 6bef6a5accd2b6dde63c16eb190fe4fd233b6b8b Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Tue, 20 Aug 2019 13:12:03 +0200 Subject: [PATCH 04/36] K64F SPI driver: Add explicit pinmap support --- .../TARGET_MCU_K64F/spi_api.c | 41 ++++++++++++++----- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/spi_api.c b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/spi_api.c index 01c2965bacd..215b285b474 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/spi_api.c +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/spi_api.c @@ -53,6 +53,29 @@ SPIName spi_get_peripheral_name(PinName mosi, PinName miso, PinName sclk) return spi_per; } +void spi_init_direct(spi_t *obj, const spi_pinmap_t *pinmap) +{ + obj->spi.instance = pinmap->peripheral; + MBED_ASSERT((int)obj->spi.instance != NC); + + // pin out the spi pins + pin_function(pinmap->mosi_pin, pinmap->mosi_function); + pin_mode(pinmap->mosi_pin, PullNone); + pin_function(pinmap->miso_pin, pinmap->miso_function); + pin_mode(pinmap->miso_pin, PullNone); + pin_function(pinmap->sclk_pin, pinmap->sclk_function); + pin_mode(pinmap->sclk_pin, PullNone); + if (pinmap->ssel_pin != NC) { + pin_function(pinmap->ssel_pin, pinmap->ssel_function); + pin_mode(pinmap->ssel_pin, PullNone); + } + + /* Set the transfer status to idle */ + obj->spi.status = kDSPI_Idle; + + obj->spi.spiDmaMasterRx.dmaUsageState = DMA_USAGE_OPPORTUNISTIC; +} + void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel) { // determine the SPI to use @@ -63,21 +86,17 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel uint32_t spi_data = pinmap_merge(spi_mosi, spi_miso); uint32_t spi_cntl = pinmap_merge(spi_sclk, spi_ssel); - obj->spi.instance = pinmap_merge(spi_data, spi_cntl); - MBED_ASSERT((int)obj->spi.instance != NC); + int peripheral = (int)pinmap_merge(spi_data, spi_cntl); // pin out the spi pins - pinmap_pinout(mosi, PinMap_SPI_MOSI); - pinmap_pinout(miso, PinMap_SPI_MISO); - pinmap_pinout(sclk, PinMap_SPI_SCLK); - if (ssel != NC) { - pinmap_pinout(ssel, PinMap_SPI_SSEL); - } + int mosi_function = (int)pinmap_find_function(mosi, PinMap_SPI_MOSI); + int miso_function = (int)pinmap_find_function(miso, PinMap_SPI_MISO); + int sclk_function = (int)pinmap_find_function(sclk, PinMap_SPI_SCLK); + int ssel_function = (int)pinmap_find_function(ssel, PinMap_SPI_SSEL); - /* Set the transfer status to idle */ - obj->spi.status = kDSPI_Idle; + const spi_pinmap_t explicit_spi_pinmap = {peripheral, mosi, mosi_function, miso, miso_function, sclk, sclk_function, ssel, ssel_function}; - obj->spi.spiDmaMasterRx.dmaUsageState = DMA_USAGE_OPPORTUNISTIC; + spi_init_direct(obj, &explicit_spi_pinmap); } void spi_free(spi_t *obj) From c3279d7cfbe1d72fd940c752e4a1c6255afae1cb Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Fri, 23 Aug 2019 09:45:40 +0200 Subject: [PATCH 05/36] STM SPI driver: Add explicit pinmap support --- targets/TARGET_STM/stm_spi_api.c | 66 ++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 21 deletions(-) diff --git a/targets/TARGET_STM/stm_spi_api.c b/targets/TARGET_STM/stm_spi_api.c index 525f731c890..282fa333472 100644 --- a/targets/TARGET_STM/stm_spi_api.c +++ b/targets/TARGET_STM/stm_spi_api.c @@ -111,21 +111,18 @@ SPIName spi_get_peripheral_name(PinName mosi, PinName miso, PinName sclk) return spi_per; } -void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel) +#if EXPLICIT_PINMAP_READY +#define SPI_INIT_DIRECT spi_init_direct +void spi_init_direct(spi_t *obj, const spi_pinmap_t *pinmap) +#else +#define SPI_INIT_DIRECT _spi_init_direct +static void _spi_init_direct(spi_t *obj, const spi_pinmap_t *pinmap) +#endif { struct spi_s *spiobj = SPI_S(obj); SPI_HandleTypeDef *handle = &(spiobj->handle); - // Determine the SPI to use - SPIName spi_mosi = (SPIName)pinmap_peripheral(mosi, PinMap_SPI_MOSI); - SPIName spi_miso = (SPIName)pinmap_peripheral(miso, PinMap_SPI_MISO); - SPIName spi_sclk = (SPIName)pinmap_peripheral(sclk, PinMap_SPI_SCLK); - SPIName spi_ssel = (SPIName)pinmap_peripheral(ssel, PinMap_SPI_SSEL); - - SPIName spi_data = (SPIName)pinmap_merge(spi_mosi, spi_miso); - SPIName spi_cntl = (SPIName)pinmap_merge(spi_sclk, spi_ssel); - - spiobj->spi = (SPIName)pinmap_merge(spi_data, spi_cntl); + spiobj->spi = (SPIName)pinmap->peripheral; MBED_ASSERT(spiobj->spi != (SPIName)NC); #if defined SPI1_BASE @@ -172,15 +169,19 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel #endif // Configure the SPI pins - pinmap_pinout(mosi, PinMap_SPI_MOSI); - pinmap_pinout(miso, PinMap_SPI_MISO); - pinmap_pinout(sclk, PinMap_SPI_SCLK); - spiobj->pin_miso = miso; - spiobj->pin_mosi = mosi; - spiobj->pin_sclk = sclk; - spiobj->pin_ssel = ssel; - if (ssel != NC) { - pinmap_pinout(ssel, PinMap_SPI_SSEL); + pin_function(pinmap->mosi_pin, pinmap->mosi_function); + pin_mode(pinmap->mosi_pin, PullNone); + pin_function(pinmap->miso_pin, pinmap->miso_function); + pin_mode(pinmap->miso_pin, PullNone); + pin_function(pinmap->sclk_pin, pinmap->sclk_function); + pin_mode(pinmap->sclk_pin, PullNone); + spiobj->pin_miso = pinmap->miso_pin; + spiobj->pin_mosi = pinmap->mosi_pin; + spiobj->pin_sclk = pinmap->sclk_pin; + spiobj->pin_ssel = pinmap->ssel_pin; + if (pinmap->ssel_pin != NC) { + pin_function(pinmap->ssel_pin, pinmap->ssel_function); + pin_mode(pinmap->ssel_pin, PullNone); handle->Init.NSS = SPI_NSS_HARD_OUTPUT; #if defined(SPI_NSS_PULSE_ENABLE) handle->Init.NSSPMode = SPI_NSS_PULSE_ENABLE; @@ -197,7 +198,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel handle->Init.Mode = SPI_MODE_MASTER; handle->Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256; - if (miso != NC) { + if (pinmap->miso_pin != NC) { handle->Init.Direction = SPI_DIRECTION_2LINES; } else { handle->Init.Direction = SPI_DIRECTION_1LINE; @@ -225,6 +226,29 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel init_spi(obj); } +void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel) +{ + // determine the SPI to use + uint32_t spi_mosi = pinmap_peripheral(mosi, PinMap_SPI_MOSI); + uint32_t spi_miso = pinmap_peripheral(miso, PinMap_SPI_MISO); + uint32_t spi_sclk = pinmap_peripheral(sclk, PinMap_SPI_SCLK); + uint32_t spi_ssel = pinmap_peripheral(ssel, PinMap_SPI_SSEL); + uint32_t spi_data = pinmap_merge(spi_mosi, spi_miso); + uint32_t spi_cntl = pinmap_merge(spi_sclk, spi_ssel); + + int peripheral = (int)pinmap_merge(spi_data, spi_cntl); + + // pin out the spi pins + int mosi_function = (int)pinmap_find_function(mosi, PinMap_SPI_MOSI); + int miso_function = (int)pinmap_find_function(miso, PinMap_SPI_MISO); + int sclk_function = (int)pinmap_find_function(sclk, PinMap_SPI_SCLK); + int ssel_function = (int)pinmap_find_function(ssel, PinMap_SPI_SSEL); + + const spi_pinmap_t explicit_spi_pinmap = {peripheral, mosi, mosi_function, miso, miso_function, sclk, sclk_function, ssel, ssel_function}; + + SPI_INIT_DIRECT(obj, &explicit_spi_pinmap); +} + void spi_free(spi_t *obj) { struct spi_s *spiobj = SPI_S(obj); From 9c999b60f5e317885dfa2297b3d0f37f4aba8129 Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Fri, 9 Aug 2019 09:28:21 +0200 Subject: [PATCH 06/36] SPI: Add explicit pinmap support --- drivers/SPI.h | 37 ++++++++++++++++++++ drivers/source/SPI.cpp | 77 +++++++++++++++++++++++++++++++++++------- 2 files changed, 102 insertions(+), 12 deletions(-) diff --git a/drivers/SPI.h b/drivers/SPI.h index c247b3ea708..eb2c714ba01 100644 --- a/drivers/SPI.h +++ b/drivers/SPI.h @@ -131,6 +131,33 @@ class SPI : private NonCopyable { */ SPI(PinName mosi, PinName miso, PinName sclk, PinName ssel, use_gpio_ssel_t); + /** Create a SPI master connected to the specified pins. + * + * @note This constructor passes the SSEL pin selection to the target HAL. + * Not all targets support SSEL, so this cannot be relied on in portable code. + * Portable code should use the alternative constructor that uses GPIO + * for SSEL. + * + * @note You can specify mosi or miso as NC if not used. + * + * @param explicit_pinmap reference to strucure which holds static pinmap. + */ + SPI(const spi_pinmap_t &explicit_pinmap); + + /** Create a SPI master connected to the specified pins. + * + * @note This constructor manipulates the SSEL pin as a GPIO output + * using a DigitalOut object. This should work on any target, and permits + * the use of select() and deselect() methods to keep the pin asserted + * between transfers. + * + * @note You can specify mosi or miso as NC if not used. + * + * @param explicit_pinmap reference to strucure which holds static pinmap. + * @param ssel SPI Chip Select pin. + */ + SPI(const spi_pinmap_t &explicit_pinmap, PinName ssel); + virtual ~SPI(); /** Configure the data transmission format. @@ -408,6 +435,12 @@ class SPI : private NonCopyable { char _write_fill; /* Select count to handle re-entrant selection */ int8_t _select_count; + /* Static pinmap data */ + const spi_pinmap_t *_explicit_pinmap; + /* SPI peripheral name */ + SPIName _peripheral_name; + /* Pointer to spi init function */ + void (*_init_func)(SPI*); private: void _do_construct(); @@ -425,6 +458,10 @@ class SPI : private NonCopyable { */ static spi_peripheral_s *_alloc(); + static void _do_init(SPI *obj); + static void _do_init_direct(SPI *obj); + + #endif //!defined(DOXYGEN_ONLY) }; diff --git a/drivers/source/SPI.cpp b/drivers/source/SPI.cpp index 61d337dbf07..1837fc17abc 100644 --- a/drivers/source/SPI.cpp +++ b/drivers/source/SPI.cpp @@ -36,8 +36,17 @@ SPI::SPI(PinName mosi, PinName miso, PinName sclk, PinName ssel) : _miso(miso), _sclk(sclk), _hw_ssel(ssel), - _sw_ssel(NC) + _sw_ssel(NC), + _explicit_pinmap(NULL), + _init_func(_do_init) { + // Need backwards compatibility with HALs not providing API +#ifdef DEVICE_SPI_COUNT + _peripheral_name = spi_get_peripheral_name(_mosi, _miso, _sclk); +#else + _peripheral_name = GlobalSPI; +#endif + _do_construct(); } @@ -49,11 +58,62 @@ SPI::SPI(PinName mosi, PinName miso, PinName sclk, PinName ssel, use_gpio_ssel_t _miso(miso), _sclk(sclk), _hw_ssel(NC), - _sw_ssel(ssel, 1) + _sw_ssel(ssel, 1), + _explicit_pinmap(NULL), + _init_func(_do_init) +{ + // Need backwards compatibility with HALs not providing API +#ifdef DEVICE_SPI_COUNT + _peripheral_name = spi_get_peripheral_name(_mosi, _miso, _sclk); +#else + _peripheral_name = GlobalSPI; +#endif + _do_construct(); +} + +SPI::SPI(const spi_pinmap_t &pinmap) : +#if DEVICE_SPI_ASYNCH + _irq(this), +#endif + _mosi(pinmap.mosi_pin), + _miso(pinmap.miso_pin), + _sclk(pinmap.sclk_pin), + _hw_ssel(pinmap.ssel_pin), + _sw_ssel(NC), + _explicit_pinmap(&pinmap), + _peripheral_name((SPIName)pinmap.peripheral), + _init_func(_do_init_direct) + +{ + _do_construct(); +} + +SPI::SPI(const spi_pinmap_t &pinmap, PinName ssel) : +#if DEVICE_SPI_ASYNCH + _irq(this), +#endif + _mosi(pinmap.mosi_pin), + _miso(pinmap.miso_pin), + _sclk(pinmap.sclk_pin), + _hw_ssel(NC), + _sw_ssel(ssel, 1), + _explicit_pinmap(&pinmap), + _peripheral_name((SPIName)pinmap.peripheral), + _init_func(_do_init_direct) { _do_construct(); } +void SPI::_do_init(SPI *obj) +{ + spi_init(&obj->_peripheral->spi, obj->_mosi, obj->_miso, obj->_sclk, obj->_hw_ssel); +} + +void SPI::_do_init_direct(SPI *obj) +{ + spi_init_direct(&obj->_peripheral->spi, obj->_explicit_pinmap); +} + void SPI::_do_construct() { // No lock needed in the constructor @@ -67,20 +127,13 @@ void SPI::_do_construct() _hz = 1000000; _write_fill = SPI_FILL_CHAR; - // Need backwards compatibility with HALs not providing API -#ifdef DEVICE_SPI_COUNT - SPIName name = spi_get_peripheral_name(_mosi, _miso, _sclk); -#else - SPIName name = GlobalSPI; -#endif - core_util_critical_section_enter(); // lookup in a critical section if we already have it else initialize it - _peripheral = SPI::_lookup(name); + _peripheral = SPI::_lookup(_peripheral_name); if (!_peripheral) { _peripheral = SPI::_alloc(); - _peripheral->name = name; + _peripheral->name = _peripheral_name; } core_util_critical_section_exit(); @@ -158,7 +211,7 @@ void SPI::frequency(int hz) void SPI::_acquire() { if (_peripheral->owner != this) { - spi_init(&_peripheral->spi, _mosi, _miso, _sclk, _hw_ssel); + _init_func(this); spi_format(&_peripheral->spi, _bits, _mode, 0); spi_frequency(&_peripheral->spi, _hz); _peripheral->owner = this; From 95824651f220419e32ff523db57f99be3831647a Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Fri, 9 Aug 2019 09:28:57 +0200 Subject: [PATCH 07/36] SPISlave: Add explicit pinmap support --- drivers/SPISlave.h | 8 ++++++++ drivers/source/SPISlave.cpp | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/drivers/SPISlave.h b/drivers/SPISlave.h index 5b9ae585577..749e45294f0 100644 --- a/drivers/SPISlave.h +++ b/drivers/SPISlave.h @@ -71,6 +71,14 @@ class SPISlave : private NonCopyable { */ SPISlave(PinName mosi, PinName miso, PinName sclk, PinName ssel); + /** Create a SPI slave connected to the specified pins. + * + * @note Either mosi or miso can be specified as NC if not used. + * + * @param explicit_pinmap reference to strucure which holds static pinmap. + */ + SPISlave(const spi_pinmap_t &pinmap); + /** Configure the data transmission format. * * @param bits Number of bits per SPI frame (4 - 16). diff --git a/drivers/source/SPISlave.cpp b/drivers/source/SPISlave.cpp index db870cdea2a..a8a1f74c4c9 100644 --- a/drivers/source/SPISlave.cpp +++ b/drivers/source/SPISlave.cpp @@ -15,6 +15,7 @@ * limitations under the License. */ #include "drivers/SPISlave.h" +#include "mbed_assert.h" #if DEVICE_SPISLAVE @@ -31,6 +32,17 @@ SPISlave::SPISlave(PinName mosi, PinName miso, PinName sclk, PinName ssel) : spi_frequency(&_spi, _hz); } +SPISlave::SPISlave(const spi_pinmap_t &pinmap) : + _spi(), + _bits(8), + _mode(0), + _hz(1000000) +{ + spi_init_direct(&_spi, &pinmap); + spi_format(&_spi, _bits, _mode, 1); + spi_frequency(&_spi, _hz); +} + void SPISlave::format(int bits, int mode) { _bits = bits; From cfbae6517ef1662a23ccdea756c3818b728c1379 Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Mon, 26 Aug 2019 11:26:25 +0200 Subject: [PATCH 08/36] Add pwmout_init_direct function to HAL API --- hal/pwmout_api.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hal/pwmout_api.h b/hal/pwmout_api.h index 62d5d7098c7..ef45a2568d5 100644 --- a/hal/pwmout_api.h +++ b/hal/pwmout_api.h @@ -38,6 +38,13 @@ typedef struct pwmout_s pwmout_t; * @{ */ +/** Initialize the pwm out peripheral and configure the pin + * + * @param obj The pwmout object to initialize + * @param pinmap pointer to strucure which holds static pinmap + */ +void pwmout_init_direct(pwmout_t* obj, const PinMap *pinmap); + /** Initialize the pwm out peripheral and configure the pin * * @param obj The pwmout object to initialize From ea7ec56b88475f6c7195258fb84f2f7f156c1c4b Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Mon, 26 Aug 2019 11:27:54 +0200 Subject: [PATCH 09/36] K64F PWM driver: Add explicit pinmap support --- .../TARGET_MCU_K64F/pwmout_api.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/pwmout_api.c b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/pwmout_api.c index 70e2fd6442b..3f95f34599f 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/pwmout_api.c +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/pwmout_api.c @@ -27,9 +27,9 @@ static float pwm_clock_mhz; /* Array of FTM peripheral base address. */ static FTM_Type *const ftm_addrs[] = FTM_BASE_PTRS; -void pwmout_init(pwmout_t* obj, PinName pin) +void pwmout_init_direct(pwmout_t* obj, const PinMap *pinmap) { - PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM); + PWMName pwm = (PWMName)pinmap->peripheral; MBED_ASSERT(pwm != (PWMName)NC); obj->pwm_name = pwm; @@ -70,7 +70,18 @@ void pwmout_init(pwmout_t* obj, PinName pin) FTM_StartTimer(ftm_addrs[instance], kFTM_SystemClock); // Wire pinout - pinmap_pinout(pin, PinMap_PWM); + pin_function(pinmap->pin, pinmap->function); + pin_mode(pinmap->pin, PullNone); +} + +void pwmout_init(pwmout_t* obj, PinName pin) +{ + int peripheral = (int)pinmap_peripheral(pin, PinMap_PWM); + int function = (int)pinmap_find_function(pin, PinMap_PWM); + + const PinMap explicit_pinmap = {pin, peripheral, function}; + + pwmout_init_direct(obj, &explicit_pinmap); } void pwmout_free(pwmout_t* obj) From 50d333a24ffa1666f1dcddcb93d39b6ccd33ee6b Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Mon, 26 Aug 2019 11:28:17 +0200 Subject: [PATCH 10/36] STM PWM driver: Add explicit pinmap support --- targets/TARGET_STM/pwmout_api.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/targets/TARGET_STM/pwmout_api.c b/targets/TARGET_STM/pwmout_api.c index cb21b22ac17..5d1ae2d6146 100644 --- a/targets/TARGET_STM/pwmout_api.c +++ b/targets/TARGET_STM/pwmout_api.c @@ -76,14 +76,20 @@ uint32_t TIM_ChannelConvert_HAL2LL(uint32_t channel, pwmout_t *obj) } } -void pwmout_init(pwmout_t *obj, PinName pin) +#if EXPLICIT_PINMAP_READY +#define PWM_INIT_DIRECT pwmout_init_direct +void pwmout_init_direct(pwmout_t* obj, const PinMap *pinmap) +#else +#define PWM_INIT_DIRECT _pwmout_init_direct +static void _pwmout_init_direct(pwmout_t* obj, const PinMap *pinmap) +#endif { // Get the peripheral name from the pin and assign it to the object - obj->pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM); + obj->pwm = (PWMName)pinmap->peripheral; MBED_ASSERT(obj->pwm != (PWMName)NC); // Get the functions (timer channel, (non)inverted) from the pin and assign it to the object - uint32_t function = pinmap_function(pin, PinMap_PWM); + uint32_t function = (uint32_t)pinmap->function; MBED_ASSERT(function != (uint32_t)NC); obj->channel = STM_PIN_CHANNEL(function); obj->inverted = STM_PIN_INVERTED(function); @@ -190,9 +196,10 @@ void pwmout_init(pwmout_t *obj, PinName pin) } #endif // Configure GPIO - pinmap_pinout(pin, PinMap_PWM); + pin_function(pinmap->pin, pinmap->function); + pin_mode(pinmap->pin, PullNone); - obj->pin = pin; + obj->pin = pinmap->pin; obj->period = 0; obj->pulse = 0; obj->prescaler = 1; @@ -200,6 +207,16 @@ void pwmout_init(pwmout_t *obj, PinName pin) pwmout_period_us(obj, 20000); // 20 ms per default } +void pwmout_init(pwmout_t* obj, PinName pin) +{ + int peripheral = (int)pinmap_peripheral(pin, PinMap_PWM); + int function = (int)pinmap_find_function(pin, PinMap_PWM); + + const PinMap explicit_pinmap = {pin, peripheral, function}; + + PWM_INIT_DIRECT(obj, &explicit_pinmap); +} + void pwmout_free(pwmout_t *obj) { // Configure GPIO From ef25bd102867e7f44ac2b73753b7674862ebae82 Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Mon, 26 Aug 2019 11:28:54 +0200 Subject: [PATCH 11/36] PwmOut: Add explicit pinmap support --- drivers/PwmOut.h | 6 ++++++ drivers/source/PwmOut.cpp | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/drivers/PwmOut.h b/drivers/PwmOut.h index 68102caaa57..c1c92837475 100644 --- a/drivers/PwmOut.h +++ b/drivers/PwmOut.h @@ -61,6 +61,12 @@ class PwmOut { */ PwmOut(PinName pin); + /** Create a PwmOut connected to the specified pin + * + * @param pinmap reference to strucure which holds static pinmap. + */ + PwmOut(const PinMap &pinmap); + ~PwmOut(); /** Set the output duty-cycle, specified as a percentage (float) diff --git a/drivers/source/PwmOut.cpp b/drivers/source/PwmOut.cpp index 67e5f36b341..0088c12c972 100644 --- a/drivers/source/PwmOut.cpp +++ b/drivers/source/PwmOut.cpp @@ -32,6 +32,13 @@ PwmOut::PwmOut(PinName pin) : _deep_sleep_locked(false) core_util_critical_section_exit(); } +PwmOut::PwmOut(const PinMap &pinmap) : _deep_sleep_locked(false) +{ + core_util_critical_section_enter(); + pwmout_init_direct(&_pwm, &pinmap); + core_util_critical_section_exit(); +} + PwmOut::~PwmOut() { core_util_critical_section_enter(); From cf099f254213a6da30ee043f66a37d3968654a98 Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Mon, 26 Aug 2019 13:17:04 +0200 Subject: [PATCH 12/36] Add analogin_init_direct() function to HAL API --- hal/analogin_api.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hal/analogin_api.h b/hal/analogin_api.h index fdf91dc62af..4ca7289b6ce 100644 --- a/hal/analogin_api.h +++ b/hal/analogin_api.h @@ -38,6 +38,14 @@ typedef struct analogin_s analogin_t; * @{ */ +/** Initialize the analogin peripheral + * + * Configures the pin used by analogin. + * @param obj The analogin object to initialize + * @param pinmap pointer to strucure which holds static pinmap + */ +void analogin_init_direct(analogin_t* obj, const PinMap *pinmap); + /** Initialize the analogin peripheral * * Configures the pin used by analogin. From c9e3a84f9757458775035ed829de275f9d498d49 Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Mon, 26 Aug 2019 13:18:29 +0200 Subject: [PATCH 13/36] K64F Analogin driver: Add explicit pinmap support --- .../TARGET_MCUXpresso_MCUS/api/analogin_api.c | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/analogin_api.c b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/analogin_api.c index 153d1d701a5..bb00e75d1e3 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/analogin_api.c +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/analogin_api.c @@ -29,9 +29,15 @@ static ADC_Type *const adc_addrs[] = ADC_BASE_PTRS; #define MAX_FADC 6000000 -void analogin_init(analogin_t *obj, PinName pin) +#if EXPLICIT_PINMAP_READY +#define ANALOGIN_INIT_DIRECT analogin_init_direct +void analogin_init_direct(analogin_t* obj, const PinMap *pinmap) +#else +#define ANALOGIN_INIT_DIRECT _analogin_init_direct +static void _analogin_init_direct(analogin_t* obj, const PinMap *pinmap) +#endif { - obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC); + obj->adc = (ADCName)pinmap->peripheral; MBED_ASSERT(obj->adc != (ADCName)NC); uint32_t instance = obj->adc >> ADC_INSTANCE_SHIFT; @@ -55,7 +61,18 @@ void analogin_init(analogin_t *obj, PinName pin) ADC16_Init(adc_addrs[instance], &adc16_config); ADC16_EnableHardwareTrigger(adc_addrs[instance], false); ADC16_SetHardwareAverage(adc_addrs[instance], kADC16_HardwareAverageCount4); - pinmap_pinout(pin, PinMap_ADC); + pin_function(pinmap->pin, pinmap->function); + pin_mode(pinmap->pin, PullNone); +} + +void analogin_init(analogin_t* obj, PinName pin) +{ + int peripheral = (int)pinmap_peripheral(pin, PinMap_ADC); + int function = (int)pinmap_find_function(pin, PinMap_ADC); + + const PinMap explicit_pinmap = {pin, peripheral, function}; + + ANALOGIN_INIT_DIRECT(obj, &explicit_pinmap); } uint16_t analogin_read_u16(analogin_t *obj) From abae2b6f793bb265207b11cd6001ab80d7d13988 Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Mon, 26 Aug 2019 13:18:50 +0200 Subject: [PATCH 14/36] STM32F4 Analogin driver: Add explicit pinmap support --- .../TARGET_STM32F4/analogin_device.c | 44 ++++++++++++++----- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/targets/TARGET_STM/TARGET_STM32F4/analogin_device.c b/targets/TARGET_STM/TARGET_STM32F4/analogin_device.c index 75ac50f609b..94f8f46071b 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/analogin_device.c +++ b/targets/TARGET_STM/TARGET_STM32F4/analogin_device.c @@ -36,25 +36,29 @@ #include "mbed_error.h" #include "PeripheralPins.h" -void analogin_init(analogin_t *obj, PinName pin) +#if EXPLICIT_PINMAP_READY +#define ANALOGIN_INIT_DIRECT analogin_init_direct +void analogin_init_direct(analogin_t* obj, const PinMap *pinmap) +#else +#define ANALOGIN_INIT_DIRECT _analogin_init_direct +static void _analogin_init_direct(analogin_t* obj, const PinMap *pinmap) +#endif { - uint32_t function = (uint32_t)NC; + uint32_t function = (uint32_t)pinmap->function; + + // Get the peripheral name from the pin and assign it to the object + obj->handle.Instance = (ADC_TypeDef *)pinmap->peripheral; // ADC Internal Channels "pins" (Temperature, Vref, Vbat, ...) // are described in PinNames.h and PeripheralPins.c // Pin value must be between 0xF0 and 0xFF - if ((pin < 0xF0) || (pin >= 0x100)) { + if ((pinmap->pin < 0xF0) || (pinmap->pin >= 0x100)) { // Normal channels - // Get the peripheral name from the pin and assign it to the object - obj->handle.Instance = (ADC_TypeDef *)pinmap_peripheral(pin, PinMap_ADC); - // Get the functions (adc channel) from the pin and assign it to the object - function = pinmap_function(pin, PinMap_ADC); // Configure GPIO - pinmap_pinout(pin, PinMap_ADC); + pin_function(pinmap->pin, pinmap->function); + pin_mode(pinmap->pin, PullNone); } else { // Internal channels - obj->handle.Instance = (ADC_TypeDef *)pinmap_peripheral(pin, PinMap_ADC_Internal); - function = pinmap_function(pin, PinMap_ADC_Internal); // No GPIO configuration for internal channels } MBED_ASSERT(obj->handle.Instance != (ADC_TypeDef *)NC); @@ -63,7 +67,7 @@ void analogin_init(analogin_t *obj, PinName pin) obj->channel = STM_PIN_CHANNEL(function); // Save pin number for the read function - obj->pin = pin; + obj->pin = pinmap->pin; // Configure ADC object structures obj->handle.State = HAL_ADC_STATE_RESET; @@ -101,6 +105,24 @@ void analogin_init(analogin_t *obj, PinName pin) } } +void analogin_init(analogin_t* obj, PinName pin) +{ + int peripheral; + int function; + + if ((pin < 0xF0) || (pin >= 0x100)) { + peripheral = (int)pinmap_peripheral(pin, PinMap_ADC); + function = (int)pinmap_find_function(pin, PinMap_ADC); + } else { + peripheral = (int)pinmap_peripheral(pin, PinMap_ADC_Internal); + function = (int)pinmap_find_function(pin, PinMap_ADC_Internal); + } + + const PinMap explicit_pinmap = {pin, peripheral, function}; + + ANALOGIN_INIT_DIRECT(obj, &explicit_pinmap); +} + uint16_t adc_read(analogin_t *obj) { ADC_ChannelConfTypeDef sConfig = {0}; From f5059128ce1158e8fdc9ece779139193ab772360 Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Mon, 26 Aug 2019 13:19:57 +0200 Subject: [PATCH 15/36] AnalogIn: Add explicit pinmap support --- drivers/AnalogIn.h | 7 ++++++- drivers/source/AnalogIn.cpp | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/AnalogIn.h b/drivers/AnalogIn.h index 6f884920749..8287fd31ec1 100644 --- a/drivers/AnalogIn.h +++ b/drivers/AnalogIn.h @@ -67,6 +67,12 @@ class AnalogIn { public: + /** Create an AnalogIn, connected to the specified pin + * + * @param pinmap reference to strucure which holds static pinmap. + */ + AnalogIn(const PinMap &pinmap); + /** Create an AnalogIn, connected to the specified pin * * @param pin AnalogIn pin to connect to @@ -135,4 +141,3 @@ class AnalogIn { #endif #endif - diff --git a/drivers/source/AnalogIn.cpp b/drivers/source/AnalogIn.cpp index 97b1b8e1386..63d910c2270 100644 --- a/drivers/source/AnalogIn.cpp +++ b/drivers/source/AnalogIn.cpp @@ -30,6 +30,14 @@ AnalogIn::AnalogIn(PinName pin) unlock(); } +AnalogIn::AnalogIn(const PinMap &pinmap) +{ + lock(); + analogin_init_direct(&_adc, &pinmap); + unlock(); +} + + float AnalogIn::read() { lock(); From cd227ba447d0283b325bb0b1059436651f6f04d0 Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Mon, 26 Aug 2019 14:06:07 +0200 Subject: [PATCH 16/36] Add analogout_init_direct() function to HAL API --- hal/analogout_api.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hal/analogout_api.h b/hal/analogout_api.h index 4983e43c37c..76306d78633 100644 --- a/hal/analogout_api.h +++ b/hal/analogout_api.h @@ -38,6 +38,14 @@ typedef struct dac_s dac_t; * @{ */ +/** Initialize the analogout peripheral + * + * Configures the pin used by analogout. + * @param obj The analogout object to initialize + * @param pinmap pointer to strucure which holds static pinmap + */ +void analogout_init_direct(dac_t* obj, const PinMap *pinmap); + /** Initialize the analogout peripheral * * Configures the pin used by analogout. From b2c99639e891787787d08f231923ed7d52b9288f Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Mon, 26 Aug 2019 14:06:50 +0200 Subject: [PATCH 17/36] K64F Analogout driver: Add explicit pinmap support --- .../api/analogout_api.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/analogout_api.c b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/analogout_api.c index d638d05ecfc..77ff46be1ec 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/analogout_api.c +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/analogout_api.c @@ -28,10 +28,16 @@ static DAC_Type *const dac_bases[] = DAC_BASE_PTRS; #define RANGE_12BIT 0xFFF -void analogout_init(dac_t *obj, PinName pin) +#if EXPLICIT_PINMAP_READY +#define ANALOGOUT_INIT_DIRECT analogout_init_direct +void analogout_init_direct(dac_t* obj, const PinMap *pinmap) +#else +#define ANALOGOUT_INIT_DIRECT _analogout_init_direct +static void _analogout_init_direct(dac_t* obj, const PinMap *pinmap) +#endif { dac_config_t dac_config; - obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC); + obj->dac = (DACName)pinmap->peripheral; if (obj->dac == (DACName)NC) { error("DAC pin mapping failed"); } @@ -44,6 +50,15 @@ void analogout_init(dac_t *obj, PinName pin) DAC_Enable(dac_bases[obj->dac], true); } +void analogout_init(dac_t* obj, PinName pin) +{ + int peripheral = (int)pinmap_peripheral(pin, PinMap_ADC); + + const PinMap explicit_pinmap = {pin, peripheral, 0}; + + ANALOGOUT_INIT_DIRECT(obj, &explicit_pinmap); +} + void analogout_free(dac_t *obj) { } From e72dad70d283778b1d2f105bef6214e5569fe2b5 Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Mon, 26 Aug 2019 14:10:54 +0200 Subject: [PATCH 18/36] STM32F4 Analogout driver: Add explicit pinmap support --- .../TARGET_STM32F4/analogout_device.c | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/targets/TARGET_STM/TARGET_STM32F4/analogout_device.c b/targets/TARGET_STM/TARGET_STM32F4/analogout_device.c index 4c72646ba3f..b0237af4c61 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/analogout_device.c +++ b/targets/TARGET_STM/TARGET_STM32F4/analogout_device.c @@ -35,14 +35,20 @@ #include "stm32f4xx_hal.h" #include "PeripheralPins.h" -void analogout_init(dac_t *obj, PinName pin) +#if EXPLICIT_PINMAP_READY +#define ANALOGOUT_INIT_DIRECT analogout_init_direct +void analogout_init_direct(dac_t* obj, const PinMap *pinmap) +#else +#define ANALOGOUT_INIT_DIRECT _analogout_init_direct +static void _analogout_init_direct(dac_t* obj, const PinMap *pinmap) +#endif { DAC_ChannelConfTypeDef sConfig = {0}; // Get the peripheral name (DAC_1, ...) from the pin and assign it to the object - obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC); + obj->dac = (DACName)pinmap->peripheral; // Get the functions (dac channel) from the pin and assign it to the object - uint32_t function = pinmap_function(pin, PinMap_DAC); + uint32_t function = (uint32_t)pinmap->function; MBED_ASSERT(function != (uint32_t)NC); // Save the channel for the write and read functions @@ -65,7 +71,8 @@ void analogout_init(dac_t *obj, PinName pin) } // Configure GPIO - pinmap_pinout(pin, PinMap_DAC); + pin_function(pinmap->pin, pinmap->function); + pin_mode(pinmap->pin, PullNone); __HAL_RCC_GPIOA_CLK_ENABLE(); @@ -88,6 +95,16 @@ void analogout_init(dac_t *obj, PinName pin) analogout_write_u16(obj, 0); } +void analogout_init(dac_t *obj, PinName pin) +{ + int peripheral = (int)pinmap_peripheral(pin, PinMap_DAC); + int function = (int)pinmap_find_function(pin, PinMap_DAC); + + const PinMap explicit_pinmap = {pin, peripheral, function}; + + ANALOGOUT_INIT_DIRECT(obj, &explicit_pinmap); +} + void analogout_free(dac_t *obj) { } From 9f78a3f786ed589235a9bf468bf204a8eb66fc4f Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Mon, 26 Aug 2019 14:12:09 +0200 Subject: [PATCH 19/36] AnalogOut: Add explicit pinmap support --- drivers/AnalogOut.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/AnalogOut.h b/drivers/AnalogOut.h index 1e28f329515..2d5a05fc6e2 100644 --- a/drivers/AnalogOut.h +++ b/drivers/AnalogOut.h @@ -66,6 +66,15 @@ class AnalogOut { analogout_init(&_dac, pin); } + /** Create an AnalogOut connected to the specified pin + * + * @param pinmap reference to strucure which holds static pinmap. + */ + AnalogOut(const PinMap &pinmap) + { + analogout_init_direct(&_dac, &pinmap); + } + /** Set the output voltage, specified as a percentage (float) * * @param value A floating-point value representing the output voltage, From e914aa1de02f64f9111ba5f5ef2986776bbc40bb Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Wed, 28 Aug 2019 13:14:54 +0200 Subject: [PATCH 20/36] Add i2c_init_direct() function to HAL API --- hal/i2c_api.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/hal/i2c_api.h b/hal/i2c_api.h index 3ade94ce778..a538617ed22 100644 --- a/hal/i2c_api.h +++ b/hal/i2c_api.h @@ -64,6 +64,14 @@ enum { I2C_ERROR_BUS_BUSY = -2 }; +typedef struct { + int peripheral; + PinName sda_pin; + int sda_function; + PinName scl_pin; + int scl_function; +} i2c_pinmap_t; + #ifdef __cplusplus extern "C" { #endif @@ -73,6 +81,14 @@ extern "C" { * @{ */ +/** Initialize the I2C peripheral. It sets the default parameters for I2C + * peripheral, and configures its specifieds pins. + * + * @param obj The I2C object + * @param pinmap Pinmap pointer to strucure which holds static pinmap + */ +void i2c_init_direct(i2c_t *obj, const i2c_pinmap_t *pinmap); + /** Initialize the I2C peripheral. It sets the default parameters for I2C * peripheral, and configures its specifieds pins. * From 9e0b7c5c1a5e0887b67063bee5f47c9f671e7e36 Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Wed, 28 Aug 2019 13:17:44 +0200 Subject: [PATCH 21/36] TARGET_MCUXpresso_MCUS I2C driver: Add explicit pinmap support --- .../TARGET_MCUXpresso_MCUS/api/i2c_api.c | 43 ++++++++++++++----- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/i2c_api.c b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/i2c_api.c index 1453e4239a1..0c795bb17be 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/i2c_api.c +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/i2c_api.c @@ -32,14 +32,18 @@ static I2C_Type *const i2c_addrs[] = I2C_BASE_PTRS; /* Array of I2C bus clock frequencies */ static clock_name_t const i2c_clocks[] = I2C_CLOCK_FREQS; -void i2c_init(i2c_t *obj, PinName sda, PinName scl) +#if EXPLICIT_PINMAP_READY +#define I2C_INIT_DIRECT i2c_init_direct +void i2c_init_direct(i2c_t *obj, const i2c_pinmap_t *pinmap) +#else +#define I2C_INIT_DIRECT _i2c_init_direct +static void _i2c_init_direct(i2c_t *obj, const i2c_pinmap_t *pinmap) +#endif { - uint32_t i2c_sda = pinmap_peripheral(sda, PinMap_I2C_SDA); - uint32_t i2c_scl = pinmap_peripheral(scl, PinMap_I2C_SCL); PORT_Type *port_addrs[] = PORT_BASE_PTRS; - PORT_Type *base = port_addrs[sda >> GPIO_PORT_SHIFT]; + PORT_Type *base = port_addrs[pinmap->sda_pin >> GPIO_PORT_SHIFT]; - obj->instance = pinmap_merge(i2c_sda, i2c_scl); + obj->instance = (uint32_t) pinmap->peripheral; obj->next_repeated_start = 0; MBED_ASSERT((int)obj->instance != NC); @@ -49,19 +53,36 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) I2C_MasterInit(i2c_addrs[obj->instance], &master_config, CLOCK_GetFreq(i2c_clocks[obj->instance])); I2C_EnableInterrupts(i2c_addrs[obj->instance], kI2C_GlobalInterruptEnable); - pinmap_pinout(sda, PinMap_I2C_SDA); - pinmap_pinout(scl, PinMap_I2C_SCL); + pin_function(pinmap->sda_pin, pinmap->sda_function); + pin_mode(pinmap->sda_pin, PullNone); + pin_function(pinmap->scl_pin, pinmap->scl_function); + pin_mode(pinmap->scl_pin, PullNone); /* Enable internal pullup resistor */ - base->PCR[sda & 0xFF] |= (PORT_PCR_PE_MASK | PORT_PCR_PS_MASK); - base->PCR[scl & 0xFF] |= (PORT_PCR_PE_MASK | PORT_PCR_PS_MASK); + base->PCR[pinmap->sda_pin & 0xFF] |= (PORT_PCR_PE_MASK | PORT_PCR_PS_MASK); + base->PCR[pinmap->scl_pin & 0xFF] |= (PORT_PCR_PE_MASK | PORT_PCR_PS_MASK); #if defined(FSL_FEATURE_PORT_HAS_OPEN_DRAIN) && FSL_FEATURE_PORT_HAS_OPEN_DRAIN - base->PCR[sda & 0xFF] |= PORT_PCR_ODE_MASK; - base->PCR[scl & 0xFF] |= PORT_PCR_ODE_MASK; + base->PCR[pinmap->sda_pin & 0xFF] |= PORT_PCR_ODE_MASK; + base->PCR[pinmap->scl_pin & 0xFF] |= PORT_PCR_ODE_MASK; #endif } +void i2c_init(i2c_t *obj, PinName sda, PinName scl) +{ + uint32_t i2c_sda = pinmap_peripheral(sda, PinMap_I2C_SDA); + uint32_t i2c_scl = pinmap_peripheral(scl, PinMap_I2C_SCL); + + int peripheral = (int)pinmap_merge(i2c_sda, i2c_scl); + + int sda_function = (int)pinmap_find_function(sda, PinMap_I2C_SDA); + int scl_function = (int)pinmap_find_function(scl, PinMap_I2C_SCL); + + const i2c_pinmap_t explicit_i2c_pinmap = {peripheral, sda, sda_function, scl, scl_function}; + + I2C_INIT_DIRECT(obj, &explicit_i2c_pinmap); +} + int i2c_start(i2c_t *obj) { I2C_Type *base = i2c_addrs[obj->instance]; From a601d54a9dfd47ac3ce2aec3d4d4f9ae76c15cba Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Wed, 28 Aug 2019 13:18:32 +0200 Subject: [PATCH 22/36] STM32F4 I2C driver: Add explicit pinmap support --- .../TARGET_STM32F4/common_objects.h | 3 +- targets/TARGET_STM/i2c_api.c | 70 ++++++++++++------- 2 files changed, 46 insertions(+), 27 deletions(-) diff --git a/targets/TARGET_STM/TARGET_STM32F4/common_objects.h b/targets/TARGET_STM/TARGET_STM32F4/common_objects.h index 00129513d57..0fc1cce9ab5 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/common_objects.h +++ b/targets/TARGET_STM/TARGET_STM32F4/common_objects.h @@ -96,6 +96,8 @@ struct i2c_s { int hz; PinName sda; PinName scl; + int sda_func; + int scl_func; IRQn_Type event_i2cIRQ; IRQn_Type error_i2cIRQ; uint8_t XferOperation; @@ -165,4 +167,3 @@ struct qspi_s { #endif #endif - diff --git a/targets/TARGET_STM/i2c_api.c b/targets/TARGET_STM/i2c_api.c index 995bda07cbf..a86d09ab9b0 100644 --- a/targets/TARGET_STM/i2c_api.c +++ b/targets/TARGET_STM/i2c_api.c @@ -82,7 +82,7 @@ static I2C_HandleTypeDef *i2c_handles[I2C_NUM]; #define FLAG_TIMEOUT ((int)0x1000) /* Declare i2c_init_internal to be used in this file */ -void i2c_init_internal(i2c_t *obj, PinName sda, PinName scl); +void i2c_init_internal(i2c_t *obj, const i2c_pinmap_t *pinmap); /* GENERIC INIT and HELPERS FUNCTIONS */ @@ -263,24 +263,20 @@ void i2c_sw_reset(i2c_t *obj) handle->Instance->CR1 |= I2C_CR1_PE; } -void i2c_init(i2c_t *obj, PinName sda, PinName scl) -{ - memset(obj, 0, sizeof(*obj)); - i2c_init_internal(obj, sda, scl); -} - -void i2c_init_internal(i2c_t *obj, PinName sda, PinName scl) +void i2c_init_internal(i2c_t *obj, const i2c_pinmap_t *pinmap) { struct i2c_s *obj_s = I2C_S(obj); // Determine the I2C to use - I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA); - I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL); - obj_s->sda = sda; - obj_s->scl = scl; - - obj_s->i2c = (I2CName)pinmap_merge(i2c_sda, i2c_scl); - MBED_ASSERT(obj_s->i2c != (I2CName)NC); + if (pinmap != NULL) { + obj_s->sda = pinmap->sda_pin; + obj_s->scl = pinmap->scl_pin; + obj_s->sda_func = pinmap->sda_function; + obj_s->scl_func = pinmap->scl_function; + + obj_s->i2c = (I2CName)pinmap->peripheral; + MBED_ASSERT(obj_s->i2c != (I2CName)NC); + } #if defined I2C1_BASE // Enable I2C1 clock and pinout if not done @@ -330,10 +326,10 @@ void i2c_init_internal(i2c_t *obj, PinName sda, PinName scl) #endif // Configure I2C pins - pinmap_pinout(sda, PinMap_I2C_SDA); - pinmap_pinout(scl, PinMap_I2C_SCL); - pin_mode(sda, OpenDrainNoPull); - pin_mode(scl, OpenDrainNoPull); + pin_function(obj_s->sda, obj_s->sda_func); + pin_function(obj_s->scl, obj_s->scl_func); + pin_mode(obj_s->sda, OpenDrainNoPull); + pin_mode(obj_s->scl, OpenDrainNoPull); // I2C configuration // Default hz value used for timeout computation @@ -360,6 +356,28 @@ void i2c_init_internal(i2c_t *obj, PinName sda, PinName scl) #endif } +void i2c_init_direct(i2c_t *obj, const i2c_pinmap_t *pinmap) +{ + memset(obj, 0, sizeof(*obj)); + i2c_init_internal(obj, pinmap); +} + +void i2c_init(i2c_t *obj, PinName sda, PinName scl) +{ + uint32_t i2c_sda = pinmap_peripheral(sda, PinMap_I2C_SDA); + uint32_t i2c_scl = pinmap_peripheral(scl, PinMap_I2C_SCL); + + int peripheral = (int)pinmap_merge(i2c_sda, i2c_scl); + + int sda_function = (int)pinmap_find_function(sda, PinMap_I2C_SDA); + int scl_function = (int)pinmap_find_function(scl, PinMap_I2C_SCL); + + const i2c_pinmap_t explicit_i2c_pinmap = {peripheral, sda, sda_function, scl, scl_function}; + + i2c_init_direct(obj, &explicit_i2c_pinmap); +} + + void i2c_frequency(i2c_t *obj, int hz) { int timeout; @@ -464,7 +482,7 @@ void i2c_reset(i2c_t *obj) /* As recommended in i2c_api.h, mainly send stop */ i2c_stop(obj); /* then re-init */ - i2c_init_internal(obj, obj_s->sda, obj_s->scl); + i2c_init_internal(obj, NULL); } /* @@ -518,7 +536,7 @@ int i2c_stop(i2c_t *obj) * re-init HAL state */ if (obj_s->XferOperation != I2C_FIRST_AND_LAST_FRAME) { - i2c_init_internal(obj, obj_s->sda, obj_s->scl); + i2c_init_internal(obj, NULL); } return 0; @@ -594,7 +612,7 @@ int i2c_stop(i2c_t *obj) #if DEVICE_I2CSLAVE if (obj_s->slave) { /* re-init slave when stop is requested */ - i2c_init_internal(obj, obj_s->sda, obj_s->scl); + i2c_init_internal(obj, NULL); return 0; } #endif @@ -635,7 +653,7 @@ int i2c_stop(i2c_t *obj) /* In case of mixed usage of the APIs (unitary + SYNC) * re-init HAL state */ if (obj_s->XferOperation != I2C_FIRST_AND_LAST_FRAME) { - i2c_init_internal(obj, obj_s->sda, obj_s->scl); + i2c_init_internal(obj, NULL); } return 0; @@ -813,7 +831,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) if ((timeout == 0) || (obj_s->event != I2C_EVENT_TRANSFER_COMPLETE)) { DEBUG_PRINTF(" TIMEOUT or error in i2c_read\r\n"); /* re-init IP to try and get back in a working state */ - i2c_init_internal(obj, obj_s->sda, obj_s->scl); + i2c_init_internal(obj, NULL); } else { count = length; } @@ -880,7 +898,7 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) if ((timeout == 0) || (obj_s->event != I2C_EVENT_TRANSFER_COMPLETE)) { DEBUG_PRINTF(" TIMEOUT or error in i2c_write\r\n"); /* re-init IP to try and get back in a working state */ - i2c_init_internal(obj, obj_s->sda, obj_s->scl); + i2c_init_internal(obj, NULL); } else { count = length; } @@ -950,7 +968,7 @@ void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c) DEBUG_PRINTF("HAL_I2C_ErrorCallback:%d, index=%d\r\n", (int) hi2c->ErrorCode, obj_s->index); /* re-init IP to try and get back in a working state */ - i2c_init_internal(obj, obj_s->sda, obj_s->scl); + i2c_init_internal(obj, NULL); #if DEVICE_I2CSLAVE /* restore slave address */ From 11698c3573d707e0e8a0131498bea1ee5ea83b94 Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Wed, 28 Aug 2019 13:19:10 +0200 Subject: [PATCH 23/36] I2C: Add explicit pinmap support --- drivers/I2C.h | 6 ++++++ drivers/I2CSlave.h | 6 ++++++ drivers/source/I2C.cpp | 17 +++++++++++++++++ drivers/source/I2CSlave.cpp | 7 +++++++ 4 files changed, 36 insertions(+) diff --git a/drivers/I2C.h b/drivers/I2C.h index 4fb06a3d267..e6190ee485b 100644 --- a/drivers/I2C.h +++ b/drivers/I2C.h @@ -101,6 +101,12 @@ class I2C : private NonCopyable { */ I2C(PinName sda, PinName scl); + /** Create an I2C Master interface, connected to the specified pins + * + * @param explicit_pinmap reference to strucure which holds static pinmap. + */ + I2C(const i2c_pinmap_t &explicit_pinmap); + /** Set the frequency of the I2C interface * * @param hz The bus frequency in hertz diff --git a/drivers/I2CSlave.h b/drivers/I2CSlave.h index 000d480f74a..c4f255a7171 100644 --- a/drivers/I2CSlave.h +++ b/drivers/I2CSlave.h @@ -86,6 +86,12 @@ class I2CSlave { */ I2CSlave(PinName sda, PinName scl); + /** Create an I2C Slave interface, connected to the specified pins. + * + * @param explicit_pinmap reference to strucure which holds static pinmap. + */ + I2CSlave(const i2c_pinmap_t &explicit_pinmap); + /** Set the frequency of the I2C interface. * * @param hz The bus frequency in Hertz. diff --git a/drivers/source/I2C.cpp b/drivers/source/I2C.cpp index 7857d22c6d3..8691f66a1f4 100644 --- a/drivers/source/I2C.cpp +++ b/drivers/source/I2C.cpp @@ -47,6 +47,23 @@ I2C::I2C(PinName sda, PinName scl) : unlock(); } +I2C::I2C(const i2c_pinmap_t &explicit_pinmap) : +#if DEVICE_I2C_ASYNCH + _irq(this), _usage(DMA_USAGE_NEVER), _deep_sleep_locked(false), +#endif + _i2c(), _hz(100000) +{ + lock(); + // The init function also set the frequency to 100000 + _sda = explicit_pinmap.sda_pin; + _scl = explicit_pinmap.scl_pin; + recover(explicit_pinmap.sda_pin, explicit_pinmap.scl_pin); + i2c_init_direct(&_i2c, &explicit_pinmap); + // Used to avoid unnecessary frequency updates + _owner = this; + unlock(); +} + void I2C::frequency(int hz) { lock(); diff --git a/drivers/source/I2CSlave.cpp b/drivers/source/I2CSlave.cpp index 489926c1463..d4619df91a7 100644 --- a/drivers/source/I2CSlave.cpp +++ b/drivers/source/I2CSlave.cpp @@ -27,6 +27,13 @@ I2CSlave::I2CSlave(PinName sda, PinName scl) : _i2c() i2c_slave_mode(&_i2c, 1); } +I2CSlave::I2CSlave(const i2c_pinmap_t &explicit_pinmap) : _i2c() +{ + i2c_init_direct(&_i2c, &explicit_pinmap); + i2c_frequency(&_i2c, 100000); + i2c_slave_mode(&_i2c, 1); +} + void I2CSlave::frequency(int hz) { i2c_frequency(&_i2c, hz); From 1dbd0029c49d812e57f9e144b53a8dcad7ed29c8 Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Thu, 29 Aug 2019 11:01:00 +0200 Subject: [PATCH 24/36] Add serial_init_direct(), serial_set_flow_control_direct() functions to HAL API --- hal/serial_api.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/hal/serial_api.h b/hal/serial_api.h index 32eb362fb39..8745afa9110 100644 --- a/hal/serial_api.h +++ b/hal/serial_api.h @@ -102,6 +102,23 @@ typedef struct serial_s serial_t; #endif +typedef struct { + int peripheral; + PinName tx_pin; + int tx_function; + PinName rx_pin; + int rx_function; + bool stdio_config; +} serial_pinmap_t; + +typedef struct { + int peripheral; + PinName tx_flow_pin; + int tx_flow_function; + PinName rx_flow_pin; + int rx_flow_function; +} serial_fc_pinmap_t; + #ifdef __cplusplus extern "C" { #endif @@ -120,6 +137,15 @@ extern "C" { */ void serial_init(serial_t *obj, PinName tx, PinName rx); +/** Initialize the serial peripheral. It sets the default parameters for serial + * peripheral, and configures its specifieds pins. + * + * @param obj The serial object + * @param pinmap pointer to strucure which holds static pinmap + */ +void serial_init_direct(serial_t *obj, const serial_pinmap_t *pinmap); + + /** Release the serial peripheral, not currently invoked. It requires further * resource management. * @@ -221,6 +247,15 @@ void serial_pinout_tx(PinName tx); * @param txflow The RX pin name */ void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, PinName txflow); + +/** Configure the serial for the flow control. It sets flow control in the hardware + * if a serial peripheral supports it, otherwise software emulation is used. + * + * @param obj The serial object + * @param type The type of the flow control. Look at the available FlowControl types. + * @param pinmap Pointer to strucure which holds static pinmap + */ +void serial_set_flow_control_direct(serial_t *obj, FlowControl type, const serial_fc_pinmap_t *pinmap); #endif /** Get the pins that support Serial TX From 46efb17649d44984e8f7cb1f835f52dcb6042603 Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Thu, 29 Aug 2019 11:01:40 +0200 Subject: [PATCH 25/36] K64F serial driver: Add explicit pinmap support --- .../TARGET_MCU_K64F/serial_api.c | 57 ++++++++++++++----- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/serial_api.c b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/serial_api.c index c1abd781421..b42460c7fa8 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/serial_api.c +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/serial_api.c @@ -48,11 +48,9 @@ static clock_name_t const uart_clocks[] = UART_CLOCK_FREQS; int stdio_uart_inited = 0; serial_t stdio_uart; -void serial_init(serial_t *obj, PinName tx, PinName rx) +void serial_init_direct(serial_t *obj, const serial_pinmap_t *pinmap) { - uint32_t uart_tx = pinmap_peripheral(tx, PinMap_UART_TX); - uint32_t uart_rx = pinmap_peripheral(rx, PinMap_UART_RX); - obj->serial.index = pinmap_merge(uart_tx, uart_rx); + obj->serial.index = (uint32_t)pinmap->peripheral; MBED_ASSERT((int)obj->serial.index != NC); uart_config_t config; @@ -64,16 +62,16 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) UART_Init(uart_addrs[obj->serial.index], &config, CLOCK_GetFreq(uart_clocks[obj->serial.index])); - pinmap_pinout(tx, PinMap_UART_TX); - pinmap_pinout(rx, PinMap_UART_RX); + pin_function(pinmap->tx_pin, pinmap->tx_function); + pin_function(pinmap->rx_pin, pinmap->rx_function); - if (tx != NC) { + if (pinmap->tx_pin != NC) { UART_EnableTx(uart_addrs[obj->serial.index], true); - pin_mode(tx, PullUp); + pin_mode(pinmap->tx_pin, PullUp); } - if (rx != NC) { + if (pinmap->rx_pin != NC) { UART_EnableRx(uart_addrs[obj->serial.index], true); - pin_mode(rx, PullUp); + pin_mode(pinmap->rx_pin, PullUp); } if (obj->serial.index == STDIO_UART) { @@ -89,6 +87,21 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) memset(&(obj->serial.uart_transfer_handle), 0, sizeof(obj->serial.uart_transfer_handle)); } +void serial_init(serial_t *obj, PinName tx, PinName rx) +{ + uint32_t uart_tx = pinmap_peripheral(tx, PinMap_UART_TX); + uint32_t uart_rx = pinmap_peripheral(rx, PinMap_UART_RX); + + int peripheral = (int)pinmap_merge(uart_tx, uart_rx); + + int tx_function = (int)pinmap_find_function(tx, PinMap_UART_TX); + int rx_function = (int)pinmap_find_function(rx, PinMap_UART_RX); + + const serial_pinmap_t explicit_uart_pinmap = {peripheral, tx, tx_function, rx, rx_function, 0}; + + serial_init_direct(obj, &explicit_uart_pinmap); +} + void serial_free(serial_t *obj) { UART_Deinit(uart_addrs[obj->serial.index]); @@ -336,24 +349,28 @@ const PinMap *serial_rts_pinmap() /* * Only hardware flow control is implemented in this API. */ -void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, PinName txflow) +void serial_set_flow_control_direct(serial_t *obj, FlowControl type, const serial_fc_pinmap_t *pinmap) { switch(type) { case FlowControlRTS: - pinmap_pinout(rxflow, PinMap_UART_RTS); + pin_function(pinmap->rx_flow_pin, pinmap->rx_flow_function); + pin_mode(pinmap->rx_flow_pin, PullNone); uart_addrs[obj->serial.index]->MODEM &= ~UART_MODEM_TXCTSE_MASK; uart_addrs[obj->serial.index]->MODEM |= UART_MODEM_RXRTSE_MASK; break; case FlowControlCTS: - pinmap_pinout(txflow, PinMap_UART_CTS); + pin_function(pinmap->tx_flow_pin, pinmap->tx_flow_function); + pin_mode(pinmap->tx_flow_pin, PullNone); uart_addrs[obj->serial.index]->MODEM &= ~UART_MODEM_RXRTSE_MASK; uart_addrs[obj->serial.index]->MODEM |= UART_MODEM_TXCTSE_MASK; break; case FlowControlRTSCTS: - pinmap_pinout(rxflow, PinMap_UART_RTS); - pinmap_pinout(txflow, PinMap_UART_CTS); + pin_function(pinmap->rx_flow_pin, pinmap->rx_flow_function); + pin_mode(pinmap->rx_flow_pin, PullNone); + pin_function(pinmap->tx_flow_pin, pinmap->tx_flow_function); + pin_mode(pinmap->tx_flow_pin, PullNone); uart_addrs[obj->serial.index]->MODEM |= UART_MODEM_TXCTSE_MASK | UART_MODEM_RXRTSE_MASK; break; @@ -366,6 +383,16 @@ void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, Pi } } +void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, PinName txflow) +{ + int tx_flow_function = (int)pinmap_find_function(txflow, PinMap_UART_CTS); + int rx_flow_function = (int)pinmap_find_function(rxflow, PinMap_UART_RTS); + + const serial_fc_pinmap_t explicit_uart_fc_pinmap = {0, txflow, tx_flow_function, rxflow, rx_flow_function}; + + serial_set_flow_control_direct(obj, type, &explicit_uart_fc_pinmap); +} + #endif static void serial_send_asynch(serial_t *obj) From 2a6de8ae681dc965aeeebf86c9ba18cb14c79cb3 Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Thu, 29 Aug 2019 11:02:22 +0200 Subject: [PATCH 26/36] STM32 serial driver: Add explicit pinmap support --- .../TARGET_STM/TARGET_STM32F4/serial_device.c | 76 +++++++++++++------ targets/TARGET_STM/serial_api.c | 68 +++++++++++------ 2 files changed, 96 insertions(+), 48 deletions(-) diff --git a/targets/TARGET_STM/TARGET_STM32F4/serial_device.c b/targets/TARGET_STM/TARGET_STM32F4/serial_device.c index e2f076641f3..197c2826996 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/serial_device.c +++ b/targets/TARGET_STM/TARGET_STM32F4/serial_device.c @@ -734,57 +734,87 @@ void serial_rx_abort_asynch(serial_t *obj) * Set HW Control Flow * @param obj The serial object * @param type The Control Flow type (FlowControlNone, FlowControlRTS, FlowControlCTS, FlowControlRTSCTS) - * @param rxflow Pin for the rxflow - * @param txflow Pin for the txflow + * @param pinmap Pointer to strucure which holds static pinmap */ -void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, PinName txflow) +#if EXPLICIT_PINMAP_READY +#define SERIAL_SET_FC_DIRECT serial_set_flow_control_direct +void serial_set_flow_control_direct(serial_t *obj, FlowControl type, const serial_fc_pinmap_t *pinmap) +#else +#define SERIAL_SET_FC_DIRECT _serial_set_flow_control_direct +static void _serial_set_flow_control_direct(serial_t *obj, FlowControl type, const serial_fc_pinmap_t *pinmap) +#endif { struct serial_s *obj_s = SERIAL_S(obj); - // Checked used UART name (UART_1, UART_2, ...) - UARTName uart_rts = (UARTName)pinmap_peripheral(rxflow, PinMap_UART_RTS); - UARTName uart_cts = (UARTName)pinmap_peripheral(txflow, PinMap_UART_CTS); - if (((UARTName)pinmap_merge(uart_rts, obj_s->uart) == (UARTName)NC) || ((UARTName)pinmap_merge(uart_cts, obj_s->uart) == (UARTName)NC)) { - MBED_ASSERT(0); - return; - } - if (type == FlowControlNone) { // Disable hardware flow control obj_s->hw_flow_ctl = UART_HWCONTROL_NONE; } if (type == FlowControlRTS) { // Enable RTS - MBED_ASSERT(uart_rts != (UARTName)NC); + MBED_ASSERT(pinmap->rx_flow_pin != (UARTName)NC); obj_s->hw_flow_ctl = UART_HWCONTROL_RTS; - obj_s->pin_rts = rxflow; + obj_s->pin_rts = pinmap->rx_flow_pin; // Enable the pin for RTS function - pinmap_pinout(rxflow, PinMap_UART_RTS); + pin_function(pinmap->rx_flow_pin, pinmap->rx_flow_function); + pin_mode(pinmap->rx_flow_pin, PullNone); } if (type == FlowControlCTS) { // Enable CTS - MBED_ASSERT(uart_cts != (UARTName)NC); + MBED_ASSERT(pinmap->tx_flow_pin != (UARTName)NC); obj_s->hw_flow_ctl = UART_HWCONTROL_CTS; - obj_s->pin_cts = txflow; + obj_s->pin_cts = pinmap->tx_flow_pin; // Enable the pin for CTS function - pinmap_pinout(txflow, PinMap_UART_CTS); + pin_function(pinmap->tx_flow_pin, pinmap->tx_flow_function); + pin_mode(pinmap->tx_flow_pin, PullNone); } if (type == FlowControlRTSCTS) { // Enable CTS & RTS - MBED_ASSERT(uart_rts != (UARTName)NC); - MBED_ASSERT(uart_cts != (UARTName)NC); + MBED_ASSERT(pinmap->rx_flow_pin != (UARTName)NC); + MBED_ASSERT(pinmap->tx_flow_pin != (UARTName)NC); obj_s->hw_flow_ctl = UART_HWCONTROL_RTS_CTS; - obj_s->pin_rts = rxflow; - obj_s->pin_cts = txflow; + obj_s->pin_rts = pinmap->rx_flow_pin;; + obj_s->pin_cts = pinmap->tx_flow_pin;; // Enable the pin for CTS function - pinmap_pinout(txflow, PinMap_UART_CTS); + pin_function(pinmap->tx_flow_pin, pinmap->tx_flow_function); + pin_mode(pinmap->tx_flow_pin, PullNone); // Enable the pin for RTS function - pinmap_pinout(rxflow, PinMap_UART_RTS); + pin_function(pinmap->rx_flow_pin, pinmap->rx_flow_function); + pin_mode(pinmap->rx_flow_pin, PullNone); } init_uart(obj); } +/** + * Set HW Control Flow + * @param obj The serial object + * @param type The Control Flow type (FlowControlNone, FlowControlRTS, FlowControlCTS, FlowControlRTSCTS) + * @param rxflow Pin for the rxflow + * @param txflow Pin for the txflow + */ +void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, PinName txflow) +{ + struct serial_s *obj_s = SERIAL_S(obj); + + UARTName uart_rts = (UARTName)pinmap_peripheral(rxflow, PinMap_UART_RTS); + UARTName uart_cts = (UARTName)pinmap_peripheral(txflow, PinMap_UART_CTS); + + if (((UARTName)pinmap_merge(uart_rts, obj_s->uart) == (UARTName)NC) || ((UARTName)pinmap_merge(uart_cts, obj_s->uart) == (UARTName)NC)) { + MBED_ASSERT(0); + return; + } + + int peripheral = (int)pinmap_merge(uart_rts, uart_cts); + + int tx_flow_function = (int)pinmap_find_function(txflow, PinMap_UART_CTS); + int rx_flow_function = (int)pinmap_find_function(rxflow, PinMap_UART_RTS); + + const serial_fc_pinmap_t explicit_uart_fc_pinmap = {peripheral, txflow, tx_flow_function, rxflow, rx_flow_function}; + + SERIAL_SET_FC_DIRECT(obj, type, &explicit_uart_fc_pinmap); +} + #endif /* DEVICE_SERIAL_FC */ #endif /* DEVICE_SERIAL */ diff --git a/targets/TARGET_STM/serial_api.c b/targets/TARGET_STM/serial_api.c index a18b85ba415..93a519d2f61 100644 --- a/targets/TARGET_STM/serial_api.c +++ b/targets/TARGET_STM/serial_api.c @@ -47,27 +47,20 @@ extern uint32_t serial_irq_ids[]; HAL_StatusTypeDef init_uart(serial_t *obj); int8_t get_uart_index(UARTName uart_name); -void serial_init(serial_t *obj, PinName tx, PinName rx) +#if EXPLICIT_PINMAP_READY +#define SERIAL_INIT_DIRECT serial_init_direct +void serial_init_direct(serial_t *obj, const serial_pinmap_t *pinmap) +#else +#define SERIAL_INIT_DIRECT _serial_init_direct +static void _serial_init_direct(serial_t *obj, const serial_pinmap_t *pinmap) +#endif { struct serial_s *obj_s = SERIAL_S(obj); - uint8_t stdio_config = 0; - - // Determine the UART to use (UART_1, UART_2, ...) - UARTName uart_tx = (UARTName)pinmap_peripheral(tx, PinMap_UART_TX); - UARTName uart_rx = (UARTName)pinmap_peripheral(rx, PinMap_UART_RX); // Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object - obj_s->uart = (UARTName)pinmap_merge(uart_tx, uart_rx); + obj_s->uart = (UARTName)pinmap->peripheral; MBED_ASSERT(obj_s->uart != (UARTName)NC); - if ((tx == STDIO_UART_TX) || (rx == STDIO_UART_RX)) { - stdio_config = 1; - } else { - if (uart_tx == pinmap_peripheral(STDIO_UART_TX, PinMap_UART_TX)) { - error("Error: new serial object is using same UART as STDIO"); - } - } - // Reset and enable clock #if defined(USART1_BASE) if (obj_s->uart == UART_1) { @@ -164,19 +157,19 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) MBED_ASSERT(obj_s->index >= 0); // Configure UART pins - pinmap_pinout(tx, PinMap_UART_TX); - pinmap_pinout(rx, PinMap_UART_RX); + pin_function(pinmap->tx_pin, pinmap->tx_function); + pin_function(pinmap->rx_pin, pinmap->rx_function); - if (tx != NC) { - pin_mode(tx, PullUp); + if (pinmap->tx_pin != NC) { + pin_mode(pinmap->tx_pin, PullUp); } - if (rx != NC) { - pin_mode(rx, PullUp); + if (pinmap->rx_pin != NC) { + pin_mode(pinmap->rx_pin, PullUp); } // Configure UART obj_s->baudrate = 9600; // baudrate default value - if (stdio_config) { + if (pinmap->stdio_config) { #if MBED_CONF_PLATFORM_STDIO_BAUD_RATE obj_s->baudrate = MBED_CONF_PLATFORM_STDIO_BAUD_RATE; // baudrate takes value from platform/mbed_lib.json #endif /* MBED_CONF_PLATFORM_STDIO_BAUD_RATE */ @@ -193,18 +186,43 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) obj_s->hw_flow_ctl = UART_HWCONTROL_NONE; #endif - obj_s->pin_tx = tx; - obj_s->pin_rx = rx; + obj_s->pin_tx = pinmap->tx_pin; + obj_s->pin_rx = pinmap->rx_pin; init_uart(obj); /* init_uart will be called again in serial_baud function, so don't worry if init_uart returns HAL_ERROR */ // For stdio management in platform/mbed_board.c and platform/mbed_retarget.cpp - if (stdio_config) { + if (pinmap->stdio_config) { stdio_uart_inited = 1; memcpy(&stdio_uart, obj, sizeof(serial_t)); } } +void serial_init(serial_t *obj, PinName tx, PinName rx) +{ + uint32_t uart_tx = pinmap_peripheral(tx, PinMap_UART_TX); + uint32_t uart_rx = pinmap_peripheral(rx, PinMap_UART_RX); + + int peripheral = (int)pinmap_merge(uart_tx, uart_rx); + + int tx_function = (int)pinmap_find_function(tx, PinMap_UART_TX); + int rx_function = (int)pinmap_find_function(rx, PinMap_UART_RX); + + uint8_t stdio_config = false; + + if ((tx == STDIO_UART_TX) || (rx == STDIO_UART_RX)) { + stdio_config = true; + } else { + if (uart_tx == pinmap_peripheral(STDIO_UART_TX, PinMap_UART_TX)) { + error("Error: new serial object is using same UART as STDIO"); + } + } + + const serial_pinmap_t explicit_uart_pinmap = {peripheral, tx, tx_function, rx, rx_function, stdio_config}; + + SERIAL_INIT_DIRECT(obj, &explicit_uart_pinmap); +} + void serial_free(serial_t *obj) { struct serial_s *obj_s = SERIAL_S(obj); From f4780b7ffe125895520963c67a309ba5642fc4d2 Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Thu, 29 Aug 2019 11:04:44 +0200 Subject: [PATCH 27/36] Serial, SerialBase, UARTSerial: Add explicit pinmap support --- drivers/Serial.h | 20 ++++++++++++++++++++ drivers/SerialBase.h | 8 ++++++++ drivers/UARTSerial.h | 7 +++++++ drivers/source/Serial.cpp | 8 ++++++++ drivers/source/SerialBase.cpp | 28 ++++++++++++++++++++++++++++ drivers/source/UARTSerial.cpp | 13 +++++++++++++ 6 files changed, 84 insertions(+) diff --git a/drivers/Serial.h b/drivers/Serial.h index d167e695805..e48397d3569 100644 --- a/drivers/Serial.h +++ b/drivers/Serial.h @@ -73,6 +73,16 @@ class Serial : public SerialBase, public Stream, private NonCopyable { */ Serial(PinName tx, PinName rx, const char *name = NULL, int baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE); + /** Create a Serial port, connected to the specified transmit and receive pins + * + * @param explicit_pinmap reference to strucure which holds static pinmap. + * @param name The name of the stream associated with this serial port (optional) + * @param baud The baud rate of the serial port (optional, defaults to MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE or 9600) + * + * @note + * Either tx or rx may be specified as NC (Not Connected) if unused + */ + Serial(const serial_pinmap_t &explicit_pinmap, const char *name = NULL, int baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE); /** Create a Serial port, connected to the specified transmit and receive pins, with the specified baud * @@ -85,6 +95,16 @@ class Serial : public SerialBase, public Stream, private NonCopyable { */ Serial(PinName tx, PinName rx, int baud); + /** Create a Serial port, connected to the specified transmit and receive pins, with the specified baud + * + * @param explicit_pinmap reference to strucure which holds static pinmap. + * @param baud The baud rate of the serial port + * + * @note + * Either tx or rx may be specified as NC (Not Connected) if unused + */ + Serial(const serial_pinmap_t &explicit_pinmap, int baud); + /* Stream gives us a FileHandle with non-functional poll()/readable()/writable. Pass through * the calls from the SerialBase instead for backwards compatibility. This problem is * part of why Stream and Serial should be deprecated. diff --git a/drivers/SerialBase.h b/drivers/SerialBase.h index 5213f325fd6..25a32dda9d1 100644 --- a/drivers/SerialBase.h +++ b/drivers/SerialBase.h @@ -176,6 +176,13 @@ class SerialBase : private NonCopyable { * @param flow2 the second flow control pin (CTS for RTSCTS) */ void set_flow_control(Flow type, PinName flow1 = NC, PinName flow2 = NC); + + /** Set the flow control type on the serial port + * + * @param type the flow control type (Disabled, RTS, CTS, RTSCTS) + * @param pinmap reference to strucure which holds static pinmap + */ + void set_flow_control(Flow type, const serial_fc_pinmap_t &explicit_pinmap); #endif static void _irq_handler(uint32_t id, SerialIrq irq_type); @@ -289,6 +296,7 @@ class SerialBase : private NonCopyable { #if !defined(DOXYGEN_ONLY) protected: SerialBase(PinName tx, PinName rx, int baud); + SerialBase(const serial_pinmap_t &explicit_pinmap, int baud); virtual ~SerialBase(); int _base_getc(); diff --git a/drivers/UARTSerial.h b/drivers/UARTSerial.h index e23a4a65b03..506e11a9cac 100644 --- a/drivers/UARTSerial.h +++ b/drivers/UARTSerial.h @@ -58,6 +58,13 @@ class UARTSerial : private SerialBase, public FileHandle, private NonCopyable Date: Thu, 12 Sep 2019 10:28:36 +0200 Subject: [PATCH 28/36] K64F, NUCLEO_F429ZI: Use explicit pinmap for console --- platform/source/mbed_retarget.cpp | 51 +++++++++++++++---- .../TARGET_MCU_K64F/TARGET_FRDM/PinNames.h | 5 +- .../TARGET_NUCLEO_F429ZI/PinNames.h | 3 ++ 3 files changed, 49 insertions(+), 10 deletions(-) diff --git a/platform/source/mbed_retarget.cpp b/platform/source/mbed_retarget.cpp index 61adeeb0f90..1b6ce12bc5d 100644 --- a/platform/source/mbed_retarget.cpp +++ b/platform/source/mbed_retarget.cpp @@ -32,6 +32,7 @@ #include "drivers/UARTSerial.h" #include "hal/us_ticker_api.h" #include "hal/lp_ticker_api.h" +#include "hal/explicit_pinmap.h" #include #include #include @@ -141,6 +142,7 @@ extern serial_t stdio_uart; class DirectSerial : public FileHandle { public: DirectSerial(PinName tx, PinName rx, int baud); + DirectSerial(const serial_pinmap_t &explicit_pinmap, int baud); virtual ssize_t write(const void *buffer, size_t size); virtual ssize_t read(void *buffer, size_t size); virtual off_t seek(off_t offset, int whence = SEEK_SET) @@ -167,14 +169,39 @@ DirectSerial::DirectSerial(PinName tx, PinName rx, int baud) if (stdio_uart_inited) { return; } - serial_init(&stdio_uart, tx, rx); + static const serial_pinmap_t console_pinmap = get_uart_pinmap(STDIO_UART_TX, STDIO_UART_RX); + serial_init_direct(&stdio_uart, &console_pinmap); serial_baud(&stdio_uart, baud); + +#if CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_RTS + static const serial_fc_pinmap_t fc_pinmap = get_uart_fc_pinmap(STDIO_UART_RTS, NC); + serial_set_flow_control_direct(&stdio_uart, FlowControlRTS, fc_pinmap); +#elif CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_CTS + static const serial_fc_pinmap_t fc_pinmap = get_uart_fc_pinmap(NC, STDIO_UART_CTS); + serial_set_flow_control_direct(&stdio_uart, FlowControlCTS, fc_pinmap); +#elif CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_RTSCTS + static const serial_fc_pinmap_t fc_pinmap = get_uart_fc_pinmap(STDIO_UART_RTS, STDIO_UART_CTS); + serial_set_flow_control_direct(&stdio_uart, FlowControlRTSCTS, fc_pinmap); +#endif +} + +DirectSerial::DirectSerial(const serial_pinmap_t &explicit_pinmap, int baud) +{ + if (stdio_uart_inited) { + return; + } + serial_init_direct(&stdio_uart, &explicit_pinmap); + serial_baud(&stdio_uart, baud); + #if CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_RTS - serial_set_flow_control(&stdio_uart, FlowControlRTS, STDIO_UART_RTS, NC); + static const serial_fc_pinmap_t fc_pinmap = get_uart_fc_pinmap(STDIO_UART_RTS, NC); + serial_set_flow_control_direct(&stdio_uart, FlowControlRTS, fc_pinmap); #elif CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_CTS - serial_set_flow_control(&stdio_uart, FlowControlCTS, NC, STDIO_UART_CTS); + static const serial_fc_pinmap_t fc_pinmap = get_uart_fc_pinmap(NC, STDIO_UART_CTS); + serial_set_flow_control_direct(&stdio_uart, FlowControlCTS, fc_pinmap); #elif CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_RTSCTS - serial_set_flow_control(&stdio_uart, FlowControlRTSCTS, STDIO_UART_RTS, STDIO_UART_CTS); + static const serial_fc_pinmap_t fc_pinmap = get_uart_fc_pinmap(STDIO_UART_RTS, STDIO_UART_CTS); + serial_set_flow_control_direct(&stdio_uart, FlowControlRTSCTS, fc_pinmap); #endif } @@ -261,17 +288,23 @@ MBED_WEAK FileHandle *mbed::mbed_override_console(int fd) static FileHandle *default_console() { #if MBED_CONF_TARGET_CONSOLE_UART && DEVICE_SERIAL + # if MBED_CONF_PLATFORM_STDIO_BUFFERED_SERIAL - static UARTSerial console(STDIO_UART_TX, STDIO_UART_RX, MBED_CONF_PLATFORM_STDIO_BAUD_RATE); + static const serial_pinmap_t console_pinmap = get_uart_pinmap(STDIO_UART_TX, STDIO_UART_RX); + static UARTSerial console(console_pinmap, MBED_CONF_PLATFORM_STDIO_BAUD_RATE); # if CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_RTS - console.set_flow_control(SerialBase::RTS, STDIO_UART_RTS, NC); + static const serial_fc_pinmap_t fc_pinmap = get_uart_fc_pinmap(STDIO_UART_RTS, NC); + console.serial_set_flow_control(SerialBase::RTS, fc_pinmap); # elif CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_CTS - console.set_flow_control(SerialBase::CTS, NC, STDIO_UART_CTS); + static const serial_fc_pinmap_t fc_pinmap = get_uart_fc_pinmap(NC, STDIO_UART_CTS); + console.serial_set_flow_control(SerialBase::CTS, fc_pinmap); # elif CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_RTSCTS - console.set_flow_control(SerialBase::RTSCTS, STDIO_UART_RTS, STDIO_UART_CTS); + static const serial_fc_pinmap_t fc_pinmap = get_uart_fc_pinmap(STDIO_UART_RTS, STDIO_UART_CTS); + console.serial_set_flow_control(SerialBase::RTSCTS, fc_pinmap); # endif # else - static DirectSerial console(STDIO_UART_TX, STDIO_UART_RX, MBED_CONF_PLATFORM_STDIO_BAUD_RATE); + static const serial_pinmap_t console_pinmap = get_uart_pinmap(STDIO_UART_TX, STDIO_UART_RX); + static DirectSerial console(console_pinmap, MBED_CONF_PLATFORM_STDIO_BAUD_RATE); # endif #else // MBED_CONF_TARGET_CONSOLE_UART && DEVICE_SERIAL static Sink console; diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PinNames.h b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PinNames.h index a2a388eb10e..d518d298638 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PinNames.h +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PinNames.h @@ -22,6 +22,9 @@ extern "C" { #endif +/* If this macro is defined, then constexpr utility functions for pin-map seach can be used. */ +#define EXPLICIT_PINMAP_READY 1 + typedef enum { PIN_INPUT, PIN_OUTPUT @@ -229,7 +232,7 @@ typedef enum { D13 = PTD1, D14 = PTE25, D15 = PTE24, - + I2C_SCL = D15, I2C_SDA = D14, diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F429xI/TARGET_NUCLEO_F429ZI/PinNames.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F429xI/TARGET_NUCLEO_F429ZI/PinNames.h index ad1011aebe8..6411fe78383 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F429xI/TARGET_NUCLEO_F429ZI/PinNames.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F429xI/TARGET_NUCLEO_F429ZI/PinNames.h @@ -38,6 +38,9 @@ extern "C" { #endif +/* If this macro is defined, then constexpr utility functions for pin-map seach can be used. */ +#define EXPLICIT_PINMAP_READY 1 + typedef enum { ALT0 = 0x100, ALT1 = 0x200, From 5ec50ebe81a6f696c4799973819832f5c3544bba Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Wed, 11 Sep 2019 09:37:53 +0200 Subject: [PATCH 29/36] mstd_cstddef: add C support and macros for C++11 --- platform/cxxsupport/mstd_cstddef | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/platform/cxxsupport/mstd_cstddef b/platform/cxxsupport/mstd_cstddef index 937f80ed521..9c7dfcbc288 100644 --- a/platform/cxxsupport/mstd_cstddef +++ b/platform/cxxsupport/mstd_cstddef @@ -27,8 +27,12 @@ * - - MSTD_CONSTEXPR_XX_14 macros that can be used to mark * things that are valid as constexpr only for C++14 or later, * permitting constexpr use where ARM C 5 would reject it. + * - - MSTD_CONSTEXPR_XX_11 macros that can be used to permit + * constexpr alternatives for C. */ +#if __cplusplus + #include /* Macros that can be used to mark functions and objects that are @@ -42,6 +46,9 @@ #define MSTD_CONSTEXPR_OBJ_14 const #endif +#define MSTD_CONSTEXPR_FN_11 constexpr +#define MSTD_CONSTEXPR_OBJ_11 constexpr + #ifdef __CC_ARM // [expr.alignof] @@ -72,4 +79,13 @@ using std::max_align_t; } +#else // __cplusplus + +#define MSTD_CONSTEXPR_FN_14 inline +#define MSTD_CONSTEXPR_OBJ_14 const +#define MSTD_CONSTEXPR_FN_11 inline +#define MSTD_CONSTEXPR_OBJ_11 const + +#endif // __cplusplus + #endif // MSTD_CSTDDEF_ From fd4a59bf27b8d71af9df22fc573c0e1825d2bf7c Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Mon, 9 Sep 2019 08:57:58 +0200 Subject: [PATCH 30/36] Add constexpr utility functions to search for pin mapping --- ...{explicit_pinmap.c => explicit_pinmap.cpp} | 7 +- hal/explicit_pinmap.h | 251 ++++++++++++++++++ 2 files changed, 252 insertions(+), 6 deletions(-) rename hal/{explicit_pinmap.c => explicit_pinmap.cpp} (93%) create mode 100644 hal/explicit_pinmap.h diff --git a/hal/explicit_pinmap.c b/hal/explicit_pinmap.cpp similarity index 93% rename from hal/explicit_pinmap.c rename to hal/explicit_pinmap.cpp index d341de2efab..5c2e532cc69 100644 --- a/hal/explicit_pinmap.c +++ b/hal/explicit_pinmap.cpp @@ -16,12 +16,7 @@ */ #include "mbed_error.h" -#include "spi_api.h" -#include "pwmout_api.h" -#include "analogin_api.h" -#include "analogout_api.h" -#include "i2c_api.h" -#include "serial_api.h" +#include "explicit_pinmap.h" /* diff --git a/hal/explicit_pinmap.h b/hal/explicit_pinmap.h new file mode 100644 index 00000000000..24055f9e0c0 --- /dev/null +++ b/hal/explicit_pinmap.h @@ -0,0 +1,251 @@ +/* mbed Microcontroller Library + * Copyright (c) 2018-2019 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 EXPLICIT_PINMAP_H +#define EXPLICIT_PINMAP_H + +#include "PinNames.h" +#include "spi_api.h" +#include "pwmout_api.h" +#include "analogin_api.h" +#include "analogout_api.h" +#include "i2c_api.h" +#include "serial_api.h" +#include + +#if EXPLICIT_PINMAP_READY +#include "PeripheralPinMaps.h" + +#if DEVICE_PWMOUT +MSTD_CONSTEXPR_FN_14 PinMap get_pwm_pinmap(const PinName pin) +{ + for (const PinMap &pinmap : PINMAP_PWM) { + if (pinmap.pin == pin) { + return {pin, pinmap.peripheral, pinmap.function}; + } + } + return {NC, NC, NC}; +} +#endif // DEVICE_PWMOUT + +#if DEVICE_ANALOGIN +MSTD_CONSTEXPR_FN_14 PinMap get_analogin_pinmap(const PinName pin) +{ + for (const PinMap &pinmap : PINMAP_ANALOGIN) { + if (pinmap.pin == pin) { + return {pin, pinmap.peripheral, pinmap.function}; + } + } + return {NC, NC, NC}; +} +#endif // DEVICE_ANALOGIN + +#if DEVICE_ANALOGOUT +MSTD_CONSTEXPR_FN_14 PinMap get_analogout_pinmap(const PinName pin) +{ + for (const PinMap &pinmap : PINMAP_ANALOGOUT) { + if (pinmap.pin == pin) { + return {pin, pinmap.peripheral, pinmap.function}; + } + } + return {NC, NC, NC}; +} +#endif // DEVICE_ANALOGOUT + +#if DEVICE_I2C +MSTD_CONSTEXPR_FN_14 i2c_pinmap_t get_i2c_pinmap(const PinName sda, const PinName scl) +{ + const PinMap *sda_map = nullptr; + for (const PinMap &pinmap : PINMAP_I2C_SDA) { + if (pinmap.pin == sda) { + sda_map = &pinmap; + break; + } + } + + const PinMap *scl_map = nullptr; + for (const PinMap &pinmap : PINMAP_I2C_SCL) { + if (pinmap.pin == scl) { + scl_map = &pinmap; + break; + } + } + + if (!sda_map || !scl_map || sda_map->peripheral != scl_map->peripheral) { + return {NC, NC, NC, NC, NC}; + } + + return {sda_map->peripheral, sda_map->pin, sda_map->function, scl_map->pin, scl_map->function}; +} +#endif //DEVICE_I2C + +#if DEVICE_SERIAL +MSTD_CONSTEXPR_FN_14 serial_pinmap_t get_uart_pinmap(const PinName tx, const PinName rx) +{ + const PinMap *tx_map = nullptr; + for (const PinMap &pinmap : PINMAP_UART_TX) { + if (pinmap.pin == tx) { + tx_map = &pinmap; + break; + } + } + + const PinMap *rx_map = nullptr; + for (const PinMap &pinmap : PINMAP_UART_RX) { + if (pinmap.pin == rx) { + rx_map = &pinmap; + break; + } + } + + if (!tx_map || !rx_map || rx_map->peripheral != tx_map->peripheral) { + return {NC, NC, NC, NC, NC, false}; + } + + if (tx_map->pin == STDIO_UART_TX && rx_map->pin == STDIO_UART_RX) { + return {tx_map->peripheral, tx_map->pin, tx_map->function, rx_map->pin, rx_map->function, true}; + } else { + return {tx_map->peripheral, tx_map->pin, tx_map->function, rx_map->pin, rx_map->function, false}; + } +} + +#if DEVICE_SERIAL_FC +MSTD_CONSTEXPR_FN_14 serial_fc_pinmap_t get_uart_fc_pinmap(const PinName rxflow, const PinName txflow) +{ + const PinMap *rts_map = nullptr; + for (const PinMap &pinmap : PINMAP_UART_RTS) { + if (pinmap.pin == rxflow) { + rts_map = &pinmap; + break; + } + } + + const PinMap *cts_map = nullptr; + for (const PinMap &pinmap : PINMAP_UART_CTS) { + if (pinmap.pin == txflow) { + cts_map = &pinmap; + break; + } + } + + if ((!rts_map || !cts_map) || (rts_map->peripheral != cts_map->peripheral)) { + return {NC, NC, NC, NC, NC}; + } + + return {cts_map->peripheral, cts_map->pin, cts_map->function, rts_map->pin, rts_map->function}; +} +#endif // DEVICE_SERIAL_FC +#endif // DEVICE_SERIAL + +#if DEVICE_SPI +MSTD_CONSTEXPR_FN_14 spi_pinmap_t get_spi_pinmap(const PinName mosi, const PinName miso, const PinName sclk, const PinName ssel) +{ + const PinMap *mosi_map = nullptr; + for (const PinMap &pinmap : PINMAP_SPI_MOSI) { + if (pinmap.pin == mosi) { + mosi_map = &pinmap; + break; + } + } + + const PinMap *miso_map = nullptr; + for (const PinMap &pinmap : PINMAP_SPI_MISO) { + if (pinmap.pin == miso) { + miso_map = &pinmap; + break; + } + } + + const PinMap *sclk_map = nullptr; + for (const PinMap &pinmap : PINMAP_SPI_SCLK) { + if (pinmap.pin == sclk) { + sclk_map = &pinmap; + break; + } + } + + const PinMap *ssel_map = nullptr; + for (const PinMap &pinmap : PINMAP_SPI_SSEL) { + if (pinmap.pin == ssel) { + ssel_map = &pinmap; + break; + } + } + + if ((!mosi_map || !miso_map || !sclk_map || !ssel_map) || + (mosi_map->peripheral != miso_map->peripheral || mosi_map->peripheral != sclk_map->peripheral) || + (ssel_map->pin != NC && mosi_map->peripheral != ssel_map->peripheral)) { + return {NC, NC, NC, NC, NC, NC, NC, NC, NC}; + } + + return {mosi_map->peripheral, mosi_map->pin, mosi_map->function, miso_map->pin, miso_map->function, sclk_map->pin, sclk_map->function, ssel_map->pin, ssel_map->function}; +} +#endif // DEVICE_SPI + +#else // EXPLICIT_PINMAP_READY + +#if DEVICE_PWMOUT +MSTD_CONSTEXPR_FN_14 PinMap get_pwm_pinmap(const PinName pin) +{ + return {pin, NC, NC}; +} +#endif // DEVICE_PWMOUT + +#if DEVICE_ANALOGIN +MSTD_CONSTEXPR_FN_14 PinMap get_analogin_pinmap(const PinName pin) +{ + return {pin, NC, NC}; +} +#endif // DEVICE_ANALOGIN + +#if DEVICE_ANALOGOUT +MSTD_CONSTEXPR_FN_14 PinMap get_analogout_pinmap(const PinName pin) +{ + return {pin, NC, NC}; +} +#endif // DEVICE_ANALOGOUT + +#if DEVICE_I2C +MSTD_CONSTEXPR_FN_14 i2c_pinmap_t get_i2c_pinmap(const PinName sda, const PinName scl) +{ + return {NC, sda, NC, scl, NC}; +} +#endif //DEVICE_I2C + +#if DEVICE_SERIAL +MSTD_CONSTEXPR_FN_14 serial_pinmap_t get_uart_pinmap(const PinName tx, const PinName rx) +{ + return {NC, tx, NC, rx, NC, false}; +} + +#if DEVICE_SERIAL_FC +MSTD_CONSTEXPR_FN_14 serial_fc_pinmap_t get_uart_fc_pinmap(const PinName rxflow, const PinName txflow) +{ + return {NC, txflow, NC, rxflow, NC}; +} +#endif // DEVICE_SERIAL_FC +#endif // DEVICE_SERIAL + +#if DEVICE_SPI +MSTD_CONSTEXPR_FN_14 spi_pinmap_t get_spi_pinmap(const PinName mosi, const PinName miso, const PinName sclk, const PinName ssel) +{ + return {NC, mosi, NC, miso, NC, sclk, NC, ssel, NC}; +} +#endif // DEVICE_SERIAL + +#endif // EXPLICIT_PINMAP_READY + +#endif // EXPLICIT_PINMAP_H From a3fceda4398da3e407a1eb32c7f13c7e0141c6fb Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Mon, 9 Sep 2019 09:00:36 +0200 Subject: [PATCH 31/36] K64F: Add constexpr pinmap tables --- .../TARGET_FRDM/PeripheralPinMaps.h | 374 ++++++++++++++++++ .../TARGET_FRDM/PeripheralPins.c | 338 +--------------- 2 files changed, 375 insertions(+), 337 deletions(-) create mode 100644 targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PeripheralPinMaps.h diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PeripheralPinMaps.h b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PeripheralPinMaps.h new file mode 100644 index 00000000000..f62b64b627d --- /dev/null +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PeripheralPinMaps.h @@ -0,0 +1,374 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * 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_PERIPHERALPINMAPS_H +#define MBED_PERIPHERALPINMAPS_H + +#include + +/************GPIO***************/ +MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_GPIO[] = { + {PTA0, GPIO_X, 1}, + {PTA1, GPIO_X, 1}, + {PTA2, GPIO_X, 1}, + {PTA3, GPIO_X, 1}, + {PTA4, GPIO_X, 1}, + {PTA5, GPIO_X, 1}, + {PTA6, GPIO_X, 1}, + {PTA7, GPIO_X, 1}, + {PTA8, GPIO_X, 1}, + {PTA9, GPIO_X, 1}, + {PTA10, GPIO_X, 1}, + {PTA11, GPIO_X, 1}, + {PTA12, GPIO_X, 1}, + {PTA13, GPIO_X, 1}, + {PTA14, GPIO_X, 1}, + {PTA15, GPIO_X, 1}, + {PTA16, GPIO_X, 1}, + {PTA17, GPIO_X, 1}, + {PTA18, GPIO_X, 1}, + {PTA19, GPIO_X, 1}, + {PTA24, GPIO_X, 1}, + {PTA25, GPIO_X, 1}, + {PTA26, GPIO_X, 1}, + {PTA27, GPIO_X, 1}, + {PTA28, GPIO_X, 1}, + {PTA29, GPIO_X, 1}, + + {PTB0, GPIO_X, 1}, + {PTB1, GPIO_X, 1}, + {PTB2, GPIO_X, 1}, + {PTB3, GPIO_X, 1}, + {PTB4, GPIO_X, 1}, + {PTB5, GPIO_X, 1}, + {PTB6, GPIO_X, 1}, + {PTB7, GPIO_X, 1}, + {PTB8, GPIO_X, 1}, + {PTB9, GPIO_X, 1}, + {PTB10, GPIO_X, 1}, + {PTB11, GPIO_X, 1}, + {PTB12, GPIO_X, 1}, + {PTB13, GPIO_X, 1}, + {PTB16, GPIO_X, 1}, + {PTB17, GPIO_X, 1}, + {PTB18, GPIO_X, 1}, + {PTB19, GPIO_X, 1}, + {PTB20, GPIO_X, 1}, + {PTB21, GPIO_X, 1}, + {PTB22, GPIO_X, 1}, + {PTB23, GPIO_X, 1}, + + {PTC0, GPIO_X, 1}, + {PTC1, GPIO_X, 1}, + {PTC2, GPIO_X, 1}, + {PTC3, GPIO_X, 1}, + {PTC4, GPIO_X, 1}, + {PTC5, GPIO_X, 1}, + {PTC6, GPIO_X, 1}, + {PTC7, GPIO_X, 1}, + {PTC8, GPIO_X, 1}, + {PTC9, GPIO_X, 1}, + {PTC10, GPIO_X, 1}, + {PTC11, GPIO_X, 1}, + {PTC12, GPIO_X, 1}, + {PTC13, GPIO_X, 1}, + {PTC14, GPIO_X, 1}, + {PTC15, GPIO_X, 1}, + {PTC16, GPIO_X, 1}, + {PTC17, GPIO_X, 1}, + {PTC18, GPIO_X, 1}, + {PTC19, GPIO_X, 1}, + + {PTD0, GPIO_X, 1}, + {PTD1, GPIO_X, 1}, + {PTD2, GPIO_X, 1}, + {PTD3, GPIO_X, 1}, + {PTD4, GPIO_X, 1}, + {PTD5, GPIO_X, 1}, + {PTD6, GPIO_X, 1}, + {PTD7, GPIO_X, 1}, + {PTD8, GPIO_X, 1}, + {PTD9, GPIO_X, 1}, + {PTD10, GPIO_X, 1}, + {PTD11, GPIO_X, 1}, + {PTD12, GPIO_X, 1}, + {PTD13, GPIO_X, 1}, + {PTD14, GPIO_X, 1}, + {PTD15, GPIO_X, 1}, + + {PTE0, GPIO_X, 1}, + {PTE1, GPIO_X, 1}, + {PTE2, GPIO_X, 1}, + {PTE3, GPIO_X, 1}, + {PTE4, GPIO_X, 1}, + {PTE5, GPIO_X, 1}, + {PTE6, GPIO_X, 1}, + {PTE7, GPIO_X, 1}, + {PTE8, GPIO_X, 1}, + {PTE9, GPIO_X, 1}, + {PTE10, GPIO_X, 1}, + {PTE11, GPIO_X, 1}, + {PTE12, GPIO_X, 1}, + // {PTE24, GPIO_X, 1}, // fixed pull-up (for I2C) + // {PTE25, GPIO_X, 1}, // fixed pull-up (for I2C) + {PTE26, GPIO_X, 1}, + {PTE27, GPIO_X, 1}, + {PTE28, GPIO_X, 1}, + + {NC , NC , 0} +}; + +/************RTC***************/ +MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_RTC[] = { + {NC, OSC32KCLK, 0}, +}; + +/************ADC***************/ +MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_ADC[] = { + {PTA17, ADC1_SE17, 0}, + {PTB0 , ADC0_SE8 , 0}, + {PTB1 , ADC0_SE9 , 0}, + {PTB2 , ADC0_SE12, 0}, + {PTB3 , ADC0_SE13, 0}, + {PTB6 , ADC1_SE12, 0}, + {PTB7 , ADC1_SE13, 0}, + {PTB10, ADC1_SE14, 0}, + {PTB11, ADC1_SE15, 0}, + {PTC0 , ADC0_SE14, 0}, + {PTC1 , ADC0_SE15, 0}, + {PTC2, ADC0_SE4b, 0}, + {PTC8, ADC1_SE4b, 0}, + {PTC9, ADC1_SE5b, 0}, + {PTC10, ADC1_SE6b, 0}, + {PTC11, ADC1_SE7b, 0}, + {PTD1, ADC0_SE5b, 0}, + {PTD5, ADC0_SE6b, 0}, + {PTD6, ADC0_SE7b, 0}, + {PTE0, ADC1_SE4a, 0}, + {PTE1, ADC1_SE5a, 0}, + {PTE2, ADC1_SE6a, 0}, + {PTE3, ADC1_SE7a, 0}, + //{PTE24, ADC0_SE17, 0}, //I2C pull up + //{PTE25, ADC0_SE18, 0}, //I2C pull up + {NC , NC , 0} +}; + +/************DAC***************/ +MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_DAC[] = { + {DAC0_OUT, DAC_0, 0}, + {NC , NC , 0} +}; + +/************I2C***************/ +MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_I2C_SDA[] = { + {PTE25, I2C_0, 5}, + {PTB1 , I2C_0, 2}, + {PTB3 , I2C_0, 2}, + {PTC11, I2C_1, 2}, + {PTA13, I2C_2, 5}, + {PTD3 , I2C_0, 7}, + {PTE0 , I2C_1, 6}, + {NC , NC , 0} +}; + +MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_I2C_SCL[] = { + {PTE24, I2C_0, 5}, + {PTB0 , I2C_0, 2}, + {PTB2 , I2C_0, 2}, + {PTC10, I2C_1, 2}, + {PTA12, I2C_2, 5}, + {PTA14, I2C_2, 5}, + {PTD2 , I2C_0, 7}, + {PTE1 , I2C_1, 6}, + {NC , NC , 0} +}; + +/************UART***************/ +MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_UART_TX[] = { + {PTB17, UART_0, 3}, + {PTC17, UART_3, 3}, + {PTD7 , UART_0, 3}, + {PTD3 , UART_2, 3}, + {PTC4 , UART_1, 3}, + {PTC15, UART_4, 3}, + {PTB11, UART_3, 3}, + {PTA14, UART_0, 3}, + {PTE24, UART_4, 3}, + {PTE4 , UART_3, 3}, + {PTE0, UART_1, 3}, + {NC , NC , 0} +}; + +MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_UART_RX[] = { + {PTB16, UART_0, 3}, + {PTE1 , UART_1, 3}, + {PTE5 , UART_3, 3}, + {PTE25, UART_4, 3}, + {PTA15, UART_0, 3}, + {PTC16, UART_3, 3}, + {PTB10, UART_3, 3}, + {PTC3 , UART_1, 3}, + {PTC14, UART_4, 3}, + {PTD2 , UART_2, 3}, + {PTD6 , UART_0, 3}, + {NC , NC , 0} +}; + +MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_UART_CTS[] = { + {PTB13, UART_3, 2}, + {PTE2 , UART_1, 3}, + {PTE6 , UART_3, 3}, + {PTE26, UART_4, 3}, + {PTA0 , UART_0, 2}, + {PTA16, UART_0, 3}, + {PTB3 , UART_0, 3}, + {PTB9 , UART_3, 3}, + {PTC2 , UART_1, 3}, + {PTC13, UART_4, 3}, + {PTC19, UART_3, 3}, + {PTD1 , UART_2, 3}, + {PTD5 , UART_0, 3}, + {NC , NC , 0} +}; + +MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_UART_RTS[] = { + {PTB12, UART_3, 2}, + {PTE3 , UART_1, 3}, + {PTE7 , UART_3, 3}, + {PTE27, UART_4, 3}, + {PTA17, UART_0, 3}, + {PTB8 , UART_3, 3}, + {PTC1 , UART_1, 3}, + {PTC12, UART_4, 3}, + {PTC18, UART_3, 3}, + {PTD0 , UART_2, 3}, + {PTD4 , UART_0, 3}, + {PTA3 , UART_0, 2}, + {PTB2 , UART_0, 3}, + {NC , NC , 0} +}; + +/************SPI***************/ +MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_SPI_SCLK[] = { + {PTD1 , SPI_0, 2}, + {PTE2 , SPI_1, 2}, + {PTA15, SPI_0, 2}, + {PTB11, SPI_1, 2}, + {PTB21, SPI_2, 2}, + {PTC5 , SPI_0, 2}, + {PTD5 , SPI_1, 7}, + {NC , NC , 0} +}; + +MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_SPI_MOSI[] = { + {PTD2 , SPI_0, 2}, + {PTE1 , SPI_1, 2}, + {PTE3 , SPI_1, 7}, + {PTA16, SPI_0, 2}, + {PTB16, SPI_1, 2}, + {PTB22, SPI_2, 2}, + {PTC6 , SPI_0, 2}, + {PTD6 , SPI_1, 7}, + {NC , NC , 0} +}; + +MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_SPI_MISO[] = { + {PTD3 , SPI_0, 2}, + {PTE1 , SPI_1, 7}, + {PTE3 , SPI_1, 2}, + {PTA17, SPI_0, 2}, + {PTB17, SPI_1, 2}, + {PTB23, SPI_2, 2}, + {PTC7 , SPI_0, 2}, + {PTD7 , SPI_1, 7}, + {NC , NC , 0} +}; + +MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_SPI_SSEL[] = { + {PTD0 , SPI_0, 2}, + {PTE4 , SPI_1, 2}, + {PTA14, SPI_0, 2}, + {PTB10, SPI_1, 2}, + {PTB20, SPI_2, 2}, + {PTC4 , SPI_0, 2}, + {PTD4 , SPI_1, 7}, + {NC , NC , 0} +}; + +/************PWM***************/ +MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_PWM[] = { + {PTA0 , PWM_6 , 3}, + {PTA1 , PWM_7 , 3}, + {PTA2 , PWM_8 , 3}, + {PTA3 , PWM_1 , 3}, + {PTA4 , PWM_2 , 3}, + {PTA5 , PWM_3 , 3}, + {PTA6 , PWM_4 , 3}, + {PTA7 , PWM_5 , 3}, + {PTA8 , PWM_9 , 3}, + {PTA9 , PWM_10, 3}, + {PTA10, PWM_17, 3}, + {PTA11, PWM_18, 3}, + {PTA12, PWM_9 , 3}, + {PTA13, PWM_10, 3}, + + {PTB0 , PWM_9 , 3}, + {PTB1 , PWM_10, 3}, + {PTB18, PWM_17, 3}, + {PTB19, PWM_18, 3}, + + {PTC1 , PWM_1 , 4}, + {PTC2 , PWM_2 , 4}, + {PTC3 , PWM_3 , 4}, + {PTC4 , PWM_4 , 4}, + {PTC5 , PWM_3 , 7}, + {PTC8 , PWM_29, 3}, + {PTC9 , PWM_30, 3}, + {PTC10, PWM_31, 3}, + {PTC11, PWM_32, 3}, + + {PTD0 , PWM_25, 4}, + {PTD1 , PWM_26, 4}, + {PTD2 , PWM_27, 4}, + {PTD3 , PWM_28, 4}, + {PTD4 , PWM_5 , 4}, + {PTD5 , PWM_6 , 4}, + {PTD6 , PWM_7 , 4}, + {PTD4 , PWM_5 , 4}, + {PTD7 , PWM_8 , 4}, + + {PTE5 , PWM_25, 6}, + {PTE6 , PWM_26, 6}, + + {NC , NC , 0} +}; + +#define PINMAP_ANALOGIN PinMap_ADC +#define PINMAP_ANALOGOUT PinMap_DAC +#define PINMAP_I2C_SDA PinMap_I2C_SDA +#define PINMAP_I2C_SCL PinMap_I2C_SCL +#define PINMAP_UART_TX PinMap_UART_TX +#define PINMAP_UART_RX PinMap_UART_RX +#define PINMAP_UART_CTS PinMap_UART_CTS +#define PINMAP_UART_RTS PinMap_UART_RTS +#define PINMAP_SPI_SCLK PinMap_SPI_SCLK +#define PINMAP_SPI_MOSI PinMap_SPI_MOSI +#define PINMAP_SPI_MISO PinMap_SPI_MISO +#define PINMAP_SPI_SSEL PinMap_SPI_SSEL +#define PINMAP_PWM PinMap_PWM + + +#endif diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PeripheralPins.c b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PeripheralPins.c index f9d4a90863d..a41c0708f46 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PeripheralPins.c +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PeripheralPins.c @@ -15,345 +15,9 @@ */ #include "PeripheralPins.h" - -/************GPIO***************/ -const PinMap PinMap_GPIO[] = { - {PTA0, GPIO_X, 1}, - {PTA1, GPIO_X, 1}, - {PTA2, GPIO_X, 1}, - {PTA3, GPIO_X, 1}, - {PTA4, GPIO_X, 1}, - {PTA5, GPIO_X, 1}, - {PTA6, GPIO_X, 1}, - {PTA7, GPIO_X, 1}, - {PTA8, GPIO_X, 1}, - {PTA9, GPIO_X, 1}, - {PTA10, GPIO_X, 1}, - {PTA11, GPIO_X, 1}, - {PTA12, GPIO_X, 1}, - {PTA13, GPIO_X, 1}, - {PTA14, GPIO_X, 1}, - {PTA15, GPIO_X, 1}, - {PTA16, GPIO_X, 1}, - {PTA17, GPIO_X, 1}, - {PTA18, GPIO_X, 1}, - {PTA19, GPIO_X, 1}, - {PTA24, GPIO_X, 1}, - {PTA25, GPIO_X, 1}, - {PTA26, GPIO_X, 1}, - {PTA27, GPIO_X, 1}, - {PTA28, GPIO_X, 1}, - {PTA29, GPIO_X, 1}, - - {PTB0, GPIO_X, 1}, - {PTB1, GPIO_X, 1}, - {PTB2, GPIO_X, 1}, - {PTB3, GPIO_X, 1}, - {PTB4, GPIO_X, 1}, - {PTB5, GPIO_X, 1}, - {PTB6, GPIO_X, 1}, - {PTB7, GPIO_X, 1}, - {PTB8, GPIO_X, 1}, - {PTB9, GPIO_X, 1}, - {PTB10, GPIO_X, 1}, - {PTB11, GPIO_X, 1}, - {PTB12, GPIO_X, 1}, - {PTB13, GPIO_X, 1}, - {PTB16, GPIO_X, 1}, - {PTB17, GPIO_X, 1}, - {PTB18, GPIO_X, 1}, - {PTB19, GPIO_X, 1}, - {PTB20, GPIO_X, 1}, - {PTB21, GPIO_X, 1}, - {PTB22, GPIO_X, 1}, - {PTB23, GPIO_X, 1}, - - {PTC0, GPIO_X, 1}, - {PTC1, GPIO_X, 1}, - {PTC2, GPIO_X, 1}, - {PTC3, GPIO_X, 1}, - {PTC4, GPIO_X, 1}, - {PTC5, GPIO_X, 1}, - {PTC6, GPIO_X, 1}, - {PTC7, GPIO_X, 1}, - {PTC8, GPIO_X, 1}, - {PTC9, GPIO_X, 1}, - {PTC10, GPIO_X, 1}, - {PTC11, GPIO_X, 1}, - {PTC12, GPIO_X, 1}, - {PTC13, GPIO_X, 1}, - {PTC14, GPIO_X, 1}, - {PTC15, GPIO_X, 1}, - {PTC16, GPIO_X, 1}, - {PTC17, GPIO_X, 1}, - {PTC18, GPIO_X, 1}, - {PTC19, GPIO_X, 1}, - - {PTD0, GPIO_X, 1}, - {PTD1, GPIO_X, 1}, - {PTD2, GPIO_X, 1}, - {PTD3, GPIO_X, 1}, - {PTD4, GPIO_X, 1}, - {PTD5, GPIO_X, 1}, - {PTD6, GPIO_X, 1}, - {PTD7, GPIO_X, 1}, - {PTD8, GPIO_X, 1}, - {PTD9, GPIO_X, 1}, - {PTD10, GPIO_X, 1}, - {PTD11, GPIO_X, 1}, - {PTD12, GPIO_X, 1}, - {PTD13, GPIO_X, 1}, - {PTD14, GPIO_X, 1}, - {PTD15, GPIO_X, 1}, - - {PTE0, GPIO_X, 1}, - {PTE1, GPIO_X, 1}, - {PTE2, GPIO_X, 1}, - {PTE3, GPIO_X, 1}, - {PTE4, GPIO_X, 1}, - {PTE5, GPIO_X, 1}, - {PTE6, GPIO_X, 1}, - {PTE7, GPIO_X, 1}, - {PTE8, GPIO_X, 1}, - {PTE9, GPIO_X, 1}, - {PTE10, GPIO_X, 1}, - {PTE11, GPIO_X, 1}, - {PTE12, GPIO_X, 1}, - // {PTE24, GPIO_X, 1}, // fixed pull-up (for I2C) - // {PTE25, GPIO_X, 1}, // fixed pull-up (for I2C) - {PTE26, GPIO_X, 1}, - {PTE27, GPIO_X, 1}, - {PTE28, GPIO_X, 1}, - - {NC , NC , 0} -}; +#include "PeripheralPinMaps.h" const PinMap *gpio_pinmap() { return PinMap_GPIO; } - -/************RTC***************/ -const PinMap PinMap_RTC[] = { - {NC, OSC32KCLK, 0}, -}; - -/************ADC***************/ -const PinMap PinMap_ADC[] = { - {PTA17, ADC1_SE17, 0}, - {PTB0 , ADC0_SE8 , 0}, - {PTB1 , ADC0_SE9 , 0}, - {PTB2 , ADC0_SE12, 0}, - {PTB3 , ADC0_SE13, 0}, - {PTB6 , ADC1_SE12, 0}, - {PTB7 , ADC1_SE13, 0}, - {PTB10, ADC1_SE14, 0}, - {PTB11, ADC1_SE15, 0}, - {PTC0 , ADC0_SE14, 0}, - {PTC1 , ADC0_SE15, 0}, - {PTC2, ADC0_SE4b, 0}, - {PTC8, ADC1_SE4b, 0}, - {PTC9, ADC1_SE5b, 0}, - {PTC10, ADC1_SE6b, 0}, - {PTC11, ADC1_SE7b, 0}, - {PTD1, ADC0_SE5b, 0}, - {PTD5, ADC0_SE6b, 0}, - {PTD6, ADC0_SE7b, 0}, - {PTE0, ADC1_SE4a, 0}, - {PTE1, ADC1_SE5a, 0}, - {PTE2, ADC1_SE6a, 0}, - {PTE3, ADC1_SE7a, 0}, - //{PTE24, ADC0_SE17, 0}, //I2C pull up - //{PTE25, ADC0_SE18, 0}, //I2C pull up - {NC , NC , 0} -}; - -/************DAC***************/ -const PinMap PinMap_DAC[] = { - {DAC0_OUT, DAC_0, 0}, - {NC , NC , 0} -}; - -/************I2C***************/ -const PinMap PinMap_I2C_SDA[] = { - {PTE25, I2C_0, 5}, - {PTB1 , I2C_0, 2}, - {PTB3 , I2C_0, 2}, - {PTC11, I2C_1, 2}, - {PTA13, I2C_2, 5}, - {PTD3 , I2C_0, 7}, - {PTE0 , I2C_1, 6}, - {NC , NC , 0} -}; - -const PinMap PinMap_I2C_SCL[] = { - {PTE24, I2C_0, 5}, - {PTB0 , I2C_0, 2}, - {PTB2 , I2C_0, 2}, - {PTC10, I2C_1, 2}, - {PTA12, I2C_2, 5}, - {PTA14, I2C_2, 5}, - {PTD2 , I2C_0, 7}, - {PTE1 , I2C_1, 6}, - {NC , NC , 0} -}; - -/************UART***************/ -const PinMap PinMap_UART_TX[] = { - {PTB17, UART_0, 3}, - {PTC17, UART_3, 3}, - {PTD7 , UART_0, 3}, - {PTD3 , UART_2, 3}, - {PTC4 , UART_1, 3}, - {PTC15, UART_4, 3}, - {PTB11, UART_3, 3}, - {PTA14, UART_0, 3}, - {PTE24, UART_4, 3}, - {PTE4 , UART_3, 3}, - {PTE0, UART_1, 3}, - {NC , NC , 0} -}; - -const PinMap PinMap_UART_RX[] = { - {PTB16, UART_0, 3}, - {PTE1 , UART_1, 3}, - {PTE5 , UART_3, 3}, - {PTE25, UART_4, 3}, - {PTA15, UART_0, 3}, - {PTC16, UART_3, 3}, - {PTB10, UART_3, 3}, - {PTC3 , UART_1, 3}, - {PTC14, UART_4, 3}, - {PTD2 , UART_2, 3}, - {PTD6 , UART_0, 3}, - {NC , NC , 0} -}; - -const PinMap PinMap_UART_CTS[] = { - {PTB13, UART_3, 2}, - {PTE2 , UART_1, 3}, - {PTE6 , UART_3, 3}, - {PTE26, UART_4, 3}, - {PTA0 , UART_0, 2}, - {PTA16, UART_0, 3}, - {PTB3 , UART_0, 3}, - {PTB9 , UART_3, 3}, - {PTC2 , UART_1, 3}, - {PTC13, UART_4, 3}, - {PTC19, UART_3, 3}, - {PTD1 , UART_2, 3}, - {PTD5 , UART_0, 3}, - {NC , NC , 0} -}; - -const PinMap PinMap_UART_RTS[] = { - {PTB12, UART_3, 2}, - {PTE3 , UART_1, 3}, - {PTE7 , UART_3, 3}, - {PTE27, UART_4, 3}, - {PTA17, UART_0, 3}, - {PTB8 , UART_3, 3}, - {PTC1 , UART_1, 3}, - {PTC12, UART_4, 3}, - {PTC18, UART_3, 3}, - {PTD0 , UART_2, 3}, - {PTD4 , UART_0, 3}, - {PTA3 , UART_0, 2}, - {PTB2 , UART_0, 3}, - {NC , NC , 0} -}; - -/************SPI***************/ -const PinMap PinMap_SPI_SCLK[] = { - {PTD1 , SPI_0, 2}, - {PTE2 , SPI_1, 2}, - {PTA15, SPI_0, 2}, - {PTB11, SPI_1, 2}, - {PTB21, SPI_2, 2}, - {PTC5 , SPI_0, 2}, - {PTD5 , SPI_1, 7}, - {NC , NC , 0} -}; - -const PinMap PinMap_SPI_MOSI[] = { - {PTD2 , SPI_0, 2}, - {PTE1 , SPI_1, 2}, - {PTE3 , SPI_1, 7}, - {PTA16, SPI_0, 2}, - {PTB16, SPI_1, 2}, - {PTB22, SPI_2, 2}, - {PTC6 , SPI_0, 2}, - {PTD6 , SPI_1, 7}, - {NC , NC , 0} -}; - -const PinMap PinMap_SPI_MISO[] = { - {PTD3 , SPI_0, 2}, - {PTE1 , SPI_1, 7}, - {PTE3 , SPI_1, 2}, - {PTA17, SPI_0, 2}, - {PTB17, SPI_1, 2}, - {PTB23, SPI_2, 2}, - {PTC7 , SPI_0, 2}, - {PTD7 , SPI_1, 7}, - {NC , NC , 0} -}; - -const PinMap PinMap_SPI_SSEL[] = { - {PTD0 , SPI_0, 2}, - {PTE4 , SPI_1, 2}, - {PTA14, SPI_0, 2}, - {PTB10, SPI_1, 2}, - {PTB20, SPI_2, 2}, - {PTC4 , SPI_0, 2}, - {PTD4 , SPI_1, 7}, - {NC , NC , 0} -}; - -/************PWM***************/ -const PinMap PinMap_PWM[] = { - {PTA0 , PWM_6 , 3}, - {PTA1 , PWM_7 , 3}, - {PTA2 , PWM_8 , 3}, - {PTA3 , PWM_1 , 3}, - {PTA4 , PWM_2 , 3}, - {PTA5 , PWM_3 , 3}, - {PTA6 , PWM_4 , 3}, - {PTA7 , PWM_5 , 3}, - {PTA8 , PWM_9 , 3}, - {PTA9 , PWM_10, 3}, - {PTA10, PWM_17, 3}, - {PTA11, PWM_18, 3}, - {PTA12, PWM_9 , 3}, - {PTA13, PWM_10, 3}, - - {PTB0 , PWM_9 , 3}, - {PTB1 , PWM_10, 3}, - {PTB18, PWM_17, 3}, - {PTB19, PWM_18, 3}, - - {PTC1 , PWM_1 , 4}, - {PTC2 , PWM_2 , 4}, - {PTC3 , PWM_3 , 4}, - {PTC4 , PWM_4 , 4}, - {PTC5 , PWM_3 , 7}, - {PTC8 , PWM_29, 3}, - {PTC9 , PWM_30, 3}, - {PTC10, PWM_31, 3}, - {PTC11, PWM_32, 3}, - - {PTD0 , PWM_25, 4}, - {PTD1 , PWM_26, 4}, - {PTD2 , PWM_27, 4}, - {PTD3 , PWM_28, 4}, - {PTD4 , PWM_5 , 4}, - {PTD5 , PWM_6 , 4}, - {PTD6 , PWM_7 , 4}, - {PTD4 , PWM_5 , 4}, - {PTD7 , PWM_8 , 4}, - - {PTE5 , PWM_25, 6}, - {PTE6 , PWM_26, 6}, - - {NC , NC , 0} -}; From 4bc1cb8e3eb048171ba2f20cd27944e17107fab0 Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Thu, 12 Sep 2019 08:57:59 +0200 Subject: [PATCH 32/36] NUCLEO_F429ZI: Add constexpr pinmap tables --- .../TARGET_NUCLEO_F429ZI/PeripheralPinMaps.h | 379 ++++++++++++++++++ .../TARGET_NUCLEO_F429ZI/PeripheralPins.c | 334 +-------------- 2 files changed, 381 insertions(+), 332 deletions(-) create mode 100644 targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F429xI/TARGET_NUCLEO_F429ZI/PeripheralPinMaps.h diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F429xI/TARGET_NUCLEO_F429ZI/PeripheralPinMaps.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F429xI/TARGET_NUCLEO_F429ZI/PeripheralPinMaps.h new file mode 100644 index 00000000000..61e24bb8213 --- /dev/null +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F429xI/TARGET_NUCLEO_F429ZI/PeripheralPinMaps.h @@ -0,0 +1,379 @@ +/* mbed Microcontroller Library + ******************************************************************************* + * Copyright (c) 2018, STMicroelectronics + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ******************************************************************************* + */ + +//============================================================================== +// Notes +// +// - The pins mentioned Px_y_ALTz are alternative possibilities which use other +// HW peripheral instances. You can use them the same way as any other "normal" +// pin (i.e. PwmOut pwm(PA_7_ALT0);). These pins are not displayed on the board +// pinout image on mbed.org. +// +// - The pins which are connected to other components present on the board have +// the comment "Connected to xxx". The pin function may not work properly in this +// case. These pins may not be displayed on the board pinout image on mbed.org. +// Please read the board reference manual and schematic for more information. +// +// - Warning: pins connected to the default STDIO_UART_TX and STDIO_UART_RX pins are commented +// See https://os.mbed.com/teams/ST/wiki/STDIO for more information. +// +//============================================================================== + +#ifndef MBED_PERIPHERALPINMAPS_H +#define MBED_PERIPHERALPINMAPS_H + +#include + +//*** ADC *** + +MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_ADC[] = { + {PA_0, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 0, 0)}, // ADC1_IN0 + {PA_0_ALT0, ADC_2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 0, 0)}, // ADC2_IN0 + {PA_0_ALT1, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 0, 0)}, // ADC3_IN0 + {PA_1, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC1_IN1 // Connected to RMII_REF_CLK [LAN8742A-CZ-TR_REFCLK0] + {PA_1_ALT0, ADC_2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC2_IN1 // Connected to RMII_REF_CLK [LAN8742A-CZ-TR_REFCLK0] + {PA_1_ALT1, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC3_IN1 // Connected to RMII_REF_CLK [LAN8742A-CZ-TR_REFCLK0] + {PA_2, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC1_IN2 // Connected to RMII_MDIO [LAN8742A-CZ-TR_MDIO] + {PA_2_ALT0, ADC_2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC2_IN2 // Connected to RMII_MDIO [LAN8742A-CZ-TR_MDIO] + {PA_2_ALT1, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC3_IN2 // Connected to RMII_MDIO [LAN8742A-CZ-TR_MDIO] + {PA_3, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC1_IN3 + {PA_3_ALT0, ADC_2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC2_IN3 + {PA_3_ALT1, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC3_IN3 + {PA_4, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC1_IN4 + {PA_4_ALT0, ADC_2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC2_IN4 + {PA_5, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC1_IN5 + {PA_5_ALT0, ADC_2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC2_IN5 + {PA_6, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC1_IN6 + {PA_6_ALT0, ADC_2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC2_IN6 + {PA_7, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC1_IN7 // Connected to RMII_CRS_DV [LAN8742A-CZ-TR_CRS_DV] + {PA_7_ALT0, ADC_2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC2_IN7 // Connected to RMII_CRS_DV [LAN8742A-CZ-TR_CRS_DV] + {PB_0, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC1_IN8 // Connected to LD1 + {PB_0_ALT0, ADC_2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC2_IN8 // Connected to LD1 + {PB_1, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC1_IN9 + {PB_1_ALT0, ADC_2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC2_IN9 + {PC_0, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 10, 0)}, // ADC1_IN10 + {PC_0_ALT0, ADC_2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 10, 0)}, // ADC2_IN10 + {PC_0_ALT1, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 10, 0)}, // ADC3_IN10 + {PC_1, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 11, 0)}, // ADC1_IN11 // Connected to RMII_MDC [LAN8742A-CZ-TR_MDC] + {PC_1_ALT0, ADC_2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 11, 0)}, // ADC2_IN11 // Connected to RMII_MDC [LAN8742A-CZ-TR_MDC] + {PC_1_ALT1, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 11, 0)}, // ADC3_IN11 // Connected to RMII_MDC [LAN8742A-CZ-TR_MDC] + {PC_2, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 12, 0)}, // ADC1_IN12 + {PC_2_ALT0, ADC_2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 12, 0)}, // ADC2_IN12 + {PC_2_ALT1, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 12, 0)}, // ADC3_IN12 + {PC_3, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 13, 0)}, // ADC1_IN13 + {PC_3_ALT0, ADC_2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 13, 0)}, // ADC2_IN13 + {PC_3_ALT1, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 13, 0)}, // ADC3_IN13 + {PC_4, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC1_IN14 // Connected to RMII_RXD0 [LAN8742A-CZ-TR_RXD0] + {PC_4_ALT0, ADC_2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC2_IN14 // Connected to RMII_RXD0 [LAN8742A-CZ-TR_RXD0] + {PC_5, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC1_IN15 // Connected to RMII_RXD1 [LAN8742A-CZ-TR_RXD1] + {PC_5_ALT0, ADC_2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC2_IN15 // Connected to RMII_RXD1 [LAN8742A-CZ-TR_RXD1] + {PF_3, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC3_IN9 + {PF_4, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC3_IN14 + {PF_5, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC3_IN15 + {PF_6, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC3_IN4 + {PF_7, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC3_IN5 + {PF_8, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC3_IN6 + {PF_9, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC3_IN7 + {PF_10, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC3_IN8 + {NC, NC, 0} +}; + +MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_ADC_Internal[] = { + {ADC_TEMP, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 16, 0)}, + {ADC_VREF, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 17, 0)}, + {ADC_VBAT, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 18, 0)}, + {NC, NC, 0} +}; + +//*** DAC *** + +MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_DAC[] = { + {PA_4, DAC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // DAC_OUT1 + {PA_5, DAC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // DAC_OUT2 + {NC, NC, 0} +}; + +//*** I2C *** + +MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_I2C_SDA[] = { + {PB_7, I2C_1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C1)}, // Connected to LD2 [Blue] + {PB_9, I2C_1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C1)}, + {PB_11, I2C_2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C2)}, + {PC_9, I2C_3, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C3)}, + {PF_0, I2C_2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C2)}, + {NC, NC, 0} +}; + +MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_I2C_SCL[] = { + {PA_8, I2C_3, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C3)}, // Connected to USB_SOF [TP1] + {PB_6, I2C_1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C1)}, + {PB_8, I2C_1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C1)}, + {PB_10, I2C_2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C2)}, + {PF_1, I2C_2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C2)}, + {NC, NC, 0} +}; + +//*** PWM *** + +// TIM5 cannot be used because already used by the us_ticker +MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_PWM[] = { + {PA_0, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 1, 0)}, // TIM2_CH1 +// {PA_0, PWM_5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 1, 0)}, // TIM5_CH1 + {PA_1, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 2, 0)}, // TIM2_CH2 // Connected to RMII_REF_CLK [LAN8742A-CZ-TR_REFCLK0] +// {PA_1, PWM_5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 2, 0)}, // TIM5_CH2 // Connected to RMII_REF_CLK [LAN8742A-CZ-TR_REFCLK0] + {PA_2, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 3, 0)}, // TIM2_CH3 // Connected to RMII_MDIO [LAN8742A-CZ-TR_MDIO] +// {PA_2, PWM_5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 3, 0)}, // TIM5_CH3 // Connected to RMII_MDIO [LAN8742A-CZ-TR_MDIO] + {PA_2_ALT0, PWM_9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 1, 0)}, // TIM9_CH1 // Connected to RMII_MDIO [LAN8742A-CZ-TR_MDIO] + {PA_3, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 4, 0)}, // TIM2_CH4 +// {PA_3, PWM_5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 4, 0)}, // TIM5_CH4 + {PA_3_ALT0, PWM_9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 2, 0)}, // TIM9_CH2 + {PA_5, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 1, 0)}, // TIM2_CH1 + {PA_5_ALT0, PWM_8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 1, 1)}, // TIM8_CH1N + {PA_6, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 1, 0)}, // TIM3_CH1 + {PA_6_ALT0, PWM_13, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_TIM13, 1, 0)}, // TIM13_CH1 + {PA_7, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 1, 1)}, // TIM1_CH1N // Connected to RMII_CRS_DV [LAN8742A-CZ-TR_CRS_DV] + {PA_7_ALT0, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 2, 0)}, // TIM3_CH2 // Connected to RMII_CRS_DV [LAN8742A-CZ-TR_CRS_DV] + {PA_7_ALT1, PWM_8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 1, 1)}, // TIM8_CH1N // Connected to RMII_CRS_DV [LAN8742A-CZ-TR_CRS_DV] + {PA_7_ALT2, PWM_14, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_TIM14, 1, 0)}, // TIM14_CH1 // Connected to RMII_CRS_DV [LAN8742A-CZ-TR_CRS_DV] + {PA_8, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 1, 0)}, // TIM1_CH1 // Connected to USB_SOF [TP1] + {PA_9, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 2, 0)}, // TIM1_CH2 // Connected to USB_VBUS + {PA_10, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 3, 0)}, // TIM1_CH3 // Connected to USB_ID + {PA_11, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 4, 0)}, // TIM1_CH4 // Connected to USB_DM + {PA_15, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 1, 0)}, // TIM2_CH1 + {PB_0, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 2, 1)}, // TIM1_CH2N // Connected to LD1 + {PB_0_ALT0, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 3, 0)}, // TIM3_CH3 // Connected to LD1 + {PB_0_ALT1, PWM_8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 2, 1)}, // TIM8_CH2N // Connected to LD1 + {PB_1, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 3, 1)}, // TIM1_CH3N + {PB_1_ALT0, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 4, 0)}, // TIM3_CH4 + {PB_1_ALT1, PWM_8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 3, 1)}, // TIM8_CH3N + {PB_3, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 2, 0)}, // TIM2_CH2 + {PB_4, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 1, 0)}, // TIM3_CH1 + {PB_5, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 2, 0)}, // TIM3_CH2 + {PB_6, PWM_4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 1, 0)}, // TIM4_CH1 + {PB_7, PWM_4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 2, 0)}, // TIM4_CH2 // Connected to LD2 [Blue] + {PB_8, PWM_4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 3, 0)}, // TIM4_CH3 + {PB_8_ALT0, PWM_10, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM10, 1, 0)}, // TIM10_CH1 + {PB_9, PWM_4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 4, 0)}, // TIM4_CH4 + {PB_9_ALT0, PWM_11, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM11, 1, 0)}, // TIM11_CH1 + {PB_10, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 3, 0)}, // TIM2_CH3 + {PB_11, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 4, 0)}, // TIM2_CH4 + {PB_13, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 1, 1)}, // TIM1_CH1N // Connected to RMII_TXD1 [LAN8742A-CZ-TR_TXD1] + {PB_14, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 2, 1)}, // TIM1_CH2N // Connected to LD3 [Red] + {PB_14_ALT0, PWM_8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 2, 1)}, // TIM8_CH2N // Connected to LD3 [Red] + {PB_14_ALT1, PWM_12, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_TIM12, 1, 0)}, // TIM12_CH1 // Connected to LD3 [Red] + {PB_15, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 3, 1)}, // TIM1_CH3N + {PB_15_ALT0, PWM_8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 3, 1)}, // TIM8_CH3N + {PB_15_ALT1, PWM_12, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_TIM12, 2, 0)}, // TIM12_CH2 + {PC_6, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 1, 0)}, // TIM3_CH1 + {PC_6_ALT0, PWM_8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 1, 0)}, // TIM8_CH1 + {PC_7, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 2, 0)}, // TIM3_CH2 + {PC_7_ALT0, PWM_8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 2, 0)}, // TIM8_CH2 + {PC_8, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 3, 0)}, // TIM3_CH3 + {PC_8_ALT0, PWM_8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 3, 0)}, // TIM8_CH3 + {PC_9, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 4, 0)}, // TIM3_CH4 + {PC_9_ALT0, PWM_8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 4, 0)}, // TIM8_CH4 + {PD_12, PWM_4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 1, 0)}, // TIM4_CH1 + {PD_13, PWM_4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 2, 0)}, // TIM4_CH2 + {PD_14, PWM_4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 3, 0)}, // TIM4_CH3 + {PD_15, PWM_4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 4, 0)}, // TIM4_CH4 + {PE_5, PWM_9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 1, 0)}, // TIM9_CH1 + {PE_6, PWM_9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 2, 0)}, // TIM9_CH2 + {PE_8, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 1, 1)}, // TIM1_CH1N + {PE_9, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 1, 0)}, // TIM1_CH1 + {PE_10, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 2, 1)}, // TIM1_CH2N + {PE_11, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 2, 0)}, // TIM1_CH2 + {PE_12, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 3, 1)}, // TIM1_CH3N + {PE_13, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 3, 0)}, // TIM1_CH3 + {PE_14, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 4, 0)}, // TIM1_CH4 + {PF_6, PWM_10, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM10, 1, 0)}, // TIM10_CH1 + {PF_7, PWM_11, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM11, 1, 0)}, // TIM11_CH1 + {PF_8, PWM_13, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_TIM13, 1, 0)}, // TIM13_CH1 + {PF_9, PWM_14, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_TIM14, 1, 0)}, // TIM14_CH1 + {NC, NC, 0} +}; + +//*** SERIAL *** + +MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_UART_TX[] = { + {PA_0, UART_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART4)}, + {PA_2, UART_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)}, // Connected to RMII_MDIO [LAN8742A-CZ-TR_MDIO] + {PA_9, UART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)}, // Connected to USB_VBUS + {PB_6, UART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)}, + {PB_10, UART_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)}, + {PC_6, UART_6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_USART6)}, + {PC_10, UART_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)}, + {PC_10_ALT0, UART_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART4)}, + {PC_12, UART_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART5)}, + {PD_5, UART_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)}, + {PD_8, UART_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)}, // Connected to STDIO_UART_TX + {PE_1, UART_8, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART8)}, + {PE_8, UART_7, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART7)}, + {PF_7, UART_7, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART7)}, + {PG_14, UART_6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_USART6)}, + {NC, NC, 0} +}; + +MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_UART_RX[] = { + {PA_1, UART_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART4)}, // Connected to RMII_REF_CLK [LAN8742A-CZ-TR_REFCLK0] + {PA_3, UART_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)}, + {PA_10, UART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)}, // Connected to USB_ID + {PB_7, UART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)}, // Connected to LD2 [Blue] + {PB_11, UART_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)}, + {PC_7, UART_6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_USART6)}, + {PC_11, UART_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)}, + {PC_11_ALT0, UART_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART4)}, + {PD_2, UART_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART5)}, + {PD_6, UART_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)}, + {PD_9, UART_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)}, // Connected to STDIO_UART_RX + {PE_0, UART_8, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART8)}, + {PE_7, UART_7, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART7)}, + {PF_6, UART_7, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART7)}, + {PG_9, UART_6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_USART6)}, + {NC, NC, 0} +}; + +MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_UART_RTS[] = { + {PA_1, UART_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)}, // Connected to RMII_REF_CLK [LAN8742A-CZ-TR_REFCLK0] + {PA_12, UART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)}, // Connected to USB_DP + {PB_14, UART_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)}, // Connected to LD3 [Red] + {PD_4, UART_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)}, + {PD_12, UART_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)}, + {PG_8, UART_6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_USART6)}, + {PG_12, UART_6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_USART6)}, + {NC, NC, 0} +}; + +MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_UART_CTS[] = { + {PA_0, UART_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)}, + {PA_11, UART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)}, // Connected to USB_DM + {PB_13, UART_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)}, // Connected to RMII_TXD1 [LAN8742A-CZ-TR_TXD1] + {PD_3, UART_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)}, + {PD_11, UART_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)}, + {PG_13, UART_6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_USART6)}, // Connected to RMII_TXD0 [LAN8742A-CZ-TR_TXD0] + {PG_15, UART_6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_USART6)}, + {NC, NC, 0} +}; + +//*** SPI *** + +MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_SPI_MOSI[] = { + {PA_7, SPI_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI1)}, // Connected to RMII_CRS_DV [LAN8742A-CZ-TR_CRS_DV] + {PB_5, SPI_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI1)}, + {PB_5_ALT0, SPI_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF6_SPI3)}, + {PB_15, SPI_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI2)}, + {PC_3, SPI_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI2)}, + {PC_12, SPI_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF6_SPI3)}, + {PD_6, SPI_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI1)}, + {PE_6, SPI_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI4)}, + {PE_14, SPI_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI4)}, + {PF_9, SPI_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI5)}, + {PF_11, SPI_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI5)}, + {PG_14, SPI_6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI6)}, + {NC, NC, 0} +}; + +MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_SPI_MISO[] = { + {PA_6, SPI_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI1)}, + {PB_4, SPI_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI1)}, + {PB_4_ALT0, SPI_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF6_SPI3)}, + {PB_14, SPI_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI2)}, // Connected to LD3 [Red] + {PC_2, SPI_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI2)}, + {PC_11, SPI_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF6_SPI3)}, + {PE_5, SPI_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI4)}, + {PE_13, SPI_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI4)}, + {PF_8, SPI_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI5)}, + {PG_12, SPI_6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI6)}, + {NC, NC, 0} +}; + +MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_SPI_SCLK[] = { + {PA_5, SPI_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI1)}, + {PB_3, SPI_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI1)}, + {PB_3_ALT0, SPI_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF6_SPI3)}, + {PB_10, SPI_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI2)}, + {PB_13, SPI_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI2)}, // Connected to RMII_TXD1 [LAN8742A-CZ-TR_TXD1] + {PC_10, SPI_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF6_SPI3)}, + {PD_3, SPI_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI2)}, + {PE_2, SPI_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI4)}, + {PE_12, SPI_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI4)}, + {PF_7, SPI_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI5)}, + {PG_13, SPI_6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI6)}, // Connected to RMII_TXD0 [LAN8742A-CZ-TR_TXD0] + {NC, NC, 0} +}; + +MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_SPI_SSEL[] = { + {PA_4, SPI_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI1)}, + {PA_4_ALT0, SPI_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF6_SPI3)}, + {PA_15, SPI_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI1)}, + {PA_15_ALT0, SPI_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF6_SPI3)}, + {PB_9, SPI_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI2)}, + {PB_12, SPI_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI2)}, + {PE_4, SPI_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI4)}, + {PE_11, SPI_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI4)}, + {PF_6, SPI_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI5)}, + {PG_8, SPI_6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI6)}, + {NC, NC, 0} +}; + +//*** CAN *** + +MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_CAN_RD[] = { + {PA_11, CAN_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)}, // Connected to USB_DM + {PB_5, CAN_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN2)}, + {PB_8, CAN_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)}, + {PB_12, CAN_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN2)}, + {PD_0, CAN_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)}, + {NC, NC, 0} +}; + +MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_CAN_TD[] = { + {PA_12, CAN_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)}, // Connected to USB_DP + {PB_6, CAN_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN2)}, + {PB_9, CAN_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)}, + {PB_13, CAN_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN2)}, // Connected to RMII_TXD1 [LAN8742A-CZ-TR_TXD1] + {PD_1, CAN_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)}, + {NC, NC, 0} +}; + +#define PINMAP_ANALOGIN PinMap_ADC +#define PINMAP_ANALOGOUT PinMap_DAC +#define PINMAP_I2C_SDA PinMap_I2C_SDA +#define PINMAP_I2C_SCL PinMap_I2C_SCL +#define PINMAP_UART_TX PinMap_UART_TX +#define PINMAP_UART_RX PinMap_UART_RX +#define PINMAP_UART_CTS PinMap_UART_CTS +#define PINMAP_UART_RTS PinMap_UART_RTS +#define PINMAP_SPI_SCLK PinMap_SPI_SCLK +#define PINMAP_SPI_MOSI PinMap_SPI_MOSI +#define PINMAP_SPI_MISO PinMap_SPI_MISO +#define PINMAP_SPI_SSEL PinMap_SPI_SSEL +#define PINMAP_PWM PinMap_PWM + +#endif \ No newline at end of file diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F429xI/TARGET_NUCLEO_F429ZI/PeripheralPins.c b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F429xI/TARGET_NUCLEO_F429ZI/PeripheralPins.c index 5a6a8d24816..3a02871e627 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F429xI/TARGET_NUCLEO_F429ZI/PeripheralPins.c +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F429xI/TARGET_NUCLEO_F429ZI/PeripheralPins.c @@ -1,6 +1,6 @@ /* mbed Microcontroller Library ******************************************************************************* - * Copyright (c) 2018, STMicroelectronics + * Copyright (c) 2019, STMicroelectronics * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -27,336 +27,6 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ******************************************************************************* */ - #include "PeripheralPins.h" #include "mbed_toolchain.h" - -//============================================================================== -// Notes -// -// - The pins mentioned Px_y_ALTz are alternative possibilities which use other -// HW peripheral instances. You can use them the same way as any other "normal" -// pin (i.e. PwmOut pwm(PA_7_ALT0);). These pins are not displayed on the board -// pinout image on mbed.org. -// -// - The pins which are connected to other components present on the board have -// the comment "Connected to xxx". The pin function may not work properly in this -// case. These pins may not be displayed on the board pinout image on mbed.org. -// Please read the board reference manual and schematic for more information. -// -// - Warning: pins connected to the default STDIO_UART_TX and STDIO_UART_RX pins are commented -// See https://os.mbed.com/teams/ST/wiki/STDIO for more information. -// -//============================================================================== - - -//*** ADC *** - -MBED_WEAK const PinMap PinMap_ADC[] = { - {PA_0, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 0, 0)}, // ADC1_IN0 - {PA_0_ALT0, ADC_2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 0, 0)}, // ADC2_IN0 - {PA_0_ALT1, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 0, 0)}, // ADC3_IN0 - {PA_1, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC1_IN1 // Connected to RMII_REF_CLK [LAN8742A-CZ-TR_REFCLK0] - {PA_1_ALT0, ADC_2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC2_IN1 // Connected to RMII_REF_CLK [LAN8742A-CZ-TR_REFCLK0] - {PA_1_ALT1, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC3_IN1 // Connected to RMII_REF_CLK [LAN8742A-CZ-TR_REFCLK0] - {PA_2, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC1_IN2 // Connected to RMII_MDIO [LAN8742A-CZ-TR_MDIO] - {PA_2_ALT0, ADC_2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC2_IN2 // Connected to RMII_MDIO [LAN8742A-CZ-TR_MDIO] - {PA_2_ALT1, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC3_IN2 // Connected to RMII_MDIO [LAN8742A-CZ-TR_MDIO] - {PA_3, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC1_IN3 - {PA_3_ALT0, ADC_2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC2_IN3 - {PA_3_ALT1, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC3_IN3 - {PA_4, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC1_IN4 - {PA_4_ALT0, ADC_2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC2_IN4 - {PA_5, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC1_IN5 - {PA_5_ALT0, ADC_2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC2_IN5 - {PA_6, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC1_IN6 - {PA_6_ALT0, ADC_2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC2_IN6 - {PA_7, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC1_IN7 // Connected to RMII_CRS_DV [LAN8742A-CZ-TR_CRS_DV] - {PA_7_ALT0, ADC_2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC2_IN7 // Connected to RMII_CRS_DV [LAN8742A-CZ-TR_CRS_DV] - {PB_0, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC1_IN8 // Connected to LD1 - {PB_0_ALT0, ADC_2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC2_IN8 // Connected to LD1 - {PB_1, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC1_IN9 - {PB_1_ALT0, ADC_2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC2_IN9 - {PC_0, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 10, 0)}, // ADC1_IN10 - {PC_0_ALT0, ADC_2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 10, 0)}, // ADC2_IN10 - {PC_0_ALT1, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 10, 0)}, // ADC3_IN10 - {PC_1, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 11, 0)}, // ADC1_IN11 // Connected to RMII_MDC [LAN8742A-CZ-TR_MDC] - {PC_1_ALT0, ADC_2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 11, 0)}, // ADC2_IN11 // Connected to RMII_MDC [LAN8742A-CZ-TR_MDC] - {PC_1_ALT1, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 11, 0)}, // ADC3_IN11 // Connected to RMII_MDC [LAN8742A-CZ-TR_MDC] - {PC_2, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 12, 0)}, // ADC1_IN12 - {PC_2_ALT0, ADC_2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 12, 0)}, // ADC2_IN12 - {PC_2_ALT1, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 12, 0)}, // ADC3_IN12 - {PC_3, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 13, 0)}, // ADC1_IN13 - {PC_3_ALT0, ADC_2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 13, 0)}, // ADC2_IN13 - {PC_3_ALT1, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 13, 0)}, // ADC3_IN13 - {PC_4, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC1_IN14 // Connected to RMII_RXD0 [LAN8742A-CZ-TR_RXD0] - {PC_4_ALT0, ADC_2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC2_IN14 // Connected to RMII_RXD0 [LAN8742A-CZ-TR_RXD0] - {PC_5, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC1_IN15 // Connected to RMII_RXD1 [LAN8742A-CZ-TR_RXD1] - {PC_5_ALT0, ADC_2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC2_IN15 // Connected to RMII_RXD1 [LAN8742A-CZ-TR_RXD1] - {PF_3, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC3_IN9 - {PF_4, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC3_IN14 - {PF_5, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC3_IN15 - {PF_6, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC3_IN4 - {PF_7, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC3_IN5 - {PF_8, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC3_IN6 - {PF_9, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC3_IN7 - {PF_10, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC3_IN8 - {NC, NC, 0} -}; - -MBED_WEAK const PinMap PinMap_ADC_Internal[] = { - {ADC_TEMP, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 16, 0)}, - {ADC_VREF, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 17, 0)}, - {ADC_VBAT, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 18, 0)}, - {NC, NC, 0} -}; - -//*** DAC *** - -MBED_WEAK const PinMap PinMap_DAC[] = { - {PA_4, DAC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // DAC_OUT1 - {PA_5, DAC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // DAC_OUT2 - {NC, NC, 0} -}; - -//*** I2C *** - -MBED_WEAK const PinMap PinMap_I2C_SDA[] = { - {PB_7, I2C_1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C1)}, // Connected to LD2 [Blue] - {PB_9, I2C_1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C1)}, - {PB_11, I2C_2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C2)}, - {PC_9, I2C_3, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C3)}, - {PF_0, I2C_2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C2)}, - {NC, NC, 0} -}; - -MBED_WEAK const PinMap PinMap_I2C_SCL[] = { - {PA_8, I2C_3, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C3)}, // Connected to USB_SOF [TP1] - {PB_6, I2C_1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C1)}, - {PB_8, I2C_1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C1)}, - {PB_10, I2C_2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C2)}, - {PF_1, I2C_2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C2)}, - {NC, NC, 0} -}; - -//*** PWM *** - -// TIM5 cannot be used because already used by the us_ticker -MBED_WEAK const PinMap PinMap_PWM[] = { - {PA_0, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 1, 0)}, // TIM2_CH1 -// {PA_0, PWM_5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 1, 0)}, // TIM5_CH1 - {PA_1, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 2, 0)}, // TIM2_CH2 // Connected to RMII_REF_CLK [LAN8742A-CZ-TR_REFCLK0] -// {PA_1, PWM_5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 2, 0)}, // TIM5_CH2 // Connected to RMII_REF_CLK [LAN8742A-CZ-TR_REFCLK0] - {PA_2, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 3, 0)}, // TIM2_CH3 // Connected to RMII_MDIO [LAN8742A-CZ-TR_MDIO] -// {PA_2, PWM_5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 3, 0)}, // TIM5_CH3 // Connected to RMII_MDIO [LAN8742A-CZ-TR_MDIO] - {PA_2_ALT0, PWM_9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 1, 0)}, // TIM9_CH1 // Connected to RMII_MDIO [LAN8742A-CZ-TR_MDIO] - {PA_3, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 4, 0)}, // TIM2_CH4 -// {PA_3, PWM_5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 4, 0)}, // TIM5_CH4 - {PA_3_ALT0, PWM_9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 2, 0)}, // TIM9_CH2 - {PA_5, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 1, 0)}, // TIM2_CH1 - {PA_5_ALT0, PWM_8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 1, 1)}, // TIM8_CH1N - {PA_6, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 1, 0)}, // TIM3_CH1 - {PA_6_ALT0, PWM_13, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_TIM13, 1, 0)}, // TIM13_CH1 - {PA_7, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 1, 1)}, // TIM1_CH1N // Connected to RMII_CRS_DV [LAN8742A-CZ-TR_CRS_DV] - {PA_7_ALT0, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 2, 0)}, // TIM3_CH2 // Connected to RMII_CRS_DV [LAN8742A-CZ-TR_CRS_DV] - {PA_7_ALT1, PWM_8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 1, 1)}, // TIM8_CH1N // Connected to RMII_CRS_DV [LAN8742A-CZ-TR_CRS_DV] - {PA_7_ALT2, PWM_14, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_TIM14, 1, 0)}, // TIM14_CH1 // Connected to RMII_CRS_DV [LAN8742A-CZ-TR_CRS_DV] - {PA_8, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 1, 0)}, // TIM1_CH1 // Connected to USB_SOF [TP1] - {PA_9, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 2, 0)}, // TIM1_CH2 // Connected to USB_VBUS - {PA_10, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 3, 0)}, // TIM1_CH3 // Connected to USB_ID - {PA_11, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 4, 0)}, // TIM1_CH4 // Connected to USB_DM - {PA_15, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 1, 0)}, // TIM2_CH1 - {PB_0, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 2, 1)}, // TIM1_CH2N // Connected to LD1 - {PB_0_ALT0, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 3, 0)}, // TIM3_CH3 // Connected to LD1 - {PB_0_ALT1, PWM_8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 2, 1)}, // TIM8_CH2N // Connected to LD1 - {PB_1, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 3, 1)}, // TIM1_CH3N - {PB_1_ALT0, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 4, 0)}, // TIM3_CH4 - {PB_1_ALT1, PWM_8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 3, 1)}, // TIM8_CH3N - {PB_3, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 2, 0)}, // TIM2_CH2 - {PB_4, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 1, 0)}, // TIM3_CH1 - {PB_5, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 2, 0)}, // TIM3_CH2 - {PB_6, PWM_4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 1, 0)}, // TIM4_CH1 - {PB_7, PWM_4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 2, 0)}, // TIM4_CH2 // Connected to LD2 [Blue] - {PB_8, PWM_4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 3, 0)}, // TIM4_CH3 - {PB_8_ALT0, PWM_10, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM10, 1, 0)}, // TIM10_CH1 - {PB_9, PWM_4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 4, 0)}, // TIM4_CH4 - {PB_9_ALT0, PWM_11, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM11, 1, 0)}, // TIM11_CH1 - {PB_10, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 3, 0)}, // TIM2_CH3 - {PB_11, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 4, 0)}, // TIM2_CH4 - {PB_13, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 1, 1)}, // TIM1_CH1N // Connected to RMII_TXD1 [LAN8742A-CZ-TR_TXD1] - {PB_14, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 2, 1)}, // TIM1_CH2N // Connected to LD3 [Red] - {PB_14_ALT0, PWM_8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 2, 1)}, // TIM8_CH2N // Connected to LD3 [Red] - {PB_14_ALT1, PWM_12, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_TIM12, 1, 0)}, // TIM12_CH1 // Connected to LD3 [Red] - {PB_15, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 3, 1)}, // TIM1_CH3N - {PB_15_ALT0, PWM_8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 3, 1)}, // TIM8_CH3N - {PB_15_ALT1, PWM_12, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_TIM12, 2, 0)}, // TIM12_CH2 - {PC_6, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 1, 0)}, // TIM3_CH1 - {PC_6_ALT0, PWM_8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 1, 0)}, // TIM8_CH1 - {PC_7, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 2, 0)}, // TIM3_CH2 - {PC_7_ALT0, PWM_8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 2, 0)}, // TIM8_CH2 - {PC_8, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 3, 0)}, // TIM3_CH3 - {PC_8_ALT0, PWM_8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 3, 0)}, // TIM8_CH3 - {PC_9, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 4, 0)}, // TIM3_CH4 - {PC_9_ALT0, PWM_8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 4, 0)}, // TIM8_CH4 - {PD_12, PWM_4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 1, 0)}, // TIM4_CH1 - {PD_13, PWM_4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 2, 0)}, // TIM4_CH2 - {PD_14, PWM_4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 3, 0)}, // TIM4_CH3 - {PD_15, PWM_4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 4, 0)}, // TIM4_CH4 - {PE_5, PWM_9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 1, 0)}, // TIM9_CH1 - {PE_6, PWM_9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 2, 0)}, // TIM9_CH2 - {PE_8, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 1, 1)}, // TIM1_CH1N - {PE_9, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 1, 0)}, // TIM1_CH1 - {PE_10, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 2, 1)}, // TIM1_CH2N - {PE_11, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 2, 0)}, // TIM1_CH2 - {PE_12, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 3, 1)}, // TIM1_CH3N - {PE_13, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 3, 0)}, // TIM1_CH3 - {PE_14, PWM_1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 4, 0)}, // TIM1_CH4 - {PF_6, PWM_10, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM10, 1, 0)}, // TIM10_CH1 - {PF_7, PWM_11, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM11, 1, 0)}, // TIM11_CH1 - {PF_8, PWM_13, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_TIM13, 1, 0)}, // TIM13_CH1 - {PF_9, PWM_14, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_TIM14, 1, 0)}, // TIM14_CH1 - {NC, NC, 0} -}; - -//*** SERIAL *** - -MBED_WEAK const PinMap PinMap_UART_TX[] = { - {PA_0, UART_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART4)}, - {PA_2, UART_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)}, // Connected to RMII_MDIO [LAN8742A-CZ-TR_MDIO] - {PA_9, UART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)}, // Connected to USB_VBUS - {PB_6, UART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)}, - {PB_10, UART_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)}, - {PC_6, UART_6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_USART6)}, - {PC_10, UART_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)}, - {PC_10_ALT0, UART_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART4)}, - {PC_12, UART_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART5)}, - {PD_5, UART_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)}, - {PD_8, UART_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)}, // Connected to STDIO_UART_TX - {PE_1, UART_8, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART8)}, - {PE_8, UART_7, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART7)}, - {PF_7, UART_7, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART7)}, - {PG_14, UART_6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_USART6)}, - {NC, NC, 0} -}; - -MBED_WEAK const PinMap PinMap_UART_RX[] = { - {PA_1, UART_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART4)}, // Connected to RMII_REF_CLK [LAN8742A-CZ-TR_REFCLK0] - {PA_3, UART_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)}, - {PA_10, UART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)}, // Connected to USB_ID - {PB_7, UART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)}, // Connected to LD2 [Blue] - {PB_11, UART_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)}, - {PC_7, UART_6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_USART6)}, - {PC_11, UART_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)}, - {PC_11_ALT0, UART_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART4)}, - {PD_2, UART_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART5)}, - {PD_6, UART_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)}, - {PD_9, UART_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)}, // Connected to STDIO_UART_RX - {PE_0, UART_8, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART8)}, - {PE_7, UART_7, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART7)}, - {PF_6, UART_7, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART7)}, - {PG_9, UART_6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_USART6)}, - {NC, NC, 0} -}; - -MBED_WEAK const PinMap PinMap_UART_RTS[] = { - {PA_1, UART_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)}, // Connected to RMII_REF_CLK [LAN8742A-CZ-TR_REFCLK0] - {PA_12, UART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)}, // Connected to USB_DP - {PB_14, UART_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)}, // Connected to LD3 [Red] - {PD_4, UART_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)}, - {PD_12, UART_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)}, - {PG_8, UART_6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_USART6)}, - {PG_12, UART_6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_USART6)}, - {NC, NC, 0} -}; - -MBED_WEAK const PinMap PinMap_UART_CTS[] = { - {PA_0, UART_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)}, - {PA_11, UART_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)}, // Connected to USB_DM - {PB_13, UART_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)}, // Connected to RMII_TXD1 [LAN8742A-CZ-TR_TXD1] - {PD_3, UART_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)}, - {PD_11, UART_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)}, - {PG_13, UART_6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_USART6)}, // Connected to RMII_TXD0 [LAN8742A-CZ-TR_TXD0] - {PG_15, UART_6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_USART6)}, - {NC, NC, 0} -}; - -//*** SPI *** - -MBED_WEAK const PinMap PinMap_SPI_MOSI[] = { - {PA_7, SPI_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI1)}, // Connected to RMII_CRS_DV [LAN8742A-CZ-TR_CRS_DV] - {PB_5, SPI_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI1)}, - {PB_5_ALT0, SPI_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF6_SPI3)}, - {PB_15, SPI_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI2)}, - {PC_3, SPI_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI2)}, - {PC_12, SPI_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF6_SPI3)}, - {PD_6, SPI_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI1)}, - {PE_6, SPI_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI4)}, - {PE_14, SPI_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI4)}, - {PF_9, SPI_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI5)}, - {PF_11, SPI_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI5)}, - {PG_14, SPI_6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI6)}, - {NC, NC, 0} -}; - -MBED_WEAK const PinMap PinMap_SPI_MISO[] = { - {PA_6, SPI_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI1)}, - {PB_4, SPI_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI1)}, - {PB_4_ALT0, SPI_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF6_SPI3)}, - {PB_14, SPI_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI2)}, // Connected to LD3 [Red] - {PC_2, SPI_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI2)}, - {PC_11, SPI_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF6_SPI3)}, - {PE_5, SPI_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI4)}, - {PE_13, SPI_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI4)}, - {PF_8, SPI_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI5)}, - {PG_12, SPI_6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI6)}, - {NC, NC, 0} -}; - -MBED_WEAK const PinMap PinMap_SPI_SCLK[] = { - {PA_5, SPI_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI1)}, - {PB_3, SPI_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI1)}, - {PB_3_ALT0, SPI_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF6_SPI3)}, - {PB_10, SPI_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI2)}, - {PB_13, SPI_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI2)}, // Connected to RMII_TXD1 [LAN8742A-CZ-TR_TXD1] - {PC_10, SPI_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF6_SPI3)}, - {PD_3, SPI_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI2)}, - {PE_2, SPI_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI4)}, - {PE_12, SPI_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI4)}, - {PF_7, SPI_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI5)}, - {PG_13, SPI_6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI6)}, // Connected to RMII_TXD0 [LAN8742A-CZ-TR_TXD0] - {NC, NC, 0} -}; - -MBED_WEAK const PinMap PinMap_SPI_SSEL[] = { - {PA_4, SPI_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI1)}, - {PA_4_ALT0, SPI_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF6_SPI3)}, - {PA_15, SPI_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI1)}, - {PA_15_ALT0, SPI_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF6_SPI3)}, - {PB_9, SPI_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI2)}, - {PB_12, SPI_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI2)}, - {PE_4, SPI_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI4)}, - {PE_11, SPI_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI4)}, - {PF_6, SPI_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI5)}, - {PG_8, SPI_6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF5_SPI6)}, - {NC, NC, 0} -}; - -//*** CAN *** - -MBED_WEAK const PinMap PinMap_CAN_RD[] = { - {PA_11, CAN_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)}, // Connected to USB_DM - {PB_5, CAN_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN2)}, - {PB_8, CAN_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)}, - {PB_12, CAN_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN2)}, - {PD_0, CAN_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)}, - {NC, NC, 0} -}; - -MBED_WEAK const PinMap PinMap_CAN_TD[] = { - {PA_12, CAN_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)}, // Connected to USB_DP - {PB_6, CAN_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN2)}, - {PB_9, CAN_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)}, - {PB_13, CAN_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN2)}, // Connected to RMII_TXD1 [LAN8742A-CZ-TR_TXD1] - {PD_1, CAN_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)}, - {NC, NC, 0} -}; +#include "PeripheralPinMaps.h" From 353346d18b91a335254213960b40f41c0d1312b3 Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Fri, 13 Sep 2019 08:29:48 +0200 Subject: [PATCH 33/36] Adapt FPGA tests for spi, i2c, analogin, pwm, uart to test direct init (explicit pinmap). --- .../analogin/main.cpp | 17 ++- .../mbed_hal_fpga_ci_test_shield/i2c/main.cpp | 29 ++++- .../mbed_hal_fpga_ci_test_shield/pwm/main.cpp | 100 ++++++++++-------- .../mbed_hal_fpga_ci_test_shield/spi/main.cpp | 34 +++--- .../uart/main.cpp | 56 ++++++---- 5 files changed, 148 insertions(+), 88 deletions(-) diff --git a/TESTS/mbed_hal_fpga_ci_test_shield/analogin/main.cpp b/TESTS/mbed_hal_fpga_ci_test_shield/analogin/main.cpp index 981ffff4d0e..3267fc85709 100644 --- a/TESTS/mbed_hal_fpga_ci_test_shield/analogin/main.cpp +++ b/TESTS/mbed_hal_fpga_ci_test_shield/analogin/main.cpp @@ -29,6 +29,7 @@ #include "mbed.h" #include "pinmap.h" +#include "hal/explicit_pinmap.h" #include "test_utils.h" #include "MbedTester.h" @@ -36,8 +37,8 @@ using namespace utest::v1; #define analogin_debug_printf(...) -#define DELTA_FLOAT 0.05f // 5% -#define DELTA_U16 3277 // 5% +#define DELTA_FLOAT (0.1f) // 10% +#define DELTA_U16 (2*3277) // 10% const PinList *form_factor = pinmap_ff_default_pins(); const PinList *restricted = pinmap_restricted_pins(); @@ -51,6 +52,7 @@ void analogin_init(PinName pin) analogin_init(&analogin, pin); } +template void analogin_test(PinName pin) { tester.reset(); @@ -60,7 +62,13 @@ void analogin_test(PinName pin) /* Test analog input */ analogin_t analogin; - analogin_init(&analogin, pin); + + if (init_direct) { + const PinMap pinmap = get_analogin_pinmap(pin); + analogin_init_direct(&analogin, &pinmap); + } else { + analogin_init(&analogin, pin); + } tester.gpio_write(MbedTester::LogicalPinGPIO0, 1, true); TEST_ASSERT_FLOAT_WITHIN(DELTA_FLOAT, 1.0f, analogin_read(&analogin)); @@ -78,7 +86,8 @@ Case cases[] = { // This will be run for all pins Case("AnalogIn - init test", all_ports), // This will be run for single pin - Case("AnalogIn - read test", all_ports), + Case("AnalogIn - read test", all_ports>), + Case("AnalogIn (direct init) - read test", all_ports>), }; utest::v1::status_t greentea_test_setup(const size_t number_of_cases) diff --git a/TESTS/mbed_hal_fpga_ci_test_shield/i2c/main.cpp b/TESTS/mbed_hal_fpga_ci_test_shield/i2c/main.cpp index 7259f805bd0..f7a7aab0d65 100644 --- a/TESTS/mbed_hal_fpga_ci_test_shield/i2c/main.cpp +++ b/TESTS/mbed_hal_fpga_ci_test_shield/i2c/main.cpp @@ -31,10 +31,10 @@ #include "mbed.h" #include "i2c_api.h" #include "pinmap.h" +#include "hal/explicit_pinmap.h" #include "test_utils.h" #include "I2CTester.h" - using namespace utest::v1; #define NACK 0 @@ -66,6 +66,7 @@ void test_i2c_init_free(PinName sda, PinName scl) gpio_set(scl); } +template void i2c_test_write(PinName sda, PinName scl) { // Remap pins for test @@ -79,7 +80,17 @@ void i2c_test_write(PinName sda, PinName scl) // Initialize mbed I2C pins i2c_t i2c; memset(&i2c, 0, sizeof(i2c)); - i2c_init(&i2c, sda, scl); + if (init_direct) { +#if EXPLICIT_PINMAP_READY + const i2c_pinmap_t pinmap = get_i2c_pinmap(sda, scl); + i2c_init_direct(&i2c, &pinmap); +#else + //skip this test case if explicit pinmap is not supported + return; +#endif + } else { + i2c_init(&i2c, sda, scl); + } i2c_frequency(&i2c, 100000); // Reset tester stats and select I2C @@ -153,6 +164,7 @@ void i2c_test_write(PinName sda, PinName scl) tester.pin_set_pull(scl, MbedTester::PullNone); } +template void i2c_test_read(PinName sda, PinName scl) { // Remap pins for test @@ -166,7 +178,12 @@ void i2c_test_read(PinName sda, PinName scl) // Initialize mbed I2C pins i2c_t i2c; memset(&i2c, 0, sizeof(i2c)); - i2c_init(&i2c, sda, scl); + if (init_direct) { + const i2c_pinmap_t pinmap = get_i2c_pinmap(sda, scl); + i2c_init_direct(&i2c, &pinmap); + } else { + i2c_init(&i2c, sda, scl); + } i2c_frequency(&i2c, 100000); // Reset tester stats and select I2C @@ -438,8 +455,10 @@ void i2c_test_byte_read(PinName sda, PinName scl) Case cases[] = { Case("i2c - init/free test all pins", all_ports), - Case("i2c - test write i2c API", all_peripherals), - Case("i2c - test read i2c API", all_peripherals), + Case("i2c - test write i2c API", all_peripherals>), + Case("i2c (direct init) - test write i2c API", all_peripherals>), + Case("i2c - test read i2c API", all_peripherals>), + Case("i2c (direct init) - test read i2c API", all_peripherals>), Case("i2c - test single byte write i2c API", all_peripherals), Case("i2c - test single byte read i2c API", all_peripherals) }; diff --git a/TESTS/mbed_hal_fpga_ci_test_shield/pwm/main.cpp b/TESTS/mbed_hal_fpga_ci_test_shield/pwm/main.cpp index 2ec859cc3b9..2167dc7019f 100644 --- a/TESTS/mbed_hal_fpga_ci_test_shield/pwm/main.cpp +++ b/TESTS/mbed_hal_fpga_ci_test_shield/pwm/main.cpp @@ -32,9 +32,9 @@ using namespace utest::v1; #include "MbedTester.h" #include "pinmap.h" +#include "hal/explicit_pinmap.h" #include "test_utils.h" - #define pwm_debug_printf(...) typedef enum { @@ -74,7 +74,7 @@ void pwm_init_free(PinName pin) } -void pwm_period_fill_test(PinName pin, uint32_t period_ms, uint32_t fill_prc, pwm_api_test_t api_test) +void pwm_period_fill_test(PinName pin, uint32_t period_ms, uint32_t fill_prc, pwm_api_test_t api_test, bool init_direct) { pwm_debug_printf("PWM test on pin = %s (%i)\r\n", pinmap_ff_default_pin_to_string(pin), pin); pwm_debug_printf("Testing period = %lu ms, duty-cycle = %lu %%\r\n", period_ms, fill_prc); @@ -86,7 +86,12 @@ void pwm_period_fill_test(PinName pin, uint32_t period_ms, uint32_t fill_prc, pw pwmout_t pwm_out; - pwmout_init(&pwm_out, pin); + if (init_direct) { + const PinMap pinmap = get_pwm_pinmap(pin); + pwmout_init_direct(&pwm_out, &pinmap); + } else { + pwmout_init(&pwm_out, pin); + } core_util_critical_section_enter(); @@ -156,10 +161,10 @@ void pwm_period_fill_test(PinName pin, uint32_t period_ms, uint32_t fill_prc, pw pwmout_free(&pwm_out); } -template +template void pwm_period_fill_test(PinName pin) { - pwm_period_fill_test(pin, period_ms, fill_prc, api_test); + pwm_period_fill_test(pin, period_ms, fill_prc, api_test, init_direct); } @@ -168,48 +173,49 @@ Case cases[] = { Case("PWM - init/free test", all_ports), // This will be run for single pin - Case("PWM - period: 10 ms, fill: 10%, api: period/write", one_peripheral >), - - Case("PWM - period: 10 ms, fill: 10%, api: period_ms/write", one_peripheral >), - Case("PWM - period: 10 ms, fill: 10%, api: period_us/write", one_peripheral >), - Case("PWM - period: 10 ms, fill: 10%, api: period/pulse_width", one_peripheral >), - Case("PWM - period: 10 ms, fill: 10%, api: period/pulse_width_ms", one_peripheral >), - Case("PWM - period: 10 ms, fill: 10%, api: period/pulse_width_us", one_peripheral >), - - Case("PWM - period: 10 ms, fill: 50%, api: period/write", one_peripheral >), - Case("PWM - period: 10 ms, fill: 50%, api: period_ms/write", one_peripheral >), - Case("PWM - period: 10 ms, fill: 50%, api: period_us/write", one_peripheral >), - Case("PWM - period: 10 ms, fill: 50%, api: period/pulse_width", one_peripheral >), - Case("PWM - period: 10 ms, fill: 50%, api: period/pulse_width_ms", one_peripheral >), - Case("PWM - period: 10 ms, fill: 50%, api: period/pulse_width_us", one_peripheral >), - - Case("PWM - period: 10 ms, fill: 90%, api: period/write", one_peripheral >), - Case("PWM - period: 10 ms, fill: 90%, api: period_ms/write", one_peripheral >), - Case("PWM - period: 10 ms, fill: 90%, api: period_us/write", one_peripheral >), - Case("PWM - period: 10 ms, fill: 90%, api: period/pulse_width", one_peripheral >), - Case("PWM - period: 10 ms, fill: 90%, api: period/pulse_width_ms", one_peripheral >), - Case("PWM - period: 10 ms, fill: 90%, api: period/pulse_width_us", one_peripheral >), - - Case("PWM - period: 50 ms, fill: 10%, api: period/write", one_peripheral >), - Case("PWM - period: 50 ms, fill: 10%, api: period_ms/write", one_peripheral >), - Case("PWM - period: 50 ms, fill: 10%, api: period_us/write", one_peripheral >), - Case("PWM - period: 50 ms, fill: 10%, api: period/pulse_width", one_peripheral >), - Case("PWM - period: 50 ms, fill: 10%, api: period/pulse_width_ms", one_peripheral >), - Case("PWM - period: 50 ms, fill: 10%, api: period/pulse_width_us", one_peripheral >), - - Case("PWM - period: 50 ms, fill: 50%, api: period/write", one_peripheral >), - Case("PWM - period: 50 ms, fill: 50%, api: period_ms/write", one_peripheral >), - Case("PWM - period: 50 ms, fill: 50%, api: period_us/write", one_peripheral >), - Case("PWM - period: 50 ms, fill: 50%, api: period/pulse_width", one_peripheral >), - Case("PWM - period: 50 ms, fill: 50%, api: period/pulse_width_ms", one_peripheral >), - Case("PWM - period: 50 ms, fill: 50%, api: period/pulse_width_us", one_peripheral >), - - Case("PWM - period: 50 ms, fill: 90%, api: period/write", one_peripheral >), - Case("PWM - period: 50 ms, fill: 90%, api: period_ms/write", one_peripheral >), - Case("PWM - period: 50 ms, fill: 90%, api: period_us/write", one_peripheral >), - Case("PWM - period: 50 ms, fill: 90%, api: period/pulse_width", one_peripheral >), - Case("PWM - period: 50 ms, fill: 90%, api: period/pulse_width_ms", one_peripheral >), - Case("PWM - period: 50 ms, fill: 90%, api: period/pulse_width_us", one_peripheral >) + Case("PWM - period: 10 ms, fill: 10%, api: period/write", one_peripheral >), + Case("PWM (direct init) - period: 10 ms, fill: 10%, api: period/write", one_peripheral >), + + Case("PWM - period: 10 ms, fill: 10%, api: period_ms/write", one_peripheral >), + Case("PWM - period: 10 ms, fill: 10%, api: period_us/write", one_peripheral >), + Case("PWM - period: 10 ms, fill: 10%, api: period/pulse_width", one_peripheral >), + Case("PWM - period: 10 ms, fill: 10%, api: period/pulse_width_ms", one_peripheral >), + Case("PWM - period: 10 ms, fill: 10%, api: period/pulse_width_us", one_peripheral >), + + Case("PWM - period: 10 ms, fill: 50%, api: period/write", one_peripheral >), + Case("PWM - period: 10 ms, fill: 50%, api: period_ms/write", one_peripheral >), + Case("PWM - period: 10 ms, fill: 50%, api: period_us/write", one_peripheral >), + Case("PWM - period: 10 ms, fill: 50%, api: period/pulse_width", one_peripheral >), + Case("PWM - period: 10 ms, fill: 50%, api: period/pulse_width_ms", one_peripheral >), + Case("PWM - period: 10 ms, fill: 50%, api: period/pulse_width_us", one_peripheral >), + + Case("PWM - period: 10 ms, fill: 90%, api: period/write", one_peripheral >), + Case("PWM - period: 10 ms, fill: 90%, api: period_ms/write", one_peripheral >), + Case("PWM - period: 10 ms, fill: 90%, api: period_us/write", one_peripheral >), + Case("PWM - period: 10 ms, fill: 90%, api: period/pulse_width", one_peripheral >), + Case("PWM - period: 10 ms, fill: 90%, api: period/pulse_width_ms", one_peripheral >), + Case("PWM - period: 10 ms, fill: 90%, api: period/pulse_width_us", one_peripheral >), + + Case("PWM - period: 50 ms, fill: 10%, api: period/write", one_peripheral >), + Case("PWM - period: 50 ms, fill: 10%, api: period_ms/write", one_peripheral >), + Case("PWM - period: 50 ms, fill: 10%, api: period_us/write", one_peripheral >), + Case("PWM - period: 50 ms, fill: 10%, api: period/pulse_width", one_peripheral >), + Case("PWM - period: 50 ms, fill: 10%, api: period/pulse_width_ms", one_peripheral >), + Case("PWM - period: 50 ms, fill: 10%, api: period/pulse_width_us", one_peripheral >), + + Case("PWM - period: 50 ms, fill: 50%, api: period/write", one_peripheral >), + Case("PWM - period: 50 ms, fill: 50%, api: period_ms/write", one_peripheral >), + Case("PWM - period: 50 ms, fill: 50%, api: period_us/write", one_peripheral >), + Case("PWM - period: 50 ms, fill: 50%, api: period/pulse_width", one_peripheral >), + Case("PWM - period: 50 ms, fill: 50%, api: period/pulse_width_ms", one_peripheral >), + Case("PWM - period: 50 ms, fill: 50%, api: period/pulse_width_us", one_peripheral >), + + Case("PWM - period: 50 ms, fill: 90%, api: period/write", one_peripheral >), + Case("PWM - period: 50 ms, fill: 90%, api: period_ms/write", one_peripheral >), + Case("PWM - period: 50 ms, fill: 90%, api: period_us/write", one_peripheral >), + Case("PWM - period: 50 ms, fill: 90%, api: period/pulse_width", one_peripheral >), + Case("PWM - period: 50 ms, fill: 90%, api: period/pulse_width_ms", one_peripheral >), + Case("PWM - period: 50 ms, fill: 90%, api: period/pulse_width_us", one_peripheral >) }; utest::v1::status_t greentea_test_setup(const size_t number_of_cases) diff --git a/TESTS/mbed_hal_fpga_ci_test_shield/spi/main.cpp b/TESTS/mbed_hal_fpga_ci_test_shield/spi/main.cpp index 0091b9801bf..a883a94ef56 100644 --- a/TESTS/mbed_hal_fpga_ci_test_shield/spi/main.cpp +++ b/TESTS/mbed_hal_fpga_ci_test_shield/spi/main.cpp @@ -32,6 +32,7 @@ using namespace utest::v1; #include "SPIMasterTester.h" #include "pinmap.h" +#include "hal/explicit_pinmap.h" #include "test_utils.h" typedef enum { @@ -69,7 +70,7 @@ void spi_test_init_free(PinName mosi, PinName miso, PinName sclk, PinName ssel) spi_free(&spi); } -void spi_test_common(PinName mosi, PinName miso, PinName sclk, PinName ssel, SPITester::SpiMode spi_mode, uint32_t sym_size, transfer_type_t transfer_type, uint32_t frequency) +void spi_test_common(PinName mosi, PinName miso, PinName sclk, PinName ssel, SPITester::SpiMode spi_mode, uint32_t sym_size, transfer_type_t transfer_type, uint32_t frequency, bool init_direct) { uint32_t sym_mask = ((1 << sym_size) - 1); @@ -82,7 +83,13 @@ void spi_test_common(PinName mosi, PinName miso, PinName sclk, PinName ssel, SPI // Initialize mbed SPI pins - spi_init(&spi, mosi, miso, sclk, ssel); + if (init_direct) { + const spi_pinmap_t pinmap = get_spi_pinmap(mosi, miso, sclk, ssel); + spi_init_direct(&spi, &pinmap); + } else { + spi_init(&spi, mosi, miso, sclk, ssel); + } + spi_format(&spi, sym_size, spi_mode, 0); spi_frequency(&spi, frequency); @@ -160,10 +167,10 @@ void spi_test_common(PinName mosi, PinName miso, PinName sclk, PinName ssel, SPI tester.reset(); } -template +template void spi_test_common(PinName mosi, PinName miso, PinName sclk, PinName ssel) { - spi_test_common(mosi, miso, sclk, ssel, spi_mode, sym_size, transfer_type, frequency); + spi_test_common(mosi, miso, sclk, ssel, spi_mode, sym_size, transfer_type, frequency, init_direct); } Case cases[] = { @@ -171,22 +178,23 @@ Case cases[] = { Case("SPI - init/free test all pins", all_ports), // This will be run for all peripherals - Case("SPI - basic test", all_peripherals >), + Case("SPI - basic test", all_peripherals >), + Case("SPI - basic test (direct init)", all_peripherals >), // This will be run for single pin configuration - Case("SPI - mode testing (MODE_1)", one_peripheral >), - Case("SPI - mode testing (MODE_2)", one_peripheral >), - Case("SPI - mode testing (MODE_3)", one_peripheral >), + Case("SPI - mode testing (MODE_1)", one_peripheral >), + Case("SPI - mode testing (MODE_2)", one_peripheral >), + Case("SPI - mode testing (MODE_3)", one_peripheral >), - Case("SPI - symbol size testing (16)", one_peripheral >), + Case("SPI - symbol size testing (16)", one_peripheral >), - Case("SPI - frequency testing (500 kHz)", one_peripheral >), - Case("SPI - frequency testing (2 MHz)", one_peripheral >), + Case("SPI - frequency testing (500 kHz)", one_peripheral >), + Case("SPI - frequency testing (2 MHz)", one_peripheral >), - Case("SPI - block write", one_peripheral >), + Case("SPI - block write", one_peripheral >), #if DEVICE_SPI_ASYNCH - Case("SPI - async mode", one_peripheral >) + Case("SPI - async mode", one_peripheral >) #endif }; diff --git a/TESTS/mbed_hal_fpga_ci_test_shield/uart/main.cpp b/TESTS/mbed_hal_fpga_ci_test_shield/uart/main.cpp index 1ff3a37740f..8004a72f4f9 100644 --- a/TESTS/mbed_hal_fpga_ci_test_shield/uart/main.cpp +++ b/TESTS/mbed_hal_fpga_ci_test_shield/uart/main.cpp @@ -37,6 +37,7 @@ using namespace utest::v1; #include "test_utils.h" #include "serial_api.h" #include "us_ticker_api.h" +#include "hal/explicit_pinmap.h" #define PUTC_REPS 16 #define GETC_REPS 16 @@ -82,7 +83,7 @@ static void test_irq_handler(uint32_t id, SerialIrq event) } } -static void uart_test_common(int baudrate, int data_bits, SerialParity parity, int stop_bits, PinName tx, PinName rx, PinName cts = NC, PinName rts = NC) +static void uart_test_common(int baudrate, int data_bits, SerialParity parity, int stop_bits, bool init_direct, PinName tx, PinName rx, PinName cts = NC, PinName rts = NC) { // The FPGA CI shield only supports None, Odd & Even. // Forced parity is not supported on Atmel, Freescale, Nordic & STM targets. @@ -117,12 +118,27 @@ static void uart_test_common(int baudrate, int data_bits, SerialParity parity, i // Initialize mbed UART pins serial_t serial; - serial_init(&serial, tx, rx); + if (init_direct) { + const serial_pinmap_t pinmap = get_uart_pinmap(tx, rx); + serial_init_direct(&serial, &pinmap); + } else { + serial_init(&serial, tx, rx); + } serial_baud(&serial, baudrate); serial_format(&serial, data_bits, parity, stop_bits); #if DEVICE_SERIAL_FC if (use_flow_control) { - serial_set_flow_control(&serial, FlowControlRTSCTS, rts, cts); + if (init_direct) { +#if EXPLICIT_PINMAP_READY + const serial_fc_pinmap_t pinmap = get_uart_fc_pinmap(rts, cts); + serial_set_flow_control_direct(&serial, FlowControlRTSCTS, &pinmap); +#else + //skip this test case if explicit pinmap is not supported + return; +#endif + } else { + serial_set_flow_control(&serial, FlowControlRTSCTS, rts, cts); + } } else { serial_set_flow_control(&serial, FlowControlNone, NC, NC); } @@ -294,16 +310,16 @@ void test_init_free_no_fc(PinName tx, PinName rx) test_init_free(tx, rx); } -template +template void test_common(PinName tx, PinName rx, PinName cts, PinName rts) { - uart_test_common(BAUDRATE, DATA_BITS, PARITY, STOP_BITS, tx, rx, cts, rts); + uart_test_common(BAUDRATE, DATA_BITS, PARITY, STOP_BITS, INIT_DIRECT, tx, rx, cts, rts); } -template +template void test_common_no_fc(PinName tx, PinName rx) { - uart_test_common(BAUDRATE, DATA_BITS, PARITY, STOP_BITS, tx, rx); + uart_test_common(BAUDRATE, DATA_BITS, PARITY, STOP_BITS, INIT_DIRECT, tx, rx); } Case cases[] = { @@ -311,34 +327,36 @@ Case cases[] = { Case("init/free, FC off", all_ports), // One set of pins from every peripheral. - Case("basic, 9600, 8N1, FC off", all_peripherals >), + Case("basic, 9600, 8N1, FC off", all_peripherals >), + Case("basic (direct init), 9600, 8N1, FC off", all_peripherals >), // One set of pins from one peripheral. // baudrate - Case("19200, 8N1, FC off", one_peripheral >), - Case("38400, 8N1, FC off", one_peripheral >), - Case("115200, 8N1, FC off", one_peripheral >), + Case("19200, 8N1, FC off", one_peripheral >), + Case("38400, 8N1, FC off", one_peripheral >), + Case("115200, 8N1, FC off", one_peripheral >), // stop bits - Case("9600, 8N2, FC off", one_peripheral >), + Case("9600, 8N2, FC off", one_peripheral >), #if DEVICE_SERIAL_FC // Every set of pins from every peripheral. Case("init/free, FC on", all_ports), // One set of pins from every peripheral. - Case("basic, 9600, 8N1, FC on", all_peripherals >), + Case("basic, 9600, 8N1, FC on", all_peripherals >), + Case("basic (direct init), 9600, 8N1, FC on", all_peripherals >), // One set of pins from one peripheral. // baudrate - Case("19200, 8N1, FC on", one_peripheral >), - Case("38400, 8N1, FC on", one_peripheral >), - Case("115200, 8N1, FC on", one_peripheral >), + Case("19200, 8N1, FC on", one_peripheral >), + Case("38400, 8N1, FC on", one_peripheral >), + Case("115200, 8N1, FC on", one_peripheral >), // data bits: not tested (some platforms support 8 bits only) // parity - Case("9600, 8O1, FC on", one_peripheral >), - Case("9600, 8E1, FC on", one_peripheral >), + Case("9600, 8O1, FC on", one_peripheral >), + Case("9600, 8E1, FC on", one_peripheral >), // stop bits - Case("9600, 8N2, FC on", one_peripheral >), + Case("9600, 8N2, FC on", one_peripheral >), #endif }; From 88d28d6d894f1915700652ff9dea3b74df1c98ac Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Wed, 18 Sep 2019 13:35:29 +0200 Subject: [PATCH 34/36] Fix spelling error --- drivers/AnalogIn.h | 2 +- drivers/AnalogOut.h | 2 +- drivers/I2C.h | 2 +- drivers/I2CSlave.h | 2 +- drivers/PwmOut.h | 2 +- drivers/SPI.h | 4 ++-- drivers/SPISlave.h | 2 +- drivers/Serial.h | 4 ++-- drivers/SerialBase.h | 2 +- drivers/UARTSerial.h | 2 +- hal/analogin_api.h | 2 +- hal/analogout_api.h | 2 +- hal/i2c_api.h | 2 +- hal/pwmout_api.h | 2 +- hal/serial_api.h | 4 ++-- hal/spi_api.h | 2 +- targets/TARGET_STM/TARGET_STM32F4/serial_device.c | 2 +- 17 files changed, 20 insertions(+), 20 deletions(-) diff --git a/drivers/AnalogIn.h b/drivers/AnalogIn.h index 8287fd31ec1..26f63f4b96e 100644 --- a/drivers/AnalogIn.h +++ b/drivers/AnalogIn.h @@ -69,7 +69,7 @@ class AnalogIn { /** Create an AnalogIn, connected to the specified pin * - * @param pinmap reference to strucure which holds static pinmap. + * @param pinmap reference to structure which holds static pinmap. */ AnalogIn(const PinMap &pinmap); diff --git a/drivers/AnalogOut.h b/drivers/AnalogOut.h index 2d5a05fc6e2..c5f773e9a42 100644 --- a/drivers/AnalogOut.h +++ b/drivers/AnalogOut.h @@ -68,7 +68,7 @@ class AnalogOut { /** Create an AnalogOut connected to the specified pin * - * @param pinmap reference to strucure which holds static pinmap. + * @param pinmap reference to structure which holds static pinmap. */ AnalogOut(const PinMap &pinmap) { diff --git a/drivers/I2C.h b/drivers/I2C.h index e6190ee485b..faf6fed87e8 100644 --- a/drivers/I2C.h +++ b/drivers/I2C.h @@ -103,7 +103,7 @@ class I2C : private NonCopyable { /** Create an I2C Master interface, connected to the specified pins * - * @param explicit_pinmap reference to strucure which holds static pinmap. + * @param explicit_pinmap reference to structure which holds static pinmap. */ I2C(const i2c_pinmap_t &explicit_pinmap); diff --git a/drivers/I2CSlave.h b/drivers/I2CSlave.h index c4f255a7171..c6a35d89edb 100644 --- a/drivers/I2CSlave.h +++ b/drivers/I2CSlave.h @@ -88,7 +88,7 @@ class I2CSlave { /** Create an I2C Slave interface, connected to the specified pins. * - * @param explicit_pinmap reference to strucure which holds static pinmap. + * @param explicit_pinmap reference to structure which holds static pinmap. */ I2CSlave(const i2c_pinmap_t &explicit_pinmap); diff --git a/drivers/PwmOut.h b/drivers/PwmOut.h index c1c92837475..4c54b5c0095 100644 --- a/drivers/PwmOut.h +++ b/drivers/PwmOut.h @@ -63,7 +63,7 @@ class PwmOut { /** Create a PwmOut connected to the specified pin * - * @param pinmap reference to strucure which holds static pinmap. + * @param pinmap reference to structure which holds static pinmap. */ PwmOut(const PinMap &pinmap); diff --git a/drivers/SPI.h b/drivers/SPI.h index eb2c714ba01..9c0a75fd126 100644 --- a/drivers/SPI.h +++ b/drivers/SPI.h @@ -140,7 +140,7 @@ class SPI : private NonCopyable { * * @note You can specify mosi or miso as NC if not used. * - * @param explicit_pinmap reference to strucure which holds static pinmap. + * @param explicit_pinmap reference to structure which holds static pinmap. */ SPI(const spi_pinmap_t &explicit_pinmap); @@ -153,7 +153,7 @@ class SPI : private NonCopyable { * * @note You can specify mosi or miso as NC if not used. * - * @param explicit_pinmap reference to strucure which holds static pinmap. + * @param explicit_pinmap reference to structure which holds static pinmap. * @param ssel SPI Chip Select pin. */ SPI(const spi_pinmap_t &explicit_pinmap, PinName ssel); diff --git a/drivers/SPISlave.h b/drivers/SPISlave.h index 749e45294f0..3bd19f63cf3 100644 --- a/drivers/SPISlave.h +++ b/drivers/SPISlave.h @@ -75,7 +75,7 @@ class SPISlave : private NonCopyable { * * @note Either mosi or miso can be specified as NC if not used. * - * @param explicit_pinmap reference to strucure which holds static pinmap. + * @param explicit_pinmap reference to structure which holds static pinmap. */ SPISlave(const spi_pinmap_t &pinmap); diff --git a/drivers/Serial.h b/drivers/Serial.h index e48397d3569..4db73d327a4 100644 --- a/drivers/Serial.h +++ b/drivers/Serial.h @@ -75,7 +75,7 @@ class Serial : public SerialBase, public Stream, private NonCopyable { /** Create a Serial port, connected to the specified transmit and receive pins * - * @param explicit_pinmap reference to strucure which holds static pinmap. + * @param explicit_pinmap reference to structure which holds static pinmap. * @param name The name of the stream associated with this serial port (optional) * @param baud The baud rate of the serial port (optional, defaults to MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE or 9600) * @@ -97,7 +97,7 @@ class Serial : public SerialBase, public Stream, private NonCopyable { /** Create a Serial port, connected to the specified transmit and receive pins, with the specified baud * - * @param explicit_pinmap reference to strucure which holds static pinmap. + * @param explicit_pinmap reference to structure which holds static pinmap. * @param baud The baud rate of the serial port * * @note diff --git a/drivers/SerialBase.h b/drivers/SerialBase.h index 25a32dda9d1..b452ac2011b 100644 --- a/drivers/SerialBase.h +++ b/drivers/SerialBase.h @@ -180,7 +180,7 @@ class SerialBase : private NonCopyable { /** Set the flow control type on the serial port * * @param type the flow control type (Disabled, RTS, CTS, RTSCTS) - * @param pinmap reference to strucure which holds static pinmap + * @param pinmap reference to structure which holds static pinmap */ void set_flow_control(Flow type, const serial_fc_pinmap_t &explicit_pinmap); #endif diff --git a/drivers/UARTSerial.h b/drivers/UARTSerial.h index 506e11a9cac..f94ad4303ce 100644 --- a/drivers/UARTSerial.h +++ b/drivers/UARTSerial.h @@ -60,7 +60,7 @@ class UARTSerial : private SerialBase, public FileHandle, private NonCopyable Date: Wed, 18 Sep 2019 14:47:53 +0200 Subject: [PATCH 35/36] Explicit pinmap - fix style --- .../uart/main.cpp | 4 +- drivers/SPI.h | 2 +- hal/analogin_api.h | 2 +- hal/analogout_api.h | 2 +- hal/explicit_pinmap.h | 4 +- hal/pwmout_api.h | 2 +- platform/cxxsupport/mstd_cstddef | 6 +- platform/source/mbed_retarget.cpp | 4 +- .../TARGET_FRDM/PeripheralPinMaps.h | 208 +++++++++--------- .../TARGET_MCU_K64F/TARGET_FRDM/PinNames.h | 100 ++++----- .../TARGET_MCU_K64F/pwmout_api.c | 25 ++- .../TARGET_MCU_K64F/serial_api.c | 52 +++-- .../TARGET_MCUXpresso_MCUS/api/analogin_api.c | 14 +- .../api/analogout_api.c | 6 +- .../TARGET_MCUXpresso_MCUS/api/i2c_api.c | 6 +- .../TARGET_STM32F4/analogin_device.c | 6 +- .../TARGET_STM32F4/analogout_device.c | 4 +- targets/TARGET_STM/pwmout_api.c | 6 +- targets/TARGET_STM/stm_spi_api.c | 4 +- 19 files changed, 232 insertions(+), 225 deletions(-) diff --git a/TESTS/mbed_hal_fpga_ci_test_shield/uart/main.cpp b/TESTS/mbed_hal_fpga_ci_test_shield/uart/main.cpp index 8004a72f4f9..af92c8d6b68 100644 --- a/TESTS/mbed_hal_fpga_ci_test_shield/uart/main.cpp +++ b/TESTS/mbed_hal_fpga_ci_test_shield/uart/main.cpp @@ -133,8 +133,8 @@ static void uart_test_common(int baudrate, int data_bits, SerialParity parity, i const serial_fc_pinmap_t pinmap = get_uart_fc_pinmap(rts, cts); serial_set_flow_control_direct(&serial, FlowControlRTSCTS, &pinmap); #else - //skip this test case if explicit pinmap is not supported - return; + //skip this test case if explicit pinmap is not supported + return; #endif } else { serial_set_flow_control(&serial, FlowControlRTSCTS, rts, cts); diff --git a/drivers/SPI.h b/drivers/SPI.h index 9c0a75fd126..f46bba63f03 100644 --- a/drivers/SPI.h +++ b/drivers/SPI.h @@ -440,7 +440,7 @@ class SPI : private NonCopyable { /* SPI peripheral name */ SPIName _peripheral_name; /* Pointer to spi init function */ - void (*_init_func)(SPI*); + void (*_init_func)(SPI *); private: void _do_construct(); diff --git a/hal/analogin_api.h b/hal/analogin_api.h index a768813799f..cd64637e501 100644 --- a/hal/analogin_api.h +++ b/hal/analogin_api.h @@ -44,7 +44,7 @@ typedef struct analogin_s analogin_t; * @param obj The analogin object to initialize * @param pinmap pointer to structure which holds static pinmap */ -void analogin_init_direct(analogin_t* obj, const PinMap *pinmap); +void analogin_init_direct(analogin_t *obj, const PinMap *pinmap); /** Initialize the analogin peripheral * diff --git a/hal/analogout_api.h b/hal/analogout_api.h index 4351ec180f5..1cf515303fc 100644 --- a/hal/analogout_api.h +++ b/hal/analogout_api.h @@ -44,7 +44,7 @@ typedef struct dac_s dac_t; * @param obj The analogout object to initialize * @param pinmap pointer to structure which holds static pinmap */ -void analogout_init_direct(dac_t* obj, const PinMap *pinmap); +void analogout_init_direct(dac_t *obj, const PinMap *pinmap); /** Initialize the analogout peripheral * diff --git a/hal/explicit_pinmap.h b/hal/explicit_pinmap.h index 24055f9e0c0..4a4870588e0 100644 --- a/hal/explicit_pinmap.h +++ b/hal/explicit_pinmap.h @@ -186,8 +186,8 @@ MSTD_CONSTEXPR_FN_14 spi_pinmap_t get_spi_pinmap(const PinName mosi, const PinNa } if ((!mosi_map || !miso_map || !sclk_map || !ssel_map) || - (mosi_map->peripheral != miso_map->peripheral || mosi_map->peripheral != sclk_map->peripheral) || - (ssel_map->pin != NC && mosi_map->peripheral != ssel_map->peripheral)) { + (mosi_map->peripheral != miso_map->peripheral || mosi_map->peripheral != sclk_map->peripheral) || + (ssel_map->pin != NC && mosi_map->peripheral != ssel_map->peripheral)) { return {NC, NC, NC, NC, NC, NC, NC, NC, NC}; } diff --git a/hal/pwmout_api.h b/hal/pwmout_api.h index 42e879b8a80..619539ad5d5 100644 --- a/hal/pwmout_api.h +++ b/hal/pwmout_api.h @@ -43,7 +43,7 @@ typedef struct pwmout_s pwmout_t; * @param obj The pwmout object to initialize * @param pinmap pointer to structure which holds static pinmap */ -void pwmout_init_direct(pwmout_t* obj, const PinMap *pinmap); +void pwmout_init_direct(pwmout_t *obj, const PinMap *pinmap); /** Initialize the pwm out peripheral and configure the pin * diff --git a/platform/cxxsupport/mstd_cstddef b/platform/cxxsupport/mstd_cstddef index 9c7dfcbc288..0afe5bfcd8a 100644 --- a/platform/cxxsupport/mstd_cstddef +++ b/platform/cxxsupport/mstd_cstddef @@ -61,8 +61,7 @@ #define alignas(N) __attribute__((aligned(N))) #endif -namespace std -{ +namespace std { // [cstddef.syn] using nullptr_t = decltype(nullptr); @@ -70,8 +69,7 @@ using nullptr_t = decltype(nullptr); #endif // __CC_ARM -namespace mstd -{ +namespace mstd { using std::size_t; using std::ptrdiff_t; using std::nullptr_t; diff --git a/platform/source/mbed_retarget.cpp b/platform/source/mbed_retarget.cpp index 1b6ce12bc5d..24e2cc6bdf8 100644 --- a/platform/source/mbed_retarget.cpp +++ b/platform/source/mbed_retarget.cpp @@ -290,8 +290,8 @@ static FileHandle *default_console() #if MBED_CONF_TARGET_CONSOLE_UART && DEVICE_SERIAL # if MBED_CONF_PLATFORM_STDIO_BUFFERED_SERIAL - static const serial_pinmap_t console_pinmap = get_uart_pinmap(STDIO_UART_TX, STDIO_UART_RX); - static UARTSerial console(console_pinmap, MBED_CONF_PLATFORM_STDIO_BAUD_RATE); + static const serial_pinmap_t console_pinmap = get_uart_pinmap(STDIO_UART_TX, STDIO_UART_RX); + static UARTSerial console(console_pinmap, MBED_CONF_PLATFORM_STDIO_BAUD_RATE); # if CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_RTS static const serial_fc_pinmap_t fc_pinmap = get_uart_fc_pinmap(STDIO_UART_RTS, NC); console.serial_set_flow_control(SerialBase::RTS, fc_pinmap); diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PeripheralPinMaps.h b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PeripheralPinMaps.h index f62b64b627d..a3d15d56731 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PeripheralPinMaps.h +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PeripheralPinMaps.h @@ -128,7 +128,7 @@ MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_GPIO[] = { {PTE27, GPIO_X, 1}, {PTE28, GPIO_X, 1}, - {NC , NC , 0} + {NC, NC, 0} }; /************RTC***************/ @@ -139,16 +139,16 @@ MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_RTC[] = { /************ADC***************/ MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_ADC[] = { {PTA17, ADC1_SE17, 0}, - {PTB0 , ADC0_SE8 , 0}, - {PTB1 , ADC0_SE9 , 0}, - {PTB2 , ADC0_SE12, 0}, - {PTB3 , ADC0_SE13, 0}, - {PTB6 , ADC1_SE12, 0}, - {PTB7 , ADC1_SE13, 0}, + {PTB0, ADC0_SE8, 0}, + {PTB1, ADC0_SE9, 0}, + {PTB2, ADC0_SE12, 0}, + {PTB3, ADC0_SE13, 0}, + {PTB6, ADC1_SE12, 0}, + {PTB7, ADC1_SE13, 0}, {PTB10, ADC1_SE14, 0}, {PTB11, ADC1_SE15, 0}, - {PTC0 , ADC0_SE14, 0}, - {PTC1 , ADC0_SE15, 0}, + {PTC0, ADC0_SE14, 0}, + {PTC1, ADC0_SE15, 0}, {PTC2, ADC0_SE4b, 0}, {PTC8, ADC1_SE4b, 0}, {PTC9, ADC1_SE5b, 0}, @@ -163,197 +163,197 @@ MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_ADC[] = { {PTE3, ADC1_SE7a, 0}, //{PTE24, ADC0_SE17, 0}, //I2C pull up //{PTE25, ADC0_SE18, 0}, //I2C pull up - {NC , NC , 0} + {NC, NC, 0} }; /************DAC***************/ MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_DAC[] = { {DAC0_OUT, DAC_0, 0}, - {NC , NC , 0} + {NC, NC, 0} }; /************I2C***************/ MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_I2C_SDA[] = { {PTE25, I2C_0, 5}, - {PTB1 , I2C_0, 2}, - {PTB3 , I2C_0, 2}, + {PTB1, I2C_0, 2}, + {PTB3, I2C_0, 2}, {PTC11, I2C_1, 2}, {PTA13, I2C_2, 5}, - {PTD3 , I2C_0, 7}, - {PTE0 , I2C_1, 6}, - {NC , NC , 0} + {PTD3, I2C_0, 7}, + {PTE0, I2C_1, 6}, + {NC, NC, 0} }; MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_I2C_SCL[] = { {PTE24, I2C_0, 5}, - {PTB0 , I2C_0, 2}, - {PTB2 , I2C_0, 2}, + {PTB0, I2C_0, 2}, + {PTB2, I2C_0, 2}, {PTC10, I2C_1, 2}, {PTA12, I2C_2, 5}, {PTA14, I2C_2, 5}, - {PTD2 , I2C_0, 7}, - {PTE1 , I2C_1, 6}, - {NC , NC , 0} + {PTD2, I2C_0, 7}, + {PTE1, I2C_1, 6}, + {NC, NC, 0} }; /************UART***************/ MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_UART_TX[] = { {PTB17, UART_0, 3}, {PTC17, UART_3, 3}, - {PTD7 , UART_0, 3}, - {PTD3 , UART_2, 3}, - {PTC4 , UART_1, 3}, + {PTD7, UART_0, 3}, + {PTD3, UART_2, 3}, + {PTC4, UART_1, 3}, {PTC15, UART_4, 3}, {PTB11, UART_3, 3}, {PTA14, UART_0, 3}, {PTE24, UART_4, 3}, - {PTE4 , UART_3, 3}, + {PTE4, UART_3, 3}, {PTE0, UART_1, 3}, - {NC , NC , 0} + {NC, NC, 0} }; MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_UART_RX[] = { {PTB16, UART_0, 3}, - {PTE1 , UART_1, 3}, - {PTE5 , UART_3, 3}, + {PTE1, UART_1, 3}, + {PTE5, UART_3, 3}, {PTE25, UART_4, 3}, {PTA15, UART_0, 3}, {PTC16, UART_3, 3}, {PTB10, UART_3, 3}, - {PTC3 , UART_1, 3}, + {PTC3, UART_1, 3}, {PTC14, UART_4, 3}, - {PTD2 , UART_2, 3}, - {PTD6 , UART_0, 3}, - {NC , NC , 0} + {PTD2, UART_2, 3}, + {PTD6, UART_0, 3}, + {NC, NC, 0} }; MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_UART_CTS[] = { {PTB13, UART_3, 2}, - {PTE2 , UART_1, 3}, - {PTE6 , UART_3, 3}, + {PTE2, UART_1, 3}, + {PTE6, UART_3, 3}, {PTE26, UART_4, 3}, - {PTA0 , UART_0, 2}, + {PTA0, UART_0, 2}, {PTA16, UART_0, 3}, - {PTB3 , UART_0, 3}, - {PTB9 , UART_3, 3}, - {PTC2 , UART_1, 3}, + {PTB3, UART_0, 3}, + {PTB9, UART_3, 3}, + {PTC2, UART_1, 3}, {PTC13, UART_4, 3}, {PTC19, UART_3, 3}, - {PTD1 , UART_2, 3}, - {PTD5 , UART_0, 3}, - {NC , NC , 0} + {PTD1, UART_2, 3}, + {PTD5, UART_0, 3}, + {NC, NC, 0} }; MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_UART_RTS[] = { {PTB12, UART_3, 2}, - {PTE3 , UART_1, 3}, - {PTE7 , UART_3, 3}, + {PTE3, UART_1, 3}, + {PTE7, UART_3, 3}, {PTE27, UART_4, 3}, {PTA17, UART_0, 3}, - {PTB8 , UART_3, 3}, - {PTC1 , UART_1, 3}, + {PTB8, UART_3, 3}, + {PTC1, UART_1, 3}, {PTC12, UART_4, 3}, {PTC18, UART_3, 3}, - {PTD0 , UART_2, 3}, - {PTD4 , UART_0, 3}, - {PTA3 , UART_0, 2}, - {PTB2 , UART_0, 3}, - {NC , NC , 0} + {PTD0, UART_2, 3}, + {PTD4, UART_0, 3}, + {PTA3, UART_0, 2}, + {PTB2, UART_0, 3}, + {NC, NC, 0} }; /************SPI***************/ MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_SPI_SCLK[] = { - {PTD1 , SPI_0, 2}, - {PTE2 , SPI_1, 2}, + {PTD1, SPI_0, 2}, + {PTE2, SPI_1, 2}, {PTA15, SPI_0, 2}, {PTB11, SPI_1, 2}, {PTB21, SPI_2, 2}, - {PTC5 , SPI_0, 2}, - {PTD5 , SPI_1, 7}, - {NC , NC , 0} + {PTC5, SPI_0, 2}, + {PTD5, SPI_1, 7}, + {NC, NC, 0} }; MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_SPI_MOSI[] = { - {PTD2 , SPI_0, 2}, - {PTE1 , SPI_1, 2}, - {PTE3 , SPI_1, 7}, + {PTD2, SPI_0, 2}, + {PTE1, SPI_1, 2}, + {PTE3, SPI_1, 7}, {PTA16, SPI_0, 2}, {PTB16, SPI_1, 2}, {PTB22, SPI_2, 2}, - {PTC6 , SPI_0, 2}, - {PTD6 , SPI_1, 7}, - {NC , NC , 0} + {PTC6, SPI_0, 2}, + {PTD6, SPI_1, 7}, + {NC, NC, 0} }; MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_SPI_MISO[] = { - {PTD3 , SPI_0, 2}, - {PTE1 , SPI_1, 7}, - {PTE3 , SPI_1, 2}, + {PTD3, SPI_0, 2}, + {PTE1, SPI_1, 7}, + {PTE3, SPI_1, 2}, {PTA17, SPI_0, 2}, {PTB17, SPI_1, 2}, {PTB23, SPI_2, 2}, - {PTC7 , SPI_0, 2}, - {PTD7 , SPI_1, 7}, - {NC , NC , 0} + {PTC7, SPI_0, 2}, + {PTD7, SPI_1, 7}, + {NC, NC, 0} }; MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_SPI_SSEL[] = { - {PTD0 , SPI_0, 2}, - {PTE4 , SPI_1, 2}, + {PTD0, SPI_0, 2}, + {PTE4, SPI_1, 2}, {PTA14, SPI_0, 2}, {PTB10, SPI_1, 2}, {PTB20, SPI_2, 2}, - {PTC4 , SPI_0, 2}, - {PTD4 , SPI_1, 7}, - {NC , NC , 0} + {PTC4, SPI_0, 2}, + {PTD4, SPI_1, 7}, + {NC, NC, 0} }; /************PWM***************/ MSTD_CONSTEXPR_OBJ_11 PinMap PinMap_PWM[] = { - {PTA0 , PWM_6 , 3}, - {PTA1 , PWM_7 , 3}, - {PTA2 , PWM_8 , 3}, - {PTA3 , PWM_1 , 3}, - {PTA4 , PWM_2 , 3}, - {PTA5 , PWM_3 , 3}, - {PTA6 , PWM_4 , 3}, - {PTA7 , PWM_5 , 3}, - {PTA8 , PWM_9 , 3}, - {PTA9 , PWM_10, 3}, + {PTA0, PWM_6, 3}, + {PTA1, PWM_7, 3}, + {PTA2, PWM_8, 3}, + {PTA3, PWM_1, 3}, + {PTA4, PWM_2, 3}, + {PTA5, PWM_3, 3}, + {PTA6, PWM_4, 3}, + {PTA7, PWM_5, 3}, + {PTA8, PWM_9, 3}, + {PTA9, PWM_10, 3}, {PTA10, PWM_17, 3}, {PTA11, PWM_18, 3}, - {PTA12, PWM_9 , 3}, + {PTA12, PWM_9, 3}, {PTA13, PWM_10, 3}, - {PTB0 , PWM_9 , 3}, - {PTB1 , PWM_10, 3}, + {PTB0, PWM_9, 3}, + {PTB1, PWM_10, 3}, {PTB18, PWM_17, 3}, {PTB19, PWM_18, 3}, - {PTC1 , PWM_1 , 4}, - {PTC2 , PWM_2 , 4}, - {PTC3 , PWM_3 , 4}, - {PTC4 , PWM_4 , 4}, - {PTC5 , PWM_3 , 7}, - {PTC8 , PWM_29, 3}, - {PTC9 , PWM_30, 3}, + {PTC1, PWM_1, 4}, + {PTC2, PWM_2, 4}, + {PTC3, PWM_3, 4}, + {PTC4, PWM_4, 4}, + {PTC5, PWM_3, 7}, + {PTC8, PWM_29, 3}, + {PTC9, PWM_30, 3}, {PTC10, PWM_31, 3}, {PTC11, PWM_32, 3}, - {PTD0 , PWM_25, 4}, - {PTD1 , PWM_26, 4}, - {PTD2 , PWM_27, 4}, - {PTD3 , PWM_28, 4}, - {PTD4 , PWM_5 , 4}, - {PTD5 , PWM_6 , 4}, - {PTD6 , PWM_7 , 4}, - {PTD4 , PWM_5 , 4}, - {PTD7 , PWM_8 , 4}, + {PTD0, PWM_25, 4}, + {PTD1, PWM_26, 4}, + {PTD2, PWM_27, 4}, + {PTD3, PWM_28, 4}, + {PTD4, PWM_5, 4}, + {PTD5, PWM_6, 4}, + {PTD6, PWM_7, 4}, + {PTD4, PWM_5, 4}, + {PTD7, PWM_8, 4}, - {PTE5 , PWM_25, 6}, - {PTE6 , PWM_26, 6}, + {PTE5, PWM_25, 6}, + {PTE6, PWM_26, 6}, - {NC , NC , 0} + {NC, NC, 0} }; #define PINMAP_ANALOGIN PinMap_ADC diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PinNames.h b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PinNames.h index d518d298638..8a894189421 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PinNames.h +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PinNames.h @@ -33,16 +33,16 @@ typedef enum { #define GPIO_PORT_SHIFT 12 typedef enum { - PTA0 = (0 << GPIO_PORT_SHIFT | 0 ), - PTA1 = (0 << GPIO_PORT_SHIFT | 1 ), - PTA2 = (0 << GPIO_PORT_SHIFT | 2 ), - PTA3 = (0 << GPIO_PORT_SHIFT | 3 ), - PTA4 = (0 << GPIO_PORT_SHIFT | 4 ), - PTA5 = (0 << GPIO_PORT_SHIFT | 5 ), - PTA6 = (0 << GPIO_PORT_SHIFT | 6 ), - PTA7 = (0 << GPIO_PORT_SHIFT | 7 ), - PTA8 = (0 << GPIO_PORT_SHIFT | 8 ), - PTA9 = (0 << GPIO_PORT_SHIFT | 9 ), + PTA0 = (0 << GPIO_PORT_SHIFT | 0), + PTA1 = (0 << GPIO_PORT_SHIFT | 1), + PTA2 = (0 << GPIO_PORT_SHIFT | 2), + PTA3 = (0 << GPIO_PORT_SHIFT | 3), + PTA4 = (0 << GPIO_PORT_SHIFT | 4), + PTA5 = (0 << GPIO_PORT_SHIFT | 5), + PTA6 = (0 << GPIO_PORT_SHIFT | 6), + PTA7 = (0 << GPIO_PORT_SHIFT | 7), + PTA8 = (0 << GPIO_PORT_SHIFT | 8), + PTA9 = (0 << GPIO_PORT_SHIFT | 9), PTA10 = (0 << GPIO_PORT_SHIFT | 10), PTA11 = (0 << GPIO_PORT_SHIFT | 11), PTA12 = (0 << GPIO_PORT_SHIFT | 12), @@ -65,16 +65,16 @@ typedef enum { PTA29 = (0 << GPIO_PORT_SHIFT | 29), PTA30 = (0 << GPIO_PORT_SHIFT | 30), PTA31 = (0 << GPIO_PORT_SHIFT | 31), - PTB0 = (1 << GPIO_PORT_SHIFT | 0 ), - PTB1 = (1 << GPIO_PORT_SHIFT | 1 ), - PTB2 = (1 << GPIO_PORT_SHIFT | 2 ), - PTB3 = (1 << GPIO_PORT_SHIFT | 3 ), - PTB4 = (1 << GPIO_PORT_SHIFT | 4 ), - PTB5 = (1 << GPIO_PORT_SHIFT | 5 ), - PTB6 = (1 << GPIO_PORT_SHIFT | 6 ), - PTB7 = (1 << GPIO_PORT_SHIFT | 7 ), - PTB8 = (1 << GPIO_PORT_SHIFT | 8 ), - PTB9 = (1 << GPIO_PORT_SHIFT | 9 ), + PTB0 = (1 << GPIO_PORT_SHIFT | 0), + PTB1 = (1 << GPIO_PORT_SHIFT | 1), + PTB2 = (1 << GPIO_PORT_SHIFT | 2), + PTB3 = (1 << GPIO_PORT_SHIFT | 3), + PTB4 = (1 << GPIO_PORT_SHIFT | 4), + PTB5 = (1 << GPIO_PORT_SHIFT | 5), + PTB6 = (1 << GPIO_PORT_SHIFT | 6), + PTB7 = (1 << GPIO_PORT_SHIFT | 7), + PTB8 = (1 << GPIO_PORT_SHIFT | 8), + PTB9 = (1 << GPIO_PORT_SHIFT | 9), PTB10 = (1 << GPIO_PORT_SHIFT | 10), PTB11 = (1 << GPIO_PORT_SHIFT | 11), PTB12 = (1 << GPIO_PORT_SHIFT | 12), @@ -97,16 +97,16 @@ typedef enum { PTB29 = (1 << GPIO_PORT_SHIFT | 29), PTB30 = (1 << GPIO_PORT_SHIFT | 30), PTB31 = (1 << GPIO_PORT_SHIFT | 31), - PTC0 = (2 << GPIO_PORT_SHIFT | 0 ), - PTC1 = (2 << GPIO_PORT_SHIFT | 1 ), - PTC2 = (2 << GPIO_PORT_SHIFT | 2 ), - PTC3 = (2 << GPIO_PORT_SHIFT | 3 ), - PTC4 = (2 << GPIO_PORT_SHIFT | 4 ), - PTC5 = (2 << GPIO_PORT_SHIFT | 5 ), - PTC6 = (2 << GPIO_PORT_SHIFT | 6 ), - PTC7 = (2 << GPIO_PORT_SHIFT | 7 ), - PTC8 = (2 << GPIO_PORT_SHIFT | 8 ), - PTC9 = (2 << GPIO_PORT_SHIFT | 9 ), + PTC0 = (2 << GPIO_PORT_SHIFT | 0), + PTC1 = (2 << GPIO_PORT_SHIFT | 1), + PTC2 = (2 << GPIO_PORT_SHIFT | 2), + PTC3 = (2 << GPIO_PORT_SHIFT | 3), + PTC4 = (2 << GPIO_PORT_SHIFT | 4), + PTC5 = (2 << GPIO_PORT_SHIFT | 5), + PTC6 = (2 << GPIO_PORT_SHIFT | 6), + PTC7 = (2 << GPIO_PORT_SHIFT | 7), + PTC8 = (2 << GPIO_PORT_SHIFT | 8), + PTC9 = (2 << GPIO_PORT_SHIFT | 9), PTC10 = (2 << GPIO_PORT_SHIFT | 10), PTC11 = (2 << GPIO_PORT_SHIFT | 11), PTC12 = (2 << GPIO_PORT_SHIFT | 12), @@ -129,16 +129,16 @@ typedef enum { PTC29 = (2 << GPIO_PORT_SHIFT | 29), PTC30 = (2 << GPIO_PORT_SHIFT | 30), PTC31 = (2 << GPIO_PORT_SHIFT | 31), - PTD0 = (3 << GPIO_PORT_SHIFT | 0 ), - PTD1 = (3 << GPIO_PORT_SHIFT | 1 ), - PTD2 = (3 << GPIO_PORT_SHIFT | 2 ), - PTD3 = (3 << GPIO_PORT_SHIFT | 3 ), - PTD4 = (3 << GPIO_PORT_SHIFT | 4 ), - PTD5 = (3 << GPIO_PORT_SHIFT | 5 ), - PTD6 = (3 << GPIO_PORT_SHIFT | 6 ), - PTD7 = (3 << GPIO_PORT_SHIFT | 7 ), - PTD8 = (3 << GPIO_PORT_SHIFT | 8 ), - PTD9 = (3 << GPIO_PORT_SHIFT | 9 ), + PTD0 = (3 << GPIO_PORT_SHIFT | 0), + PTD1 = (3 << GPIO_PORT_SHIFT | 1), + PTD2 = (3 << GPIO_PORT_SHIFT | 2), + PTD3 = (3 << GPIO_PORT_SHIFT | 3), + PTD4 = (3 << GPIO_PORT_SHIFT | 4), + PTD5 = (3 << GPIO_PORT_SHIFT | 5), + PTD6 = (3 << GPIO_PORT_SHIFT | 6), + PTD7 = (3 << GPIO_PORT_SHIFT | 7), + PTD8 = (3 << GPIO_PORT_SHIFT | 8), + PTD9 = (3 << GPIO_PORT_SHIFT | 9), PTD10 = (3 << GPIO_PORT_SHIFT | 10), PTD11 = (3 << GPIO_PORT_SHIFT | 11), PTD12 = (3 << GPIO_PORT_SHIFT | 12), @@ -161,16 +161,16 @@ typedef enum { PTD29 = (3 << GPIO_PORT_SHIFT | 29), PTD30 = (3 << GPIO_PORT_SHIFT | 30), PTD31 = (3 << GPIO_PORT_SHIFT | 31), - PTE0 = (4 << GPIO_PORT_SHIFT | 0 ), - PTE1 = (4 << GPIO_PORT_SHIFT | 1 ), - PTE2 = (4 << GPIO_PORT_SHIFT | 2 ), - PTE3 = (4 << GPIO_PORT_SHIFT | 3 ), - PTE4 = (4 << GPIO_PORT_SHIFT | 4 ), - PTE5 = (4 << GPIO_PORT_SHIFT | 5 ), - PTE6 = (4 << GPIO_PORT_SHIFT | 6 ), - PTE7 = (4 << GPIO_PORT_SHIFT | 7 ), - PTE8 = (4 << GPIO_PORT_SHIFT | 8 ), - PTE9 = (4 << GPIO_PORT_SHIFT | 9 ), + PTE0 = (4 << GPIO_PORT_SHIFT | 0), + PTE1 = (4 << GPIO_PORT_SHIFT | 1), + PTE2 = (4 << GPIO_PORT_SHIFT | 2), + PTE3 = (4 << GPIO_PORT_SHIFT | 3), + PTE4 = (4 << GPIO_PORT_SHIFT | 4), + PTE5 = (4 << GPIO_PORT_SHIFT | 5), + PTE6 = (4 << GPIO_PORT_SHIFT | 6), + PTE7 = (4 << GPIO_PORT_SHIFT | 7), + PTE8 = (4 << GPIO_PORT_SHIFT | 8), + PTE9 = (4 << GPIO_PORT_SHIFT | 9), PTE10 = (4 << GPIO_PORT_SHIFT | 10), PTE11 = (4 << GPIO_PORT_SHIFT | 11), PTE12 = (4 << GPIO_PORT_SHIFT | 12), diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/pwmout_api.c b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/pwmout_api.c index 3f95f34599f..e89fb9a2297 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/pwmout_api.c +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/pwmout_api.c @@ -27,7 +27,7 @@ static float pwm_clock_mhz; /* Array of FTM peripheral base address. */ static FTM_Type *const ftm_addrs[] = FTM_BASE_PTRS; -void pwmout_init_direct(pwmout_t* obj, const PinMap *pinmap) +void pwmout_init_direct(pwmout_t *obj, const PinMap *pinmap) { PWMName pwm = (PWMName)pinmap->peripheral; MBED_ASSERT(pwm != (PWMName)NC); @@ -74,7 +74,7 @@ void pwmout_init_direct(pwmout_t* obj, const PinMap *pinmap) pin_mode(pinmap->pin, PullNone); } -void pwmout_init(pwmout_t* obj, PinName pin) +void pwmout_init(pwmout_t *obj, PinName pin) { int peripheral = (int)pinmap_peripheral(pin, PinMap_PWM); int function = (int)pinmap_find_function(pin, PinMap_PWM); @@ -84,12 +84,12 @@ void pwmout_init(pwmout_t* obj, PinName pin) pwmout_init_direct(obj, &explicit_pinmap); } -void pwmout_free(pwmout_t* obj) +void pwmout_free(pwmout_t *obj) { FTM_Deinit(ftm_addrs[obj->pwm_name >> TPM_SHIFT]); } -void pwmout_write(pwmout_t* obj, float value) +void pwmout_write(pwmout_t *obj, float value) { if (value < 0.0f) { value = 0.0f; @@ -107,30 +107,31 @@ void pwmout_write(pwmout_t* obj, float value) FTM_SetSoftwareTrigger(base, true); } -float pwmout_read(pwmout_t* obj) +float pwmout_read(pwmout_t *obj) { FTM_Type *base = ftm_addrs[obj->pwm_name >> TPM_SHIFT]; uint16_t count = (base->CONTROLS[obj->pwm_name & 0xF].CnV) & FTM_CnV_VAL_MASK; uint16_t mod = base->MOD & FTM_MOD_MOD_MASK; - if (mod == 0) + if (mod == 0) { return 0.0; + } float v = (float)(count) / (float)(mod); return (v > 1.0f) ? (1.0f) : (v); } -void pwmout_period(pwmout_t* obj, float seconds) +void pwmout_period(pwmout_t *obj, float seconds) { pwmout_period_us(obj, seconds * 1000000.0f); } -void pwmout_period_ms(pwmout_t* obj, int ms) +void pwmout_period_ms(pwmout_t *obj, int ms) { pwmout_period_us(obj, ms * 1000); } // Set the PWM period, keeping the duty cycle the same. -void pwmout_period_us(pwmout_t* obj, int us) +void pwmout_period_us(pwmout_t *obj, int us) { FTM_Type *base = ftm_addrs[obj->pwm_name >> TPM_SHIFT]; float dc = pwmout_read(obj); @@ -157,17 +158,17 @@ void pwmout_period_us(pwmout_t* obj, int us) pwmout_write(obj, dc); } -void pwmout_pulsewidth(pwmout_t* obj, float seconds) +void pwmout_pulsewidth(pwmout_t *obj, float seconds) { pwmout_pulsewidth_us(obj, seconds * 1000000.0f); } -void pwmout_pulsewidth_ms(pwmout_t* obj, int ms) +void pwmout_pulsewidth_ms(pwmout_t *obj, int ms) { pwmout_pulsewidth_us(obj, ms * 1000); } -void pwmout_pulsewidth_us(pwmout_t* obj, int us) +void pwmout_pulsewidth_us(pwmout_t *obj, int us) { FTM_Type *base = ftm_addrs[obj->pwm_name >> TPM_SHIFT]; uint32_t value = (uint32_t)(pwm_clock_mhz * (float)us); diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/serial_api.c b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/serial_api.c index b42460c7fa8..98a9ec3dc03 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/serial_api.c +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/serial_api.c @@ -119,8 +119,7 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b uint8_t temp; /* Set bit count and parity mode. */ temp = base->C1 & ~(UART_C1_PE_MASK | UART_C1_PT_MASK | UART_C1_M_MASK); - if (parity != ParityNone) - { + if (parity != ParityNone) { /* Enable Parity */ temp |= (UART_C1_PE_MASK | UART_C1_M_MASK); if (parity == ParityOdd) { @@ -147,18 +146,19 @@ static inline void uart_irq(uint32_t transmit_empty, uint32_t receive_full, uint UART_Type *base = uart_addrs[index]; /* If RX overrun. */ - if (UART_S1_OR_MASK & base->S1) - { + if (UART_S1_OR_MASK & base->S1) { /* Read base->D, otherwise the RX does not work. */ (void)base->D; } if (serial_irq_ids[index] != 0) { - if (transmit_empty && (UART_GetEnabledInterrupts(uart_addrs[index]) & kUART_TxDataRegEmptyInterruptEnable)) + if (transmit_empty && (UART_GetEnabledInterrupts(uart_addrs[index]) & kUART_TxDataRegEmptyInterruptEnable)) { irq_handler(serial_irq_ids[index], TxIrq); + } - if (receive_full && (UART_GetEnabledInterrupts(uart_addrs[index]) & kUART_RxDataRegFullInterruptEnable)) + if (receive_full && (UART_GetEnabledInterrupts(uart_addrs[index]) & kUART_RxDataRegFullInterruptEnable)) { irq_handler(serial_irq_ids[index], RxIrq); + } } } @@ -269,8 +269,9 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable) default: break; } - if (all_disabled) + if (all_disabled) { NVIC_DisableIRQ(uart_irqs[obj->serial.index]); + } } } @@ -292,16 +293,18 @@ void serial_putc(serial_t *obj, int c) int serial_readable(serial_t *obj) { uint32_t status_flags = UART_GetStatusFlags(uart_addrs[obj->serial.index]); - if (status_flags & kUART_RxOverrunFlag) + if (status_flags & kUART_RxOverrunFlag) { UART_ClearStatusFlags(uart_addrs[obj->serial.index], kUART_RxOverrunFlag); + } return (status_flags & kUART_RxDataRegFullFlag); } int serial_writable(serial_t *obj) { uint32_t status_flags = UART_GetStatusFlags(uart_addrs[obj->serial.index]); - if (status_flags & kUART_RxOverrunFlag) + if (status_flags & kUART_RxOverrunFlag) { UART_ClearStatusFlags(uart_addrs[obj->serial.index], kUART_RxOverrunFlag); + } return (status_flags & kUART_TxDataRegEmptyFlag); } @@ -351,7 +354,7 @@ const PinMap *serial_rts_pinmap() */ void serial_set_flow_control_direct(serial_t *obj, FlowControl type, const serial_fc_pinmap_t *pinmap) { - switch(type) { + switch (type) { case FlowControlRTS: pin_function(pinmap->rx_flow_pin, pinmap->rx_flow_function); pin_mode(pinmap->rx_flow_pin, PullNone); @@ -404,7 +407,7 @@ static void serial_send_asynch(serial_t *obj) sendXfer.dataSize = obj->tx_buff.length; if (obj->serial.uartDmaRx.dmaUsageState == DMA_USAGE_ALLOCATED || - obj->serial.uartDmaRx.dmaUsageState == DMA_USAGE_TEMPORARY_ALLOCATED) { + obj->serial.uartDmaRx.dmaUsageState == DMA_USAGE_TEMPORARY_ALLOCATED) { UART_SendEDMA(uart_addrs[obj->serial.index], &obj->serial.uart_dma_handle, &sendXfer); } else { UART_TransferSendNonBlocking(uart_addrs[obj->serial.index], &obj->serial.uart_transfer_handle, &sendXfer); @@ -420,7 +423,7 @@ static void serial_receive_asynch(serial_t *obj) receiveXfer.dataSize = obj->rx_buff.length; if (obj->serial.uartDmaRx.dmaUsageState == DMA_USAGE_ALLOCATED || - obj->serial.uartDmaRx.dmaUsageState == DMA_USAGE_TEMPORARY_ALLOCATED) { + obj->serial.uartDmaRx.dmaUsageState == DMA_USAGE_TEMPORARY_ALLOCATED) { UART_ReceiveEDMA(uart_addrs[obj->serial.index], &obj->serial.uart_dma_handle, &receiveXfer); } else { UART_TransferReceiveNonBlocking(uart_addrs[obj->serial.index], &obj->serial.uart_transfer_handle, &receiveXfer, NULL); @@ -464,7 +467,7 @@ static bool serial_allocate_dma(serial_t *obj, uint32_t handler) EDMA_CreateHandle(&(obj->serial.uartDmaTx.handle), DMA0, obj->serial.uartDmaTx.dmaChannel); UART_TransferCreateHandleEDMA(uart_addrs[obj->serial.index], &obj->serial.uart_dma_handle, (uart_edma_transfer_callback_t)handler, - NULL, &obj->serial.uartDmaTx.handle, &obj->serial.uartDmaRx.handle); + NULL, &obj->serial.uartDmaTx.handle, &obj->serial.uartDmaRx.handle); return true; } @@ -512,7 +515,8 @@ void serial_enable_event(serial_t *obj, int event, uint8_t enable) } } -static void serial_tx_buffer_set(serial_t *obj, void *tx, int tx_length, uint8_t width) { +static void serial_tx_buffer_set(serial_t *obj, void *tx, int tx_length, uint8_t width) +{ (void)width; // Exit if a transmit is already on-going @@ -528,9 +532,11 @@ static void serial_tx_buffer_set(serial_t *obj, void *tx, int tx_length, uint8_t int serial_tx_asynch(serial_t *obj, const void *tx, size_t tx_length, uint8_t tx_width, uint32_t handler, uint32_t event, DMAUsage hint) { // Check that a buffer has indeed been set up - MBED_ASSERT(tx != (void*)0); + MBED_ASSERT(tx != (void *)0); - if (tx_length == 0) return 0; + if (tx_length == 0) { + return 0; + } if (serial_tx_active(obj)) { return 0; @@ -582,7 +588,9 @@ void serial_rx_buffer_set(serial_t *obj, void *rx, int rx_length, uint8_t width) // We only support byte buffers for now MBED_ASSERT(width == 8); - if (serial_rx_active(obj)) return; + if (serial_rx_active(obj)) { + return; + } obj->rx_buff.buffer = rx; obj->rx_buff.length = rx_length; @@ -595,15 +603,17 @@ void serial_rx_buffer_set(serial_t *obj, void *rx, int rx_length, uint8_t width) void serial_rx_asynch(serial_t *obj, void *rx, size_t rx_length, uint8_t rx_width, uint32_t handler, uint32_t event, uint8_t char_match, DMAUsage hint) { // Check that a buffer has indeed been set up - MBED_ASSERT(rx != (void*)0); - if (rx_length == 0) return; + MBED_ASSERT(rx != (void *)0); + if (rx_length == 0) { + return; + } if (serial_rx_active(obj)) { return; } // Set up buffer - serial_rx_buffer_set(obj,(void*) rx, rx_length, rx_width); + serial_rx_buffer_set(obj, (void *) rx, rx_length, rx_width); // Set up events serial_enable_event(obj, SERIAL_EVENT_RX_ALL, false); @@ -711,7 +721,7 @@ int serial_irq_handler_asynch(serial_t *obj) } } #if 0 - if (obj->char_match != SERIAL_RESERVED_CHAR_MATCH){ + if (obj->char_match != SERIAL_RESERVED_CHAR_MATCH) { /* Check for character match event */ if (buf[obj->rx_buff.length - 1] == obj->char_match) { status |= SERIAL_EVENT_RX_CHARACTER_MATCH; diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/analogin_api.c b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/analogin_api.c index bb00e75d1e3..ce2e8073abe 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/analogin_api.c +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/analogin_api.c @@ -31,10 +31,10 @@ static ADC_Type *const adc_addrs[] = ADC_BASE_PTRS; #if EXPLICIT_PINMAP_READY #define ANALOGIN_INIT_DIRECT analogin_init_direct -void analogin_init_direct(analogin_t* obj, const PinMap *pinmap) +void analogin_init_direct(analogin_t *obj, const PinMap *pinmap) #else #define ANALOGIN_INIT_DIRECT _analogin_init_direct -static void _analogin_init_direct(analogin_t* obj, const PinMap *pinmap) +static void _analogin_init_direct(analogin_t *obj, const PinMap *pinmap) #endif { obj->adc = (ADCName)pinmap->peripheral; @@ -47,8 +47,9 @@ static void _analogin_init_direct(analogin_t* obj, const PinMap *pinmap) bus_clock = CLOCK_GetFreq(kCLOCK_BusClk); uint32_t clkdiv; for (clkdiv = 0; clkdiv < 4; clkdiv++) { - if ((bus_clock >> clkdiv) <= MAX_FADC) + if ((bus_clock >> clkdiv) <= MAX_FADC) { break; + } } if (clkdiv == 4) { clkdiv = 0x3; //Set max div @@ -65,7 +66,7 @@ static void _analogin_init_direct(analogin_t* obj, const PinMap *pinmap) pin_mode(pinmap->pin, PullNone); } -void analogin_init(analogin_t* obj, PinName pin) +void analogin_init(analogin_t *obj, PinName pin) { int peripheral = (int)pinmap_peripheral(pin, PinMap_ADC); int function = (int)pinmap_find_function(pin, PinMap_ADC); @@ -88,7 +89,7 @@ uint16_t analogin_read_u16(analogin_t *obj) #endif ADC16_SetChannelMuxMode(adc_addrs[instance], - obj->adc & (1 << ADC_B_CHANNEL_SHIFT) ? kADC16_ChannelMuxB : kADC16_ChannelMuxA); + obj->adc & (1 << ADC_B_CHANNEL_SHIFT) ? kADC16_ChannelMuxB : kADC16_ChannelMuxA); /* * When in software trigger mode, each conversion would be launched once calling the "ADC16_ChannelConfigure()" @@ -96,8 +97,7 @@ uint16_t analogin_read_u16(analogin_t *obj) */ ADC16_SetChannelConfig(adc_addrs[instance], 0, &adc16_channel_config); while (0U == (kADC16_ChannelConversionDoneFlag & - ADC16_GetChannelStatusFlags(adc_addrs[instance], 0))) - { + ADC16_GetChannelStatusFlags(adc_addrs[instance], 0))) { } return ADC16_GetChannelConversionValue(adc_addrs[instance], 0); } diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/analogout_api.c b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/analogout_api.c index 77ff46be1ec..62fb8ae2900 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/analogout_api.c +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/analogout_api.c @@ -30,10 +30,10 @@ static DAC_Type *const dac_bases[] = DAC_BASE_PTRS; #if EXPLICIT_PINMAP_READY #define ANALOGOUT_INIT_DIRECT analogout_init_direct -void analogout_init_direct(dac_t* obj, const PinMap *pinmap) +void analogout_init_direct(dac_t *obj, const PinMap *pinmap) #else #define ANALOGOUT_INIT_DIRECT _analogout_init_direct -static void _analogout_init_direct(dac_t* obj, const PinMap *pinmap) +static void _analogout_init_direct(dac_t *obj, const PinMap *pinmap) #endif { dac_config_t dac_config; @@ -50,7 +50,7 @@ static void _analogout_init_direct(dac_t* obj, const PinMap *pinmap) DAC_Enable(dac_bases[obj->dac], true); } -void analogout_init(dac_t* obj, PinName pin) +void analogout_init(dac_t *obj, PinName pin) { int peripheral = (int)pinmap_peripheral(pin, PinMap_ADC); diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/i2c_api.c b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/i2c_api.c index 0c795bb17be..0affddbc205 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/i2c_api.c +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/i2c_api.c @@ -98,8 +98,7 @@ int i2c_start(i2c_t *obj) } #if defined(FSL_FEATURE_I2C_HAS_DOUBLE_BUFFERING) && FSL_FEATURE_I2C_HAS_DOUBLE_BUFFERING - while (!(base->S2 & I2C_S2_EMPTY_MASK)) - { + while (!(base->S2 & I2C_S2_EMPTY_MASK)) { } #endif /* FSL_FEATURE_I2C_HAS_DOUBLE_BUFFERING */ @@ -217,8 +216,7 @@ int i2c_byte_read(i2c_t *obj, int last) data = base->D; /* Wait until data transfer complete. */ - while (!(base->S & kI2C_IntPendingFlag)) - { + while (!(base->S & kI2C_IntPendingFlag)) { } /* Clear the IICIF flag. */ diff --git a/targets/TARGET_STM/TARGET_STM32F4/analogin_device.c b/targets/TARGET_STM/TARGET_STM32F4/analogin_device.c index 94f8f46071b..4e7359c8ec2 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/analogin_device.c +++ b/targets/TARGET_STM/TARGET_STM32F4/analogin_device.c @@ -38,10 +38,10 @@ #if EXPLICIT_PINMAP_READY #define ANALOGIN_INIT_DIRECT analogin_init_direct -void analogin_init_direct(analogin_t* obj, const PinMap *pinmap) +void analogin_init_direct(analogin_t *obj, const PinMap *pinmap) #else #define ANALOGIN_INIT_DIRECT _analogin_init_direct -static void _analogin_init_direct(analogin_t* obj, const PinMap *pinmap) +static void _analogin_init_direct(analogin_t *obj, const PinMap *pinmap) #endif { uint32_t function = (uint32_t)pinmap->function; @@ -105,7 +105,7 @@ static void _analogin_init_direct(analogin_t* obj, const PinMap *pinmap) } } -void analogin_init(analogin_t* obj, PinName pin) +void analogin_init(analogin_t *obj, PinName pin) { int peripheral; int function; diff --git a/targets/TARGET_STM/TARGET_STM32F4/analogout_device.c b/targets/TARGET_STM/TARGET_STM32F4/analogout_device.c index b0237af4c61..764fd0b6ff8 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/analogout_device.c +++ b/targets/TARGET_STM/TARGET_STM32F4/analogout_device.c @@ -37,10 +37,10 @@ #if EXPLICIT_PINMAP_READY #define ANALOGOUT_INIT_DIRECT analogout_init_direct -void analogout_init_direct(dac_t* obj, const PinMap *pinmap) +void analogout_init_direct(dac_t *obj, const PinMap *pinmap) #else #define ANALOGOUT_INIT_DIRECT _analogout_init_direct -static void _analogout_init_direct(dac_t* obj, const PinMap *pinmap) +static void _analogout_init_direct(dac_t *obj, const PinMap *pinmap) #endif { DAC_ChannelConfTypeDef sConfig = {0}; diff --git a/targets/TARGET_STM/pwmout_api.c b/targets/TARGET_STM/pwmout_api.c index 5d1ae2d6146..763272b52eb 100644 --- a/targets/TARGET_STM/pwmout_api.c +++ b/targets/TARGET_STM/pwmout_api.c @@ -78,10 +78,10 @@ uint32_t TIM_ChannelConvert_HAL2LL(uint32_t channel, pwmout_t *obj) #if EXPLICIT_PINMAP_READY #define PWM_INIT_DIRECT pwmout_init_direct -void pwmout_init_direct(pwmout_t* obj, const PinMap *pinmap) +void pwmout_init_direct(pwmout_t *obj, const PinMap *pinmap) #else #define PWM_INIT_DIRECT _pwmout_init_direct -static void _pwmout_init_direct(pwmout_t* obj, const PinMap *pinmap) +static void _pwmout_init_direct(pwmout_t *obj, const PinMap *pinmap) #endif { // Get the peripheral name from the pin and assign it to the object @@ -207,7 +207,7 @@ static void _pwmout_init_direct(pwmout_t* obj, const PinMap *pinmap) pwmout_period_us(obj, 20000); // 20 ms per default } -void pwmout_init(pwmout_t* obj, PinName pin) +void pwmout_init(pwmout_t *obj, PinName pin) { int peripheral = (int)pinmap_peripheral(pin, PinMap_PWM); int function = (int)pinmap_find_function(pin, PinMap_PWM); diff --git a/targets/TARGET_STM/stm_spi_api.c b/targets/TARGET_STM/stm_spi_api.c index 282fa333472..160a84679c2 100644 --- a/targets/TARGET_STM/stm_spi_api.c +++ b/targets/TARGET_STM/stm_spi_api.c @@ -221,7 +221,7 @@ static void _spi_init_direct(spi_t *obj, const spi_pinmap_t *pinmap) * According the STM32 Datasheet for SPI peripheral we need to PULLDOWN * or PULLUP the SCK pin according the polarity used. */ - pin_mode(spiobj->pin_sclk, (handle->Init.CLKPolarity == SPI_POLARITY_LOW) ? PullDown: PullUp); + pin_mode(spiobj->pin_sclk, (handle->Init.CLKPolarity == SPI_POLARITY_LOW) ? PullDown : PullUp); init_spi(obj); } @@ -366,7 +366,7 @@ void spi_format(spi_t *obj, int bits, int mode, int slave) * According the STM32 Datasheet for SPI peripheral we need to PULLDOWN * or PULLUP the SCK pin according the polarity used. */ - pull = (handle->Init.CLKPolarity == SPI_POLARITY_LOW) ? PullDown: PullUp; + pull = (handle->Init.CLKPolarity == SPI_POLARITY_LOW) ? PullDown : PullUp; pin_mode(spiobj->pin_sclk, pull); init_spi(obj); From 958147e7ee90e7b80d51e29dc229841f34afc85e Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Wed, 25 Sep 2019 14:27:25 +0200 Subject: [PATCH 36/36] Explicit pinmap: Fix build failures reported by CI --- hal/explicit_pinmap.h | 29 ++++++++++--------- platform/source/mbed_retarget.cpp | 12 ++++---- .../TARGET_ONSEMI/TARGET_NCS36510/objects.h | 1 - targets/TARGET_STM/i2c_api.c | 16 ++++++++-- 4 files changed, 35 insertions(+), 23 deletions(-) diff --git a/hal/explicit_pinmap.h b/hal/explicit_pinmap.h index 4a4870588e0..65edc06d5a0 100644 --- a/hal/explicit_pinmap.h +++ b/hal/explicit_pinmap.h @@ -29,6 +29,7 @@ #if EXPLICIT_PINMAP_READY #include "PeripheralPinMaps.h" + #if DEVICE_PWMOUT MSTD_CONSTEXPR_FN_14 PinMap get_pwm_pinmap(const PinName pin) { @@ -37,7 +38,7 @@ MSTD_CONSTEXPR_FN_14 PinMap get_pwm_pinmap(const PinName pin) return {pin, pinmap.peripheral, pinmap.function}; } } - return {NC, NC, NC}; + return {NC, (int) NC, (int) NC}; } #endif // DEVICE_PWMOUT @@ -49,7 +50,7 @@ MSTD_CONSTEXPR_FN_14 PinMap get_analogin_pinmap(const PinName pin) return {pin, pinmap.peripheral, pinmap.function}; } } - return {NC, NC, NC}; + return {NC, (int) NC, (int) NC}; } #endif // DEVICE_ANALOGIN @@ -61,7 +62,7 @@ MSTD_CONSTEXPR_FN_14 PinMap get_analogout_pinmap(const PinName pin) return {pin, pinmap.peripheral, pinmap.function}; } } - return {NC, NC, NC}; + return {NC, (int) NC, (int) NC}; } #endif // DEVICE_ANALOGOUT @@ -85,7 +86,7 @@ MSTD_CONSTEXPR_FN_14 i2c_pinmap_t get_i2c_pinmap(const PinName sda, const PinNam } if (!sda_map || !scl_map || sda_map->peripheral != scl_map->peripheral) { - return {NC, NC, NC, NC, NC}; + return {(int) NC, NC, (int) NC, NC, (int) NC}; } return {sda_map->peripheral, sda_map->pin, sda_map->function, scl_map->pin, scl_map->function}; @@ -112,7 +113,7 @@ MSTD_CONSTEXPR_FN_14 serial_pinmap_t get_uart_pinmap(const PinName tx, const Pin } if (!tx_map || !rx_map || rx_map->peripheral != tx_map->peripheral) { - return {NC, NC, NC, NC, NC, false}; + return {(int) NC, NC, (int) NC, NC, (int) NC, false}; } if (tx_map->pin == STDIO_UART_TX && rx_map->pin == STDIO_UART_RX) { @@ -142,7 +143,7 @@ MSTD_CONSTEXPR_FN_14 serial_fc_pinmap_t get_uart_fc_pinmap(const PinName rxflow, } if ((!rts_map || !cts_map) || (rts_map->peripheral != cts_map->peripheral)) { - return {NC, NC, NC, NC, NC}; + return {(int) NC, NC, (int) NC, NC, (int) NC}; } return {cts_map->peripheral, cts_map->pin, cts_map->function, rts_map->pin, rts_map->function}; @@ -188,7 +189,7 @@ MSTD_CONSTEXPR_FN_14 spi_pinmap_t get_spi_pinmap(const PinName mosi, const PinNa if ((!mosi_map || !miso_map || !sclk_map || !ssel_map) || (mosi_map->peripheral != miso_map->peripheral || mosi_map->peripheral != sclk_map->peripheral) || (ssel_map->pin != NC && mosi_map->peripheral != ssel_map->peripheral)) { - return {NC, NC, NC, NC, NC, NC, NC, NC, NC}; + return {(int) NC, NC, (int) NC, NC, (int) NC, NC, (int) NC, NC, (int) NC}; } return {mosi_map->peripheral, mosi_map->pin, mosi_map->function, miso_map->pin, miso_map->function, sclk_map->pin, sclk_map->function, ssel_map->pin, ssel_map->function}; @@ -200,41 +201,41 @@ MSTD_CONSTEXPR_FN_14 spi_pinmap_t get_spi_pinmap(const PinName mosi, const PinNa #if DEVICE_PWMOUT MSTD_CONSTEXPR_FN_14 PinMap get_pwm_pinmap(const PinName pin) { - return {pin, NC, NC}; + return {pin, (int) NC, (int) NC}; } #endif // DEVICE_PWMOUT #if DEVICE_ANALOGIN MSTD_CONSTEXPR_FN_14 PinMap get_analogin_pinmap(const PinName pin) { - return {pin, NC, NC}; + return {pin, (int) NC, (int) NC}; } #endif // DEVICE_ANALOGIN #if DEVICE_ANALOGOUT MSTD_CONSTEXPR_FN_14 PinMap get_analogout_pinmap(const PinName pin) { - return {pin, NC, NC}; + return {pin, (int) NC, (int) NC}; } #endif // DEVICE_ANALOGOUT #if DEVICE_I2C MSTD_CONSTEXPR_FN_14 i2c_pinmap_t get_i2c_pinmap(const PinName sda, const PinName scl) { - return {NC, sda, NC, scl, NC}; + return {(int) NC, sda, (int) NC, scl, (int) NC}; } #endif //DEVICE_I2C #if DEVICE_SERIAL MSTD_CONSTEXPR_FN_14 serial_pinmap_t get_uart_pinmap(const PinName tx, const PinName rx) { - return {NC, tx, NC, rx, NC, false}; + return {(int) NC, tx, (int) NC, rx, (int) NC, false}; } #if DEVICE_SERIAL_FC MSTD_CONSTEXPR_FN_14 serial_fc_pinmap_t get_uart_fc_pinmap(const PinName rxflow, const PinName txflow) { - return {NC, txflow, NC, rxflow, NC}; + return {(int) NC, txflow, (int) NC, rxflow, (int) NC}; } #endif // DEVICE_SERIAL_FC #endif // DEVICE_SERIAL @@ -242,7 +243,7 @@ MSTD_CONSTEXPR_FN_14 serial_fc_pinmap_t get_uart_fc_pinmap(const PinName rxflow, #if DEVICE_SPI MSTD_CONSTEXPR_FN_14 spi_pinmap_t get_spi_pinmap(const PinName mosi, const PinName miso, const PinName sclk, const PinName ssel) { - return {NC, mosi, NC, miso, NC, sclk, NC, ssel, NC}; + return {(int) NC, mosi, (int) NC, miso, (int) NC, sclk, (int) NC, ssel, (int) NC}; } #endif // DEVICE_SERIAL diff --git a/platform/source/mbed_retarget.cpp b/platform/source/mbed_retarget.cpp index 24e2cc6bdf8..1c4086b598d 100644 --- a/platform/source/mbed_retarget.cpp +++ b/platform/source/mbed_retarget.cpp @@ -175,13 +175,13 @@ DirectSerial::DirectSerial(PinName tx, PinName rx, int baud) #if CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_RTS static const serial_fc_pinmap_t fc_pinmap = get_uart_fc_pinmap(STDIO_UART_RTS, NC); - serial_set_flow_control_direct(&stdio_uart, FlowControlRTS, fc_pinmap); + serial_set_flow_control_direct(&stdio_uart, FlowControlRTS, &fc_pinmap); #elif CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_CTS static const serial_fc_pinmap_t fc_pinmap = get_uart_fc_pinmap(NC, STDIO_UART_CTS); - serial_set_flow_control_direct(&stdio_uart, FlowControlCTS, fc_pinmap); + serial_set_flow_control_direct(&stdio_uart, FlowControlCTS, &fc_pinmap); #elif CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_RTSCTS static const serial_fc_pinmap_t fc_pinmap = get_uart_fc_pinmap(STDIO_UART_RTS, STDIO_UART_CTS); - serial_set_flow_control_direct(&stdio_uart, FlowControlRTSCTS, fc_pinmap); + serial_set_flow_control_direct(&stdio_uart, FlowControlRTSCTS, &fc_pinmap); #endif } @@ -195,13 +195,13 @@ DirectSerial::DirectSerial(const serial_pinmap_t &explicit_pinmap, int baud) #if CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_RTS static const serial_fc_pinmap_t fc_pinmap = get_uart_fc_pinmap(STDIO_UART_RTS, NC); - serial_set_flow_control_direct(&stdio_uart, FlowControlRTS, fc_pinmap); + serial_set_flow_control_direct(&stdio_uart, FlowControlRTS, &fc_pinmap); #elif CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_CTS static const serial_fc_pinmap_t fc_pinmap = get_uart_fc_pinmap(NC, STDIO_UART_CTS); - serial_set_flow_control_direct(&stdio_uart, FlowControlCTS, fc_pinmap); + serial_set_flow_control_direct(&stdio_uart, FlowControlCTS, &fc_pinmap); #elif CONSOLE_FLOWCONTROL == CONSOLE_FLOWCONTROL_RTSCTS static const serial_fc_pinmap_t fc_pinmap = get_uart_fc_pinmap(STDIO_UART_RTS, STDIO_UART_CTS); - serial_set_flow_control_direct(&stdio_uart, FlowControlRTSCTS, fc_pinmap); + serial_set_flow_control_direct(&stdio_uart, FlowControlRTSCTS, &fc_pinmap); #endif } diff --git a/targets/TARGET_ONSEMI/TARGET_NCS36510/objects.h b/targets/TARGET_ONSEMI/TARGET_NCS36510/objects.h index f95941bb87d..de6146728e6 100644 --- a/targets/TARGET_ONSEMI/TARGET_NCS36510/objects.h +++ b/targets/TARGET_ONSEMI/TARGET_NCS36510/objects.h @@ -40,7 +40,6 @@ extern "C" { #include "PortNames.h" #include "PeripheralNames.h" #include "target_config.h" -#include "spi.h" typedef enum { FlowControlNone_1, diff --git a/targets/TARGET_STM/i2c_api.c b/targets/TARGET_STM/i2c_api.c index a86d09ab9b0..3ae8bb71e56 100644 --- a/targets/TARGET_STM/i2c_api.c +++ b/targets/TARGET_STM/i2c_api.c @@ -271,9 +271,10 @@ void i2c_init_internal(i2c_t *obj, const i2c_pinmap_t *pinmap) if (pinmap != NULL) { obj_s->sda = pinmap->sda_pin; obj_s->scl = pinmap->scl_pin; +#if EXPLICIT_PINMAP_READY obj_s->sda_func = pinmap->sda_function; obj_s->scl_func = pinmap->scl_function; - +#endif obj_s->i2c = (I2CName)pinmap->peripheral; MBED_ASSERT(obj_s->i2c != (I2CName)NC); } @@ -326,8 +327,13 @@ void i2c_init_internal(i2c_t *obj, const i2c_pinmap_t *pinmap) #endif // Configure I2C pins +#if EXPLICIT_PINMAP_READY pin_function(obj_s->sda, obj_s->sda_func); pin_function(obj_s->scl, obj_s->scl_func); +#else + pinmap_pinout(obj_s->sda, PinMap_I2C_SDA); + pinmap_pinout(obj_s->scl, PinMap_I2C_SCL); +#endif pin_mode(obj_s->sda, OpenDrainNoPull); pin_mode(obj_s->scl, OpenDrainNoPull); @@ -356,7 +362,13 @@ void i2c_init_internal(i2c_t *obj, const i2c_pinmap_t *pinmap) #endif } +#if EXPLICIT_PINMAP_READY +#define I2C_INIT_DIRECT i2c_init_direct void i2c_init_direct(i2c_t *obj, const i2c_pinmap_t *pinmap) +#else +#define I2C_INIT_DIRECT _i2c_init_direct +static void _i2c_init_direct(i2c_t *obj, const i2c_pinmap_t *pinmap) +#endif { memset(obj, 0, sizeof(*obj)); i2c_init_internal(obj, pinmap); @@ -374,7 +386,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) const i2c_pinmap_t explicit_i2c_pinmap = {peripheral, sda, sda_function, scl, scl_function}; - i2c_init_direct(obj, &explicit_i2c_pinmap); + I2C_INIT_DIRECT(obj, &explicit_i2c_pinmap); }