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..af92c8d6b68 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 }; diff --git a/drivers/AnalogIn.h b/drivers/AnalogIn.h index 6f884920749..26f63f4b96e 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 structure 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/AnalogOut.h b/drivers/AnalogOut.h index 1e28f329515..c5f773e9a42 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 structure 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, diff --git a/drivers/I2C.h b/drivers/I2C.h index 4fb06a3d267..faf6fed87e8 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 structure 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..c6a35d89edb 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 structure 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/PwmOut.h b/drivers/PwmOut.h index 68102caaa57..4c54b5c0095 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 structure which holds static pinmap. + */ + PwmOut(const PinMap &pinmap); + ~PwmOut(); /** Set the output duty-cycle, specified as a percentage (float) diff --git a/drivers/SPI.h b/drivers/SPI.h index c247b3ea708..f46bba63f03 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 structure 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 structure 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/SPISlave.h b/drivers/SPISlave.h index 5b9ae585577..3bd19f63cf3 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 structure 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/Serial.h b/drivers/Serial.h index d167e695805..4db73d327a4 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 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) + * + * @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 structure 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..b452ac2011b 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 structure 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..f94ad4303ce 100644 --- a/drivers/UARTSerial.h +++ b/drivers/UARTSerial.h @@ -58,6 +58,13 @@ class UARTSerial : private SerialBase, public FileHandle, private NonCopyable_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; 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; diff --git a/drivers/source/Serial.cpp b/drivers/source/Serial.cpp index 03ee49697ad..fa95a688101 100644 --- a/drivers/source/Serial.cpp +++ b/drivers/source/Serial.cpp @@ -24,10 +24,18 @@ Serial::Serial(PinName tx, PinName rx, const char *name, int baud) : SerialBase( { } +Serial::Serial(const serial_pinmap_t &explicit_pinmap, const char *name, int baud) : SerialBase(explicit_pinmap, baud), Stream(name) +{ +} + Serial::Serial(PinName tx, PinName rx, int baud): SerialBase(tx, rx, baud), Stream(NULL) { } +Serial::Serial(const serial_pinmap_t &explicit_pinmap, int baud): SerialBase(explicit_pinmap, baud), Stream(NULL) +{ +} + int Serial::_getc() { // Mutex is already held diff --git a/drivers/source/SerialBase.cpp b/drivers/source/SerialBase.cpp index 856944fd347..0f66c0bee1c 100644 --- a/drivers/source/SerialBase.cpp +++ b/drivers/source/SerialBase.cpp @@ -43,6 +43,26 @@ SerialBase::SerialBase(PinName tx, PinName rx, int baud) : serial_irq_handler(&_serial, SerialBase::_irq_handler, (uint32_t)this); } +SerialBase::SerialBase(const serial_pinmap_t &explicit_pinmap, int baud) : +#if DEVICE_SERIAL_ASYNCH + _thunk_irq(this), _tx_usage(DMA_USAGE_NEVER), + _rx_usage(DMA_USAGE_NEVER), _tx_callback(NULL), + _rx_callback(NULL), _tx_asynch_set(false), + _rx_asynch_set(false), +#endif + _serial(), _baud(baud) +{ + // No lock needed in the constructor + + for (size_t i = 0; i < sizeof _irq / sizeof _irq[0]; i++) { + _irq[i] = NULL; + } + + serial_init_direct(&_serial, &explicit_pinmap); + serial_baud(&_serial, _baud); + serial_irq_handler(&_serial, SerialBase::_irq_handler, (uint32_t)this); +} + void SerialBase::baud(int baudrate) { lock(); @@ -195,6 +215,14 @@ void SerialBase::set_flow_control(Flow type, PinName flow1, PinName flow2) } unlock(); } + +void SerialBase::set_flow_control(Flow type, const serial_fc_pinmap_t &explicit_pinmap) +{ + lock(); + FlowControl flow_type = (FlowControl)type; + serial_set_flow_control_direct(&_serial, flow_type, &explicit_pinmap); + unlock(); +} #endif #if DEVICE_SERIAL_ASYNCH diff --git a/drivers/source/UARTSerial.cpp b/drivers/source/UARTSerial.cpp index 0475bf820ed..9ae5cadb8bf 100644 --- a/drivers/source/UARTSerial.cpp +++ b/drivers/source/UARTSerial.cpp @@ -36,6 +36,19 @@ UARTSerial::UARTSerial(PinName tx, PinName rx, int baud) : enable_rx_irq(); } +UARTSerial::UARTSerial(const serial_pinmap_t &explicit_pinmap, int baud) : + SerialBase(explicit_pinmap, baud), + _blocking(true), + _tx_irq_enabled(false), + _rx_irq_enabled(false), + _tx_enabled(true), + _rx_enabled(true), + _dcd_irq(NULL) +{ + /* Attatch IRQ routines to the serial device. */ + enable_rx_irq(); +} + UARTSerial::~UARTSerial() { delete _dcd_irq; diff --git a/hal/analogin_api.h b/hal/analogin_api.h index fdf91dc62af..cd64637e501 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 structure which holds static pinmap + */ +void analogin_init_direct(analogin_t *obj, const PinMap *pinmap); + /** Initialize the analogin peripheral * * Configures the pin used by analogin. diff --git a/hal/analogout_api.h b/hal/analogout_api.h index 4983e43c37c..1cf515303fc 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 structure which holds static pinmap + */ +void analogout_init_direct(dac_t *obj, const PinMap *pinmap); + /** Initialize the analogout peripheral * * Configures the pin used by analogout. diff --git a/hal/explicit_pinmap.cpp b/hal/explicit_pinmap.cpp new file mode 100644 index 00000000000..5c2e532cc69 --- /dev/null +++ b/hal/explicit_pinmap.cpp @@ -0,0 +1,78 @@ +/* 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 "explicit_pinmap.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 diff --git a/hal/explicit_pinmap.h b/hal/explicit_pinmap.h new file mode 100644 index 00000000000..65edc06d5a0 --- /dev/null +++ b/hal/explicit_pinmap.h @@ -0,0 +1,252 @@ +/* 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, (int) NC, (int) 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, (int) NC, (int) 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, (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) +{ + 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 {(int) NC, NC, (int) NC, NC, (int) 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 {(int) NC, NC, (int) NC, NC, (int) 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 {(int) NC, NC, (int) NC, NC, (int) 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 {(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}; +} +#endif // DEVICE_SPI + +#else // EXPLICIT_PINMAP_READY + +#if DEVICE_PWMOUT +MSTD_CONSTEXPR_FN_14 PinMap get_pwm_pinmap(const PinName pin) +{ + 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, (int) NC, (int) NC}; +} +#endif // DEVICE_ANALOGIN + +#if DEVICE_ANALOGOUT +MSTD_CONSTEXPR_FN_14 PinMap get_analogout_pinmap(const PinName pin) +{ + 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 {(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 {(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 {(int) NC, txflow, (int) NC, rxflow, (int) 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 {(int) NC, mosi, (int) NC, miso, (int) NC, sclk, (int) NC, ssel, (int) NC}; +} +#endif // DEVICE_SERIAL + +#endif // EXPLICIT_PINMAP_READY + +#endif // EXPLICIT_PINMAP_H diff --git a/hal/i2c_api.h b/hal/i2c_api.h index 3ade94ce778..9468b323639 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 structure 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. * diff --git a/hal/pwmout_api.h b/hal/pwmout_api.h index 62d5d7098c7..619539ad5d5 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 structure 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 diff --git a/hal/serial_api.h b/hal/serial_api.h index 32eb362fb39..f480b5def5d 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 structure 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 structure 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 diff --git a/hal/spi_api.h b/hal/spi_api.h index a6ac1a3da42..25cd50a8ba2 100644 --- a/hal/spi_api.h +++ b/hal/spi_api.h @@ -53,6 +53,18 @@ typedef struct spi_s spi_t; #endif +typedef struct { + 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; + #ifdef __cplusplus extern "C" { #endif @@ -73,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 structure 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 diff --git a/platform/cxxsupport/mstd_cstddef b/platform/cxxsupport/mstd_cstddef index 937f80ed521..0afe5bfcd8a 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] @@ -54,8 +61,7 @@ #define alignas(N) __attribute__((aligned(N))) #endif -namespace std -{ +namespace std { // [cstddef.syn] using nullptr_t = decltype(nullptr); @@ -63,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; @@ -72,4 +77,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_ diff --git a/platform/source/mbed_retarget.cpp b/platform/source/mbed_retarget.cpp index 61adeeb0f90..1c4086b598d 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/PeripheralPinMaps.h b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PeripheralPinMaps.h new file mode 100644 index 00000000000..a3d15d56731 --- /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} -}; 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..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 @@ -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 @@ -30,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), @@ -62,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), @@ -94,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), @@ -126,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), @@ -158,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), @@ -229,7 +232,7 @@ typedef enum { D13 = PTD1, D14 = PTE25, D15 = PTE24, - + I2C_SCL = D15, I2C_SDA = D14, 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..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,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,15 +70,26 @@ 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_free(pwmout_t* obj) +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) { 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; @@ -96,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); @@ -146,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 c1abd781421..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 @@ -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]); @@ -106,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) { @@ -134,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); + } } } @@ -256,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]); + } } } @@ -279,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); } @@ -336,24 +352,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) { + 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 +386,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) @@ -377,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); @@ -393,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); @@ -437,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; } @@ -485,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 @@ -501,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; @@ -555,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; @@ -568,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); @@ -684,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/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) 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..ce2e8073abe 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; @@ -41,8 +47,9 @@ void analogin_init(analogin_t *obj, PinName pin) 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 @@ -55,7 +62,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) @@ -71,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()" @@ -79,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 d638d05ecfc..62fb8ae2900 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) { } 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..0affddbc205 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]; @@ -77,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 */ @@ -196,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_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/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" 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, diff --git a/targets/TARGET_STM/TARGET_STM32F4/analogin_device.c b/targets/TARGET_STM/TARGET_STM32F4/analogin_device.c index 75ac50f609b..4e7359c8ec2 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}; diff --git a/targets/TARGET_STM/TARGET_STM32F4/analogout_device.c b/targets/TARGET_STM/TARGET_STM32F4/analogout_device.c index 4c72646ba3f..764fd0b6ff8 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) { } 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/TARGET_STM32F4/serial_device.c b/targets/TARGET_STM/TARGET_STM32F4/serial_device.c index e2f076641f3..c006fcf5978 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 structure 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/i2c_api.c b/targets/TARGET_STM/i2c_api.c index 995bda07cbf..3ae8bb71e56 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,21 @@ 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; +#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); + } #if defined I2C1_BASE // Enable I2C1 clock and pinout if not done @@ -330,10 +327,15 @@ 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); +#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); // I2C configuration // Default hz value used for timeout computation @@ -360,6 +362,34 @@ void i2c_init_internal(i2c_t *obj, PinName sda, PinName scl) #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); +} + +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 +494,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 +548,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 +624,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 +665,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 +843,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 +910,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 +980,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 */ diff --git a/targets/TARGET_STM/pwmout_api.c b/targets/TARGET_STM/pwmout_api.c index cb21b22ac17..763272b52eb 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 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); diff --git a/targets/TARGET_STM/stm_spi_api.c b/targets/TARGET_STM/stm_spi_api.c index 525f731c890..160a84679c2 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; @@ -220,11 +221,34 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel * 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); } +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); @@ -342,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);