From f6a35f76af96ca211d92df51c4cd70b4061ef985 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 9 Mar 2023 11:08:46 +1100 Subject: [PATCH] stm32/modmachine: Make machine.info print using mp_printf. Signed-off-by: Damien George --- ports/stm32/modmachine.c | 47 ++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/ports/stm32/modmachine.c b/ports/stm32/modmachine.c index f51a2fd703..0021ef1c48 100644 --- a/ports/stm32/modmachine.c +++ b/ports/stm32/modmachine.c @@ -24,7 +24,6 @@ * THE SOFTWARE. */ -#include #include #include "modmachine.h" @@ -163,24 +162,26 @@ void machine_deinit(void) { // machine.info([dump_alloc_table]) // Print out lots of information about the board. STATIC mp_obj_t machine_info(size_t n_args, const mp_obj_t *args) { + const mp_print_t *print = &mp_plat_print; + // get and print unique id; 96 bits { byte *id = (byte *)MP_HAL_UNIQUE_ID_ADDRESS; - printf("ID=%02x%02x%02x%02x:%02x%02x%02x%02x:%02x%02x%02x%02x\n", id[0], id[1], id[2], id[3], id[4], id[5], id[6], id[7], id[8], id[9], id[10], id[11]); + mp_printf(print, "ID=%02x%02x%02x%02x:%02x%02x%02x%02x:%02x%02x%02x%02x\n", id[0], id[1], id[2], id[3], id[4], id[5], id[6], id[7], id[8], id[9], id[10], id[11]); } - printf("DEVID=0x%04x\nREVID=0x%04x\n", (unsigned int)HAL_GetDEVID(), (unsigned int)HAL_GetREVID()); + mp_printf(print, "DEVID=0x%04x\nREVID=0x%04x\n", (unsigned int)HAL_GetDEVID(), (unsigned int)HAL_GetREVID()); // get and print clock speeds // SYSCLK=168MHz, HCLK=168MHz, PCLK1=42MHz, PCLK2=84MHz { #if defined(STM32F0) || defined(STM32G0) - printf("S=%u\nH=%u\nP1=%u\n", + mp_printf(print, "S=%u\nH=%u\nP1=%u\n", (unsigned int)HAL_RCC_GetSysClockFreq(), (unsigned int)HAL_RCC_GetHCLKFreq(), (unsigned int)HAL_RCC_GetPCLK1Freq()); #else - printf("S=%u\nH=%u\nP1=%u\nP2=%u\n", + mp_printf(print, "S=%u\nH=%u\nP1=%u\nP2=%u\n", (unsigned int)HAL_RCC_GetSysClockFreq(), (unsigned int)HAL_RCC_GetHCLKFreq(), (unsigned int)HAL_RCC_GetPCLK1Freq(), @@ -190,35 +191,35 @@ STATIC mp_obj_t machine_info(size_t n_args, const mp_obj_t *args) { // to print info about memory { - printf("_etext=%p\n", &_etext); - printf("_sidata=%p\n", &_sidata); - printf("_sdata=%p\n", &_sdata); - printf("_edata=%p\n", &_edata); - printf("_sbss=%p\n", &_sbss); - printf("_ebss=%p\n", &_ebss); - printf("_sstack=%p\n", &_sstack); - printf("_estack=%p\n", &_estack); - printf("_ram_start=%p\n", &_ram_start); - printf("_heap_start=%p\n", &_heap_start); - printf("_heap_end=%p\n", &_heap_end); - printf("_ram_end=%p\n", &_ram_end); + mp_printf(print, "_etext=%p\n", &_etext); + mp_printf(print, "_sidata=%p\n", &_sidata); + mp_printf(print, "_sdata=%p\n", &_sdata); + mp_printf(print, "_edata=%p\n", &_edata); + mp_printf(print, "_sbss=%p\n", &_sbss); + mp_printf(print, "_ebss=%p\n", &_ebss); + mp_printf(print, "_sstack=%p\n", &_sstack); + mp_printf(print, "_estack=%p\n", &_estack); + mp_printf(print, "_ram_start=%p\n", &_ram_start); + mp_printf(print, "_heap_start=%p\n", &_heap_start); + mp_printf(print, "_heap_end=%p\n", &_heap_end); + mp_printf(print, "_ram_end=%p\n", &_ram_end); } // qstr info { size_t n_pool, n_qstr, n_str_data_bytes, n_total_bytes; qstr_pool_info(&n_pool, &n_qstr, &n_str_data_bytes, &n_total_bytes); - printf("qstr:\n n_pool=%u\n n_qstr=%u\n n_str_data_bytes=%u\n n_total_bytes=%u\n", n_pool, n_qstr, n_str_data_bytes, n_total_bytes); + mp_printf(print, "qstr:\n n_pool=%u\n n_qstr=%u\n n_str_data_bytes=%u\n n_total_bytes=%u\n", n_pool, n_qstr, n_str_data_bytes, n_total_bytes); } // GC info { gc_info_t info; gc_info(&info); - printf("GC:\n"); - printf(" %u total\n", info.total); - printf(" %u : %u\n", info.used, info.free); - printf(" 1=%u 2=%u m=%u\n", info.num_1block, info.num_2block, info.max_block); + mp_printf(print, "GC:\n"); + mp_printf(print, " %u total\n", info.total); + mp_printf(print, " %u : %u\n", info.used, info.free); + mp_printf(print, " 1=%u 2=%u m=%u\n", info.num_1block, info.num_2block, info.max_block); } // free space on flash @@ -230,7 +231,7 @@ STATIC mp_obj_t machine_info(size_t n_args, const mp_obj_t *args) { fs_user_mount_t *vfs_fat = MP_OBJ_TO_PTR(vfs->obj); DWORD nclst; f_getfree(&vfs_fat->fatfs, &nclst); - printf("LFS free: %u bytes\n", (uint)(nclst * vfs_fat->fatfs.csize * 512)); + mp_printf(print, "LFS free: %u bytes\n", (uint)(nclst * vfs_fat->fatfs.csize * 512)); break; } }