Skip to content

[RFC] Use minimal printf by default inside the OS #12168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions UNITTESTS/platform/ATCmdParser/unittest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# Source files
set(unittest-sources
../platform/source/ATCmdParser.cpp
../platform/source/minimal-printf/mbed_printf.c
../platform/source/minimal-printf/mbed_printf_implementation.c
)

# Test files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ using namespace mbed;
#endif /* DATAFLASH_DEBUG */

#if DATAFLASH_DEBUG
#define DEBUG_PRINTF(...) printf(__VA_ARGS__)
#define DEBUG_PRINTF(...) mbed_printf(__VA_ARGS__)
#else
#define DEBUG_PRINTF(...)
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,24 @@
* DataFlashBlockDevice dataflash2(PTE2, PTE4, PTE1, PTE5, PTE6);
*
* int main() {
* printf("dataflash test\n");
* mbed_printf("dataflash test\n");
*
* // Initialize the SPI flash device and print the memory layout
* dataflash.init();
* printf("dataflash size: %llu\n", dataflash.size());
* printf("dataflash read size: %llu\n", dataflash.get_read_size());
* printf("dataflash program size: %llu\n", dataflash.get_program_size());
* printf("dataflash erase size: %llu\n", dataflash.get_erase_size());
* mbed_printf("dataflash size: %llu\n", dataflash.size());
* mbed_printf("dataflash read size: %llu\n", dataflash.get_read_size());
* mbed_printf("dataflash program size: %llu\n", dataflash.get_program_size());
* mbed_printf("dataflash erase size: %llu\n", dataflash.get_erase_size());
*
* // Write "Hello World!" to the first block
* char *buffer = (char*)malloc(dataflash.get_erase_size());
* sprintf(buffer, "Hello World!\n");
* mbed_sprintf(buffer, "Hello World!\n");
* dataflash.erase(0, dataflash.get_erase_size());
* dataflash.program(buffer, 0, dataflash.get_erase_size());
*
* // Read back what was stored
* dataflash.read(buffer, 0, dataflash.get_erase_size());
* printf("%s", buffer);
* mbed_printf("%s", buffer);
*
* // Deinitialize the device
* dataflash.deinit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#define FSLITTLE_LOG(_fmt, ...) \
do \
{ \
printf(_fmt, __VA_ARGS__); \
mbed_printf(_fmt, __VA_ARGS__); \
}while(0);

#define noFSLITTLE_DEBUG
Expand All @@ -64,7 +64,7 @@ extern uint32_t fslittle_optLogLevel_g;
{ \
if(fslittle_optDebug_g && (fslittle_optLogLevel_g >= FSLITTLE_LOG_DEBUG)) \
{ \
printf(_fmt, __VA_ARGS__); \
mbed_printf(_fmt, __VA_ARGS__); \
} \
}while(0);

Expand All @@ -74,7 +74,7 @@ extern uint32_t fslittle_optLogLevel_g;
{ \
if(fslittle_optDebug_g && (fslittle_optLogLevel_g >= FSLITTLE_LOG_ERR)) \
{ \
printf(_fmt, __VA_ARGS__); \
mbed_printf(_fmt, __VA_ARGS__); \
} \
}while(0);

Expand All @@ -84,7 +84,7 @@ extern uint32_t fslittle_optLogLevel_g;
{ \
if(fslittle_optDebug_g && (fslittle_optLogLevel_g >= FSLITTLE_LOG_FENTRY)) \
{ \
printf(_fmt, __VA_ARGS__); \
mbed_printf(_fmt, __VA_ARGS__); \
} \
}while(0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extern "C" {
#define FSLITTLE_TEST_UTEST_MESSAGE(_buf, _max_len, _fmt, ...) \
do \
{ \
snprintf((_buf), (_max_len), (_fmt), __VA_ARGS__); \
mbed_snprintf((_buf), (_max_len), (_fmt), __VA_ARGS__); \
}while(0);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ using namespace mbed;
#endif

#if FLASHIAP_DEBUG
#define DEBUG_PRINTF(...) printf(__VA_ARGS__)
#define DEBUG_PRINTF(...) mbed_printf(__VA_ARGS__)
#else
#define DEBUG_PRINTF(...)
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,24 @@
* I2CEEBlockDevice i2cee(D14, D15, 0xa0, 32*1024);
*
* int main() {
* printf("i2cee test\n");
* mbed_printf("i2cee test\n");
*
* // Initialize the device and print the memory layout
* i2cee.init();
* printf("i2cee size: %llu\n", i2cee.size());
* printf("i2cee read size: %llu\n", i2cee.get_read_size());
* printf("i2cee program size: %llu\n", i2cee.get_program_size());
* printf("i2cee erase size: %llu\n", i2cee.get_erase_size());
* mbed_printf("i2cee size: %llu\n", i2cee.size());
* mbed_printf("i2cee read size: %llu\n", i2cee.get_read_size());
* mbed_printf("i2cee program size: %llu\n", i2cee.get_program_size());
* mbed_printf("i2cee erase size: %llu\n", i2cee.get_erase_size());
*
* // Write "Hello World!" to the first block
* char *buffer = (char*)malloc(i2cee.get_erase_size());
* sprintf(buffer, "Hello World!\n");
* mbed_sprintf(buffer, "Hello World!\n");
* i2cee.erase(0, i2cee.get_erase_size());
* i2cee.program(buffer, 0, i2cee.get_erase_size());
*
* // Read back what was stored
* i2cee.read(buffer, 0, i2cee.get_erase_size());
* printf("%s", buffer);
* mbed_printf("%s", buffer);
*
* // Deinitialize the device
* i2cee.deinit();
Expand Down
22 changes: 11 additions & 11 deletions components/storage/blockdevice/COMPONENT_I2CEE/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@ https://en.wikipedia.org/wiki/EEPROM
I2CEEBlockDevice i2cee(D14, D15, 0xa0, 32*1024);

int main() {
printf("i2cee test\n");
mbed_printf("i2cee test\n");

// Initialize the device and print the memory layout
i2cee.init();
printf("i2cee size: %llu\n", i2cee.size());
printf("i2cee read size: %llu\n", i2cee.get_read_size());
printf("i2cee program size: %llu\n", i2cee.get_program_size());
printf("i2cee erase size: %llu\n", i2cee.get_erase_size());
mbed_printf("i2cee size: %llu\n", i2cee.size());
mbed_printf("i2cee read size: %llu\n", i2cee.get_read_size());
mbed_printf("i2cee program size: %llu\n", i2cee.get_program_size());
mbed_printf("i2cee erase size: %llu\n", i2cee.get_erase_size());

// Write "Hello World!" to the first block
char *buffer = (char*)malloc(i2cee.get_erase_size());
sprintf(buffer, "Hello World!\n");
mbed_sprintf(buffer, "Hello World!\n");
i2cee.erase(0, i2cee.get_erase_size());
i2cee.program(buffer, 0, i2cee.get_erase_size());

// Read back what was stored
i2cee.read(buffer, 0, i2cee.get_erase_size());
printf("%s", buffer);
mbed_printf("%s", buffer);

// Deinitialize the device
i2cee.deinit();
Expand Down Expand Up @@ -66,7 +66,7 @@ struct t_setting {
};

int main() {
printf("i2cee struct test\n");
mbed_printf("i2cee struct test\n");

// No. of bytes to be stored, but topped up to be multiplied by block size
unsigned int setting_block_size = ceil(sizeof(setting)/(double)BLOCK_SIZE)*BLOCK_SIZE;
Expand All @@ -78,7 +78,7 @@ int main() {
i2cee.init();

// Save struct to EEPROM
printf("\nSaving struct version: %u, name: %s\n", setting.version, setting.name);
mbed_printf("\nSaving struct version: %u, name: %s\n", setting.version, setting.name);
memcpy(buffer, &setting, sizeof(setting));
i2cee.program(buffer, 0, setting_block_size);

Expand All @@ -89,9 +89,9 @@ int main() {
if (i2cee.read(buffer, 0, setting_block_size ) == 0){ // get data into buffer
// Convert what we read into struct
memcpy(&tmp, buffer, sizeof(tmp)); // copy only size of struct not setting_block_size
printf("\nTemporary struct version: %u, name: %s\n", tmp.version, tmp.name);
mbed_printf("\nTemporary struct version: %u, name: %s\n", tmp.version, tmp.name);
} else {
printf("Error when reading\n");
mbed_printf("Error when reading\n");
}

// Deinitialize the device
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void test_read_write()
bd_size_t size = (bd.*ATTRS[a].method)();

if (size >= (1ULL << 10 * i)) {
printf("%s: %llu%sbytes (%llubytes)\n",
mbed_printf("%s: %llu%sbytes (%llubytes)\n",
ATTRS[a].name, size >> 10 * i, prefixes[i], size);
break;
}
Expand Down Expand Up @@ -71,40 +71,40 @@ void test_read_write()
}

// Write, sync, and read the block
printf("test %0*llx:%llu...\n", addrwidth, block, block_size);
mbed_printf("test %0*llx:%llu...\n", addrwidth, block, block_size);

err = bd.erase(block, block_size);
TEST_ASSERT_EQUAL(0, err);

err = bd.program(write_block, block, block_size);
TEST_ASSERT_EQUAL(0, err);

printf("write %0*llx:%llu ", addrwidth, block, block_size);
mbed_printf("write %0*llx:%llu ", addrwidth, block, block_size);

for (int i = 0; i < block_size && i < 16; i++) {
printf("%02x", write_block[i]);
mbed_printf("%02x", write_block[i]);
}

if (block_size > 16) {
printf("...\n");
mbed_printf("...\n");
}

printf("\n");
mbed_printf("\n");

err = bd.read(read_block, block, block_size);
TEST_ASSERT_EQUAL(0, err);

printf("read %0*llx:%llu ", addrwidth, block, block_size);
mbed_printf("read %0*llx:%llu ", addrwidth, block, block_size);

for (int i = 0; i < block_size && i < 16; i++) {
printf("%02x", read_block[i]);
mbed_printf("%02x", read_block[i]);
}

if (block_size > 16) {
printf("...");
mbed_printf("...");
}

printf("\n");
mbed_printf("\n");

// Find error mask for debugging
memset(error_mask, 0, TEST_ERROR_MASK);
Expand All @@ -120,13 +120,13 @@ void test_read_write()
}
}

printf("error %0*llx:%llu ", addrwidth, block, block_size);
mbed_printf("error %0*llx:%llu ", addrwidth, block, block_size);

for (int i = 0; i < TEST_ERROR_MASK; i++) {
printf("%02x", error_mask[i]);
mbed_printf("%02x", error_mask[i]);
}

printf("\n");
mbed_printf("\n");

// Check that the data was unmodified
srand(seed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,26 @@ enum qspif_polarity_mode {
*
* int main()
* {
* printf("QSPI SFDP Flash Block Device example\n");
* mbed_printf("QSPI SFDP Flash Block Device example\n");
*
* // Initialize the SPI flash device and print the memory layout
* block_device.init();
* bd_size_t sector_size_at_address_0 = block_device.get_erase_size(0);
*
* printf("QSPIF BD size: %llu\n", block_device.size());
* printf("QSPIF BD read size: %llu\n", block_device.get_read_size());
* printf("QSPIF BD program size: %llu\n", block_device.get_program_size());
* printf("QSPIF BD erase size (at address 0): %llu\n", sector_size_at_address_0);
* mbed_printf("QSPIF BD size: %llu\n", block_device.size());
* mbed_printf("QSPIF BD read size: %llu\n", block_device.get_read_size());
* mbed_printf("QSPIF BD program size: %llu\n", block_device.get_program_size());
* mbed_printf("QSPIF BD erase size (at address 0): %llu\n", sector_size_at_address_0);
*
* // Write "Hello World!" to the first block
* char *buffer = (char *) malloc(sector_size_at_address_0);
* sprintf(buffer, "Hello World!\n");
* mbed_sprintf(buffer, "Hello World!\n");
* block_device.erase(0, sector_size_at_address_0);
* block_device.program(buffer, 0, sector_size_at_address_0);
*
* // Read back what was stored
* block_device.read(buffer, 0, sector_size_at_address_0);
* printf("%s", buffer);
* mbed_printf("%s", buffer);
*
* // Deinitialize the device
* block_device.deinit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,22 +157,22 @@ void SPIFReducedBlockDevice::_cmdread(
_cs = 1;

if (SPIF_DEBUG) {
printf("spif <- %02x", op);
mbed_printf("spif <- %02x", op);
for (uint32_t i = 0; i < addrc; i++) {
if (i < addrc) {
printf("%02lx", 0xff & (addr >> 8 * (addrc - 1 - i)));
mbed_printf("%02lx", 0xff & (addr >> 8 * (addrc - 1 - i)));
} else {
printf(" ");
mbed_printf(" ");
}
}
printf(" ");
mbed_printf(" ");
for (uint32_t i = 0; i < 16 && i < retc; i++) {
printf("%02x", rets[i]);
mbed_printf("%02x", rets[i]);
}
if (retc > 16) {
printf("...");
mbed_printf("...");
}
printf("\n");
mbed_printf("\n");
}
}

Expand All @@ -193,22 +193,22 @@ void SPIFReducedBlockDevice::_cmdwrite(
_cs = 1;

if (SPIF_DEBUG) {
printf("spif -> %02x", op);
mbed_printf("spif -> %02x", op);
for (uint32_t i = 0; i < addrc; i++) {
if (i < addrc) {
printf("%02lx", 0xff & (addr >> 8 * (addrc - 1 - i)));
mbed_printf("%02lx", 0xff & (addr >> 8 * (addrc - 1 - i)));
} else {
printf(" ");
mbed_printf(" ");
}
}
printf(" ");
mbed_printf(" ");
for (uint32_t i = 0; i < 16 && i < argc; i++) {
printf("%02x", args[i]);
mbed_printf("%02x", args[i]);
}
if (argc > 16) {
printf("...");
mbed_printf("...");
}
printf("\n");
mbed_printf("\n");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,24 @@
* SPIFReducedBlockDevice rspif(PTE2, PTE4, PTE1, PTE5);
*
* int main() {
* printf("reduced spif test\n");
* mbed_printf("reduced spif test\n");
*
* // Initialize the Reduced SPI flash device and print the memory layout
* rspif.init();
* printf("rspif size: %llu\n", rspif.size());
* printf("rspif read size: %llu\n", rspif.get_read_size());
* printf("rspif program size: %llu\n", rspif.get_program_size());
* printf("rspif erase size: %llu\n", rspif.get_erase_size());
* mbed_printf("rspif size: %llu\n", rspif.size());
* mbed_printf("rspif read size: %llu\n", rspif.get_read_size());
* mbed_printf("rspif program size: %llu\n", rspif.get_program_size());
* mbed_printf("rspif erase size: %llu\n", rspif.get_erase_size());
*
* // Write "Hello World!" to the first block
* char *buffer = (char*)malloc(rspif.get_erase_size());
* sprintf(buffer, "Hello World!\n");
* mbed_sprintf(buffer, "Hello World!\n");
* rspif.erase(0, rspif.get_erase_size());
* rspif.program(buffer, 0, rspif.get_erase_size());
*
* // Read back what was stored
* rspif.read(buffer, 0, rspif.get_erase_size());
* printf("%s", buffer);
* mbed_printf("%s", buffer);
*
* // Deinitialize the device
* rspif.deinit();
Expand Down
Loading