From 6ce7792045066a4526d7acad085931d0908eaff2 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Wed, 2 Feb 2022 20:58:21 +0100 Subject: [PATCH 1/2] Remove "hh" in fmt where it makes no difference --- Firmware/ConfigurationStore.cpp | 4 ++-- Firmware/Marlin_main.cpp | 8 ++++---- Firmware/cmdqueue.cpp | 2 +- Firmware/fsensor.cpp | 18 +++++++++--------- Firmware/mmu.cpp | 4 ++-- Firmware/pat9125.c | 4 ++-- Firmware/tmc2130.cpp | 10 +++++----- Firmware/ultralcd.cpp | 6 +++--- 8 files changed, 28 insertions(+), 28 deletions(-) diff --git a/Firmware/ConfigurationStore.cpp b/Firmware/ConfigurationStore.cpp index adccb399..f7909a6d 100644 --- a/Firmware/ConfigurationStore.cpp +++ b/Firmware/ConfigurationStore.cpp @@ -32,7 +32,7 @@ static bool EEPROM_writeData(uint8_t* pos, uint8_t* value, uint8_t size, const c #endif //DEBUG_EEPROM_WRITE { #ifdef DEBUG_EEPROM_WRITE - printf_P(PSTR("EEPROM_WRITE_VAR addr=0x%04x size=0x%02hhx name=%s\n"), pos, size, name); + printf_P(PSTR("EEPROM_WRITE_VAR addr=0x%04x size=0x%02x name=%s\n"), pos, size, name); #endif //DEBUG_EEPROM_WRITE while (size--) { @@ -56,7 +56,7 @@ static void EEPROM_readData(uint8_t* pos, uint8_t* value, uint8_t size, const ch #endif //DEBUG_EEPROM_READ { #ifdef DEBUG_EEPROM_READ - printf_P(PSTR("EEPROM_READ_VAR addr=0x%04x size=0x%02hhx name=%s\n"), pos, size, name); + printf_P(PSTR("EEPROM_READ_VAR addr=0x%04x size=0x%02x name=%s\n"), pos, size, name); #endif //DEBUG_EEPROM_READ while(size--) { diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 5b6c3171..b04ffcdb 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -1518,7 +1518,7 @@ void setup() xflash_rd_uid(uid); puts_P(_n("XFLASH UID=")); for (uint8_t i = 0; i < 8; i ++) - printf_P(PSTR("%02hhx"), uid[i]); + printf_P(PSTR("%02x"), uid[i]); putchar('\n'); list_sec_lang_from_external_flash(); #endif //DEBUG_XFLASH @@ -4450,7 +4450,7 @@ void process_commands() tmc2130_chopper_config[axis].hend = chop2 & 15; tmc2130_chopper_config[axis].tbl = chop3 & 3; tmc2130_setup_chopper(axis, tmc2130_mres[axis], tmc2130_current_h[axis], tmc2130_current_r[axis]); - //printf_P(_N("TMC_SET_CHOP_%c %hhd %hhd %hhd %hhd\n"), "xyze"[axis], chop0, chop1, chop2, chop3); + //printf_P(_N("TMC_SET_CHOP_%c %d %d %d %d\n"), "xyze"[axis], chop0, chop1, chop2, chop3); } } } @@ -4459,7 +4459,7 @@ void process_commands() { uint8_t bl = (uint8_t)strtol(CMDBUFFER_CURRENT_STRING + 10, NULL, 10); st_backlash_x = bl; - printf_P(_N("st_backlash_x = %hhd\n"), st_backlash_x); + printf_P(_N("st_backlash_x = %d\n"), st_backlash_x); } #endif //BACKLASH_X #ifdef BACKLASH_Y @@ -4467,7 +4467,7 @@ void process_commands() { uint8_t bl = (uint8_t)strtol(CMDBUFFER_CURRENT_STRING + 10, NULL, 10); st_backlash_y = bl; - printf_P(_N("st_backlash_y = %hhd\n"), st_backlash_y); + printf_P(_N("st_backlash_y = %d\n"), st_backlash_y); } #endif //BACKLASH_Y #endif //TMC2130 diff --git a/Firmware/cmdqueue.cpp b/Firmware/cmdqueue.cpp index 1d4e2b92..0342c19d 100755 --- a/Firmware/cmdqueue.cpp +++ b/Firmware/cmdqueue.cpp @@ -94,7 +94,7 @@ void cmdqueue_reset() { while (buflen) { - // printf_P(PSTR("dumping: \"%s\" of type %hu\n"), cmdbuffer+bufindr+CMDHDRSIZE, CMDBUFFER_CURRENT_TYPE); + // printf_P(PSTR("dumping: \"%s\" of type %u\n"), cmdbuffer+bufindr+CMDHDRSIZE, CMDBUFFER_CURRENT_TYPE); ClearToSend(); cmdqueue_pop_front(); } diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index ac7d202e..3eab4538 100755 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -188,7 +188,7 @@ void fsensor_init(void) { #ifdef PAT9125 uint8_t pat9125 = pat9125_init(); - printf_P(PSTR("PAT9125_init:%hhu\n"), pat9125); + printf_P(PSTR("PAT9125_init:%u\n"), pat9125); #endif //PAT9125 uint8_t fsensor_enabled = eeprom_read_byte((uint8_t*)EEPROM_FSENSOR); fsensor_autoload_enabled=eeprom_read_byte((uint8_t*)EEPROM_FSENS_AUTOLOAD_ENABLED); @@ -237,7 +237,7 @@ bool fsensor_enable(bool bUpdateEEPROM) if (mmu_enabled == false) { //filament sensor is pat9125, enable only if it is working uint8_t pat9125 = pat9125_init(); - printf_P(PSTR("PAT9125_init:%hhu\n"), pat9125); + printf_P(PSTR("PAT9125_init:%u\n"), pat9125); if (pat9125) fsensor_not_responding = false; else @@ -435,8 +435,8 @@ void fsensor_oq_meassure_stop(void) { if (!fsensor_enabled) return; if (!fsensor_oq_meassure_enabled) return; - printf_P(PSTR("fsensor_oq_meassure_stop, %hhu samples\n"), fsensor_oq_samples); - printf_P(_N(" st_sum=%u yd_sum=%u er_sum=%u er_max=%hhu\n"), fsensor_oq_st_sum, fsensor_oq_yd_sum, fsensor_oq_er_sum, fsensor_oq_er_max); + printf_P(PSTR("fsensor_oq_meassure_stop, %u samples\n"), fsensor_oq_samples); + printf_P(_N(" st_sum=%u yd_sum=%u er_sum=%u er_max=%u\n"), fsensor_oq_st_sum, fsensor_oq_yd_sum, fsensor_oq_er_sum, fsensor_oq_er_max); printf_P(_N(" yd_min=%u yd_max=%u yd_avg=%u sh_avg=%u\n"), fsensor_oq_yd_min, fsensor_oq_yd_max, (uint16_t)((uint32_t)fsensor_oq_yd_sum * fsensor_chunk_len / fsensor_oq_st_sum), (uint16_t)(fsensor_oq_sh_sum / fsensor_oq_samples)); fsensor_oq_meassure = false; } @@ -453,10 +453,10 @@ bool fsensor_oq_result(void) bool res_er_sum = (fsensor_oq_er_sum <= FSENSOR_OQ_MAX_ES); printf_P(_N(" er_sum = %u %S\n"), fsensor_oq_er_sum, (res_er_sum?_OK:_NG)); bool res_er_max = (fsensor_oq_er_max <= FSENSOR_OQ_MAX_EM); - printf_P(_N(" er_max = %hhu %S\n"), fsensor_oq_er_max, (res_er_max?_OK:_NG)); + printf_P(_N(" er_max = %u %S\n"), fsensor_oq_er_max, (res_er_max?_OK:_NG)); uint8_t yd_avg = ((uint32_t)fsensor_oq_yd_sum * fsensor_chunk_len / fsensor_oq_st_sum); bool res_yd_avg = (yd_avg >= FSENSOR_OQ_MIN_YD) && (yd_avg <= FSENSOR_OQ_MAX_YD); - printf_P(_N(" yd_avg = %hhu %S\n"), yd_avg, (res_yd_avg?_OK:_NG)); + printf_P(_N(" yd_avg = %u %S\n"), yd_avg, (res_yd_avg?_OK:_NG)); bool res_yd_max = (fsensor_oq_yd_max <= (yd_avg * FSENSOR_OQ_MAX_PD)); printf_P(_N(" yd_max = %u %S\n"), fsensor_oq_yd_max, (res_yd_max?_OK:_NG)); bool res_yd_min = (fsensor_oq_yd_min >= (yd_avg / FSENSOR_OQ_MAX_ND)); @@ -472,7 +472,7 @@ bool fsensor_oq_result(void) bool res_sh_avg = (sh_avg <= FSENSOR_OQ_MAX_SH); if (yd_qua >= 8) res_sh_avg = true; - printf_P(_N(" sh_avg = %hhu %S\n"), sh_avg, (res_sh_avg?_OK:_NG)); + printf_P(_N(" sh_avg = %u %S\n"), sh_avg, (res_sh_avg?_OK:_NG)); bool res = res_er_sum && res_er_max && res_yd_avg && res_yd_max && res_yd_min && res_sh_avg; printf_P(_N("fsensor_oq_result %S\n"), (res?_OK:_NG)); return res; @@ -559,8 +559,8 @@ FORCE_INLINE static void fsensor_isr(int st_cnt) #ifdef DEBUG_FSENSOR_LOG if (fsensor_log) { - printf_P(_N("FSENSOR cnt=%d dy=%d err=%hhu %S\n"), st_cnt, pat9125_y, fsensor_err_cnt, (fsensor_err_cnt > old_err_cnt)?_N("NG!"):_N("OK")); - if (fsensor_oq_meassure) printf_P(_N("FSENSOR st_sum=%u yd_sum=%u er_sum=%u er_max=%hhu yd_max=%u\n"), fsensor_oq_st_sum, fsensor_oq_yd_sum, fsensor_oq_er_sum, fsensor_oq_er_max, fsensor_oq_yd_max); + printf_P(_N("FSENSOR cnt=%d dy=%d err=%u %S\n"), st_cnt, pat9125_y, fsensor_err_cnt, (fsensor_err_cnt > old_err_cnt)?_N("NG!"):_N("OK")); + if (fsensor_oq_meassure) printf_P(_N("FSENSOR st_sum=%u yd_sum=%u er_sum=%u er_max=%u yd_max=%u\n"), fsensor_oq_st_sum, fsensor_oq_yd_sum, fsensor_oq_er_sum, fsensor_oq_er_max, fsensor_oq_yd_max); } #endif //DEBUG_FSENSOR_LOG diff --git a/Firmware/mmu.cpp b/Firmware/mmu.cpp index 0d6ebe4c..6526b153 100755 --- a/Firmware/mmu.cpp +++ b/Firmware/mmu.cpp @@ -264,7 +264,7 @@ void mmu_loop(void) case S::GetFindaInit: if (mmu_rx_ok() > 0) { - fscanf_P(uart2io, PSTR("%hhu"), &mmu_finda); //scan finda from buffer + fscanf_P(uart2io, PSTR("%hhu"), &mmu_finda); //scan finda from buffer. MUST BE %hhu!!! mmu_last_finda_response.start(); FDEBUG_PRINTF_P(PSTR("MMU => '%dok'\n"), mmu_finda); puts_P(PSTR("MMU - ENABLED")); @@ -377,7 +377,7 @@ void mmu_loop(void) } if (mmu_rx_ok() > 0) { - fscanf_P(uart2io, PSTR("%hhu"), &mmu_finda); //scan finda from buffer + fscanf_P(uart2io, PSTR("%hhu"), &mmu_finda); //scan finda from buffer. MUST BE %hhu!!! mmu_last_finda_response.start(); FDEBUG_PRINTF_P(PSTR("MMU => '%dok'\n"), mmu_finda); //printf_P(PSTR("Eact: %d\n"), int(e_active())); diff --git a/Firmware/pat9125.c b/Firmware/pat9125.c index ea22c015..0cfce568 100644 --- a/Firmware/pat9125.c +++ b/Firmware/pat9125.c @@ -188,8 +188,8 @@ uint8_t pat9125_init(void) pat9125_wr_reg(PAT9125_RES_X, PAT9125_XRES); pat9125_wr_reg(PAT9125_RES_Y, PAT9125_YRES); - fprintf_P(uartout, PSTR("PAT9125_RES_X=%hhu\n"), pat9125_rd_reg(PAT9125_RES_X)); - fprintf_P(uartout, PSTR("PAT9125_RES_Y=%hhu\n"), pat9125_rd_reg(PAT9125_RES_Y)); + fprintf_P(uartout, PSTR("PAT9125_RES_X=%u\n"), pat9125_rd_reg(PAT9125_RES_X)); + fprintf_P(uartout, PSTR("PAT9125_RES_Y=%u\n"), pat9125_rd_reg(PAT9125_RES_Y)); return 1; } diff --git a/Firmware/tmc2130.cpp b/Firmware/tmc2130.cpp index 7560a084..f4d114df 100755 --- a/Firmware/tmc2130.cpp +++ b/Firmware/tmc2130.cpp @@ -471,8 +471,8 @@ void tmc2130_setup_chopper(uint8_t axis, uint8_t mres, uint8_t current_h, uint8_ intpol = 0; } #endif -// DBG(_n("tmc2130_setup_chopper(axis=%hhd, mres=%hhd, curh=%hhd, curr=%hhd\n"), axis, mres, current_h, current_r); -// DBG(_n(" toff=%hhd, hstr=%hhd, hend=%hhd, tbl=%hhd\n"), toff, hstrt, hend, tbl); +// DBG(_n("tmc2130_setup_chopper(axis=%d, mres=%d, curh=%d, curr=%d\n"), axis, mres, current_h, current_r); +// DBG(_n(" toff=%d, hstr=%d, hend=%d, tbl=%d\n"), toff, hstrt, hend, tbl); if (current_r <= 31) { tmc2130_wr_CHOPCONF(axis, toff, hstrt, hend, fd3, 0, rndtf, chm, tbl, 1, 0, 0, 0, mres, intpol, dedge, 0); @@ -511,7 +511,7 @@ void tmc2130_print_currents() void tmc2130_set_pwm_ampl(uint8_t axis, uint8_t pwm_ampl) { -// DBG(_n("tmc2130_set_pwm_ampl(axis=%hhd, pwm_ampl=%hhd\n"), axis, pwm_ampl); +// DBG(_n("tmc2130_set_pwm_ampl(axis=%d, pwm_ampl=%d\n"), axis, pwm_ampl); tmc2130_pwm_ampl[axis] = pwm_ampl; if (((axis == 0) || (axis == 1)) && (tmc2130_mode == TMC2130_MODE_SILENT)) tmc2130_wr_PWMCONF(axis, tmc2130_pwm_ampl[axis], tmc2130_pwm_grad[axis], tmc2130_pwm_freq[axis], tmc2130_pwm_auto[axis], 0, 0); @@ -519,7 +519,7 @@ void tmc2130_set_pwm_ampl(uint8_t axis, uint8_t pwm_ampl) void tmc2130_set_pwm_grad(uint8_t axis, uint8_t pwm_grad) { -// DBG(_n("tmc2130_set_pwm_grad(axis=%hhd, pwm_grad=%hhd\n"), axis, pwm_grad); +// DBG(_n("tmc2130_set_pwm_grad(axis=%d, pwm_grad=%d\n"), axis, pwm_grad); tmc2130_pwm_grad[axis] = pwm_grad; if (((axis == 0) || (axis == 1)) && (tmc2130_mode == TMC2130_MODE_SILENT)) tmc2130_wr_PWMCONF(axis, tmc2130_pwm_ampl[axis], tmc2130_pwm_grad[axis], tmc2130_pwm_freq[axis], tmc2130_pwm_auto[axis], 0, 0); @@ -893,7 +893,7 @@ void tmc2130_set_wave(uint8_t axis, uint8_t amp, uint8_t fac1000) { // TMC2130 wave compression algorithm // optimized for minimal memory requirements -// printf_P(PSTR("tmc2130_set_wave %hhd %hhd\n"), axis, fac1000); +// printf_P(PSTR("tmc2130_set_wave %d %d\n"), axis, fac1000); if (fac1000 < TMC2130_WAVE_FAC1000_MIN) fac1000 = 0; if (fac1000 > TMC2130_WAVE_FAC1000_MAX) fac1000 = TMC2130_WAVE_FAC1000_MAX; float fac = 0; diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 84f90512..d80102e9 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -469,7 +469,7 @@ void lcdui_print_percent_done(void) return; //do not also print the percentage } } - sprintf_P(per, num?_N("%3hhd"):_N("---"), calc_percent_done()); + sprintf_P(per, num?_N("%3d"):_N("---"), calc_percent_done()); lcd_printf_P(_N("%3S%3s%%"), src, per); } @@ -2703,7 +2703,7 @@ void lcd_menu_statistics() "%S:\n" "%18.2fm \n" "%S:\n" - "%10ldh %02hhdm %02hhds" + "%10ldh %02dm %02ds" ), _i("Filament used"), _met, ////MSG_FILAMENT_USED c=19 _i("Print time"), _h, _m, _s); ////MSG_PRINT_TIME c=19 @@ -2725,7 +2725,7 @@ void lcd_menu_statistics() "%S:\n" "%18.2fm \n" "%S:\n" - "%10ldd %02hhdh %02hhdm" + "%10ldd %02dh %02dm" ), _i("Total filament"), _filament_m, ////MSG_TOTAL_FILAMENT c=19 _i("Total print time"), _days, _hours, _minutes); ////MSG_TOTAL_PRINT_TIME c=19 From f25bddce355a94a11e03c911bce29755583a91d4 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Wed, 2 Feb 2022 21:06:58 +0100 Subject: [PATCH 2/2] Simplify GETPC() --- Firmware/Dcodes.cpp | 2 +- Firmware/asm.h | 21 +++++++++------------ Firmware/xflash_dump.cpp | 2 +- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/Firmware/Dcodes.cpp b/Firmware/Dcodes.cpp index d99a2c89..4a51b4d7 100644 --- a/Firmware/Dcodes.cpp +++ b/Firmware/Dcodes.cpp @@ -990,7 +990,7 @@ void __attribute__((noinline)) serial_dump_and_reset(dump_crash_reason reason) // sample SP/PC sp = SP; - GETPC(&pc); + pc = GETPC(); // extend WDT long enough to allow writing the entire stream wdt_enable(WDTO_8S); diff --git a/Firmware/asm.h b/Firmware/asm.h index 2ffb88ad..0c3d7457 100644 --- a/Firmware/asm.h +++ b/Firmware/asm.h @@ -1,24 +1,21 @@ #pragma once #include +#include "macros.h" #ifdef __AVR_ATmega2560__ // return the current PC (on AVRs with 22bit PC) -static inline void GETPC(uint32_t* v) +FORCE_INLINE __uint24 GETPC(void) { - uint8_t a, b, c; - asm - ( + __uint24 ret; + asm ( "rcall .\n" - "pop %2\n" - "pop %1\n" - "pop %0\n" - : "=r" (a), "=r" (b), "=r" (c) + "pop %A0\n" + "pop %B0\n" + "pop %C0\n" + : "=&r" (ret) ); - ((uint8_t*)v)[0] = a; - ((uint8_t*)v)[1] = b; - ((uint8_t*)v)[2] = c; - ((uint8_t*)v)[3] = 0; + return ret; } #endif diff --git a/Firmware/xflash_dump.cpp b/Firmware/xflash_dump.cpp index e69c1d3a..4caba11b 100644 --- a/Firmware/xflash_dump.cpp +++ b/Firmware/xflash_dump.cpp @@ -59,7 +59,7 @@ static void __attribute__((noinline)) xfdump_dump_core(dump_header_t& hdr, uint3 // sample SP/PC hdr.sp = SP; - GETPC(&hdr.pc); + hdr.pc = GETPC(); // write header static_assert(sizeof(hdr) <= 256, "header is larger than a single page write");