diff --git a/core/embed/projects/prodtest/cmd/prodtest_pmic.c b/core/embed/projects/prodtest/cmd/prodtest_pmic.c index a5b357d5f3..d7d1c0aae4 100644 --- a/core/embed/projects/prodtest/cmd/prodtest_pmic.c +++ b/core/embed/projects/prodtest/cmd/prodtest_pmic.c @@ -51,12 +51,49 @@ static void prodtest_pmic_charge_enable(cli_t* cli) { return; } + npm1300_report_t report = {0}; + cli_trace(cli, "Enabling battery charging @ %dmA...", npm1300_get_charging_limit()); - if (!npm1300_set_charging(true)) { - cli_error(cli, CLI_ERROR, "Failed to enable battery charging."); - return; + while (true) { + if (!npm1300_set_charging(true)) { + cli_error(cli, CLI_ERROR, "Failed to enable battery charging."); + return; + } + + systick_delay_ms(10); + + if (!npm1300_measure_sync(&report)) { + cli_error(cli, CLI_ERROR, "Failed to get NPM1300 report."); + return; + } + + bool charging = ((report.ibat_meas_status >> 2) & 0x03) == 3; + + cli_trace( + cli, "Trying to start charging: %d.%03d %d.%03d %d.%03d 0x%02X 0x%02X", + (int)report.vbat, (int)(report.vbat * 1000) % 1000, + (int)report.ibat, (int)abs(report.ibat * 1000) % 1000, + (int)report.ntc_temp, (int)abs(report.ntc_temp * 1000) % 1000, + report.ibat_meas_status, report.buck_status); + + + if (charging) { + systick_delay_ms(100); + // confirm that we are still charging after some delay + npm1300_measure_sync(&report); + + charging = ((report.ibat_meas_status >> 2) & 0x03) == 3; + + if (charging) { + break; + } + } + + if (cli_aborted(cli)) { + return; + } } cli_ok(cli, ""); @@ -198,6 +235,52 @@ static void prodtest_pmic_report(cli_t* cli) { cli_ok(cli, ""); } +// +// static void prodtest_pmic_resurrect(cli_t* cli) { +// +// +// if (cli_arg_count(cli) > 0) { +// cli_error_arg_count(cli); +// return; +// } +// +// +// while (true) { +// npm1300_report_t report; +// +// if (!npm1300_measure_sync(&report)) { +// cli_error(cli, CLI_ERROR, "Failed to get NPM1300 report."); +// return; +// } +// +// npm1300_set_charging(true); +// +// bool ibat_charging = ((report.ibat_meas_status >> 2) & 0x03) == 3; +// if (ibat_charging) { +// cli_trace(cli, "Charging established"); +// //break; +// } +// +// cli_progress( +// cli, "%d.%03d %d.%03d %d.%03d %d.%03d %d.%03d 0x%02X 0x%02X", +// (int)report.vbat, (int)(report.vbat * 1000) % 1000, +// (int)report.ibat, (int)abs(report.ibat * 1000) % 1000, +// (int)report.ntc_temp, (int)abs(report.ntc_temp * 1000) % 1000, +// (int)report.vsys, (int)(report.vsys * 1000) % 1000, +// (int)report.die_temp, (int)abs(report.die_temp * 1000) % 1000, +// report.ibat_meas_status, report.buck_status); +// +// +// if (cli_aborted(cli)) { +// return; +// } +// +// } +// +// cli_ok(cli, ""); +// } + + // clang-format off PRODTEST_CLI_CMD( @@ -240,6 +323,6 @@ PRODTEST_CLI_CMD( .func = prodtest_pmic_report, .info = "Retrieve PMIC report", .args = "[] []" -); + ); #endif // USE_POWERCTL diff --git a/core/embed/projects/prodtest/cmd/prodtest_prodtest.c b/core/embed/projects/prodtest/cmd/prodtest_prodtest.c index 00fd34f756..4b4d4f2cfe 100644 --- a/core/embed/projects/prodtest/cmd/prodtest_prodtest.c +++ b/core/embed/projects/prodtest/cmd/prodtest_prodtest.c @@ -44,7 +44,7 @@ static void prodtest_prodtest_version(cli_t* cli) { return; } - cli_ok(cli, "%d.%d.%d", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH); + cli_ok(cli, "%d.%d.%d.%d", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, VERSION_BUILD); } static void prodtest_prodtest_wipe(cli_t* cli) { diff --git a/core/embed/projects/prodtest/version.h b/core/embed/projects/prodtest/version.h index c4f7c7eec2..885f382f62 100644 --- a/core/embed/projects/prodtest/version.h +++ b/core/embed/projects/prodtest/version.h @@ -5,7 +5,7 @@ #define VERSION_MAJOR 0 #define VERSION_MINOR 3 #define VERSION_PATCH 0 -#define VERSION_BUILD 0 +#define VERSION_BUILD 1 #define FIX_VERSION_MAJOR 0 #define FIX_VERSION_MINOR 2 diff --git a/core/embed/sys/powerctl/npm1300/npm1300.c b/core/embed/sys/powerctl/npm1300/npm1300.c index 01dc959676..433c22cb87 100644 --- a/core/embed/sys/powerctl/npm1300/npm1300.c +++ b/core/embed/sys/powerctl/npm1300/npm1300.c @@ -612,6 +612,8 @@ static void npm1300_calculate_report(npm1300_driver_t* drv, // I2C operations for enabling of the charging static const i2c_op_t npm1300_ops_charging_enable[] = { + NPM_WRITE_CONST(NPM1300_TASKCLEARCHGERR, 1), + NPM_WRITE_CONST(NPM1300_TASKRELEASEERR, 1), NPM_WRITE_CONST(NPM1300_BCHGENABLESET, NPM1300_BCHGENABLESET_ENABLECHG), };