From 214df550c0c9749800b3c032fa20ac3d4e12f0fc Mon Sep 17 00:00:00 2001 From: Kimmo Vaisanen Date: Tue, 14 Apr 2020 12:52:56 +0300 Subject: [PATCH] Cellular: Check if serial is supported Baud rate can be only changed if BufferedSerial (or Serial in general) object is supported --- features/cellular/framework/AT/AT_CellularDevice.cpp | 11 ++++++++++- features/cellular/framework/device/ATHandler.cpp | 5 ++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/features/cellular/framework/AT/AT_CellularDevice.cpp b/features/cellular/framework/AT/AT_CellularDevice.cpp index 0d005418c7..5c3c536c8b 100644 --- a/features/cellular/framework/AT/AT_CellularDevice.cpp +++ b/features/cellular/framework/AT/AT_CellularDevice.cpp @@ -598,7 +598,10 @@ nsapi_error_t AT_CellularDevice::clear() nsapi_error_t AT_CellularDevice::set_baud_rate(int baud_rate) { - nsapi_error_t error = set_baud_rate_impl(baud_rate); + nsapi_error_t error; + +#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) + error = set_baud_rate_impl(baud_rate); if (error) { tr_warning("Baudrate was not changed to desired value: %d", baud_rate); @@ -609,6 +612,12 @@ nsapi_error_t AT_CellularDevice::set_baud_rate(int baud_rate) // Give some time before starting using the UART with the new baud rate rtos::ThisThread::sleep_for(3000); +#else + // Currently ATHandler only supports BufferedSerial based communication and + // if serial is disabled, baud rate cannot be set + tr_warn("set_baud_rate: Serial not supported"); + error = NSAPI_ERROR_UNSUPPORTED; +#endif return error; } diff --git a/features/cellular/framework/device/ATHandler.cpp b/features/cellular/framework/device/ATHandler.cpp index fccfe90134..0bb914c7a7 100644 --- a/features/cellular/framework/device/ATHandler.cpp +++ b/features/cellular/framework/device/ATHandler.cpp @@ -1545,6 +1545,9 @@ void ATHandler::write_hex_string(const char *str, size_t size) void ATHandler::set_baud(int baud_rate) { +#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) static_cast(_fileHandle)->set_baud(baud_rate); +#else + tr_error("Device does not support BufferedSerial"); +#endif } -