Skip to content

Commit 7241717

Browse files
committed
Use minimal printf by default inside the OS
1 parent 78267c2 commit 7241717

31 files changed

+157
-96
lines changed

drivers/AnalogIn.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ namespace mbed {
5757
* int main() {
5858
* while(1) {
5959
* if(temperature > 0.5) {
60-
* printf("Too hot! (%f)", temperature.read());
60+
* mbed_printf("Too hot! (%f)", temperature.read());
6161
* }
6262
* }
6363
* }

drivers/CAN.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class CAN : private NonCopyable<CAN> {
140140
*
141141
* void send() {
142142
* if(can1.write(CANMessage(1337U, &counter, 1))) {
143-
* printf("Message sent: %d\n", counter);
143+
* mbed_printf("Message sent: %d\n", counter);
144144
* counter++;
145145
* }
146146
* led1 = !led1;
@@ -151,7 +151,7 @@ class CAN : private NonCopyable<CAN> {
151151
* CANMessage msg;
152152
* while(1) {
153153
* if(can2.read(msg)) {
154-
* printf("Message received: %d\n\n", msg.data[0]);
154+
* mbed_printf("Message received: %d\n\n", msg.data[0]);
155155
* led2 = !led2;
156156
* }
157157
* wait(0.2);

drivers/Ethernet.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ namespace mbed {
5656
* int size = eth.receive();
5757
* if(size > 0) {
5858
* eth.read(buf, size);
59-
* printf("Destination: %02X:%02X:%02X:%02X:%02X:%02X\n",
59+
* mbed_printf("Destination: %02X:%02X:%02X:%02X:%02X:%02X\n",
6060
* buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
61-
* printf("Source: %02X:%02X:%02X:%02X:%02X:%02X\n",
61+
* mbed_printf("Source: %02X:%02X:%02X:%02X:%02X:%02X\n",
6262
* buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]);
6363
* }
6464
*
@@ -187,9 +187,9 @@ class
187187
* int main() {
188188
* wait(1); // Needed after startup.
189189
* if (eth.link()) {
190-
* printf("online\n");
190+
* mbed_printf("online\n");
191191
* } else {
192-
* printf("offline\n");
192+
* mbed_printf("offline\n");
193193
* }
194194
* }
195195
* @endcode

drivers/I2C.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ namespace mbed {
7474
* i2c.read( addr8bit, cmd, 2);
7575
*
7676
* float tmp = (float((cmd[0]<<8)|cmd[1]) / 256.0);
77-
* printf("Temp = %.2f\n", tmp);
77+
* mbed_printf("Temp = %.2f\n", tmp);
7878
* }
7979
* }
8080
* @endcode

drivers/I2CSlave.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,18 @@ namespace mbed {
5151
* case I2CSlave::ReadAddressed:
5252
* int status = slave.write(message, sizeof(message));
5353
* if (status == 0) {
54-
* printf("Written message: %s\n", message);
54+
* mbed_printf("Written message: %s\n", message);
5555
* } else {
56-
* printf("Failed to write message.\n");
56+
* mbed_printf("Failed to write message.\n");
5757
* }
5858
* break;
5959
* case I2CSlave::WriteGeneral:
6060
* int byte_read = slave.read();
61-
* printf("Read General: %c (%d)\n", byte_read, byte_read);
61+
* mbed_printf("Read General: %c (%d)\n", byte_read, byte_read);
6262
* break;
6363
* case I2CSlave::WriteAddressed:
6464
* int byte_read = slave.read();
65-
* printf("Read Addressed: %c (%d)\n", byte_read, byte_read);
65+
* mbed_printf("Read Addressed: %c (%d)\n", byte_read, byte_read);
6666
* break;
6767
* }
6868
* }

drivers/InterruptIn.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ namespace mbed {
4949
* DigitalOut led(LED1);
5050
*
5151
* void trigger() {
52-
* printf("triggered!\n");
52+
* mbed_printf("triggered!\n");
5353
* }
5454
*
5555
* int main() {

drivers/MbedCRC.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ constexpr CrcMode choose_crc_mode(uint32_t polynomial, uint8_t width, CrcMode mo
116116
* char test[] = "123456789";
117117
* uint32_t crc = 0;
118118
*
119-
* printf("\nPolynomial = 0x%lx Width = %d \n", ct.get_polynomial(), ct.get_width());
119+
* mbed_printf("\nPolynomial = 0x%lx Width = %d \n", ct.get_polynomial(), ct.get_width());
120120
*
121121
* ct.compute((void *)test, strlen((const char*)test), &crc);
122122
*
123-
* printf("The CRC of data \"123456789\" is : 0x%lx\n", crc);
123+
* mbed_printf("The CRC of data \"123456789\" is : 0x%lx\n", crc);
124124
* return 0;
125125
* }
126126
* @endcode
@@ -134,12 +134,12 @@ constexpr CrcMode choose_crc_mode(uint32_t polynomial, uint8_t width, CrcMode mo
134134
* char test[] = "123456789";
135135
* uint32_t crc = 0;
136136
*
137-
* printf("\nPolynomial = 0x%lx Width = %d \n", ct.get_polynomial(), ct.get_width());
137+
* mbed_printf("\nPolynomial = 0x%lx Width = %d \n", ct.get_polynomial(), ct.get_width());
138138
* ct.compute_partial_start(&crc);
139139
* ct.compute_partial((void *)&test, 4, &crc);
140140
* ct.compute_partial((void *)&test[4], 5, &crc);
141141
* ct.compute_partial_stop(&crc);
142-
* printf("The CRC of data \"123456789\" is : 0x%lx\n", crc);
142+
* mbed_printf("The CRC of data \"123456789\" is : 0x%lx\n", crc);
143143
* return 0;
144144
* }
145145
* @endcode

drivers/QSPI.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ typedef int qspi_inst_t;
7373
*
7474
* qspi_status_t result = qspi_device.write(CMD_WRITE, 0, ADDRESS, tx_buf, &buf_len);
7575
* if (result != QSPI_STATUS_OK) {
76-
* printf("Write failed");
76+
* mbed_printf("Write failed");
7777
* }
7878
* result = qspi_device.read(CMD_READ, 0, ADDRESS, rx_buf, &buf_len);
7979
* if (result != QSPI_STATUS_OK) {
80-
* printf("Read failed");
80+
* mbed_printf("Read failed");
8181
* }
8282
*
8383
* }

drivers/ResetReason.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class ResetReason {
4747
* const reset_reason_t reason = ResetReason::get();
4848
*
4949
* if (reason == RESET_REASON_WATCHDOG) {
50-
* printf("Watchdog reset\n");
50+
* mbed_printf("Watchdog reset\n");
5151
* rollback();
5252
* }
5353
* @endcode

drivers/Timer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ namespace mbed {
4747
* begin = timer.read_us();
4848
* led = !led;
4949
* end = timer.read_us();
50-
* printf("Toggle the led takes %d us", end - begin);
50+
* mbed_printf("Toggle the led takes %d us", end - begin);
5151
* }
5252
* @endcode
5353
*/

drivers/USBAudio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
*
5656
* USBAudio audio(true, 44100, 2, 44100, 2);
5757
*
58-
* printf("Looping audio\r\n");
58+
* mbed_printf("Looping audio\r\n");
5959
* static uint8_t buf[128];
6060
* while (true) {
6161
* if (!audio.read(buf, sizeof(buf))) {

drivers/source/RawSerial.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* limitations under the License.
1616
*/
1717
#include "drivers/RawSerial.h"
18+
#include "platform/mbed_printf.h"
1819
#include <stdio.h>
1920

2021

@@ -74,14 +75,14 @@ int RawSerial::vprintf(const char *format, std::va_list arg)
7475
// ARMCC microlib does not properly handle a size of 0.
7576
// As a workaround supply a dummy buffer with a size of 1.
7677
char dummy_buf[1];
77-
int len = vsnprintf(dummy_buf, sizeof(dummy_buf), format, arg);
78+
int len = mbed_vsnprintf(dummy_buf, sizeof(dummy_buf), format, arg);
7879
if (len < STRING_STACK_LIMIT) {
7980
char temp[STRING_STACK_LIMIT];
80-
vsprintf(temp, format, arg);
81+
mbed_vsprintf(temp, format, arg);
8182
puts(temp);
8283
} else {
8384
char *temp = new char[len + 1];
84-
vsprintf(temp, format, arg);
85+
mbed_vsprintf(temp, format, arg);
8586
puts(temp);
8687
delete[] temp;
8788
}

drivers/source/usb/USBCDC_ECM.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ void USBCDC_ECM::callback_request(const setup_packet_t *setup)
277277
uint32_t size = 0;
278278

279279
if (setup->bmRequestType.Type == CLASS_TYPE) {
280-
//printf("In USBCallback_request: CLASS specific Request: %02x\n", setup->bRequest);
280+
//mbed_printf("In USBCallback_request: CLASS specific Request: %02x\n", setup->bRequest);
281281
switch (setup->bRequest) {
282282
case SET_ETHERNET_MULTICAST_FILTERS:
283283
/* TODO: Support is optional, not implemented here */

drivers/source/usb/USBDevice.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "usb_phy_api.h"
2424
#include "mbed_assert.h"
2525
#include "platform/mbed_error.h"
26+
#include "platform/mbed_printf.h"
2627

2728
//#define DEBUG
2829

@@ -64,15 +65,15 @@ bool USBDevice::_request_get_descriptor()
6465

6566
bool success = false;
6667
#ifdef DEBUG
67-
printf("get descr: type: %d\r\n", DESCRIPTOR_TYPE(_transfer.setup.wValue));
68+
mbed_printf("get descr: type: %d\r\n", DESCRIPTOR_TYPE(_transfer.setup.wValue));
6869
#endif
6970
switch (DESCRIPTOR_TYPE(_transfer.setup.wValue)) {
7071
case DEVICE_DESCRIPTOR: {
7172
if (device_desc() != NULL) {
7273
if ((device_desc()[0] == DEVICE_DESCRIPTOR_LENGTH) \
7374
&& (device_desc()[1] == DEVICE_DESCRIPTOR)) {
7475
#ifdef DEBUG
75-
printf("device descr\r\n");
76+
mbed_printf("device descr\r\n");
7677
#endif
7778
_transfer.remaining = DEVICE_DESCRIPTOR_LENGTH;
7879
_transfer.ptr = (uint8_t *)device_desc();
@@ -88,7 +89,7 @@ bool USBDevice::_request_get_descriptor()
8889
if ((configuration_desc(idx)[0] == CONFIGURATION_DESCRIPTOR_LENGTH) \
8990
&& (configuration_desc(idx)[1] == CONFIGURATION_DESCRIPTOR)) {
9091
#ifdef DEBUG
91-
printf("conf descr request\r\n");
92+
mbed_printf("conf descr request\r\n");
9293
#endif
9394
/* Get wTotalLength */
9495
_transfer.remaining = configuration_desc(idx)[2] \
@@ -103,12 +104,12 @@ bool USBDevice::_request_get_descriptor()
103104
}
104105
case STRING_DESCRIPTOR: {
105106
#ifdef DEBUG
106-
printf("str descriptor\r\n");
107+
mbed_printf("str descriptor\r\n");
107108
#endif
108109
switch (DESCRIPTOR_INDEX(_transfer.setup.wValue)) {
109110
case STRING_OFFSET_LANGID:
110111
#ifdef DEBUG
111-
printf("1\r\n");
112+
mbed_printf("1\r\n");
112113
#endif
113114
_transfer.remaining = string_langid_desc()[0];
114115
_transfer.ptr = (uint8_t *)string_langid_desc();
@@ -117,7 +118,7 @@ bool USBDevice::_request_get_descriptor()
117118
break;
118119
case STRING_OFFSET_IMANUFACTURER:
119120
#ifdef DEBUG
120-
printf("2\r\n");
121+
mbed_printf("2\r\n");
121122
#endif
122123
_transfer.remaining = string_imanufacturer_desc()[0];
123124
_transfer.ptr = (uint8_t *)string_imanufacturer_desc();
@@ -126,7 +127,7 @@ bool USBDevice::_request_get_descriptor()
126127
break;
127128
case STRING_OFFSET_IPRODUCT:
128129
#ifdef DEBUG
129-
printf("3\r\n");
130+
mbed_printf("3\r\n");
130131
#endif
131132
_transfer.remaining = string_iproduct_desc()[0];
132133
_transfer.ptr = (uint8_t *)string_iproduct_desc();
@@ -135,7 +136,7 @@ bool USBDevice::_request_get_descriptor()
135136
break;
136137
case STRING_OFFSET_ISERIAL:
137138
#ifdef DEBUG
138-
printf("4\r\n");
139+
mbed_printf("4\r\n");
139140
#endif
140141
_transfer.remaining = string_iserial_desc()[0];
141142
_transfer.ptr = (uint8_t *)string_iserial_desc();
@@ -144,7 +145,7 @@ bool USBDevice::_request_get_descriptor()
144145
break;
145146
case STRING_OFFSET_ICONFIGURATION:
146147
#ifdef DEBUG
147-
printf("5\r\n");
148+
mbed_printf("5\r\n");
148149
#endif
149150
_transfer.remaining = string_iconfiguration_desc()[0];
150151
_transfer.ptr = (uint8_t *)string_iconfiguration_desc();
@@ -153,7 +154,7 @@ bool USBDevice::_request_get_descriptor()
153154
break;
154155
case STRING_OFFSET_IINTERFACE:
155156
#ifdef DEBUG
156-
printf("6\r\n");
157+
mbed_printf("6\r\n");
157158
#endif
158159
_transfer.remaining = string_iinterface_desc()[0];
159160
_transfer.ptr = (uint8_t *)string_iinterface_desc();
@@ -165,20 +166,20 @@ bool USBDevice::_request_get_descriptor()
165166
}
166167
case INTERFACE_DESCRIPTOR: {
167168
#ifdef DEBUG
168-
printf("interface descr\r\n");
169+
mbed_printf("interface descr\r\n");
169170
#endif
170171
break;
171172
}
172173
case ENDPOINT_DESCRIPTOR: {
173174
#ifdef DEBUG
174-
printf("endpoint descr\r\n");
175+
mbed_printf("endpoint descr\r\n");
175176
#endif
176177
/* TODO: Support is optional, not implemented here */
177178
break;
178179
}
179180
default: {
180181
#ifdef DEBUG
181-
printf("ERROR\r\n");
182+
mbed_printf("ERROR\r\n");
182183
#endif
183184
break;
184185
}
@@ -678,7 +679,7 @@ void USBDevice::_control_setup()
678679
_transfer.user_callback = Request;
679680

680681
#ifdef DEBUG
681-
printf("dataTransferDirection: %d\r\nType: %d\r\nRecipient: %d\r\nbRequest: %d\r\nwValue: %d\r\nwIndex: %d\r\nwLength: %d\r\n", _transfer.setup.bmRequestType.dataTransferDirection,
682+
mbed_printf("dataTransferDirection: %d\r\nType: %d\r\nRecipient: %d\r\nbRequest: %d\r\nwValue: %d\r\nwIndex: %d\r\nwLength: %d\r\n", _transfer.setup.bmRequestType.dataTransferDirection,
682683
_transfer.setup.bmRequestType.Type,
683684
_transfer.setup.bmRequestType.Recipient,
684685
_transfer.setup.bRequest,
@@ -945,7 +946,7 @@ void USBDevice::ep0_in()
945946
}
946947

947948
#ifdef DEBUG
948-
printf("ep0_in\r\n");
949+
mbed_printf("ep0_in\r\n");
949950
#endif
950951
if (_transfer.stage == Status) {
951952
// No action needed on status stage

0 commit comments

Comments
 (0)