Skip to content

Commit eb5574d

Browse files
committed
Remove unreachable statements warnings
The warnings are observed when building with the IAR toolchain.
1 parent d8c2c6f commit eb5574d

File tree

3 files changed

+174
-21
lines changed

3 files changed

+174
-21
lines changed

drivers/source/usb/USBDevice.cpp

Lines changed: 171 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "USBDescriptor.h"
2323
#include "usb_phy_api.h"
2424
#include "mbed_assert.h"
25+
#include "platform/mbed_error.h"
2526

2627
//#define DEBUG
2728

@@ -852,8 +853,17 @@ void USBDevice::ep0_setup()
852853
assert_locked();
853854

854855
if (_device.state < Default) {
855-
MBED_ASSERT(0);
856+
#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
857+
MBED_ERROR(
858+
MBED_MAKE_ERROR(
859+
MBED_MODULE_DRIVER_USB,
860+
MBED_ERROR_CODE_NOT_READY
861+
),
862+
"Device state is \"Powered\" or \"Detached\""
863+
);
864+
#else
856865
return;
866+
#endif // defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
857867
}
858868

859869
_setup_ready = true;
@@ -874,15 +884,33 @@ void USBDevice::ep0_out()
874884
assert_locked();
875885

876886
if (_device.state < Default) {
877-
MBED_ASSERT(0);
887+
#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
888+
MBED_ERROR(
889+
MBED_MAKE_ERROR(
890+
MBED_MODULE_DRIVER_USB,
891+
MBED_ERROR_CODE_NOT_READY
892+
),
893+
"Device state is \"Powered\" or \"Detached\""
894+
);
895+
#else
878896
return;
897+
#endif // defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
879898
}
880899

881900
if (_transfer.user_callback != None) {
882901
/* EP0 OUT should not receive data if the stack is waiting
883902
on a user callback for the buffer to fill or status */
884-
MBED_ASSERT(0);
903+
#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
904+
MBED_ERROR(
905+
MBED_MAKE_ERROR(
906+
MBED_MODULE_DRIVER_USB,
907+
MBED_ERROR_CODE_NOT_READY
908+
),
909+
"The stack is waiting on a user callback for the buffer to fill or status."
910+
);
911+
#else
885912
return;
913+
#endif // defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
886914
}
887915

888916
if (_transfer.stage == Status) {
@@ -903,8 +931,17 @@ void USBDevice::ep0_in()
903931
assert_locked();
904932

905933
if (_device.state < Default) {
906-
MBED_ASSERT(0);
934+
#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
935+
MBED_ERROR(
936+
MBED_MAKE_ERROR(
937+
MBED_MODULE_DRIVER_USB,
938+
MBED_ERROR_CODE_NOT_READY
939+
),
940+
"Device state is \"Powered\" or \"Detached\""
941+
);
942+
#else
907943
return;
944+
#endif // defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
908945
}
909946

910947
#ifdef DEBUG
@@ -928,8 +965,17 @@ void USBDevice::out(usb_ep_t endpoint)
928965
assert_locked();
929966

930967
if (!EP_INDEXABLE(endpoint)) {
931-
MBED_ASSERT(0);
968+
#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
969+
MBED_ERROR(
970+
MBED_MAKE_ERROR(
971+
MBED_MODULE_DRIVER_USB,
972+
MBED_ERROR_CODE_INVALID_INDEX
973+
),
974+
"The endpoint is not indexable."
975+
);
976+
#else
932977
return;
978+
#endif // defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
933979
}
934980

935981
endpoint_info_t *info = &_endpoint_info[EP_TO_INDEX(endpoint)];
@@ -946,8 +992,17 @@ void USBDevice::in(usb_ep_t endpoint)
946992
assert_locked();
947993

948994
if (!EP_INDEXABLE(endpoint)) {
949-
MBED_ASSERT(0);
995+
#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
996+
MBED_ERROR(
997+
MBED_MAKE_ERROR(
998+
MBED_MODULE_DRIVER_USB,
999+
MBED_ERROR_CODE_INVALID_INDEX
1000+
),
1001+
"The endpoint is not indexable."
1002+
);
1003+
#else
9501004
return;
1005+
#endif // defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
9511006
}
9521007

9531008
endpoint_info_t *info = &_endpoint_info[EP_TO_INDEX(endpoint)];
@@ -1056,9 +1111,18 @@ bool USBDevice::endpoint_add(usb_ep_t endpoint, uint32_t max_packet_size, usb_ep
10561111
lock();
10571112

10581113
if (!EP_INDEXABLE(endpoint)) {
1059-
MBED_ASSERT(0);
1114+
#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
1115+
MBED_ERROR(
1116+
MBED_MAKE_ERROR(
1117+
MBED_MODULE_DRIVER_USB,
1118+
MBED_ERROR_CODE_INVALID_INDEX
1119+
),
1120+
"The endpoint is not indexable."
1121+
);
1122+
#else
10601123
unlock();
10611124
return false;
1125+
#endif // defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
10621126
}
10631127

10641128
if (!_endpoint_add_remove_allowed) {
@@ -1087,9 +1151,18 @@ void USBDevice::endpoint_remove(usb_ep_t endpoint)
10871151
lock();
10881152

10891153
if (!EP_INDEXABLE(endpoint)) {
1090-
MBED_ASSERT(0);
1154+
#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
1155+
MBED_ERROR(
1156+
MBED_MAKE_ERROR(
1157+
MBED_MODULE_DRIVER_USB,
1158+
MBED_ERROR_CODE_INVALID_INDEX
1159+
),
1160+
"The endpoint is not indexable."
1161+
);
1162+
#else
10911163
unlock();
10921164
return;
1165+
#endif // defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
10931166
}
10941167

10951168
if (!_endpoint_add_remove_allowed) {
@@ -1133,9 +1206,18 @@ void USBDevice::endpoint_stall(usb_ep_t endpoint)
11331206
lock();
11341207

11351208
if (!EP_INDEXABLE(endpoint)) {
1136-
MBED_ASSERT(0);
1209+
#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
1210+
MBED_ERROR(
1211+
MBED_MAKE_ERROR(
1212+
MBED_MODULE_DRIVER_USB,
1213+
MBED_ERROR_CODE_INVALID_INDEX
1214+
),
1215+
"The endpoint is not indexable."
1216+
);
1217+
#else
11371218
unlock();
11381219
return;
1220+
#endif // defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
11391221
}
11401222

11411223
endpoint_info_t *info = &_endpoint_info[EP_TO_INDEX(endpoint)];
@@ -1161,9 +1243,18 @@ void USBDevice::endpoint_unstall(usb_ep_t endpoint)
11611243
lock();
11621244

11631245
if (!EP_INDEXABLE(endpoint)) {
1164-
MBED_ASSERT(0);
1246+
#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
1247+
MBED_ERROR(
1248+
MBED_MAKE_ERROR(
1249+
MBED_MODULE_DRIVER_USB,
1250+
MBED_ERROR_CODE_INVALID_INDEX
1251+
),
1252+
"The endpoint is not indexable."
1253+
);
1254+
#else
11651255
unlock();
11661256
return;
1257+
#endif // defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
11671258
}
11681259

11691260
endpoint_info_t *info = &_endpoint_info[EP_TO_INDEX(endpoint)];
@@ -1306,9 +1397,18 @@ void USBDevice::endpoint_abort(usb_ep_t endpoint)
13061397
lock();
13071398

13081399
if (!EP_INDEXABLE(endpoint)) {
1309-
MBED_ASSERT(0);
1400+
#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
1401+
MBED_ERROR(
1402+
MBED_MAKE_ERROR(
1403+
MBED_MODULE_DRIVER_USB,
1404+
MBED_ERROR_CODE_INVALID_INDEX
1405+
),
1406+
"The endpoint is not indexable."
1407+
);
1408+
#else
13101409
unlock();
13111410
return;
1411+
#endif // defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
13121412
}
13131413

13141414
endpoint_info_t *info = &_endpoint_info[EP_TO_INDEX(endpoint)];
@@ -1332,9 +1432,18 @@ bool USBDevice::read_start(usb_ep_t endpoint, uint8_t *buffer, uint32_t max_size
13321432
lock();
13331433

13341434
if (!EP_INDEXABLE(endpoint)) {
1335-
MBED_ASSERT(0);
1435+
#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
1436+
MBED_ERROR(
1437+
MBED_MAKE_ERROR(
1438+
MBED_MODULE_DRIVER_USB,
1439+
MBED_ERROR_CODE_INVALID_INDEX
1440+
),
1441+
"The endpoint is not indexable."
1442+
);
1443+
#else
13361444
unlock();
13371445
return false;
1446+
#endif // defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
13381447
}
13391448

13401449
endpoint_info_t *info = &_endpoint_info[EP_TO_INDEX(endpoint)];
@@ -1346,9 +1455,18 @@ bool USBDevice::read_start(usb_ep_t endpoint, uint8_t *buffer, uint32_t max_size
13461455
}
13471456

13481457
if (max_size < info->max_packet_size) {
1349-
MBED_ASSERT(0);
1458+
#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
1459+
MBED_ERROR(
1460+
MBED_MAKE_ERROR(
1461+
MBED_MODULE_DRIVER_USB,
1462+
MBED_ERROR_CODE_INVALID_SIZE
1463+
),
1464+
"The size of the data to read is less than the max packet size for this endpoint."
1465+
);
1466+
#else
13501467
unlock();
13511468
return false;
1469+
#endif // defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
13521470
}
13531471

13541472
if (info->pending) {
@@ -1372,9 +1490,18 @@ uint32_t USBDevice::read_finish(usb_ep_t endpoint)
13721490
lock();
13731491

13741492
if (!EP_INDEXABLE(endpoint)) {
1375-
MBED_ASSERT(0);
1493+
#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
1494+
MBED_ERROR(
1495+
MBED_MAKE_ERROR(
1496+
MBED_MODULE_DRIVER_USB,
1497+
MBED_ERROR_CODE_INVALID_INDEX
1498+
),
1499+
"The endpoint is not indexable."
1500+
);
1501+
#else
13761502
unlock();
13771503
return 0;
1504+
#endif // defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
13781505
}
13791506

13801507
endpoint_info_t *info = &_endpoint_info[EP_TO_INDEX(endpoint)];
@@ -1396,9 +1523,18 @@ bool USBDevice::write_start(usb_ep_t endpoint, uint8_t *buffer, uint32_t size)
13961523
lock();
13971524

13981525
if (!EP_INDEXABLE(endpoint)) {
1399-
MBED_ASSERT(0);
1526+
#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
1527+
MBED_ERROR(
1528+
MBED_MAKE_ERROR(
1529+
MBED_MODULE_DRIVER_USB,
1530+
MBED_ERROR_CODE_INVALID_INDEX
1531+
),
1532+
"The endpoint is not indexable"
1533+
);
1534+
#else
14001535
unlock();
14011536
return false;
1537+
#endif // defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
14021538
}
14031539

14041540
endpoint_info_t *info = &_endpoint_info[EP_TO_INDEX(endpoint)];
@@ -1410,10 +1546,18 @@ bool USBDevice::write_start(usb_ep_t endpoint, uint8_t *buffer, uint32_t size)
14101546
}
14111547

14121548
if (size > info->max_packet_size) {
1413-
// Size being written is too large
1414-
MBED_ASSERT(0);
1549+
#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
1550+
MBED_ERROR(
1551+
MBED_MAKE_ERROR(
1552+
MBED_MODULE_DRIVER_USB,
1553+
MBED_ERROR_CODE_INVALID_SIZE
1554+
),
1555+
"Size being written is too large."
1556+
);
1557+
#else
14151558
unlock();
14161559
return false;
1560+
#endif // defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
14171561
}
14181562

14191563
if (info->pending) {
@@ -1442,9 +1586,18 @@ uint32_t USBDevice::write_finish(usb_ep_t endpoint)
14421586
lock();
14431587

14441588
if (!EP_INDEXABLE(endpoint)) {
1445-
MBED_ASSERT(0);
1589+
#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
1590+
MBED_ERROR(
1591+
MBED_MAKE_ERROR(
1592+
MBED_MODULE_DRIVER_USB,
1593+
MBED_ERROR_CODE_INVALID_INDEX
1594+
),
1595+
"The endpoint is not indexable."
1596+
);
1597+
#else
14461598
unlock();
14471599
return 0;
1600+
#endif // defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
14481601
}
14491602

14501603
endpoint_info_t *info = &_endpoint_info[EP_TO_INDEX(endpoint)];

hal/mbed_pinmap_common.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ uint32_t pinmap_merge(uint32_t a, uint32_t b)
5252

5353
// mis-match error case
5454
MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_PINMAP_INVALID), "pinmap mis-match", a);
55-
return (uint32_t)NC;
5655
}
5756

5857
uint32_t pinmap_find_peripheral(PinName pin, const PinMap *map)

hal/mbed_ticker_api.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ static void initialize(const ticker_data_t *ticker)
4141

4242
const ticker_info_t *info = ticker->interface->get_info();
4343
uint32_t frequency = info->frequency;
44+
45+
MBED_ASSERT(info->frequency == 0);
4446
if (info->frequency == 0) {
45-
MBED_ASSERT(0);
4647
frequency = 1000000;
4748
}
4849

@@ -55,8 +56,8 @@ static void initialize(const ticker_data_t *ticker)
5556
}
5657

5758
uint32_t bits = info->bits;
59+
MBED_ASSERT((info->bits > 32) || (info->bits < 4));
5860
if ((info->bits > 32) || (info->bits < 4)) {
59-
MBED_ASSERT(0);
6061
bits = 32;
6162
}
6263
uint32_t max_delta = 0x7 << (bits - 4); // 7/16th

0 commit comments

Comments
 (0)