From 0e228caac1e35170f26b438b3a375b706b667077 Mon Sep 17 00:00:00 2001 From: kopecdav Date: Fri, 9 May 2025 14:03:31 +0200 Subject: [PATCH] feat(core) add prodtest precharge test [no changelog] --- .../prodtest/cmd/prodtest_power_manager.c | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/core/embed/projects/prodtest/cmd/prodtest_power_manager.c b/core/embed/projects/prodtest/cmd/prodtest_power_manager.c index aca147d504..49dde5bd31 100644 --- a/core/embed/projects/prodtest/cmd/prodtest_power_manager.c +++ b/core/embed/projects/prodtest/cmd/prodtest_power_manager.c @@ -322,6 +322,72 @@ void prodtest_pm_event_monitor(cli_t* cli) { cli_ok(cli, ""); } +void prodtest_pm_precharge(cli_t* cli) { + if (cli_arg_count(cli) > 0) { + cli_error_arg_count(cli); + return; + } + + // This test consider that the device is connected with USB and placed in + // ambient temperature. Battery will be charged with constanst current + // and precharge voltage is statically taken from the battery chaging curve + // + // It is expected that battery voltage during the charging is being lifted + // due to effect of internal resistance of the battery. So battery voltage + // will drop a bit after the charging is stopped. + + // voltage while charging is being lifted due to charging with quite high charging + // current. When the test terminate by reaching the given woltage. The current + // and + float precharge_voltage_V = 3.45f; + + pm_charging_enable(); + + cli_trace(cli, "Precharging the device..."); + + while(true){ + + pm_report_t report; + pm_status_t status = pm_get_report(&report); + + if (status != PM_OK) { + cli_error(cli, CLI_ERROR, "Failed to get power manager report"); + return; + } + + if (report.usb_connected == false) { + cli_error(cli, CLI_ERROR, "USB power source is not connected"); + return; + } + + cli_trace(cli, "Battery voltage: %d.%03d V -> taret %d.%03d V", + (int)report.battery_voltage_v, + (int)(report.battery_voltage_v * 1000) % 1000, + (int)precharge_voltage_V, + (int)(precharge_voltage_V * 1000) % 1000); + cli_progress(cli,"%d.%03d %d.%03d", + (int)report.battery_voltage_v, + (int)(report.battery_voltage_v * 1000) % 1000, + (int)precharge_voltage_V, + (int)(precharge_voltage_V * 1000) % 1000); + + if (cli_aborted(cli)) { + cli_trace(cli, "aborted"); + break; + } + + // Check if the battery voltage is above the precharge voltag + if(report.battery_voltage_v >= precharge_voltage_V){ + // Target achieved + cli_trace(cli, "Battery voltage reached the target voltage."); + break; + } + } + + cli_ok(cli, ""); +} + + // clang-format off PRODTEST_CLI_CMD( @@ -373,4 +439,11 @@ PRODTEST_CLI_CMD( .args = "" ); +PRODTEST_CLI_CMD( + .name = "pm-precharge", + .func = prodtest_pm_precharge, + .info = "Precharge the device to specific voltage", + .args = "" +); + #endif /* USE POWER_MANAGER */