From 8fab5bca18d3b9a86c537a0eee5cf8c94958ccea Mon Sep 17 00:00:00 2001 From: Przemek Wirkus Date: Tue, 22 Jul 2014 12:14:17 +0100 Subject: [PATCH 1/9] Bugfix: Replaced magic value of UNDEF test result with proper const name --- workspace_tools/singletest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/workspace_tools/singletest.py b/workspace_tools/singletest.py index d4cebc94aa..22de6e790f 100644 --- a/workspace_tools/singletest.py +++ b/workspace_tools/singletest.py @@ -306,7 +306,7 @@ class SingleTestRunner(object): single_test_result = self.TEST_RESULT_UNDEF # singe test run result if not _copy_res: # Serial port copy error - single_test_result = "IOERR_COPY" + single_test_result = self.TEST_RESULT_IOERR_COPY print "Error: Copy method '%s'. %s"% (_copy_method, _err_msg) else: # Copy Extra Files From 2415d391d7b20bd5fd00525581140ed849ae2008 Mon Sep 17 00:00:00 2001 From: Przemek Wirkus Date: Thu, 24 Jul 2014 15:33:25 +0100 Subject: [PATCH 2/9] Added pseudo random seed source from compiler -D option --- libraries/tests/mbed/env/test_env.cpp | 22 +++++++++++++++++----- libraries/tests/mbed/env/test_env.h | 8 +++++--- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/libraries/tests/mbed/env/test_env.cpp b/libraries/tests/mbed/env/test_env.cpp index 65c35e286b..0dd3819a81 100644 --- a/libraries/tests/mbed/env/test_env.cpp +++ b/libraries/tests/mbed/env/test_env.cpp @@ -1,6 +1,7 @@ #include "test_env.h" -void led_blink(PinName led, float delay) { +void led_blink(PinName led, float delay) +{ if (led != NC) { DigitalOut myled(led); while (1) { @@ -11,18 +12,29 @@ void led_blink(PinName led, float delay) { while(1); } -void notify_start() { +void notify_start() +{ printf("{{start}}" NL); } -void notify_completion(bool success) { +void notify_completion(bool success) +{ if (success) { printf("{{success}}" NL); } else { printf("{{failure}}" NL); } - printf("{{end}}" NL); - led_blink(LED1, success ? 1.0 : 0.1); } + +// -DMBED_BUILD_TIMESTAMP=1406208182.13 +unsigned int testenv_randseed() +{ + unsigned int seed = 0; +#ifdef MBED_BUILD_TIMESTAMP + long long_seed = MBED_BUILD_TIMESTAMP * 100.0f; + seed = long_seed & 0xFFFFFFFF; +#endif /* MBED_BUILD_TIMESTAMP */ + return seed; +} diff --git a/libraries/tests/mbed/env/test_env.h b/libraries/tests/mbed/env/test_env.h index 3b063659fc..2462d8a534 100644 --- a/libraries/tests/mbed/env/test_env.h +++ b/libraries/tests/mbed/env/test_env.h @@ -4,12 +4,14 @@ #include #include "mbed.h" -#define NL "\n" +#define NL "\n" +// Test result related notification functions void led_blink(PinName led, float delay); - void notify_start(); - void notify_completion(bool success); +// Test functionality useful during testing +unsigned int testenv_randseed(); + #endif From 4c10fbb660aace75d5edcb69032bf9659c6d31cf Mon Sep 17 00:00:00 2001 From: Przemek Wirkus Date: Fri, 25 Jul 2014 17:37:16 +0100 Subject: [PATCH 3/9] Changed copyright date to 2014 --- workspace_tools/singletest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/workspace_tools/singletest.py b/workspace_tools/singletest.py index 22de6e790f..95fa94d217 100644 --- a/workspace_tools/singletest.py +++ b/workspace_tools/singletest.py @@ -2,7 +2,7 @@ """ mbed SDK -Copyright (c) 2011-2013 ARM Limited +Copyright (c) 2011-2014 ARM Limited Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. From cd0552186709faab283076103f010cfe209f78aa Mon Sep 17 00:00:00 2001 From: Przemek Wirkus Date: Mon, 28 Jul 2014 09:20:46 +0100 Subject: [PATCH 4/9] Added simple random seed provider. --- libraries/tests/mbed/env/test_env.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/tests/mbed/env/test_env.cpp b/libraries/tests/mbed/env/test_env.cpp index 0dd3819a81..de26afcfe1 100644 --- a/libraries/tests/mbed/env/test_env.cpp +++ b/libraries/tests/mbed/env/test_env.cpp @@ -33,7 +33,7 @@ unsigned int testenv_randseed() { unsigned int seed = 0; #ifdef MBED_BUILD_TIMESTAMP - long long_seed = MBED_BUILD_TIMESTAMP * 100.0f; + long long_seed = static_cast(MBED_BUILD_TIMESTAMP); seed = long_seed & 0xFFFFFFFF; #endif /* MBED_BUILD_TIMESTAMP */ return seed; From 12c7ba5ee27eacfbf32c7c3615d0139ad552127d Mon Sep 17 00:00:00 2001 From: Przemek Wirkus Date: Mon, 28 Jul 2014 13:35:10 +0100 Subject: [PATCH 5/9] Small refactoring for SD card tests for TARGET_K64F platform --- libraries/tests/mbed/i2c_eeprom/main.cpp | 6 +++--- libraries/tests/mbed/i2c_eeprom_line/main.cpp | 6 +++--- libraries/tests/mbed/sd/main.cpp | 3 +++ libraries/tests/rtos/mbed/file/main.cpp | 3 +++ 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/libraries/tests/mbed/i2c_eeprom/main.cpp b/libraries/tests/mbed/i2c_eeprom/main.cpp index 16ba2e1350..68d5aeec84 100644 --- a/libraries/tests/mbed/i2c_eeprom/main.cpp +++ b/libraries/tests/mbed/i2c_eeprom/main.cpp @@ -27,6 +27,9 @@ I2C i2c(PTC9, PTC8); #elif defined(TARGET_KL46Z) I2C i2c(PTC9, PTC8); +#elif defined(TARGET_K64F) +I2C i2c(PTE25, PTE24); + #elif defined(TARGET_K20D50M) I2C i2c(PTB3, PTB2); @@ -47,9 +50,6 @@ I2C i2c(P0_23, P0_22); defined(TARGET_NUCLEO_L053R8) I2C i2c(I2C_SDA, I2C_SCL); -#elif defined(TARGET_K64F) -I2C i2c(PTE25, PTE24); - #elif defined(TARGET_LPC11U68) I2C i2c(SDA, SCL); diff --git a/libraries/tests/mbed/i2c_eeprom_line/main.cpp b/libraries/tests/mbed/i2c_eeprom_line/main.cpp index b32d7a3334..ddad2dab6a 100644 --- a/libraries/tests/mbed/i2c_eeprom_line/main.cpp +++ b/libraries/tests/mbed/i2c_eeprom_line/main.cpp @@ -37,6 +37,9 @@ I2C i2c(PTC9, PTC8); #elif defined(TARGET_KL46Z) I2C i2c(PTC9, PTC8); +#elif defined(TARGET_K64F) +I2C i2c(PTE25, PTE24); + #elif defined(TARGET_K20D50M) I2C i2c(PTB3, PTB2); @@ -60,9 +63,6 @@ I2C i2c(SDA, SCL); defined(TARGET_NUCLEO_L053R8) I2C i2c(I2C_SDA, I2C_SCL); -#elif defined(TARGET_K64F) -I2C i2c(PTE25, PTE24); - #else I2C i2c(p28, p27); #endif diff --git a/libraries/tests/mbed/sd/main.cpp b/libraries/tests/mbed/sd/main.cpp index c7660bf783..062c4e9b7e 100644 --- a/libraries/tests/mbed/sd/main.cpp +++ b/libraries/tests/mbed/sd/main.cpp @@ -8,6 +8,9 @@ SDFileSystem sd(PTD2, PTD3, PTD1, PTD0, "sd"); #elif defined(TARGET_KL46Z) SDFileSystem sd(PTD6, PTD7, PTD5, PTD4, "sd"); +#elif defined(TARGET_K64F) +SDFileSystem sd(PTD2, PTD3, PTD1, PTD0, "sd"); + #elif defined(TARGET_K20D50M) SDFileSystem sd(PTD2, PTD3, PTD1, PTC2, "sd"); diff --git a/libraries/tests/rtos/mbed/file/main.cpp b/libraries/tests/rtos/mbed/file/main.cpp index 017040dfdb..0d603ceea3 100644 --- a/libraries/tests/rtos/mbed/file/main.cpp +++ b/libraries/tests/rtos/mbed/file/main.cpp @@ -17,6 +17,9 @@ void sd_thread(void const *argument) #elif defined(TARGET_KL46Z) SDFileSystem sd(PTD6, PTD7, PTD5, PTD4, "sd"); +#elif defined(TARGET_K64F) + SDFileSystem sd(PTD2, PTD3, PTD1, PTD0, "sd"); + #else SDFileSystem sd(p11, p12, p13, p14, "sd"); #endif From 68b2f4648f55c86a299be2b6b0f9b11f98d750ff Mon Sep 17 00:00:00 2001 From: Przemek Wirkus Date: Mon, 28 Jul 2014 14:04:26 +0100 Subject: [PATCH 6/9] FAT library will be now built to .a / .ar separate folder. New switch -f / --fat is introduced for build.py script --- workspace_tools/build.py | 4 ++++ workspace_tools/libraries.py | 9 +++++++++ workspace_tools/paths.py | 1 + workspace_tools/tests.py | 8 ++++---- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/workspace_tools/build.py b/workspace_tools/build.py index c47b6208c2..5268b59009 100755 --- a/workspace_tools/build.py +++ b/workspace_tools/build.py @@ -55,6 +55,8 @@ if __name__ == '__main__': default=False, help="Compile the USB Device library") parser.add_option("-d", "--dsp", action="store_true", dest="dsp", default=False, help="Compile the DSP library") + parser.add_option("-f", "--fat", action="store_true", dest="fat", + default=False, help="Compile FS ad SD card file system library") parser.add_option("-b", "--ublox", action="store_true", dest="ublox", default=False, help="Compile the u-blox library") parser.add_option("-D", "", action="append", dest="macros", @@ -110,6 +112,8 @@ if __name__ == '__main__': libraries.append("usb_host") if options.dsp: libraries.extend(["cmsis_dsp", "dsp"]) + if options.fat: + libraries.extend(["fat"]) if options.ublox: libraries.extend(["rtx", "rtos", "usb_host", "ublox"]) diff --git a/workspace_tools/libraries.py b/workspace_tools/libraries.py index 9361ad0e8a..5bb19913e0 100644 --- a/workspace_tools/libraries.py +++ b/workspace_tools/libraries.py @@ -64,6 +64,14 @@ LIBRARIES = [ "dependencies": [MBED_LIBRARIES, DSP_CMSIS], }, + # File system libraries + { + "id": "fat", + "source_dir": [FAT_FS, SD_FS], + "build_dir": FS_LIBRARY, + "dependencies": [MBED_LIBRARIES] + }, + # Network libraries { "id": "eth", @@ -79,6 +87,7 @@ LIBRARIES = [ "dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, USB_HOST_LIBRARIES], }, + # Unit Testing library { "id": "cpputest", "source_dir": [CPPUTEST_SRC, CPPUTEST_PLATFORM_SRC, CPPUTEST_TESTRUNNER_SCR], diff --git a/workspace_tools/paths.py b/workspace_tools/paths.py index f0898be88f..2b601e8170 100644 --- a/workspace_tools/paths.py +++ b/workspace_tools/paths.py @@ -72,6 +72,7 @@ UBLOX_LIBRARY = join(NET_LIBRARIES, "UbloxUSBModem") FS_PATH = join(LIB_DIR, "fs") FAT_FS = join(FS_PATH, "fat") SD_FS = join(FS_PATH, "sd") +FS_LIBRARY = join(BUILD_DIR, "fat") # DSP DSP = join(LIB_DIR, "dsp") diff --git a/workspace_tools/tests.py b/workspace_tools/tests.py index b81fa9ccc7..63156377f6 100644 --- a/workspace_tools/tests.py +++ b/workspace_tools/tests.py @@ -156,7 +156,7 @@ TESTS = [ { "id": "MBED_A12", "description": "SD File System", "source_dir": join(TEST_DIR, "mbed", "sd"), - "dependencies": [MBED_LIBRARIES, TEST_MBED_LIB, SD_FS, FAT_FS], + "dependencies": [MBED_LIBRARIES, TEST_MBED_LIB, FS_LIBRARY], "automated": True, "duration": 15, "peripherals": ["SD"] @@ -400,7 +400,7 @@ TESTS = [ { "id": "MBED_19", "description": "SD FS Directory", "source_dir": join(TEST_DIR, "mbed", "dir_sd"), - "dependencies": [MBED_LIBRARIES, SD_FS, FAT_FS], + "dependencies": [MBED_LIBRARIES, FS_LIBRARY], "peripherals": ["SD"] }, { @@ -596,7 +596,7 @@ TESTS = [ { "id": "RTOS_9", "description": "SD File write-read", "source_dir": join(TEST_DIR, "rtos", "mbed", "file"), - "dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, TEST_MBED_LIB, SD_FS, FAT_FS], + "dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, TEST_MBED_LIB, FS_LIBRARY], "automated": True, "peripherals": ["SD"], "mcu": ["LPC1768", "LPC11U24", "LPC812", "KL25Z", "KL05Z", "K64F", "KL46Z"], @@ -822,7 +822,7 @@ TESTS = [ { "id": "EXAMPLE_2", "description": "FS + RTOS", "source_dir": join(TEST_DIR, "mbed", "fs"), - "dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, TEST_MBED_LIB, SD_FS, FAT_FS], + "dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, TEST_MBED_LIB, FS_LIBRARY], }, # CPPUTEST Library provides Unit testing Framework From 8c41ea4aae23ae319e2fda0957e7acbaef7f7d93 Mon Sep 17 00:00:00 2001 From: sg- Date: Mon, 28 Jul 2014 12:46:50 -0500 Subject: [PATCH 7/9] Had duplicate set of api drivers in the directory - deleted added define guards to xxxxx_api.c files for device.h peripheral gating --- .../TARGET_KPSDK_MCUS/PeripheralNames.h | 131 ------- .../TARGET_KPSDK_MCUS/PortNames.h | 35 -- .../TARGET_K64F/TARGET_MTS_GAMBIT/PinNames.h | 15 +- .../TARGET_K64F/analogin_api.c | 3 + .../TARGET_K64F/analogout_api.c | 4 + .../TARGET_K64F/gpio_irq_api.c | 4 + .../TARGET_KPSDK_MCUS/TARGET_K64F/i2c_api.c | 3 + .../TARGET_KPSDK_MCUS/TARGET_K64F/port_api.c | 5 + .../TARGET_K64F/pwmout_api.c | 4 + .../TARGET_KPSDK_MCUS/TARGET_K64F/rtc_api.c | 5 + .../TARGET_K64F/serial_api.c | 3 + .../TARGET_KPSDK_MCUS/TARGET_K64F/spi_api.c | 5 + .../TARGET_KPSDK_MCUS/analogin_api.c | 94 ----- .../TARGET_KPSDK_MCUS/analogout_api.c | 82 ----- .../TARGET_KPSDK_MCUS/device.h | 58 --- .../TARGET_KPSDK_MCUS/gpio_api.c | 59 ---- .../TARGET_KPSDK_MCUS/gpio_irq_api.c | 207 ----------- .../TARGET_KPSDK_MCUS/gpio_object.h | 50 --- .../TARGET_KPSDK_MCUS/i2c_api.c | 331 ------------------ .../TARGET_KPSDK_MCUS/objects.h | 69 ---- .../TARGET_KPSDK_MCUS/pinmap.c | 49 --- .../TARGET_KPSDK_MCUS/port_api.c | 69 ---- .../TARGET_KPSDK_MCUS/pwmout_api.c | 172 --------- .../TARGET_KPSDK_MCUS/rtc_api.c | 68 ---- .../TARGET_KPSDK_MCUS/serial_api.c | 244 ------------- .../TARGET_KPSDK_MCUS/sleep.c | 49 --- .../TARGET_KPSDK_MCUS/spi_api.c | 184 ---------- .../TARGET_KPSDK_MCUS/us_ticker.c | 153 -------- 28 files changed, 46 insertions(+), 2109 deletions(-) delete mode 100644 libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/PeripheralNames.h delete mode 100644 libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/PortNames.h delete mode 100644 libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/analogin_api.c delete mode 100644 libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/analogout_api.c delete mode 100644 libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/device.h delete mode 100644 libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/gpio_api.c delete mode 100644 libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/gpio_irq_api.c delete mode 100644 libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/gpio_object.h delete mode 100644 libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/i2c_api.c delete mode 100644 libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/objects.h delete mode 100644 libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/pinmap.c delete mode 100644 libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/port_api.c delete mode 100644 libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/pwmout_api.c delete mode 100644 libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/rtc_api.c delete mode 100644 libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/serial_api.c delete mode 100644 libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/sleep.c delete mode 100644 libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/spi_api.c delete mode 100644 libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/us_ticker.c diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/PeripheralNames.h b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/PeripheralNames.h deleted file mode 100644 index 6bb0e03ea1..0000000000 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/PeripheralNames.h +++ /dev/null @@ -1,131 +0,0 @@ -/* 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_PERIPHERALNAMES_H -#define MBED_PERIPHERALNAMES_H - -#include "cmsis.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef enum { - OSC32KCLK = 0, -} RTCName; - -typedef enum { - UART_0 = 0, - UART_1 = 1, - UART_2 = 2, - UART_3 = 3, - UART_4 = 4, -} UARTName; - -#define STDIO_UART_TX USBTX -#define STDIO_UART_RX USBRX -#define STDIO_UART UART_0 - -typedef enum { - I2C_0 = 0, - I2C_1 = 1, - I2C_2 = 2, -} I2CName; - -#define TPM_SHIFT 8 -typedef enum { - PWM_1 = (0 << TPM_SHIFT) | (0), // FTM0 CH0 - PWM_2 = (0 << TPM_SHIFT) | (1), // FTM0 CH1 - PWM_3 = (0 << TPM_SHIFT) | (2), // FTM0 CH2 - PWM_4 = (0 << TPM_SHIFT) | (3), // FTM0 CH3 - PWM_5 = (0 << TPM_SHIFT) | (4), // FTM0 CH4 - PWM_6 = (0 << TPM_SHIFT) | (5), // FTM0 CH5 - PWM_7 = (0 << TPM_SHIFT) | (6), // FTM0 CH6 - PWM_8 = (0 << TPM_SHIFT) | (7), // FTM0 CH7 - PWM_9 = (1 << TPM_SHIFT) | (0), // FTM1 CH0 - PWM_10 = (1 << TPM_SHIFT) | (1), // FTM1 CH1 - PWM_11 = (1 << TPM_SHIFT) | (2), // FTM1 CH2 - PWM_12 = (1 << TPM_SHIFT) | (3), // FTM1 CH3 - PWM_13 = (1 << TPM_SHIFT) | (4), // FTM1 CH4 - PWM_14 = (1 << TPM_SHIFT) | (5), // FTM1 CH5 - PWM_15 = (1 << TPM_SHIFT) | (6), // FTM1 CH6 - PWM_16 = (1 << TPM_SHIFT) | (7), // FTM1 CH7 - PWM_17 = (2 << TPM_SHIFT) | (0), // FTM2 CH0 - PWM_18 = (2 << TPM_SHIFT) | (1), // FTM2 CH1 - PWM_19 = (2 << TPM_SHIFT) | (2), // FTM2 CH2 - PWM_20 = (2 << TPM_SHIFT) | (3), // FTM2 CH3 - PWM_21 = (2 << TPM_SHIFT) | (4), // FTM2 CH4 - PWM_22 = (2 << TPM_SHIFT) | (5), // FTM2 CH5 - PWM_23 = (2 << TPM_SHIFT) | (6), // FTM2 CH6 - PWM_24 = (2 << TPM_SHIFT) | (7), // FTM2 CH7 - // could be 4 or could be 3... not sure what register - // this is for... too much abstraction - PWM_25 = (3 << TPM_SHIFT) | (0), // FTM3 CH0 - PWM_26 = (3 << TPM_SHIFT) | (1), // FTM3 CH1 - PWM_27 = (3 << TPM_SHIFT) | (2), // FTM3 CH2 - PWM_28 = (3 << TPM_SHIFT) | (3), // FTM3 CH3 - PWM_29 = (3 << TPM_SHIFT) | (4), // FTM3 CH4 - PWM_30 = (3 << TPM_SHIFT) | (5), // FTM3 CH5 - PWM_31 = (3 << TPM_SHIFT) | (6), // FTM3 CH6 - PWM_32 = (3 << TPM_SHIFT) | (7), // FTM3 CH7 -} PWMName; - -#define ADC_INSTANCE_SHIFT 8 -#define ADC_B_CHANNEL_SHIFT 5 -typedef enum { - ADC0_SE4b = (0 << ADC_INSTANCE_SHIFT) | (1 << ADC_B_CHANNEL_SHIFT) | 4, - ADC0_SE5b = (0 << ADC_INSTANCE_SHIFT) | (1 << ADC_B_CHANNEL_SHIFT) | 5, - ADC0_SE6b = (0 << ADC_INSTANCE_SHIFT) | (1 << ADC_B_CHANNEL_SHIFT) | 6, - ADC0_SE7b = (0 << ADC_INSTANCE_SHIFT) | (1 << ADC_B_CHANNEL_SHIFT) | 7, - ADC0_SE8 = (0 << ADC_INSTANCE_SHIFT) | 8, - ADC0_SE9 = (0 << ADC_INSTANCE_SHIFT) | 9, - ADC0_SE12 = (0 << ADC_INSTANCE_SHIFT) | 12, - ADC0_SE13 = (0 << ADC_INSTANCE_SHIFT) | 13, - ADC0_SE14 = (0 << ADC_INSTANCE_SHIFT) | 14, - ADC0_SE15 = (0 << ADC_INSTANCE_SHIFT) | 15, - ADC0_SE16 = (0 << ADC_INSTANCE_SHIFT) | 16, - ADC0_SE17 = (0 << ADC_INSTANCE_SHIFT) | 17, - ADC0_SE18 = (0 << ADC_INSTANCE_SHIFT) | 18, - ADC1_SE4b = (1 << ADC_INSTANCE_SHIFT) | 4, - ADC1_SE5b = (1 << ADC_INSTANCE_SHIFT) | 5, - ADC1_SE6b = (1 << ADC_INSTANCE_SHIFT) | 6, - ADC1_SE7b = (1 << ADC_INSTANCE_SHIFT) | 7, - ADC1_SE8 = (1 << ADC_INSTANCE_SHIFT) | 8, - ADC1_SE9 = (1 << ADC_INSTANCE_SHIFT) | 9, - ADC1_SE12 = (1 << ADC_INSTANCE_SHIFT) | 12, - ADC1_SE13 = (1 << ADC_INSTANCE_SHIFT) | 13, - ADC1_SE14 = (1 << ADC_INSTANCE_SHIFT) | 14, - ADC1_SE15 = (1 << ADC_INSTANCE_SHIFT) | 15, - ADC1_SE16 = (1 << ADC_INSTANCE_SHIFT) | 16, - ADC1_SE17 = (1 << ADC_INSTANCE_SHIFT) | 17, - ADC1_SE18 = (1 << ADC_INSTANCE_SHIFT) | 18, -} ADCName; - -typedef enum { - DAC_0 = 0 -} DACName; - - -typedef enum { - SPI_0 = 0, - SPI_1 = 1, - SPI_2 = 2, -} SPIName; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/PortNames.h b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/PortNames.h deleted file mode 100644 index 476845b76d..0000000000 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/PortNames.h +++ /dev/null @@ -1,35 +0,0 @@ -/* 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_PORTNAMES_H -#define MBED_PORTNAMES_H - -#ifdef __cplusplus -extern "C" { -#endif - -typedef enum { - PortA = 0, - PortB = 1, - PortC = 2, - PortD = 3, - PortE = 4 -} PortName; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/TARGET_MTS_GAMBIT/PinNames.h b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/TARGET_MTS_GAMBIT/PinNames.h index 4731ed3a28..438756cd86 100644 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/TARGET_MTS_GAMBIT/PinNames.h +++ b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/TARGET_MTS_GAMBIT/PinNames.h @@ -191,16 +191,21 @@ typedef enum { PTE30 = (4 << GPIO_PORT_SHIFT | 30), PTE31 = (4 << GPIO_PORT_SHIFT | 31), + // #TODO all friendly names per platform + // led color naming + LED_RED = PTA0, + LED_GREEN = PTA1, + LED_BLUE = PTA2, // mbed original LED naming - //LED1 = LED_RED, - //LED2 = LED_GREEN, - //LED3 = LED_BLUE, - //LED4 = LED_RED, + LED1 = LED_RED, + LED2 = LED_GREEN, + LED3 = LED_BLUE, + LED4 = LED_RED, //Push buttons //SW2 = PTC6, //SW3 = PTA4, - + // USB Pins USBTX = PTB17, USBRX = PTB16, diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/analogin_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/analogin_api.c index 96d8d26551..13d33877cc 100644 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/analogin_api.c +++ b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/analogin_api.c @@ -16,6 +16,8 @@ #include "mbed_assert.h" #include "analogin_api.h" +#if DEVICE_ANALOGIN + #include "cmsis.h" #include "pinmap.h" #include "PeripheralNames.h" @@ -70,3 +72,4 @@ float analogin_read(analogin_t *obj) { return (float)value * (1.0f / (float)0xFFFF); } +#endif diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/analogout_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/analogout_api.c index 7c461e0c93..fd0fa58cac 100644 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/analogout_api.c +++ b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/analogout_api.c @@ -15,6 +15,8 @@ */ #include "analogout_api.h" +#if DEVICE_ANALOGOUT + #include "cmsis.h" #include "pinmap.h" #include "error.h" @@ -76,3 +78,5 @@ uint16_t analogout_read_u16(dac_t *obj) { uint32_t value = dac_read(obj); // 12-bit return (value << 4) | ((value >> 8) & 0x003F); } + +#endif diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/gpio_irq_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/gpio_irq_api.c index a30e21ff2b..a7c6966886 100644 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/gpio_irq_api.c +++ b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/gpio_irq_api.c @@ -17,6 +17,9 @@ #include "cmsis.h" #include "gpio_irq_api.h" + +#if DEVICE_INTERRUPTIN + #include "gpio_api.h" #include "fsl_gpio_hal.h" #include "fsl_port_hal.h" @@ -205,3 +208,4 @@ void gpio_irq_disable(gpio_irq_t *obj) { } } +#endif diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/i2c_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/i2c_api.c index ca96d7d047..31f9863bfc 100644 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/i2c_api.c +++ b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/i2c_api.c @@ -16,6 +16,8 @@ #include "mbed_assert.h" #include "i2c_api.h" +#if DEVICE_I2C + #include "cmsis.h" #include "pinmap.h" #include "fsl_clock_manager.h" @@ -307,3 +309,4 @@ void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask) { } #endif +#endif diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/port_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/port_api.c index 767b0efe24..8c02d8c372 100644 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/port_api.c +++ b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/port_api.c @@ -14,6 +14,9 @@ * limitations under the License. */ #include "port_api.h" + +#if DEVICE_PORTIN || DEVICE_PORTOUT + #include "pinmap.h" #include "gpio_api.h" @@ -67,3 +70,5 @@ void port_write(port_t *obj, int value) { int port_read(port_t *obj) { return (int)(gpio_hal_read_port_input((uint32_t)obj->port) & obj->mask); } + +#endif diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/pwmout_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/pwmout_api.c index ceaa76b756..c408068640 100644 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/pwmout_api.c +++ b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/pwmout_api.c @@ -16,6 +16,8 @@ #include "mbed_assert.h" #include "pwmout_api.h" +#if DEVICE_PWMOUT + #include "cmsis.h" #include "pinmap.h" #include "fsl_ftm_hal.h" @@ -124,3 +126,5 @@ void pwmout_pulsewidth_us(pwmout_t* obj, int us) { uint32_t value = (uint32_t)(pwm_clock_mhz * (float)us); ftm_hal_set_channel_count_value(obj->pwm_name >> TPM_SHIFT, obj->pwm_name & 0xF, value); } + +#endif diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/rtc_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/rtc_api.c index 0b326c66aa..a5df3d6fbc 100644 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/rtc_api.c +++ b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/rtc_api.c @@ -14,6 +14,9 @@ * limitations under the License. */ #include "rtc_api.h" + +#if DEVICE_RTC + #include "pinmap.h" #include "fsl_rtc_hal.h" #include "fsl_clock_manager.h" @@ -63,3 +66,5 @@ void rtc_write(time_t t) { BW_RTC_TSR_TSR(t); rtc_hal_counter_enable(true); } + +#endif diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/serial_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/serial_api.c index 7c337c298e..3ce69e9cc8 100644 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/serial_api.c +++ b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/serial_api.c @@ -15,6 +15,8 @@ */ #include "serial_api.h" +#if DEVICE_SERIAL + // math.h required for floating point operations for baud rate calculation #include #include "mbed_assert.h" @@ -213,3 +215,4 @@ void serial_break_clear(serial_t *obj) { uart_hal_queue_break_char_to_send(obj->index, false); } +#endif diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/spi_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/spi_api.c index 88031c3f5e..d1fd528d5b 100644 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/spi_api.c +++ b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K64F/spi_api.c @@ -17,6 +17,9 @@ #include "mbed_assert.h" #include "spi_api.h" + +#if DEVICE_SPI + #include "cmsis.h" #include "pinmap.h" #include "error.h" @@ -137,3 +140,5 @@ void spi_slave_write(spi_t *obj, int value) { while (!spi_writeable(obj)); dspi_hal_write_data_slave_mode(obj->instance, (uint32_t)value); } + +#endif diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/analogin_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/analogin_api.c deleted file mode 100644 index 2e11e90118..0000000000 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/analogin_api.c +++ /dev/null @@ -1,94 +0,0 @@ -/* 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. - */ -#include "mbed_assert.h" -#include "analogin_api.h" - -#include "cmsis.h" -#include "pinmap.h" -#include "PeripheralNames.h" -#include "fsl_adc_hal.h" -#include "fsl_clock_manager.h" - -#define MAX_FADC 6000000 - -static const PinMap PinMap_ADC[] = { - {PTC2, ADC0_SE4b, 0}, - {PTC8, ADC1_SE4b, 0}, - {PTC9, ADC1_SE5b, 0}, - {PTD1, ADC0_SE5b, 0}, - {PTC10, ADC1_SE6b, 0}, - {PTD5, ADC0_SE6b, 0}, - {PTC11, ADC1_SE7b, 0}, - {PTD6, ADC0_SE7b, 0}, - {PTB0 , ADC0_SE8 , 0}, - {PTB1 , ADC0_SE9 , 0}, - {PTB2 , ADC0_SE12, 0}, - {PTB3 , ADC0_SE13, 0}, - {PTC0 , ADC0_SE14, 0}, - {PTB10, ADC1_SE14, 0}, - {PTB11, ADC1_SE15, 0}, - {PTC1 , ADC0_SE15, 0}, - {PTA17, ADC1_SE17, 0}, - //{PTE24, ADC0_SE17, 0}, //I2C pull up - //{PTE25, ADC0_SE18, 0}, //I2C pull up - {NC , NC , 0} -}; - -void analogin_init(analogin_t *obj, PinName pin) { - obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC); - MBED_ASSERT(obj->adc != (ADCName)NC); - - uint32_t instance = obj->adc >> ADC_INSTANCE_SHIFT; - - clock_manager_set_gate(kClockModuleADC, instance, true); - - uint32_t bus_clock; - clock_manager_get_frequency(kBusClock, &bus_clock); - uint32_t clkdiv; - for (clkdiv = 0; clkdiv < 4; clkdiv++) { - if ((bus_clock >> clkdiv) <= MAX_FADC) - break; - } - if (clkdiv == 4) { - clkdiv = 0x7; //Set max div - } - /* adc is enabled/triggered when reading. */ - adc_hal_set_clock_source_mode(instance, (adc_clock_source_mode_t)(clkdiv >> 2)); - adc_hal_set_clock_divider_mode(instance, (adc_clock_divider_mode_t)(clkdiv & 0x3)); - adc_hal_set_reference_voltage_mode(instance, kAdcVoltageVref); - adc_hal_set_resolution_mode(instance, kAdcSingleDiff16); - adc_hal_configure_continuous_conversion(instance, false); - adc_hal_configure_hw_trigger(instance, false); /* sw trigger */ - adc_hal_configure_hw_average(instance, true); - adc_hal_set_hw_average_mode(instance, kAdcHwAverageCount4); - adc_hal_set_group_mux(instance, kAdcChannelMuxB); /* only B channels are avail */ - - pinmap_pinout(pin, PinMap_ADC); -} - -uint16_t analogin_read_u16(analogin_t *obj) { - uint32_t instance = obj->adc >> ADC_INSTANCE_SHIFT; - /* sw trigger (SC1A) */ - adc_hal_enable(instance, 0, (adc_channel_mode_t)(obj->adc & 0xF), false); - while (!adc_hal_is_conversion_completed(instance, 0)); - return adc_hal_get_conversion_value(instance, 0); -} - -float analogin_read(analogin_t *obj) { - uint16_t value = analogin_read_u16(obj); - return (float)value * (1.0f / (float)0xFFFF); -} - diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/analogout_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/analogout_api.c deleted file mode 100644 index b40dacf562..0000000000 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/analogout_api.c +++ /dev/null @@ -1,82 +0,0 @@ -/* 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. - */ -#include "analogout_api.h" - -#include "cmsis.h" -#include "pinmap.h" -#include "error.h" - -#define RANGE_12BIT 0xFFF - -const PinMap PinMap_DAC[] = { - {DAC0_OUT, DAC_0, 0}, - {NC , NC , 0} -}; - -void analogout_init(dac_t *obj, PinName pin) { - obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC); - if (obj->dac == (DACName)NC) { - error("DAC pin mapping failed"); - } - - SIM->SCGC2 |= SIM_SCGC2_DAC0_MASK; - - DAC0->DAT[obj->dac].DATH = 0; - DAC0->DAT[obj->dac].DATL = 0; - - DAC0->C1 = DAC_C1_DACBFMD(2); // One-Time Scan Mode - - DAC0->C0 = DAC_C0_DACEN_MASK // Enable - | DAC_C0_DACSWTRG_MASK // Software Trigger - | DAC_C0_DACRFS_MASK; // VDDA selected - - analogout_write_u16(obj, 0); -} - -void analogout_free(dac_t *obj) {} - -static inline void dac_write(dac_t *obj, int value) { - DAC0->DAT[obj->dac].DATL = (uint8_t)( value & 0xFF); - DAC0->DAT[obj->dac].DATH = (uint8_t)((value >> 8) & 0xFF); -} - -static inline int dac_read(dac_t *obj) { - return ((DAC0->DAT[obj->dac].DATH << 8) | DAC0->DAT[obj->dac].DATL); -} - -void analogout_write(dac_t *obj, float value) { - if (value < 0.0f) { - dac_write(obj, 0); - } else if (value > 1.0f) { - dac_write(obj, RANGE_12BIT); - } else { - dac_write(obj, value * (float)RANGE_12BIT); - } -} - -void analogout_write_u16(dac_t *obj, uint16_t value) { - dac_write(obj, value >> 4); // 12-bit -} - -float analogout_read(dac_t *obj) { - uint32_t value = dac_read(obj); - return (float)value * (1.0f / (float)RANGE_12BIT); -} - -uint16_t analogout_read_u16(dac_t *obj) { - uint32_t value = dac_read(obj); // 12-bit - return (value << 4) | ((value >> 8) & 0x003F); -} diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/device.h b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/device.h deleted file mode 100644 index 8f3ef7e125..0000000000 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/device.h +++ /dev/null @@ -1,58 +0,0 @@ -/* 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_DEVICE_H -#define MBED_DEVICE_H - -#define DEVICE_PORTIN 1 -#define DEVICE_PORTOUT 1 -#define DEVICE_PORTINOUT 1 - -#define DEVICE_INTERRUPTIN 1 - -#define DEVICE_ANALOGIN 1 -#define DEVICE_ANALOGOUT 1 - -#define DEVICE_SERIAL 1 - -#define DEVICE_I2C 1 -#define DEVICE_I2CSLAVE 1 - -#define DEVICE_SPI 1 -#define DEVICE_SPISLAVE 1 - -#define DEVICE_CAN 0 - -#define DEVICE_RTC 1 - -#define DEVICE_ETHERNET 0 - -#define DEVICE_PWMOUT 1 - -#define DEVICE_SEMIHOST 0 -#define DEVICE_LOCALFILESYSTEM 0 -#define DEVICE_ID_LENGTH 24 - -#define DEVICE_SLEEP 1 - -#define DEVICE_DEBUG_AWARENESS 0 - -#define DEVICE_STDIO_MESSAGES 1 - -#define DEVICE_ERROR_RED 1 - -#include "objects.h" - -#endif diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/gpio_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/gpio_api.c deleted file mode 100644 index a789bb005b..0000000000 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/gpio_api.c +++ /dev/null @@ -1,59 +0,0 @@ -/* 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. - */ -#include "mbed_assert.h" -#include "gpio_api.h" -#include "pinmap.h" -#include "fsl_port_hal.h" -#include "fsl_gpio_hal.h" -#include "fsl_sim_hal.h" - -uint32_t gpio_set(PinName pin) { - MBED_ASSERT(pin != (PinName)NC); - uint32_t pin_num = pin & 0xFF; - - pin_function(pin, (int)kPortMuxAsGpio); - return 1 << pin_num; -} - -void gpio_init(gpio_t *obj, PinName pin) { - obj->pinName = pin; - if (pin == (PinName)NC) - return; - - uint32_t port = pin >> GPIO_PORT_SHIFT; - uint32_t pin_num = pin & 0xFF; - clock_hal_set_gate(kSimClockModulePORT, port, true); - port_hal_mux_control(port, pin_num, kPortMuxAsGpio); -} - -void gpio_mode(gpio_t *obj, PinMode mode) { - pin_mode(obj->pinName, mode); -} - -void gpio_dir(gpio_t *obj, PinDirection direction) { - MBED_ASSERT(obj->pinName != (PinName)NC); - uint32_t port = obj->pinName >> GPIO_PORT_SHIFT; - uint32_t pin_num = obj->pinName & 0xFF; - - switch (direction) { - case PIN_INPUT: - gpio_hal_set_pin_direction(port, pin_num, kGpioDigitalInput); - break; - case PIN_OUTPUT: - gpio_hal_set_pin_direction(port, pin_num, kGpioDigitalOutput); - break; - } -} diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/gpio_irq_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/gpio_irq_api.c deleted file mode 100644 index a30e21ff2b..0000000000 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/gpio_irq_api.c +++ /dev/null @@ -1,207 +0,0 @@ -/* 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. - */ -#include -#include "cmsis.h" - -#include "gpio_irq_api.h" -#include "gpio_api.h" -#include "fsl_gpio_hal.h" -#include "fsl_port_hal.h" -#include "error.h" - -#define CHANNEL_NUM 160 - -static uint32_t channel_ids[CHANNEL_NUM] = {0}; -static gpio_irq_handler irq_handler; - -#define IRQ_DISABLED (0) -#define IRQ_RAISING_EDGE (9) -#define IRQ_FALLING_EDGE (10) -#define IRQ_EITHER_EDGE (11) - -static void handle_interrupt_in(PortName port, int ch_base) { - uint32_t i; - - for (i = 0; i < 32; i++) { - if (port_hal_read_pin_interrupt_flag(port, i)) { - uint32_t id = channel_ids[ch_base + i]; - if (id == 0) { - continue; - } - - gpio_irq_event event = IRQ_NONE; - switch (BR_PORT_PCRn_IRQC(port, i)) { - case IRQ_RAISING_EDGE: - event = IRQ_RISE; - break; - - case IRQ_FALLING_EDGE: - event = IRQ_FALL; - break; - - case IRQ_EITHER_EDGE: - event = (gpio_hal_read_pin_input(port, i)) ? (IRQ_RISE) : (IRQ_FALL); - break; - } - if (event != IRQ_NONE) { - irq_handler(id, event); - } - } - } - port_hal_clear_port_interrupt_flag(port); -} - -void gpio_irqA(void) {handle_interrupt_in(PortA, 0);} -void gpio_irqB(void) {handle_interrupt_in(PortB, 32);} -void gpio_irqC(void) {handle_interrupt_in(PortC, 64);} -void gpio_irqD(void) {handle_interrupt_in(PortD, 96);} -void gpio_irqE(void) {handle_interrupt_in(PortE, 128);} - -int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32_t id) { - if (pin == NC) { - return -1; - } - - irq_handler = handler; - obj->port = pin >> GPIO_PORT_SHIFT; - obj->pin = pin & 0x7F; - - uint32_t ch_base, vector; - IRQn_Type irq_n; - switch (obj->port) { - case PortA: - ch_base = 0; - irq_n = PORTA_IRQn; - vector = (uint32_t)gpio_irqA; - break; - case PortB: - ch_base = 32; - irq_n = PORTB_IRQn; - vector = (uint32_t)gpio_irqB; - break; - case PortC: - ch_base = 64; - irq_n = PORTC_IRQn; - vector = (uint32_t)gpio_irqC; - break; - case PortD: - ch_base = 96; - irq_n = PORTD_IRQn; - vector = (uint32_t)gpio_irqD; - break; - case PortE: - ch_base = 128; - irq_n = PORTE_IRQn; - vector = (uint32_t)gpio_irqE; - break; - - default: - error("gpio_irq only supported on port A-E."); - break; - } - NVIC_SetVector(irq_n, vector); - NVIC_EnableIRQ(irq_n); - - obj->ch = ch_base + obj->pin; - channel_ids[obj->ch] = id; - - return 0; -} - -void gpio_irq_free(gpio_irq_t *obj) { - channel_ids[obj->ch] = 0; -} - -void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable) { - port_interrupt_config_t irq_settings = kPortIntDisabled; - - switch (BR_PORT_PCRn_IRQC(obj->port, obj->pin)) { - case IRQ_DISABLED: - if (enable) - irq_settings = (event == IRQ_RISE) ? (kPortIntRisingEdge) : (kPortIntFallingEdge); - break; - - case IRQ_RAISING_EDGE: - if (enable) { - irq_settings = (event == IRQ_RISE) ? (kPortIntRisingEdge) : (kPortIntEitherEdge); - } else { - if (event == IRQ_FALL) - irq_settings = kPortIntRisingEdge; - } - break; - - case IRQ_FALLING_EDGE: - if (enable) { - irq_settings = (event == IRQ_FALL) ? (kPortIntFallingEdge) : (kPortIntEitherEdge); - } else { - if (event == IRQ_RISE) - irq_settings = kPortIntFallingEdge; - } - break; - - case IRQ_EITHER_EDGE: - if (enable) { - irq_settings = kPortIntEitherEdge; - } else { - irq_settings = (event == IRQ_RISE) ? (kPortIntFallingEdge) : (kPortIntRisingEdge); - } - break; - } - - port_hal_configure_pin_interrupt(obj->port, obj->pin, irq_settings); - port_hal_clear_pin_interrupt_flag(obj->port, obj->pin); -} - -void gpio_irq_enable(gpio_irq_t *obj) { - switch (obj->port) { - case PortA: - NVIC_EnableIRQ(PORTA_IRQn); - break; - case PortB: - NVIC_EnableIRQ(PORTB_IRQn); - break; - case PortC: - NVIC_EnableIRQ(PORTC_IRQn); - break; - case PortD: - NVIC_EnableIRQ(PORTD_IRQn); - break; - case PortE: - NVIC_EnableIRQ(PORTE_IRQn); - break; - } -} - -void gpio_irq_disable(gpio_irq_t *obj) { - switch (obj->port) { - case PortA: - NVIC_DisableIRQ(PORTA_IRQn); - break; - case PortB: - NVIC_DisableIRQ(PORTB_IRQn); - break; - case PortC: - NVIC_DisableIRQ(PORTC_IRQn); - break; - case PortD: - NVIC_DisableIRQ(PORTD_IRQn); - break; - case PortE: - NVIC_DisableIRQ(PORTE_IRQn); - break; - } -} - diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/gpio_object.h b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/gpio_object.h deleted file mode 100644 index 723210e4ca..0000000000 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/gpio_object.h +++ /dev/null @@ -1,50 +0,0 @@ -/* 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_GPIO_OBJECT_H -#define MBED_GPIO_OBJECT_H - -#include "mbed_assert.h" -#include "fsl_gpio_hal.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - PinName pinName; -} gpio_t; - -static inline void gpio_write(gpio_t *obj, int value) { - MBED_ASSERT(obj->pinName != (PinName)NC); - uint32_t port = obj->pinName >> GPIO_PORT_SHIFT; - uint32_t pin = obj->pinName & 0xFF; - - gpio_hal_write_pin_output(port, pin, value); -} - -static inline int gpio_read(gpio_t *obj) { - MBED_ASSERT(obj->pinName != (PinName)NC); - uint32_t port = obj->pinName >> GPIO_PORT_SHIFT; - uint32_t pin = obj->pinName & 0xFF; - - return (int)gpio_hal_read_pin_input(port, pin); -} - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/i2c_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/i2c_api.c deleted file mode 100644 index 60b2f81cc2..0000000000 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/i2c_api.c +++ /dev/null @@ -1,331 +0,0 @@ -/* 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. - */ -#include "mbed_assert.h" -#include "i2c_api.h" - -#include "cmsis.h" -#include "pinmap.h" -#include "fsl_clock_manager.h" -#include "fsl_i2c_hal.h" -#include "fsl_port_hal.h" -#include "fsl_sim_hal.h" - -static 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} -}; - -static 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} -}; - -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); - obj->instance = pinmap_merge(i2c_sda, i2c_scl); - MBED_ASSERT((int)obj->instance != NC); - - clock_manager_set_gate(kClockModuleI2C, obj->instance, true); - clock_manager_set_gate(kClockModulePORT, sda >> GPIO_PORT_SHIFT, true); - clock_manager_set_gate(kClockModulePORT, scl >> GPIO_PORT_SHIFT, true); - i2c_hal_enable(obj->instance); - i2c_frequency(obj, 100000); - - pinmap_pinout(sda, PinMap_I2C_SDA); - pinmap_pinout(scl, PinMap_I2C_SCL); - port_hal_configure_open_drain(sda >> GPIO_PORT_SHIFT, sda & 0xFF, true); - port_hal_configure_open_drain(scl >> GPIO_PORT_SHIFT, scl & 0xFF, true); -} - -int i2c_start(i2c_t *obj) { - i2c_hal_send_start(obj->instance); - return 0; -} - -int i2c_stop(i2c_t *obj) { - volatile uint32_t n = 0; - i2c_hal_send_stop(obj->instance); - - // It seems that there are timing problems - // when there is no waiting time after a STOP. - // This wait is also included on the samples - // code provided with the freedom board - for (n = 0; n < 200; n++) __NOP(); - return 0; -} - -static int timeout_status_poll(i2c_t *obj, uint32_t mask) { - uint32_t i, timeout = 100000; - - for (i = 0; i < timeout; i++) { - if (HW_I2C_S_RD(obj->instance) & mask) - return 0; - } - return 1; -} - -// this function waits the end of a tx transfer and return the status of the transaction: -// 0: OK ack received -// 1: OK ack not received -// 2: failure -static int i2c_wait_end_tx_transfer(i2c_t *obj) { - // wait for the interrupt flag - if (timeout_status_poll(obj, I2C_S_IICIF_MASK)) { - return 2; - } - - i2c_hal_clear_interrupt(obj->instance); - - // wait transfer complete - if (timeout_status_poll(obj, I2C_S_TCF_MASK)) { - return 2; - } - - // check if we received the ACK or not - return i2c_hal_get_receive_ack(obj->instance) ? 0 : 1; -} - -// this function waits the end of a rx transfer and return the status of the transaction: -// 0: OK -// 1: failure -static int i2c_wait_end_rx_transfer(i2c_t *obj) { - // wait for the end of the rx transfer - if (timeout_status_poll(obj, I2C_S_IICIF_MASK)) { - return 1; - } - - i2c_hal_clear_interrupt(obj->instance); - - return 0; -} - -static int i2c_do_write(i2c_t *obj, int value) { - i2c_hal_write(obj->instance, value); - - // init and wait the end of the transfer - return i2c_wait_end_tx_transfer(obj); -} - -static int i2c_do_read(i2c_t *obj, char * data, int last) { - if (last) { - i2c_hal_send_nak(obj->instance); - } else { - i2c_hal_send_ack(obj->instance); - } - - *data = (i2c_hal_read(obj->instance) & 0xFF); - - // start rx transfer and wait the end of the transfer - return i2c_wait_end_rx_transfer(obj); -} - -void i2c_frequency(i2c_t *obj, int hz) { - uint32_t busClock; - - clock_manager_error_code_t error = clock_manager_get_frequency(kBusClock, &busClock); - if (error == kClockManagerSuccess) { - i2c_hal_set_baud(obj->instance, busClock, hz / 1000, NULL); - } -} - -int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) { - int count; - char dummy_read, *ptr; - - if (i2c_start(obj)) { - i2c_stop(obj); - return I2C_ERROR_BUS_BUSY; - } - - if (i2c_do_write(obj, (address | 0x01))) { - i2c_stop(obj); - return I2C_ERROR_NO_SLAVE; - } - - // set rx mode - i2c_hal_set_direction(obj->instance, kI2CReceive); - - // Read in bytes - for (count = 0; count < (length); count++) { - ptr = (count == 0) ? &dummy_read : &data[count - 1]; - uint8_t stop_ = (count == (length - 1)) ? 1 : 0; - if (i2c_do_read(obj, ptr, stop_)) { - i2c_stop(obj); - return count; - } - } - - // If not repeated start, send stop. - if (stop) - i2c_stop(obj); - - // last read - data[count-1] = i2c_hal_read(obj->instance); - - return length; -} - -int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) { - int i; - - if (i2c_start(obj)) { - i2c_stop(obj); - return I2C_ERROR_BUS_BUSY; - } - - if (i2c_do_write(obj, (address & 0xFE))) { - i2c_stop(obj); - return I2C_ERROR_NO_SLAVE; - } - - for (i = 0; i < length; i++) { - if(i2c_do_write(obj, data[i])) { - i2c_stop(obj); - return i; - } - } - - if (stop) - i2c_stop(obj); - - return length; -} - -void i2c_reset(i2c_t *obj) { - i2c_stop(obj); -} - -int i2c_byte_read(i2c_t *obj, int last) { - char data; - - // set rx mode - i2c_hal_set_direction(obj->instance, kI2CReceive); - - // Setup read - i2c_do_read(obj, &data, last); - - // set tx mode - i2c_hal_set_direction(obj->instance, kI2CTransmit); - return i2c_hal_read(obj->instance); -} - -int i2c_byte_write(i2c_t *obj, int data) { - // set tx mode - i2c_hal_set_direction(obj->instance, kI2CTransmit); - - return !i2c_do_write(obj, (data & 0xFF)); -} - - -#if DEVICE_I2CSLAVE -void i2c_slave_mode(i2c_t *obj, int enable_slave) { - if (enable_slave) { - // set slave mode - BW_I2C_C1_MST(obj->instance, 0); - i2c_hal_enable_interrupt(obj->instance); - } else { - // set master mode - BW_I2C_C1_MST(obj->instance, 1); - } -} - -int i2c_slave_receive(i2c_t *obj) { - switch(HW_I2C_S_RD(obj->instance)) { - // read addressed - case 0xE6: - return 1; - // write addressed - case 0xE2: - return 3; - default: - return 0; - } -} - -int i2c_slave_read(i2c_t *obj, char *data, int length) { - uint8_t dummy_read; - uint8_t *ptr; - int count; - - // set rx mode - i2c_hal_set_direction(obj->instance, kI2CTransmit); - - // first dummy read - dummy_read = i2c_hal_read(obj->instance); - if (i2c_wait_end_rx_transfer(obj)) - return 0; - - // read address - dummy_read = i2c_hal_read(obj->instance); - if (i2c_wait_end_rx_transfer(obj)) - return 0; - - // read (length - 1) bytes - for (count = 0; count < (length - 1); count++) { - data[count] = i2c_hal_read(obj->instance); - if (i2c_wait_end_rx_transfer(obj)) - return count; - } - - // read last byte - ptr = (length == 0) ? &dummy_read : (uint8_t *)&data[count]; - *ptr = i2c_hal_read(obj->instance); - - return (length) ? (count + 1) : 0; -} - -int i2c_slave_write(i2c_t *obj, const char *data, int length) { - int i, count = 0; - - // set tx mode - i2c_hal_set_direction(obj->instance, kI2CTransmit); - - for (i = 0; i < length; i++) { - if (i2c_do_write(obj, data[count++]) == 2) - return i; - } - - // set rx mode - i2c_hal_set_direction(obj->instance, kI2CReceive); - - // dummy rx transfer needed - // otherwise the master cannot generate a stop bit - i2c_hal_read(obj->instance); - if (i2c_wait_end_rx_transfer(obj) == 2) - return count; - - return count; -} - -void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask) { - i2c_hal_set_upper_slave_address_7bit(obj->instance, address & 0xfe); -} -#endif - diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/objects.h b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/objects.h deleted file mode 100644 index 68203df302..0000000000 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/objects.h +++ /dev/null @@ -1,69 +0,0 @@ -/* 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_OBJECTS_H -#define MBED_OBJECTS_H - -#include "cmsis.h" -#include "PortNames.h" -#include "PeripheralNames.h" -#include "PinNames.h" - -#ifdef __cplusplus -extern "C" { -#endif - -struct gpio_irq_s { - uint32_t port; - uint32_t pin; - uint32_t ch; -}; - -struct port_s { - PortName port; - uint32_t mask; -}; - -struct pwmout_s { - PWMName pwm_name; -}; - -struct serial_s { - int index; -}; - -struct analogin_s { - ADCName adc; -}; - -struct i2c_s { - uint32_t instance; -}; - -struct spi_s { - uint32_t instance; -}; - -struct dac_s { - DACName dac; -}; - -#include "gpio_object.h" - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/pinmap.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/pinmap.c deleted file mode 100644 index ecd34ee9eb..0000000000 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/pinmap.c +++ /dev/null @@ -1,49 +0,0 @@ -/* 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. - */ -#include "mbed_assert.h" -#include "pinmap.h" -#include "error.h" -#include "fsl_clock_manager.h" -#include "fsl_port_hal.h" - -void pin_function(PinName pin, int function) { - MBED_ASSERT(pin != (PinName)NC); - clock_manager_set_gate(kClockModulePORT, pin >> GPIO_PORT_SHIFT, true); - port_hal_mux_control(pin >> GPIO_PORT_SHIFT, pin & 0xFF, (port_mux_t)function); -} - -void pin_mode(PinName pin, PinMode mode) { - MBED_ASSERT(pin != (PinName)NC); - uint32_t instance = pin >> GPIO_PORT_SHIFT; - uint32_t pinName = pin & 0xFF; - - switch (mode) { - case PullNone: - port_hal_configure_pull(instance, pinName, false); - port_hal_pull_select(instance, pinName, kPortPullDown); - break; - case PullDown: - port_hal_configure_pull(instance, pinName, true); - port_hal_pull_select(instance, pinName, kPortPullDown); - break; - case PullUp: - port_hal_configure_pull(instance, pinName, true); - port_hal_pull_select(instance, pinName, kPortPullUp); - break; - default: - break; - } -} diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/port_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/port_api.c deleted file mode 100644 index 767b0efe24..0000000000 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/port_api.c +++ /dev/null @@ -1,69 +0,0 @@ -/* 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. - */ -#include "port_api.h" -#include "pinmap.h" -#include "gpio_api.h" - -PinName port_pin(PortName port, int pin_n) { - return (PinName)((port << GPIO_PORT_SHIFT) | pin_n); -} - -void port_init(port_t *obj, PortName port, int mask, PinDirection dir) { - obj->port = port; - obj->mask = mask; - - // The function is set per pin: reuse gpio logic - for (uint32_t i = 0; i < 32; i++) { - if (obj->mask & (1 << i)) { - gpio_set(port_pin(obj->port, i)); - } - } - - port_dir(obj, dir); -} - -void port_mode(port_t *obj, PinMode mode) { - - // The mode is set per pin: reuse pinmap logic - for (uint32_t i = 0; i < 32; i++) { - if (obj->mask & (1 << i)) { - pin_mode(port_pin(obj->port, i), mode); - } - } -} - -void port_dir(port_t *obj, PinDirection dir) { - uint32_t direction = gpio_hal_get_port_direction((uint32_t)obj->port); - switch (dir) { - case PIN_INPUT : - direction &= ~obj->mask; - gpio_hal_set_port_direction((uint32_t)obj->port, direction); - break; - case PIN_OUTPUT: - direction |= obj->mask; - gpio_hal_set_port_direction((uint32_t)obj->port, direction); - break; - } -} - -void port_write(port_t *obj, int value) { - uint32_t input = gpio_hal_read_port_input((uint32_t)obj->port) & ~obj->mask; - gpio_hal_write_port_output((uint32_t)obj->port, input | (uint32_t)(value & obj->mask)); -} - -int port_read(port_t *obj) { - return (int)(gpio_hal_read_port_input((uint32_t)obj->port) & obj->mask); -} diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/pwmout_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/pwmout_api.c deleted file mode 100644 index a4d102ae7a..0000000000 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/pwmout_api.c +++ /dev/null @@ -1,172 +0,0 @@ -/* 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. - */ -#include "mbed_assert.h" -#include "pwmout_api.h" - -#include "cmsis.h" -#include "pinmap.h" -#include "fsl_ftm_hal.h" -#include "fsl_mcg_hal.h" -#include "fsl_clock_manager.h" - -static 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} -}; - -static float pwm_clock_mhz; - -void pwmout_init(pwmout_t* obj, PinName pin) { - PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM); - MBED_ASSERT(pwm != (PWMName)NC); - - obj->pwm_name = pwm; - - uint32_t pwm_base_clock; - clock_manager_get_frequency(kBusClock, &pwm_base_clock); - float clkval = (float)pwm_base_clock / 1000000.0f; - uint32_t clkdiv = 0; - while (clkval > 1) { - clkdiv++; - clkval /= 2.0f; - if (clkdiv == 7) { - break; - } - } - - pwm_clock_mhz = clkval; - uint32_t channel = pwm & 0xF; - uint32_t instance = pwm >> TPM_SHIFT; - clock_manager_set_gate(kClockModuleFTM, instance, true); - ftm_hal_set_tof_frequency(instance, 3); - ftm_hal_set_clock_source(instance, kClock_source_FTM_SystemClk); - ftm_hal_set_clock_ps(instance, (ftm_clock_ps_t)clkdiv); - ftm_hal_set_counter_init_val(instance, 0); - // default to 20ms: standard for servos, and fine for e.g. brightness control - pwmout_period_ms(obj, 20); - pwmout_write (obj, 0); - ftm_config_t config = { - .mode = kFtmEdgeAlignedPWM, - .channel = channel, - .edge_mode = {.ftm_pwm_edge_mode = kFtmHighTrue} - }; - ftm_hal_enable_pwm_mode(instance, &config); - - // Wire pinout - pinmap_pinout(pin, PinMap_PWM); -} - -void pwmout_free(pwmout_t* obj) { -} - -void pwmout_write(pwmout_t* obj, float value) { - uint32_t instance = obj->pwm_name >> TPM_SHIFT; - if (value < 0.0f) { - value = 0.0f; - } else if (value > 1.0f) { - value = 1.0f; - } - uint16_t mod = ftm_hal_get_mod(instance); - uint32_t new_count = (uint32_t)((float)(mod) * value); - // Stop FTM clock to ensure instant update of MOD register - ftm_hal_set_clock_source(instance, kClock_source_FTM_None); - ftm_hal_set_channel_count_value(instance, obj->pwm_name & 0xF, new_count); - ftm_hal_set_counter(instance, 0); - ftm_hal_set_clock_source(instance, kClock_source_FTM_SystemClk); -} - -float pwmout_read(pwmout_t* obj) { - uint16_t count = ftm_hal_get_channel_count_value(obj->pwm_name >> TPM_SHIFT, obj->pwm_name & 0xF, 0); - uint16_t mod = ftm_hal_get_mod(obj->pwm_name >> TPM_SHIFT); - 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) { - pwmout_period_us(obj, seconds * 1000000.0f); -} - -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) { - uint32_t instance = obj->pwm_name >> TPM_SHIFT; - float dc = pwmout_read(obj); - // Stop FTM clock to ensure instant update of MOD register - ftm_hal_set_clock_source(instance, kClock_source_FTM_None); - ftm_hal_set_mod(instance, (uint32_t)(pwm_clock_mhz * (float)us) - 1); - pwmout_write(obj, dc); - ftm_hal_set_clock_source(instance, kClock_source_FTM_SystemClk); -} - -void pwmout_pulsewidth(pwmout_t* obj, float seconds) { - pwmout_pulsewidth_us(obj, seconds * 1000000.0f); -} - -void pwmout_pulsewidth_ms(pwmout_t* obj, int ms) { - pwmout_pulsewidth_us(obj, ms * 1000); -} - -void pwmout_pulsewidth_us(pwmout_t* obj, int us) { - uint32_t value = (uint32_t)(pwm_clock_mhz * (float)us); - ftm_hal_set_channel_count_value(obj->pwm_name >> TPM_SHIFT, obj->pwm_name & 0xF, value); -} diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/rtc_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/rtc_api.c deleted file mode 100644 index c0315ad95f..0000000000 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/rtc_api.c +++ /dev/null @@ -1,68 +0,0 @@ -/* 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. - */ -#include "rtc_api.h" -#include "pinmap.h" -#include "fsl_rtc_hal.h" -#include "fsl_clock_manager.h" - -const PinMap PinMap_RTC[] = { - {NC, OSC32KCLK, 0}, -}; - -void rtc_init(void) { - rtc_hal_init_config_t hal_config = {0}; - - hal_config.disableClockOutToPeripheral = true; - if (PinMap_RTC[0].pin == NC) { - hal_config.enable32kOscillator = true; - } - clock_manager_set_gate(kClockModuleRTC, 0U, true); - hal_config.startSecondsCounterAt = 1; /* TSR = 1 */ - rtc_hal_init(&hal_config); - - // select RTC clock source - SIM->SOPT1 &= ~SIM_SOPT1_OSC32KSEL_MASK; - SIM->SOPT1 |= SIM_SOPT1_OSC32KSEL(PinMap_RTC[0].peripheral); - - rtc_hal_config_oscillator(true); - rtc_hal_counter_enable(true); -} - -void rtc_free(void) { - // [TODO] -} - -/* - * Little check routine to see if the RTC has been enabled - * 0 = Disabled, 1 = Enabled - */ -int rtc_isenabled(void) { - clock_manager_set_gate(kClockModuleRTC, 0U, true); - return (int)rtc_hal_is_counter_enabled(); -} - -time_t rtc_read(void) { - return BR_RTC_TSR_TSR; -} - -void rtc_write(time_t t) { - if (t == 0) { - t = 1; - } - rtc_hal_counter_enable(false); - BW_RTC_TSR_TSR(t); - rtc_hal_counter_enable(true); -} diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/serial_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/serial_api.c deleted file mode 100644 index 463b57bf1a..0000000000 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/serial_api.c +++ /dev/null @@ -1,244 +0,0 @@ -/* 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. - */ -#include "serial_api.h" - -// math.h required for floating point operations for baud rate calculation -#include -#include "mbed_assert.h" - -#include - -#include "cmsis.h" -#include "pinmap.h" -#include "fsl_uart_hal.h" -#include "fsl_clock_manager.h" -#include "fsl_uart_features.h" - -/* TODO: - putchar/getchar 9 and 10 bits support -*/ - -static 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} -}; - -static 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}, - {PTC6 , UART_0, 3}, - {NC , NC , 0} -}; - -#define UART_NUM 4 - -static uint32_t serial_irq_ids[UART_NUM] = {0}; -static uart_irq_handler irq_handler; - -int stdio_uart_inited = 0; -serial_t stdio_uart; - -static uint32_t serial_get_clock(uint32_t uart_instance) -{ - uint32_t uartSourceClock; - - if ((uart_instance == 0) || (uart_instance == 1)) { - clock_manager_get_frequency(kSystemClock, &uartSourceClock); - } else { - clock_manager_get_frequency(kBusClock, &uartSourceClock); - } - return uartSourceClock; -} - -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); - obj->index = (UARTName)pinmap_merge(uart_tx, uart_rx); - MBED_ASSERT((int)obj->index != NC); - - uart_config_t uart_config; - uart_config.baudRate = 9600; - uart_config.bitCountPerChar = kUart8BitsPerChar; - uart_config.parityMode = kUartParityDisabled; - uart_config.rxDataInvert = 0; - uart_config.stopBitCount = kUartOneStopBit; - uart_config.txDataInvert = 0; - - uart_config.uartSourceClockInHz = serial_get_clock(obj->index); - - clock_manager_set_gate(kClockModuleUART, obj->index, true); - uart_hal_init(obj->index, &uart_config); - - pinmap_pinout(tx, PinMap_UART_TX); - pinmap_pinout(rx, PinMap_UART_RX); - - pin_mode(tx, PullUp); - pin_mode(rx, PullUp); - - if (obj->index == STDIO_UART) { - stdio_uart_inited = 1; - memcpy(&stdio_uart, obj, sizeof(serial_t)); - } -} - -void serial_free(serial_t *obj) { - serial_irq_ids[obj->index] = 0; -} - -void serial_baud(serial_t *obj, int baudrate) { - uart_hal_set_baud_rate(obj->index, serial_get_clock(obj->index), (uint32_t)baudrate); -} - -void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) { - uart_hal_configure_bit_count_per_char(obj->index, (uart_bit_count_per_char_t)data_bits); - uart_hal_configure_parity_mode(obj->index, (uart_parity_mode_t)parity); - uart_hal_configure_stop_bit_count(obj->index, (uart_stop_bit_count_t)stop_bits); -} - -/****************************************************************************** - * INTERRUPTS HANDLING - ******************************************************************************/ -static inline void uart_irq(uint32_t transmit_empty, uint32_t receive_full, uint32_t index) { - if (serial_irq_ids[index] != 0) { - if (transmit_empty) - irq_handler(serial_irq_ids[index], TxIrq); - - if (receive_full) - irq_handler(serial_irq_ids[index], RxIrq); - } -} - -void uart0_irq() { - uart_irq(uart_hal_is_transmit_data_register_empty(0), uart_hal_is_receive_data_register_full(0), 0); - if (uart_hal_is_receive_overrun_detected(0)) - uart_hal_clear_status_flag(0, kUartReceiveOverrun); -} -void uart1_irq() { - uart_irq(uart_hal_is_transmit_data_register_empty(1), uart_hal_is_receive_data_register_full(1), 1); -} - -void uart2_irq() { - uart_irq(uart_hal_is_transmit_data_register_empty(2), uart_hal_is_receive_data_register_full(2), 2); -} - -void uart3_irq() { - uart_irq(uart_hal_is_transmit_data_register_empty(3), uart_hal_is_receive_data_register_full(3), 3); -} - -void uart4_irq() { - uart_irq(uart_hal_is_transmit_data_register_empty(4), uart_hal_is_receive_data_register_full(4), 4); -} - -void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id) { - irq_handler = handler; - serial_irq_ids[obj->index] = id; -} - -void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable) { - IRQn_Type irq_n = (IRQn_Type)0; - uint32_t vector = 0; - - switch (obj->index) { - case 0: irq_n=UART0_RX_TX_IRQn; vector = (uint32_t)&uart0_irq; break; - case 1: irq_n=UART1_RX_TX_IRQn; vector = (uint32_t)&uart1_irq; break; - case 2: irq_n=UART2_RX_TX_IRQn; vector = (uint32_t)&uart2_irq; break; - case 3: irq_n=UART3_RX_TX_IRQn; vector = (uint32_t)&uart3_irq; break; - case 4: irq_n=UART4_RX_TX_IRQn; vector = (uint32_t)&uart4_irq; break; - } - - if (enable) { - switch (irq) { - case RxIrq: uart_hal_enable_rx_data_register_full_interrupt(obj->index); break; - case TxIrq: uart_hal_enable_tx_data_register_empty_interrupt(obj->index); break; - } - NVIC_SetVector(irq_n, vector); - NVIC_EnableIRQ(irq_n); - - } else { // disable - int all_disabled = 0; - SerialIrq other_irq = (irq == RxIrq) ? (TxIrq) : (RxIrq); - switch (irq) { - case RxIrq: uart_hal_disable_rx_data_register_full_interrupt(obj->index); break; - case TxIrq: uart_hal_disable_tx_data_register_empty_interrupt(obj->index); break; - } - switch (other_irq) { - case RxIrq: all_disabled = uart_hal_is_receive_data_full_interrupt_enabled(obj->index) == 0; break; - case TxIrq: all_disabled = uart_hal_is_tx_data_register_empty_interrupt_enabled(obj->index) == 0; break; - } - if (all_disabled) - NVIC_DisableIRQ(irq_n); - } -} - -int serial_getc(serial_t *obj) { - while (!serial_readable(obj)); - uint8_t data; - uart_hal_getchar(obj->index, &data); - - return data; -} - -void serial_putc(serial_t *obj, int c) { - while (!serial_writable(obj)); - uart_hal_putchar(obj->index, (uint8_t)c); -} - -int serial_readable(serial_t *obj) { - if (uart_hal_is_receive_overrun_detected(obj->index)) - uart_hal_clear_status_flag(obj->index, kUartReceiveOverrun); - return uart_hal_is_receive_data_register_full(obj->index); -} - -int serial_writable(serial_t *obj) { - if (uart_hal_is_receive_overrun_detected(obj->index)) - uart_hal_clear_status_flag(obj->index, kUartReceiveOverrun); - - return uart_hal_is_transmit_data_register_empty(obj->index); -} - -void serial_clear(serial_t *obj) { -} - -void serial_pinout_tx(PinName tx) { - pinmap_pinout(tx, PinMap_UART_TX); -} - -void serial_break_set(serial_t *obj) { - uart_hal_queue_break_char_to_send(obj->index, true); -} - -void serial_break_clear(serial_t *obj) { - uart_hal_queue_break_char_to_send(obj->index, false); -} - diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/sleep.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/sleep.c deleted file mode 100644 index ebebdc7c60..0000000000 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/sleep.c +++ /dev/null @@ -1,49 +0,0 @@ -/* 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. - */ -#include "sleep_api.h" -#include "cmsis.h" -#include "fsl_mcg_hal.h" -#include "fsl_smc_hal.h" - -void sleep(void) { - smc_power_mode_protection_config_t sleep_config = {true}; - smc_hal_config_power_mode_protection(&sleep_config); - - SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk; - __WFI(); -} - -void deepsleep(void) { - mcg_clock_select_t mcg_clock = clock_get_clks(); - - smc_power_mode_protection_config_t sleep_config = {true}; - smc_hal_config_power_mode_protection(&sleep_config); - SMC->PMCTRL = SMC_PMCTRL_STOPM(2); - - //Deep sleep for ARM core: - SCB->SCR = 1 << SCB_SCR_SLEEPDEEP_Pos; - - __WFI(); - - //Switch back to PLL as clock source if needed - //The interrupt that woke up the device will run at reduced speed - if (mcg_clock == kMcgClockSelectOut) { - if (clock_get_plls() == kMcgPllSelectPllcs) { - while (clock_get_lock0() == kMcgLockUnlocked); - } - clock_set_clks(kMcgClockSelectOut); - } -} diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/spi_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/spi_api.c deleted file mode 100644 index 1d7b88594f..0000000000 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/spi_api.c +++ /dev/null @@ -1,184 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 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. - */ -#include -#include "mbed_assert.h" - -#include "spi_api.h" -#include "cmsis.h" -#include "pinmap.h" -#include "error.h" -#include "fsl_clock_manager.h" -#include "fsl_dspi_hal.h" - -static 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} -}; - -static 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} -}; - -static 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} -}; - -static 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} -}; - -static void spi_set_delays(uint32_t instance) { - dspi_delay_settings_config_t delay_config; - delay_config.pcsToSck = 1; /*!< PCS to SCK delay (CSSCK): initialize the scalar - * value to '1' to provide the master with a little - * more data-in read setup time. - */ - delay_config.pcsToSckPre = 0; /*!< PCS to SCK delay prescalar (PCSSCK) */ - delay_config.afterSckPre = 0; /*!< After SCK delay prescalar (PASC)*/ - delay_config.afterSck = 0; /*!< After SCK delay scalar (ASC)*/ - delay_config.afterTransferPre = 0; /*!< Delay after transfer prescalar (PDT)*/ - delay_config.afterTransfer = 0; - dspi_hal_configure_delays(instance, kDspiCtar0, &delay_config); -} - -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); - - obj->instance = pinmap_merge(spi_data, spi_cntl); - MBED_ASSERT((int)obj->instance != NC); - - // enable power and clocking - clock_manager_set_gate(kClockModuleSPI, obj->instance, true); - - dspi_hal_disable(obj->instance); - // set default format and frequency - if (ssel == NC) { - spi_format(obj, 8, 0, 0); // 8 bits, mode 0, master - } else { - spi_format(obj, 8, 0, 1); // 8 bits, mode 0, slave - } - spi_set_delays(obj->instance); - spi_frequency(obj, 1000000); - - dspi_hal_enable(obj->instance); - dspi_hal_start_transfer(obj->instance); - - // 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); - } -} - -void spi_free(spi_t *obj) { - // [TODO] -} -void spi_format(spi_t *obj, int bits, int mode, int slave) { - dspi_data_format_config_t config = {0}; - config.bitsPerFrame = (uint32_t)bits; - config.clkPolarity = (mode & 0x2) ? kDspiClockPolarity_ActiveLow : kDspiClockPolarity_ActiveHigh; - config.clkPhase = (mode & 0x1) ? kDspiClockPhase_SecondEdge : kDspiClockPhase_FirstEdge; - config.direction = kDspiMsbFirst; - dspi_status_t result = dspi_hal_configure_data_format(obj->instance, kDspiCtar0, &config); - if (result != kStatus_DSPI_Success) { - error("Failed to configure SPI data format"); - } - - if (slave) { - dspi_hal_set_master_slave(obj->instance, kDspiSlave); - } else { - dspi_hal_set_master_slave(obj->instance, kDspiMaster); - } -} - -void spi_frequency(spi_t *obj, int hz) { - uint32_t busClock; - clock_manager_get_frequency(kBusClock, &busClock); - dspi_hal_set_baud(obj->instance, kDspiCtar0, (uint32_t)hz, busClock); -} - -static inline int spi_writeable(spi_t * obj) { - return dspi_hal_get_status_flag(obj->instance, kDspiTxFifoFillRequest); -} - -static inline int spi_readable(spi_t * obj) { - return dspi_hal_get_status_flag(obj->instance, kDspiRxFifoDrainRequest); -} - -int spi_master_write(spi_t *obj, int value) { - // wait tx buffer empty - while(!spi_writeable(obj)); - dspi_command_config_t command = {0}; - command.isEndOfQueue = true; - command.isChipSelectContinuous = 0; - dspi_hal_write_data_master_mode(obj->instance, &command, (uint16_t)value); - dspi_hal_clear_status_flag(obj->instance, kDspiTxFifoFillRequest); - - // wait rx buffer full - while (!spi_readable(obj)); - dspi_hal_clear_status_flag(obj->instance, kDspiRxFifoDrainRequest); - return dspi_hal_read_data(obj->instance) & 0xff; -} - -int spi_slave_receive(spi_t *obj) { - return spi_readable(obj); -} - -int spi_slave_read(spi_t *obj) { - return dspi_hal_read_data(obj->instance); -} - -void spi_slave_write(spi_t *obj, int value) { - while (!spi_writeable(obj)); - dspi_hal_write_data_slave_mode(obj->instance, (uint32_t)value); -} diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/us_ticker.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/us_ticker.c deleted file mode 100644 index 9cd3545e5f..0000000000 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/us_ticker.c +++ /dev/null @@ -1,153 +0,0 @@ -/* 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. - */ -#include -#include "us_ticker_api.h" -#include "PeripheralNames.h" -#include "fsl_pit_hal.h" -#include "fsl_sim_hal.h" -#include "fsl_clock_manager.h" -#include "fsl_clock_configs.h" - -static void pit_init(void); -static void lptmr_init(void); - -static int us_ticker_inited = 0; - -void us_ticker_init(void) { - if (us_ticker_inited) { - return; - } - us_ticker_inited = 1; - - pit_init(); - lptmr_init(); -} - - -uint32_t us_ticker_read() { - if (!us_ticker_inited) { - us_ticker_init(); - } - - return ~(pit_hal_read_timer_count(1)); -} -/****************************************************************************** - * Timer for us timing. - ******************************************************************************/ -static void pit_init(void) { - uint32_t busClock; - - clock_hal_set_gate(kSimClockModulePIT, 0, true); - pit_hal_enable(); - clock_manager_get_frequency(kBusClock, &busClock); - pit_hal_set_timer_period_count(0, busClock / 1000000 - 1); - pit_hal_set_timer_period_count(1, 0xFFFFFFFF); - pit_hal_configure_timer_chain(1, true); - - pit_hal_timer_start(0); - pit_hal_timer_start(1); -} - -/****************************************************************************** - * Timer Event - * - * It schedules interrupts at given (32bit)us interval of time. - * It is implemented used the 16bit Low Power Timer that remains powered in all - * power modes. - ******************************************************************************/ -static void lptmr_isr(void); - -static void lptmr_init(void) { - clock_hal_set_gate(kSimClockModuleLPTIMER, 0, true); - - /* Set interrupt handler */ - NVIC_SetVector(LPTimer_IRQn, (uint32_t)lptmr_isr); - NVIC_EnableIRQ(LPTimer_IRQn); - - /* TODO: check clock manager, due to nonstandard 50 MHz */ - //No suitable external oscillator clock -> Use fast internal oscillator (4MHz / divider) - MCG->C1 |= MCG_C1_IRCLKEN_MASK; - MCG->C2 |= MCG_C2_IRCS_MASK; - LPTMR0->PSR = LPTMR_PSR_PCS(0); - switch (MCG->SC & MCG_SC_FCRDIV_MASK) { - case MCG_SC_FCRDIV(0): //4MHz - LPTMR0->PSR |= LPTMR_PSR_PRESCALE(1); - break; - case MCG_SC_FCRDIV(1): //2MHz - LPTMR0->PSR |= LPTMR_PSR_PRESCALE(0); - break; - default: //1MHz or anything else, in which case we put it on 1MHz - MCG->SC &= ~MCG_SC_FCRDIV_MASK; - MCG->SC |= MCG_SC_FCRDIV(2); - LPTMR0->PSR |= LPTMR_PSR_PBYP_MASK; - } -} - -void us_ticker_disable_interrupt(void) { - BW_LPTMR_CSR_TIE(0); -} - -void us_ticker_clear_interrupt(void) { - // we already clear interrupt in lptmr_isr -} - -static uint32_t us_ticker_int_counter = 0; -static uint16_t us_ticker_int_remainder = 0; - -static void lptmr_set(unsigned short count) { - HW_LPTMR_CSR_WR(0); - BW_LPTMR_CMR_COMPARE(count); - BW_LPTMR_CSR_TIE(1); - BW_LPTMR_CSR_TEN(1); -} - -static void lptmr_isr(void) { - // write 1 to TCF to clear the LPT timer compare flag - BW_LPTMR_CSR_TCF(1); - - if (us_ticker_int_counter > 0) { - lptmr_set(0xFFFF); - us_ticker_int_counter--; - } else { - if (us_ticker_int_remainder > 0) { - lptmr_set(us_ticker_int_remainder); - us_ticker_int_remainder = 0; - } else { - // This function is going to disable the interrupts if there are - // no other events in the queue - us_ticker_irq_handler(); - } - } -} - -void us_ticker_set_interrupt(unsigned int timestamp) { - int delta = (int)(timestamp - us_ticker_read()); - if (delta <= 0) { - // This event was in the past: - us_ticker_irq_handler(); - return; - } - - us_ticker_int_counter = (uint32_t)(delta >> 16); - us_ticker_int_remainder = (uint16_t)(0xFFFF & delta); - if (us_ticker_int_counter > 0) { - lptmr_set(0xFFFF); - us_ticker_int_counter--; - } else { - lptmr_set(us_ticker_int_remainder); - us_ticker_int_remainder = 0; - } -} From a545702123a4423973489eab27ce407bd22adf9d Mon Sep 17 00:00:00 2001 From: Sissors Date: Mon, 28 Jul 2014 21:14:57 +0200 Subject: [PATCH 8/9] Sleep fix + some device.h settings LPC1114 has no semihosting and also no localfilesystem. I took the liberty of guessing the LPC11Cxx also don't have those. Sleep code did nothing outside of locking up the microcontroller (because semihosting was enabled). Code seems to be copied from LPC11u24, but the LPC1114 is fundamentally different. (For example deep-sleep bit is now the deep-powerdown bit, which you dont want). Aditionally it keeps current peripheral state during deepsleep and when waking up. Datasheet rates LPC1114 at 6uA in deepsleep, I measured it at 3.7uA. That makes me a happy panda. --- .../TARGET_LPC11CXX/device.h | 4 +- .../TARGET_LPC11XX/device.h | 4 +- .../TARGET_NXP/TARGET_LPC11XX_11CXX/sleep.c | 44 +++---------------- 3 files changed, 11 insertions(+), 41 deletions(-) diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11CXX/device.h b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11CXX/device.h index 0ef445e8de..f7d2f2a614 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11CXX/device.h +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11CXX/device.h @@ -41,8 +41,8 @@ #define DEVICE_PWMOUT 1 -#define DEVICE_SEMIHOST 1 -#define DEVICE_LOCALFILESYSTEM 1 +#define DEVICE_SEMIHOST 0 +#define DEVICE_LOCALFILESYSTEM 0 #define DEVICE_ID_LENGTH 32 #define DEVICE_MAC_OFFSET 20 diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11XX/device.h b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11XX/device.h index ab3d323804..a45349a9e3 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11XX/device.h +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11XX/device.h @@ -41,8 +41,8 @@ #define DEVICE_PWMOUT 1 -#define DEVICE_SEMIHOST 1 -#define DEVICE_LOCALFILESYSTEM 1 +#define DEVICE_SEMIHOST 0 +#define DEVICE_LOCALFILESYSTEM 0 #define DEVICE_ID_LENGTH 32 #define DEVICE_MAC_OFFSET 20 diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/sleep.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/sleep.c index d9b3e19ddb..8507cc5a75 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/sleep.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/sleep.c @@ -18,10 +18,6 @@ #include "mbed_interface.h" void sleep(void) { -#if DEVICE_SEMIHOST - // ensure debug is disconnected - mbed_interface_disconnect(); -#endif // PCON[DPDEN] set to sleep LPC_PMU->PCON = 0x0; @@ -33,46 +29,20 @@ void sleep(void) { __WFI(); } -/* -* The mbed lpc1768 does not support the deepsleep mode -* as a debugger is connected to it (the mbed interface). -* -* As mentionned in an application note from NXP: -* -* http://www.po-star.com/public/uploads/20120319123122_141.pdf -* -* {{{ -* The user should be aware of certain limitations during debugging. -* The most important is that, due to limitations of the Cortex-M3 -* integration, the LPC17xx cannot wake up in the usual manner from -* Deep Sleep and Power-down modes. It is recommended not to use these -* modes during debug. Once an application is downloaded via JTAG/SWD -* interface, the USB to SWD/JTAG debug adapter (Keil ULINK2 for example) -* should be removed from the target board, and thereafter, power cycle -* the LPC17xx to allow wake-up from deep sleep and power-down modes -* }}} -* -* As the interface firmware does not reset the target when a -* mbed_interface_disconnect() semihosting call is made, the -* core cannot wake-up from deepsleep. -* -* We treat a deepsleep() as a normal sleep(). -*/ - void deepsleep(void) { -#if DEVICE_SEMIHOST - // ensure debug is disconnected - mbed_interface_disconnect(); -#endif // PCON[DPDEN] set to deepsleep - LPC_PMU->PCON = 0x2; + LPC_PMU->PCON = 0; // SRC[SLEEPDEEP] set to 1 = deep sleep SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; - // Power up everything after powerdown - LPC_SYSCON->PDAWAKECFG &= 0xFFFFF800; + //According to user manual it is kinda picky about reserved bits, so we follow that nicely + //Keep WDOSC and BOD in same state as they are now during deepsleep + LPC_SYSCON->PDSLEEPCFG = 0x000018B7 | (LPC_SYSCON->PDRUNCFG & (PDRUNCFG_WDTOSC_PD | PDRUNCFG_BOD_PD)); + + // Power up same as before powerdown + LPC_SYSCON->PDAWAKECFG = LPC_SYSCON->PDRUNCFG; // wait for interrupt __WFI(); From 97cdccdf03123273db4c4a7ae5a9ae572cedc3b5 Mon Sep 17 00:00:00 2001 From: 23chrischen <23chrischen@gmail.com> Date: Tue, 29 Jul 2014 09:43:48 -0500 Subject: [PATCH 9/9] Change F411 to Cortex-M4F instead of Cortex-M4 --- workspace_tools/targets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/workspace_tools/targets.py b/workspace_tools/targets.py index d865abd34f..cd5afbc8d2 100644 --- a/workspace_tools/targets.py +++ b/workspace_tools/targets.py @@ -301,7 +301,7 @@ class NUCLEO_F401RE(Target): class NUCLEO_F411RE(Target): def __init__(self): Target.__init__(self) - self.core = "Cortex-M4" + self.core = "Cortex-M4F" self.extra_labels = ['STM', 'STM32F4', 'STM32F411RE'] self.supported_toolchains = ["ARM", "uARM"] self.default_toolchain = "uARM"