Skip to content

Commit b6c25b1

Browse files
committed
Remove serial flow control functions from image if flow control is not used
1 parent 160342b commit b6c25b1

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

drivers/SerialBase.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,12 +356,14 @@ class SerialBase : private NonCopyable<SerialBase> {
356356
const PinName _tx_pin;
357357
const PinName _rx_pin;
358358
const serial_pinmap_t *_static_pinmap = NULL;
359+
void (SerialBase::*_set_flow_control_dp_func)(Flow, PinName, PinName) = NULL;
359360

360361
#if DEVICE_SERIAL_FC
361362
Flow _flow_type = Disabled;
362363
PinName _flow1 = NC;
363364
PinName _flow2 = NC;
364365
const serial_fc_pinmap_t *_static_pinmap_fc = NULL;
366+
void (SerialBase::*_set_flow_control_sp_func)(Flow, const serial_fc_pinmap_t &) = NULL;
365367
#endif
366368

367369
#endif

drivers/source/SerialBase.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ void SerialBase::_init()
151151
{
152152
serial_init(&_serial, _tx_pin, _rx_pin);
153153
#if DEVICE_SERIAL_FC
154-
set_flow_control(_flow_type, _flow1, _flow2);
154+
if (_set_flow_control_dp_func) {
155+
(this->*_set_flow_control_dp_func)(_flow_type, _flow1, _flow2);
156+
}
155157
#endif
156158
serial_baud(&_serial, _baud);
157159
serial_irq_handler(&_serial, SerialBase::_irq_handler, (uint32_t)this);
@@ -161,8 +163,8 @@ void SerialBase::_init_direct()
161163
{
162164
serial_init_direct(&_serial, _static_pinmap);
163165
#if DEVICE_SERIAL_FC
164-
if (_static_pinmap_fc) {
165-
set_flow_control(_flow_type, *_static_pinmap_fc);
166+
if (_static_pinmap_fc && _set_flow_control_dp_func) {
167+
(this->*_set_flow_control_sp_func)(_flow_type, *_static_pinmap_fc);
166168
}
167169
#endif
168170
serial_baud(&_serial, _baud);
@@ -303,6 +305,7 @@ SerialBase::~SerialBase()
303305
void SerialBase::set_flow_control(Flow type, PinName flow1, PinName flow2)
304306
{
305307
MBED_ASSERT(_static_pinmap == NULL); // this function must be used when serial object has been created using dynamic pin-map constructor
308+
_set_flow_control_dp_func = &SerialBase::set_flow_control;
306309
lock();
307310

308311
_flow_type = type;
@@ -333,6 +336,7 @@ void SerialBase::set_flow_control(Flow type, PinName flow1, PinName flow2)
333336
void SerialBase::set_flow_control(Flow type, const serial_fc_pinmap_t &static_pinmap)
334337
{
335338
MBED_ASSERT(_static_pinmap != NULL); // this function must be used when serial object has been created using static pin-map constructor
339+
_set_flow_control_sp_func = &SerialBase::set_flow_control;
336340
lock();
337341
_static_pinmap_fc = &static_pinmap;
338342
_flow_type = type;

0 commit comments

Comments
 (0)