From 960941cb0a88bbe23665aca26b4bc939f9eaa07f Mon Sep 17 00:00:00 2001 From: Russ Butler Date: Tue, 24 May 2016 14:31:37 -0500 Subject: [PATCH] Add IAR support Make the following changes for IAR support: -define __deprecated_message for IAR -fix python error in iar.py -move variable length array in buffered serial from cpp file to c file. IAR only supports variable length arrays in c. --- frameworks/utest/utest/shim.h | 2 + .../ATParser/BufferedSerial/BufferedPrint.c | 41 +++++++++++++++++++ .../BufferedSerial/BufferedSerial.cpp | 24 ++++------- tools/toolchains/iar.py | 2 +- 4 files changed, 53 insertions(+), 16 deletions(-) create mode 100644 net/ESP8266Interface/ESP8266/ATParser/BufferedSerial/BufferedPrint.c diff --git a/frameworks/utest/utest/shim.h b/frameworks/utest/utest/shim.h index 78a6f6048a..f9505d5f73 100644 --- a/frameworks/utest/utest/shim.h +++ b/frameworks/utest/utest/shim.h @@ -30,6 +30,8 @@ # ifndef __deprecated_message # if defined(__CC_ARM) # define __deprecated_message(msg) __attribute__((deprecated)) +# elif defined (__ICCARM__) +# define __deprecated_message(msg) # else # define __deprecated_message(msg) __attribute__((deprecated(msg))) # endif diff --git a/net/ESP8266Interface/ESP8266/ATParser/BufferedSerial/BufferedPrint.c b/net/ESP8266Interface/ESP8266/ATParser/BufferedSerial/BufferedPrint.c new file mode 100644 index 0000000000..8542c211a5 --- /dev/null +++ b/net/ESP8266Interface/ESP8266/ATParser/BufferedSerial/BufferedPrint.c @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2014-2015 ARM Limited. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "mbed_error.h" + +size_t BufferedSerialThunk(void *buf_serial, const void *s, size_t length); + +int BufferedPrintfC(void *stream, int size, const char* format, va_list arg) +{ + int r; + char buffer[size]; + memset(buffer, 0, size); + r = vsprintf(buffer, format, arg); + // this may not hit the heap but should alert the user anyways + if(r > (int32_t) size) { + error("%s %d buffer overwrite (max_buf_size: %d exceeded: %d)!\r\n", __FILE__, __LINE__, size, r); + return 0; + } + if ( r > 0 ) { + BufferedSerialThunk(stream, buffer, r); + } + return r; +} diff --git a/net/ESP8266Interface/ESP8266/ATParser/BufferedSerial/BufferedSerial.cpp b/net/ESP8266Interface/ESP8266/ATParser/BufferedSerial/BufferedSerial.cpp index da3cbfa168..9010cd3907 100644 --- a/net/ESP8266Interface/ESP8266/ATParser/BufferedSerial/BufferedSerial.cpp +++ b/net/ESP8266Interface/ESP8266/ATParser/BufferedSerial/BufferedSerial.cpp @@ -23,6 +23,8 @@ #include "BufferedSerial.h" #include +extern "C" int BufferedPrintfC(void *stream, int size, const char* format, va_list arg); + BufferedSerial::BufferedSerial(PinName tx, PinName rx, uint32_t buf_size, uint32_t tx_multiple, const char* name) : RawSerial(tx, rx) , _rxbuf(buf_size), _txbuf((uint32_t)(tx_multiple*buf_size)) { @@ -79,26 +81,18 @@ int BufferedSerial::puts(const char *s) return 0; } +extern "C" size_t BufferedSerialThunk(void *buf_serial, const void *s, size_t length) +{ + BufferedSerial *buffered_serial = (BufferedSerial *)buf_serial; + return buffered_serial->write(s, length); +} + int BufferedSerial::printf(const char* format, ...) { - char buffer[this->_buf_size]; - memset(buffer,0,this->_buf_size); - int r = 0; - va_list arg; va_start(arg, format); - r = vsprintf(buffer, format, arg); - // this may not hit the heap but should alert the user anyways - if(r > (int32_t) this->_buf_size) { - error("%s %d buffer overwrite (max_buf_size: %d exceeded: %d)!\r\n", __FILE__, __LINE__,this->_buf_size,r); - va_end(arg); - return 0; - } + int r = BufferedPrintfC((void*)this, this->_buf_size, format, arg); va_end(arg); - if ( r > 0 ) { - r = BufferedSerial::write(buffer, r); - } - return r; } diff --git a/tools/toolchains/iar.py b/tools/toolchains/iar.py index a27f1bb52e..bef166cbde 100644 --- a/tools/toolchains/iar.py +++ b/tools/toolchains/iar.py @@ -149,7 +149,7 @@ class IAR(mbedToolchain): cmd = [self.ld, "-o", output, "--skip_dynamic_initialization", "--map=%s" % map_file] + objects + libraries if mem_map: - args.extend(["--config", mem_map]) + cmd.extend(["--config", mem_map]) # Call cmdline hook cmd = self.hook.get_cmdline_linker(cmd)