mirror of https://github.com/ARMmbed/mbed-os.git
Merge branch 'master' of https://github.com/mbedmicro/mbed
commit
af8ec9b497
|
@ -53,14 +53,16 @@
|
|||
* #endcode
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "device.h"
|
||||
#include "toolchain.h"
|
||||
|
||||
#if DEVICE_STDIO_MESSAGES
|
||||
#include <stdio.h>
|
||||
#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
|
||||
|
|
|
@ -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 <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include "device.h"
|
||||
#include "toolchain.h"
|
||||
#if DEVICE_STDIO_MESSAGES
|
||||
#include <stdio.h>
|
||||
#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);
|
||||
}
|
|
@ -16,6 +16,7 @@
|
|||
// math.h required for floating point operations for baud rate calculation
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "serial_api.h"
|
||||
#include "cmsis.h"
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
// math.h required for floating point operations for baud rate calculation
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "serial_api.h"
|
||||
#include "cmsis.h"
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
// math.h required for floating point operations for baud rate calculation
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "serial_api.h"
|
||||
#include "cmsis.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,
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
// math.h required for floating point operations for baud rate calculation
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "serial_api.h"
|
||||
#include "cmsis.h"
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
// math.h required for floating point operations for baud rate calculation
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "serial_api.h"
|
||||
#include "cmsis.h"
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
// math.h required for floating point operations for baud rate calculation
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "serial_api.h"
|
||||
#include "cmsis.h"
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
// math.h required for floating point operations for baud rate calculation
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "serial_api.h"
|
||||
#include "cmsis.h"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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"),
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue