diff --git a/libraries/mbed/api/error.h b/libraries/mbed/api/error.h index 0abe725c16..c62f22b602 100644 --- a/libraries/mbed/api/error.h +++ b/libraries/mbed/api/error.h @@ -53,14 +53,16 @@ * #endcode */ -#include -#include "device.h" +#include "toolchain.h" -#if DEVICE_STDIO_MESSAGES - #include - #define error(...) (fprintf(stderr, __VA_ARGS__), exit(1)) -#else - #define error(...) (exit(1)) +#ifdef __cplusplus +extern "C" { +#endif + +void error(const char* format, ...); + +#ifdef __cplusplus +} #endif #endif diff --git a/libraries/mbed/common/error.c b/libraries/mbed/common/error.c new file mode 100644 index 0000000000..7c6a556c03 --- /dev/null +++ b/libraries/mbed/common/error.c @@ -0,0 +1,33 @@ +/* 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 +#include "device.h" +#include "toolchain.h" +#if DEVICE_STDIO_MESSAGES +#include +#endif + +WEAK void error(const char* format, ...); +WEAK void error(const char* format, ...) { +#if DEVICE_STDIO_MESSAGES + va_list arg; + va_start(arg, format); + vfprintf(stderr, format, arg); + va_end(arg); +#endif + exit(1); +} diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/serial_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/serial_api.c index 57ee01da35..123dd6af0d 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/serial_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/serial_api.c @@ -16,6 +16,7 @@ // math.h required for floating point operations for baud rate calculation #include #include +#include #include "serial_api.h" #include "cmsis.h" diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/serial_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/serial_api.c index b798789e0e..55bfc1a5a8 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/serial_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/serial_api.c @@ -16,6 +16,7 @@ // math.h required for floating point operations for baud rate calculation #include #include +#include #include "serial_api.h" #include "cmsis.h" diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC13XX/serial_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC13XX/serial_api.c index 1db3211e0f..3b405a2c68 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC13XX/serial_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC13XX/serial_api.c @@ -16,6 +16,7 @@ // math.h required for floating point operations for baud rate calculation #include #include +#include #include "serial_api.h" #include "cmsis.h" diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/TARGET_MBED_LPC1768/PinNames.h b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/TARGET_MBED_LPC1768/PinNames.h index 82a764366c..4bf7230307 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/TARGET_MBED_LPC1768/PinNames.h +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/TARGET_MBED_LPC1768/PinNames.h @@ -96,6 +96,8 @@ typedef enum { D11 = P0_9, D12 = P0_8, D13 = P0_7, + D14 = P0_27, + D15 = P0_28, A0 = P0_23, A1 = P0_24, diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/serial_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/serial_api.c index b74e7b527c..c9bbee6bf0 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/serial_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/serial_api.c @@ -16,6 +16,7 @@ // math.h required for floating point operations for baud rate calculation #include #include +#include #include "serial_api.h" #include "cmsis.h" diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/serial_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/serial_api.c index 517d28c58a..a4a4b311fb 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/serial_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/serial_api.c @@ -16,6 +16,7 @@ // math.h required for floating point operations for baud rate calculation #include #include +#include #include "serial_api.h" #include "cmsis.h" diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/serial_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/serial_api.c index a11d4a522f..26d01224b7 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/serial_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/serial_api.c @@ -16,6 +16,7 @@ // math.h required for floating point operations for baud rate calculation #include #include +#include #include "serial_api.h" #include "cmsis.h" diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/serial_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/serial_api.c index b5af98f6a1..6efec95413 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/serial_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/serial_api.c @@ -18,6 +18,7 @@ // math.h required for floating point operations for baud rate calculation #include #include +#include #include "serial_api.h" #include "cmsis.h" diff --git a/libraries/mbed/targets/hal/TARGET_STM/TARGET_DISCO_F051R8/i2c_api.c b/libraries/mbed/targets/hal/TARGET_STM/TARGET_DISCO_F051R8/i2c_api.c index ed221a0acb..73b7f1ba68 100644 --- a/libraries/mbed/targets/hal/TARGET_STM/TARGET_DISCO_F051R8/i2c_api.c +++ b/libraries/mbed/targets/hal/TARGET_STM/TARGET_DISCO_F051R8/i2c_api.c @@ -86,7 +86,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) { void i2c_frequency(i2c_t *obj, int hz) { I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c); I2C_InitTypeDef I2C_InitStructure; - uint32_t tim; + uint32_t tim = 0; // Values calculated with I2C_Timing_Configuration_V1.0.1.xls file (see AN4235) // with Rise time = 100ns and Fall time = 10ns diff --git a/libraries/mbed/targets/hal/TARGET_STM/TARGET_DISCO_F051R8/pinmap.c b/libraries/mbed/targets/hal/TARGET_STM/TARGET_DISCO_F051R8/pinmap.c index 16f55fe88f..3f2812695e 100644 --- a/libraries/mbed/targets/hal/TARGET_STM/TARGET_DISCO_F051R8/pinmap.c +++ b/libraries/mbed/targets/hal/TARGET_STM/TARGET_DISCO_F051R8/pinmap.c @@ -27,6 +27,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ******************************************************************************* */ +#include "device.h" #include "pinmap.h" #include "error.h" diff --git a/libraries/mbed/targets/hal/TARGET_STM/TARGET_DISCO_F100RB/pinmap.c b/libraries/mbed/targets/hal/TARGET_STM/TARGET_DISCO_F100RB/pinmap.c index 5d712cc319..e82f85b1cc 100644 --- a/libraries/mbed/targets/hal/TARGET_STM/TARGET_DISCO_F100RB/pinmap.c +++ b/libraries/mbed/targets/hal/TARGET_STM/TARGET_DISCO_F100RB/pinmap.c @@ -27,6 +27,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ******************************************************************************* */ +#include "device.h" #include "pinmap.h" #include "error.h" diff --git a/libraries/mbed/targets/hal/TARGET_STM/TARGET_DISCO_F407VG/PeripheralNames.h b/libraries/mbed/targets/hal/TARGET_STM/TARGET_DISCO_F407VG/PeripheralNames.h index 1f03dd45fa..c745bbc45e 100644 --- a/libraries/mbed/targets/hal/TARGET_STM/TARGET_DISCO_F407VG/PeripheralNames.h +++ b/libraries/mbed/targets/hal/TARGET_STM/TARGET_DISCO_F407VG/PeripheralNames.h @@ -40,6 +40,11 @@ typedef enum { ADC_1 = (int)ADC1_BASE } ADCName; +typedef enum { + DAC_0 = 0, + DAC_1 +} DACName; + typedef enum { UART_1 = (int)USART1_BASE, UART_2 = (int)USART2_BASE, diff --git a/libraries/mbed/targets/hal/TARGET_STM/TARGET_DISCO_F407VG/analogout_api.c b/libraries/mbed/targets/hal/TARGET_STM/TARGET_DISCO_F407VG/analogout_api.c new file mode 100644 index 0000000000..519f1acbb5 --- /dev/null +++ b/libraries/mbed/targets/hal/TARGET_STM/TARGET_DISCO_F407VG/analogout_api.c @@ -0,0 +1,160 @@ +/* mbed Microcontroller Library + * Copyright (c) 2014, 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. + */ +#include "analogout_api.h" + +#if DEVICE_ANALOGOUT + +#include "cmsis.h" +#include "pinmap.h" +#include "error.h" +#include "stm32f4xx_hal.h" + +#define RANGE_12BIT (0xFFF) + +DAC_HandleTypeDef DacHandle; +static DAC_ChannelConfTypeDef sConfig; + +static const PinMap PinMap_DAC[] = { + {PA_4, DAC_0, STM_PIN_DATA(STM_MODE_ANALOG, GPIO_NOPULL, 0xFF)}, // DAC_OUT1 + {PA_5, DAC_1, STM_PIN_DATA(STM_MODE_ANALOG, GPIO_NOPULL, 0xFF)}, // DAC_OUT2 + {NC, NC, 0} +}; + +void analogout_init(dac_t *obj, PinName pin) +{ + uint32_t channel ; + HAL_StatusTypeDef status; + + // Get the peripheral name (DAC_1, ...) from the pin and assign it to the object + obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC); + + if (obj->dac == (DACName)NC) { + error("DAC pin mapping failed"); + } + + // Configure GPIO + pinmap_pinout(pin, PinMap_DAC); + + // Save the channel for the write and read functions + obj->channel = pin; + + __GPIOA_CLK_ENABLE(); + + __DAC_CLK_ENABLE(); + + DacHandle.Instance = DAC; + + status = HAL_DAC_Init(&DacHandle); + if ( status != HAL_OK ) { + error("HAL_DAC_Init failed"); + } + + sConfig.DAC_Trigger = DAC_TRIGGER_NONE; + sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE; + + if (obj->channel == PA_4) { + channel = DAC_CHANNEL_1; + } else { + channel = DAC_CHANNEL_2; + } + + if (HAL_DAC_ConfigChannel(&DacHandle, &sConfig, channel) != HAL_OK) { + error("HAL_DAC_ConfigChannel failed"); + } + + if (HAL_DAC_Start(&DacHandle, channel) != HAL_OK) { + error("HAL_DAC_Start failed"); + } + + if (HAL_DAC_SetValue(&DacHandle, channel, DAC_ALIGN_12B_R, 0x000) != HAL_OK) { + error("HAL_DAC_SetValue failed"); + } + +} + +void analogout_free(dac_t *obj) +{ +} + +static inline void dac_write(dac_t *obj, uint16_t value) +{ + HAL_StatusTypeDef status; + + if (obj->channel == PA_4) { + status = HAL_DAC_SetValue(&DacHandle, DAC_CHANNEL_1, DAC_ALIGN_12B_R, value); + } else if (obj->channel == PA_5) { + status = HAL_DAC_SetValue(&DacHandle, DAC_CHANNEL_2, DAC_ALIGN_12B_R, value); + } + + if ( status != HAL_OK ) { + error("ADC pin mapping failed"); + } +} + +static inline int dac_read(dac_t *obj) +{ + if (obj->channel == PA_4) { + return (int)HAL_DAC_GetValue(&DacHandle, DAC_CHANNEL_1); + } else if (obj->channel == PA_5) { + return (int)HAL_DAC_GetValue(&DacHandle, DAC_CHANNEL_2); + } +} + +void analogout_write(dac_t *obj, float value) +{ + if (value < 0.0f) { + dac_write(obj, 0); // Min value + } else if (value > 1.0f) { + dac_write(obj, (uint16_t)RANGE_12BIT); // Max value + } else { + dac_write(obj, (uint16_t)(value * (float)RANGE_12BIT)); + } +} + +void analogout_write_u16(dac_t *obj, uint16_t value) +{ + if (value > (uint16_t)RANGE_12BIT) { + value = (uint16_t)RANGE_12BIT; // Max value + } + + dac_write(obj, value); +} + +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) +{ + return (uint16_t)dac_read(obj); +} + +#endif // DEVICE_ANALOGOUT diff --git a/libraries/mbed/targets/hal/TARGET_STM/TARGET_DISCO_F407VG/device.h b/libraries/mbed/targets/hal/TARGET_STM/TARGET_DISCO_F407VG/device.h index 302ed7582d..2e448ed8df 100644 --- a/libraries/mbed/targets/hal/TARGET_STM/TARGET_DISCO_F407VG/device.h +++ b/libraries/mbed/targets/hal/TARGET_STM/TARGET_DISCO_F407VG/device.h @@ -37,7 +37,7 @@ #define DEVICE_INTERRUPTIN 1 #define DEVICE_ANALOGIN 1 -#define DEVICE_ANALOGOUT 0 // Not present on this device +#define DEVICE_ANALOGOUT 1 #define DEVICE_SERIAL 1 diff --git a/libraries/mbed/targets/hal/TARGET_STM/TARGET_DISCO_F407VG/objects.h b/libraries/mbed/targets/hal/TARGET_STM/TARGET_DISCO_F407VG/objects.h index 22cc3f3328..48e48fa345 100644 --- a/libraries/mbed/targets/hal/TARGET_STM/TARGET_DISCO_F407VG/objects.h +++ b/libraries/mbed/targets/hal/TARGET_STM/TARGET_DISCO_F407VG/objects.h @@ -59,6 +59,11 @@ struct analogin_s { PinName pin; }; +struct dac_s { + DACName dac; + PinName channel; +}; + struct serial_s { UARTName uart; int index; // Used by irq diff --git a/libraries/mbed/targets/hal/TARGET_STM/TARGET_DISCO_F407VG/pinmap.c b/libraries/mbed/targets/hal/TARGET_STM/TARGET_DISCO_F407VG/pinmap.c index 0c25fca917..b88ddeda79 100644 --- a/libraries/mbed/targets/hal/TARGET_STM/TARGET_DISCO_F407VG/pinmap.c +++ b/libraries/mbed/targets/hal/TARGET_STM/TARGET_DISCO_F407VG/pinmap.c @@ -27,6 +27,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ******************************************************************************* */ +#include "device.h" #include "pinmap.h" #include "error.h" #include "stm32f4xx_hal.h" diff --git a/workspace_tools/export/__init__.py b/workspace_tools/export/__init__.py index 1c3eb1e919..67de0229ca 100644 --- a/workspace_tools/export/__init__.py +++ b/workspace_tools/export/__init__.py @@ -26,7 +26,7 @@ from workspace_tools.targets import EXPORT_MAP EXPORTERS = { 'uvision': uvision4.Uvision4, - 'codered': codered.CodeRed, + 'lpcxpresso': codered.CodeRed, 'codesourcery': codesourcery.CodeSourcery, 'gcc_arm': gccarm.GccArm, 'ds5_5': ds5_5.DS5_5, diff --git a/workspace_tools/export/gcc_arm_disco_f407vg.tmpl b/workspace_tools/export/gcc_arm_disco_f407vg.tmpl index 9f9e8a4950..d78cf2a7e7 100644 --- a/workspace_tools/export/gcc_arm_disco_f407vg.tmpl +++ b/workspace_tools/export/gcc_arm_disco_f407vg.tmpl @@ -19,15 +19,21 @@ OBJCOPY = $(GCC_BIN)arm-none-eabi-objcopy OBJDUMP = $(GCC_BIN)arm-none-eabi-objdump SIZE = $(GCC_BIN)arm-none-eabi-size -CPU = -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp +CPU = -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=$(FLOAT_ABI) CC_FLAGS = $(CPU) -c -g -fno-common -fmessage-length=0 -Wall -fno-exceptions -ffunction-sections -fdata-sections CC_FLAGS += -MMD -MP CC_SYMBOLS = {% for s in symbols %}-D{{s}} {% endfor %} -LD_FLAGS = -mcpu=cortex-m4 -mthumb -Wl,--gc-sections --specs=nano.specs -u _printf_float -u _scanf_float +LD_FLAGS = $(CPU) -Wl,--gc-sections --specs=nano.specs -u _printf_float -u _scanf_float LD_FLAGS += -Wl,-Map=$(PROJECT).map,--cref LD_SYS_LIBS = -lstdc++ -lsupc++ -lm -lc -lgcc -lnosys +ifeq ($(SOFTFP),1) + FLOAT_ABI = softfp +else + FLOAT_ABI = hard +endif + ifeq ($(DEBUG), 1) CC_FLAGS += -DDEBUG -O0 else diff --git a/workspace_tools/export_test.py b/workspace_tools/export_test.py index fa908ef21f..53229628e7 100644 --- a/workspace_tools/export_test.py +++ b/workspace_tools/export_test.py @@ -79,9 +79,9 @@ if __name__ == '__main__': ('uvision', 'LPC1768'), ('uvision', 'LPC11U24'), ('uvision', 'KL25Z'), ('uvision', 'LPC1347'), ('uvision', 'LPC1114'), ('uvision', 'LPC4088'), ('uvision', 'NUCLEO_F103RB'), ('uvision', 'NUCLEO_L152RE'), ('uvision', 'NUCLEO_F401RE'), ('uvision', 'NUCLEO_F030R8'), ('uvision', 'NUCLEO_F302R8'), - ('codered', 'LPC1768'), ('codered', 'LPC4088'),('codered', 'LPC1114'), - ('codered', 'LPC11U35_401'), - ('codered', 'LPC11U35_501'), + ('lpcxpresso', 'LPC1768'), ('lpcxpresso', 'LPC4088'),('lpcxpresso', 'LPC1114'), + ('lpcxpresso', 'LPC11U35_401'), + ('lpcxpresso', 'LPC11U35_501'), # Linux path: /home/emimon01/bin/gcc-cs/bin/ # Windows path: "C:/Program Files (x86)/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_EABI/bin/" ('codesourcery', 'LPC1768'), @@ -110,4 +110,4 @@ if __name__ == '__main__': test_export(toolchain, target) print "\n=== Test error messages ===" - test_export('codered', 'LPC11U24', expected_error='codered') + test_export('lpcxpresso', 'LPC11U24', expected_error='lpcxpresso') diff --git a/workspace_tools/synch.py b/workspace_tools/synch.py index a588ed9522..a49f738041 100644 --- a/workspace_tools/synch.py +++ b/workspace_tools/synch.py @@ -68,7 +68,7 @@ OFFICIAL_CODE = ( ("UbloxModemHTTPClientTest", ["tests/net/cellular/http/common", "tests/net/cellular/http/ubloxusb"]), ("UbloxModemSMSTest", ["tests/net/cellular/sms/common", "tests/net/cellular/sms/ubloxusb"]), - ("ble-api", "ble/ble-api"), + ("BLE_API", "ble/ble-api", "Bluetooth-Low-Energy"), ("nRF51822", "ble/nRF51822", "Nordic-Semiconductor"), )