[FL-952] I2C: correctly handle STOP flags. Apps: increase cli_app stack size. (#408)

* I2C: correctly handle STOP flags. Apps: increase cli_app stack size.
* API HAL Power: simplify api_hal_power_dump_state. Format sources.
This commit is contained in:
あく 2021-04-12 21:09:38 +03:00 committed by GitHub
parent 5d08b35b54
commit 616b7325c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 70 additions and 38 deletions

View File

@ -36,7 +36,7 @@ int32_t keypad_test(void* p);
const FlipperApplication FLIPPER_SERVICES[] = { const FlipperApplication FLIPPER_SERVICES[] = {
#ifdef APP_CLI #ifdef APP_CLI
{.app = cli_task, .name = "cli_task", .stack_size = 1024, .icon = A_Plugins_14}, {.app = cli_task, .name = "cli_task", .stack_size = 2048, .icon = A_Plugins_14},
#endif #endif
#ifdef APP_EXAMPLE_BLINK #ifdef APP_EXAMPLE_BLINK

View File

@ -156,11 +156,7 @@ void power_cli_dfu(string_t args, void* context) {
} }
void power_cli_test(string_t args, void* context) { void power_cli_test(string_t args, void* context) {
string_t buffer; api_hal_power_dump_state();
string_init(buffer);
api_hal_power_dump_state(buffer);
printf(string_get_cstr(buffer));
string_clear(buffer);
} }
void power_cli_otg_on(string_t args, void* context) { void power_cli_otg_on(string_t args, void* context) {

View File

@ -47,6 +47,9 @@ bool api_hal_i2c_tx(
uint32_t time_left = timeout; uint32_t time_left = timeout;
bool ret = true; bool ret = true;
while(LL_I2C_IsActiveFlag_BUSY(instance))
;
LL_I2C_HandleTransfer( LL_I2C_HandleTransfer(
instance, instance,
address, address,
@ -55,9 +58,11 @@ bool api_hal_i2c_tx(
LL_I2C_MODE_AUTOEND, LL_I2C_MODE_AUTOEND,
LL_I2C_GENERATE_START_WRITE); LL_I2C_GENERATE_START_WRITE);
while(!LL_I2C_IsActiveFlag_STOP(instance)) { while(!LL_I2C_IsActiveFlag_STOP(instance) || size > 0) {
if(LL_I2C_IsActiveFlag_TXIS(instance)) { if(LL_I2C_IsActiveFlag_TXIS(instance)) {
LL_I2C_TransmitData8(instance, (*data++)); LL_I2C_TransmitData8(instance, (*data));
data++;
size--;
time_left = timeout; time_left = timeout;
} }
@ -70,6 +75,7 @@ bool api_hal_i2c_tx(
} }
LL_I2C_ClearFlag_STOP(instance); LL_I2C_ClearFlag_STOP(instance);
return ret; return ret;
} }
@ -82,6 +88,9 @@ bool api_hal_i2c_rx(
uint32_t time_left = timeout; uint32_t time_left = timeout;
bool ret = true; bool ret = true;
while(LL_I2C_IsActiveFlag_BUSY(instance))
;
LL_I2C_HandleTransfer( LL_I2C_HandleTransfer(
instance, instance,
address, address,
@ -90,9 +99,11 @@ bool api_hal_i2c_rx(
LL_I2C_MODE_AUTOEND, LL_I2C_MODE_AUTOEND,
LL_I2C_GENERATE_START_READ); LL_I2C_GENERATE_START_READ);
while(!LL_I2C_IsActiveFlag_STOP(instance)) { while(!LL_I2C_IsActiveFlag_STOP(instance) || size > 0) {
if(LL_I2C_IsActiveFlag_RXNE(instance)) { if(LL_I2C_IsActiveFlag_RXNE(instance)) {
*data++ = LL_I2C_ReceiveData8(instance); *data = LL_I2C_ReceiveData8(instance);
data++;
size--;
time_left = timeout; time_left = timeout;
} }
@ -105,6 +116,7 @@ bool api_hal_i2c_rx(
} }
LL_I2C_ClearFlag_STOP(instance); LL_I2C_ClearFlag_STOP(instance);
return ret; return ret;
} }

View File

@ -88,7 +88,7 @@ float api_hal_power_get_system_voltage();
float api_hal_power_get_usb_voltage(); float api_hal_power_get_usb_voltage();
/** Get power system component state */ /** Get power system component state */
void api_hal_power_dump_state(string_t buffer); void api_hal_power_dump_state();
/** Enable 3.3v on external gpio and sd card */ /** Enable 3.3v on external gpio and sd card */
void api_hal_power_enable_external_3_3v(); void api_hal_power_enable_external_3_3v();

View File

@ -50,6 +50,9 @@ bool api_hal_i2c_tx(
uint32_t time_left = timeout; uint32_t time_left = timeout;
bool ret = true; bool ret = true;
while(LL_I2C_IsActiveFlag_BUSY(instance))
;
LL_I2C_HandleTransfer( LL_I2C_HandleTransfer(
instance, instance,
address, address,
@ -58,9 +61,11 @@ bool api_hal_i2c_tx(
LL_I2C_MODE_AUTOEND, LL_I2C_MODE_AUTOEND,
LL_I2C_GENERATE_START_WRITE); LL_I2C_GENERATE_START_WRITE);
while(!LL_I2C_IsActiveFlag_STOP(instance)) { while(!LL_I2C_IsActiveFlag_STOP(instance) || size > 0) {
if(LL_I2C_IsActiveFlag_TXIS(instance)) { if(LL_I2C_IsActiveFlag_TXIS(instance)) {
LL_I2C_TransmitData8(instance, (*data++)); LL_I2C_TransmitData8(instance, (*data));
data++;
size--;
time_left = timeout; time_left = timeout;
} }
@ -73,6 +78,7 @@ bool api_hal_i2c_tx(
} }
LL_I2C_ClearFlag_STOP(instance); LL_I2C_ClearFlag_STOP(instance);
return ret; return ret;
} }
@ -85,6 +91,9 @@ bool api_hal_i2c_rx(
uint32_t time_left = timeout; uint32_t time_left = timeout;
bool ret = true; bool ret = true;
while(LL_I2C_IsActiveFlag_BUSY(instance))
;
LL_I2C_HandleTransfer( LL_I2C_HandleTransfer(
instance, instance,
address, address,
@ -93,9 +102,11 @@ bool api_hal_i2c_rx(
LL_I2C_MODE_AUTOEND, LL_I2C_MODE_AUTOEND,
LL_I2C_GENERATE_START_READ); LL_I2C_GENERATE_START_READ);
while(!LL_I2C_IsActiveFlag_STOP(instance)) { while(!LL_I2C_IsActiveFlag_STOP(instance) || size > 0) {
if(LL_I2C_IsActiveFlag_RXNE(instance)) { if(LL_I2C_IsActiveFlag_RXNE(instance)) {
*data++ = LL_I2C_ReceiveData8(instance); *data = LL_I2C_ReceiveData8(instance);
data++;
size--;
time_left = timeout; time_left = timeout;
} }
@ -108,6 +119,7 @@ bool api_hal_i2c_rx(
} }
LL_I2C_ClearFlag_STOP(instance); LL_I2C_ClearFlag_STOP(instance);
return ret; return ret;
} }

View File

@ -201,47 +201,47 @@ float api_hal_power_get_usb_voltage(){
return (float)bq25896_get_vbus_voltage() / 1000.0f; return (float)bq25896_get_vbus_voltage() / 1000.0f;
} }
void api_hal_power_dump_state(string_t buffer) { void api_hal_power_dump_state() {
BatteryStatus battery_status; BatteryStatus battery_status;
OperationStatus operation_status; OperationStatus operation_status;
if (bq27220_get_battery_status(&battery_status) == BQ27220_ERROR if (bq27220_get_battery_status(&battery_status) == BQ27220_ERROR
|| bq27220_get_operation_status(&operation_status) == BQ27220_ERROR) { || bq27220_get_operation_status(&operation_status) == BQ27220_ERROR) {
string_cat_printf(buffer, "Failed to get bq27220 status. Communication error.\r\n"); printf("Failed to get bq27220 status. Communication error.\r\n");
} else { } else {
string_cat_printf(buffer, printf(
"bq27220: CALMD: %d, SEC0: %d, SEC1: %d, EDV2: %d, VDQ: %d, INITCOMP: %d, SMTH: %d, BTPINT: %d, CFGUPDATE: %d\r\n", "bq27220: CALMD: %d, SEC0: %d, SEC1: %d, EDV2: %d, VDQ: %d, INITCOMP: %d, SMTH: %d, BTPINT: %d, CFGUPDATE: %d\r\n",
operation_status.CALMD, operation_status.SEC0, operation_status.SEC1, operation_status.CALMD, operation_status.SEC0, operation_status.SEC1,
operation_status.EDV2, operation_status.VDQ, operation_status.INITCOMP, operation_status.EDV2, operation_status.VDQ, operation_status.INITCOMP,
operation_status.SMTH, operation_status.BTPINT, operation_status.CFGUPDATE operation_status.SMTH, operation_status.BTPINT, operation_status.CFGUPDATE
); );
// Battery status register, part 1 // Battery status register, part 1
string_cat_printf(buffer, printf(
"bq27220: CHGINH: %d, FC: %d, OTD: %d, OTC: %d, SLEEP: %d, OCVFAIL: %d, OCVCOMP: %d, FD: %d\r\n", "bq27220: CHGINH: %d, FC: %d, OTD: %d, OTC: %d, SLEEP: %d, OCVFAIL: %d, OCVCOMP: %d, FD: %d\r\n",
battery_status.CHGINH, battery_status.FC, battery_status.OTD, battery_status.CHGINH, battery_status.FC, battery_status.OTD,
battery_status.OTC, battery_status.SLEEP, battery_status.OCVFAIL, battery_status.OTC, battery_status.SLEEP, battery_status.OCVFAIL,
battery_status.OCVCOMP, battery_status.FD battery_status.OCVCOMP, battery_status.FD
); );
// Battery status register, part 2 // Battery status register, part 2
string_cat_printf(buffer, printf(
"bq27220: DSG: %d, SYSDWN: %d, TDA: %d, BATTPRES: %d, AUTH_GD: %d, OCVGD: %d, TCA: %d, RSVD: %d\r\n", "bq27220: DSG: %d, SYSDWN: %d, TDA: %d, BATTPRES: %d, AUTH_GD: %d, OCVGD: %d, TCA: %d, RSVD: %d\r\n",
battery_status.DSG, battery_status.SYSDWN, battery_status.TDA, battery_status.DSG, battery_status.SYSDWN, battery_status.TDA,
battery_status.BATTPRES, battery_status.AUTH_GD, battery_status.OCVGD, battery_status.BATTPRES, battery_status.AUTH_GD, battery_status.OCVGD,
battery_status.TCA, battery_status.RSVD battery_status.TCA, battery_status.RSVD
); );
// Voltage and current info // Voltage and current info
string_cat_printf(buffer, printf(
"bq27220: Full capacity: %dmAh, Design capacity: %dmAh, Remaining capacity: %dmAh, State of Charge: %d%%, State of health: %d%%\r\n", "bq27220: Full capacity: %dmAh, Design capacity: %dmAh, Remaining capacity: %dmAh, State of Charge: %d%%, State of health: %d%%\r\n",
bq27220_get_full_charge_capacity(), bq27220_get_design_capacity(), bq27220_get_remaining_capacity(), bq27220_get_full_charge_capacity(), bq27220_get_design_capacity(), bq27220_get_remaining_capacity(),
bq27220_get_state_of_charge(), bq27220_get_state_of_health() bq27220_get_state_of_charge(), bq27220_get_state_of_health()
); );
string_cat_printf(buffer, printf(
"bq27220: Voltage: %dmV, Current: %dmA, Temperature: %dC\r\n", "bq27220: Voltage: %dmV, Current: %dmA, Temperature: %dC\r\n",
bq27220_get_voltage(), bq27220_get_current(), (int)api_hal_power_get_battery_temperature(ApiHalPowerICFuelGauge) bq27220_get_voltage(), bq27220_get_current(), (int)api_hal_power_get_battery_temperature(ApiHalPowerICFuelGauge)
); );
} }
string_cat_printf(buffer, printf(
"bq25896: VBUS: %d, VSYS: %d, VBAT: %d, Current: %d, NTC: %dm%%\r\n", "bq25896: VBUS: %d, VSYS: %d, VBAT: %d, Current: %d, NTC: %ldm%%\r\n",
bq25896_get_vbus_voltage(), bq25896_get_vsys_voltage(), bq25896_get_vbus_voltage(), bq25896_get_vsys_voltage(),
bq25896_get_vbat_voltage(), bq25896_get_vbat_current(), bq25896_get_vbat_voltage(), bq25896_get_vbat_current(),
bq25896_get_ntc_mpct() bq25896_get_ntc_mpct()

View File

@ -38,7 +38,7 @@
#define HAL_COMP_MODULE_ENABLED #define HAL_COMP_MODULE_ENABLED
#define HAL_CRC_MODULE_ENABLED #define HAL_CRC_MODULE_ENABLED
#define HAL_HSEM_MODULE_ENABLED #define HAL_HSEM_MODULE_ENABLED
#define HAL_I2C_MODULE_ENABLED // #define HAL_I2C_MODULE_ENABLED
/*#define HAL_IPCC_MODULE_ENABLED */ /*#define HAL_IPCC_MODULE_ENABLED */
/*#define HAL_IRDA_MODULE_ENABLED */ /*#define HAL_IRDA_MODULE_ENABLED */
/*#define HAL_IWDG_MODULE_ENABLED */ /*#define HAL_IWDG_MODULE_ENABLED */

View File

@ -50,6 +50,9 @@ bool api_hal_i2c_tx(
uint32_t time_left = timeout; uint32_t time_left = timeout;
bool ret = true; bool ret = true;
while(LL_I2C_IsActiveFlag_BUSY(instance))
;
LL_I2C_HandleTransfer( LL_I2C_HandleTransfer(
instance, instance,
address, address,
@ -58,9 +61,11 @@ bool api_hal_i2c_tx(
LL_I2C_MODE_AUTOEND, LL_I2C_MODE_AUTOEND,
LL_I2C_GENERATE_START_WRITE); LL_I2C_GENERATE_START_WRITE);
while(!LL_I2C_IsActiveFlag_STOP(instance)) { while(!LL_I2C_IsActiveFlag_STOP(instance) || size > 0) {
if(LL_I2C_IsActiveFlag_TXIS(instance)) { if(LL_I2C_IsActiveFlag_TXIS(instance)) {
LL_I2C_TransmitData8(instance, (*data++)); LL_I2C_TransmitData8(instance, (*data));
data++;
size--;
time_left = timeout; time_left = timeout;
} }
@ -73,6 +78,7 @@ bool api_hal_i2c_tx(
} }
LL_I2C_ClearFlag_STOP(instance); LL_I2C_ClearFlag_STOP(instance);
return ret; return ret;
} }
@ -85,6 +91,9 @@ bool api_hal_i2c_rx(
uint32_t time_left = timeout; uint32_t time_left = timeout;
bool ret = true; bool ret = true;
while(LL_I2C_IsActiveFlag_BUSY(instance))
;
LL_I2C_HandleTransfer( LL_I2C_HandleTransfer(
instance, instance,
address, address,
@ -93,9 +102,11 @@ bool api_hal_i2c_rx(
LL_I2C_MODE_AUTOEND, LL_I2C_MODE_AUTOEND,
LL_I2C_GENERATE_START_READ); LL_I2C_GENERATE_START_READ);
while(!LL_I2C_IsActiveFlag_STOP(instance)) { while(!LL_I2C_IsActiveFlag_STOP(instance) || size > 0) {
if(LL_I2C_IsActiveFlag_RXNE(instance)) { if(LL_I2C_IsActiveFlag_RXNE(instance)) {
*data++ = LL_I2C_ReceiveData8(instance); *data = LL_I2C_ReceiveData8(instance);
data++;
size--;
time_left = timeout; time_left = timeout;
} }
@ -108,6 +119,7 @@ bool api_hal_i2c_rx(
} }
LL_I2C_ClearFlag_STOP(instance); LL_I2C_ClearFlag_STOP(instance);
return ret; return ret;
} }

View File

@ -202,47 +202,47 @@ float api_hal_power_get_usb_voltage(){
return (float)bq25896_get_vbus_voltage() / 1000.0f; return (float)bq25896_get_vbus_voltage() / 1000.0f;
} }
void api_hal_power_dump_state(string_t buffer) { void api_hal_power_dump_state() {
BatteryStatus battery_status; BatteryStatus battery_status;
OperationStatus operation_status; OperationStatus operation_status;
if (bq27220_get_battery_status(&battery_status) == BQ27220_ERROR if (bq27220_get_battery_status(&battery_status) == BQ27220_ERROR
|| bq27220_get_operation_status(&operation_status) == BQ27220_ERROR) { || bq27220_get_operation_status(&operation_status) == BQ27220_ERROR) {
string_cat_printf(buffer, "Failed to get bq27220 status. Communication error.\r\n"); printf("Failed to get bq27220 status. Communication error.\r\n");
} else { } else {
string_cat_printf(buffer, printf(
"bq27220: CALMD: %d, SEC0: %d, SEC1: %d, EDV2: %d, VDQ: %d, INITCOMP: %d, SMTH: %d, BTPINT: %d, CFGUPDATE: %d\r\n", "bq27220: CALMD: %d, SEC0: %d, SEC1: %d, EDV2: %d, VDQ: %d, INITCOMP: %d, SMTH: %d, BTPINT: %d, CFGUPDATE: %d\r\n",
operation_status.CALMD, operation_status.SEC0, operation_status.SEC1, operation_status.CALMD, operation_status.SEC0, operation_status.SEC1,
operation_status.EDV2, operation_status.VDQ, operation_status.INITCOMP, operation_status.EDV2, operation_status.VDQ, operation_status.INITCOMP,
operation_status.SMTH, operation_status.BTPINT, operation_status.CFGUPDATE operation_status.SMTH, operation_status.BTPINT, operation_status.CFGUPDATE
); );
// Battery status register, part 1 // Battery status register, part 1
string_cat_printf(buffer, printf(
"bq27220: CHGINH: %d, FC: %d, OTD: %d, OTC: %d, SLEEP: %d, OCVFAIL: %d, OCVCOMP: %d, FD: %d\r\n", "bq27220: CHGINH: %d, FC: %d, OTD: %d, OTC: %d, SLEEP: %d, OCVFAIL: %d, OCVCOMP: %d, FD: %d\r\n",
battery_status.CHGINH, battery_status.FC, battery_status.OTD, battery_status.CHGINH, battery_status.FC, battery_status.OTD,
battery_status.OTC, battery_status.SLEEP, battery_status.OCVFAIL, battery_status.OTC, battery_status.SLEEP, battery_status.OCVFAIL,
battery_status.OCVCOMP, battery_status.FD battery_status.OCVCOMP, battery_status.FD
); );
// Battery status register, part 2 // Battery status register, part 2
string_cat_printf(buffer, printf(
"bq27220: DSG: %d, SYSDWN: %d, TDA: %d, BATTPRES: %d, AUTH_GD: %d, OCVGD: %d, TCA: %d, RSVD: %d\r\n", "bq27220: DSG: %d, SYSDWN: %d, TDA: %d, BATTPRES: %d, AUTH_GD: %d, OCVGD: %d, TCA: %d, RSVD: %d\r\n",
battery_status.DSG, battery_status.SYSDWN, battery_status.TDA, battery_status.DSG, battery_status.SYSDWN, battery_status.TDA,
battery_status.BATTPRES, battery_status.AUTH_GD, battery_status.OCVGD, battery_status.BATTPRES, battery_status.AUTH_GD, battery_status.OCVGD,
battery_status.TCA, battery_status.RSVD battery_status.TCA, battery_status.RSVD
); );
// Voltage and current info // Voltage and current info
string_cat_printf(buffer, printf(
"bq27220: Full capacity: %dmAh, Design capacity: %dmAh, Remaining capacity: %dmAh, State of Charge: %d%%, State of health: %d%%\r\n", "bq27220: Full capacity: %dmAh, Design capacity: %dmAh, Remaining capacity: %dmAh, State of Charge: %d%%, State of health: %d%%\r\n",
bq27220_get_full_charge_capacity(), bq27220_get_design_capacity(), bq27220_get_remaining_capacity(), bq27220_get_full_charge_capacity(), bq27220_get_design_capacity(), bq27220_get_remaining_capacity(),
bq27220_get_state_of_charge(), bq27220_get_state_of_health() bq27220_get_state_of_charge(), bq27220_get_state_of_health()
); );
string_cat_printf(buffer, printf(
"bq27220: Voltage: %dmV, Current: %dmA, Temperature: %dC\r\n", "bq27220: Voltage: %dmV, Current: %dmA, Temperature: %dC\r\n",
bq27220_get_voltage(), bq27220_get_current(), (int)api_hal_power_get_battery_temperature(ApiHalPowerICFuelGauge) bq27220_get_voltage(), bq27220_get_current(), (int)api_hal_power_get_battery_temperature(ApiHalPowerICFuelGauge)
); );
} }
string_cat_printf(buffer, printf(
"bq25896: VBUS: %d, VSYS: %d, VBAT: %d, Current: %d, NTC: %dm%%\r\n", "bq25896: VBUS: %d, VSYS: %d, VBAT: %d, Current: %d, NTC: %ldm%%\r\n",
bq25896_get_vbus_voltage(), bq25896_get_vsys_voltage(), bq25896_get_vbus_voltage(), bq25896_get_vsys_voltage(),
bq25896_get_vbat_voltage(), bq25896_get_vbat_current(), bq25896_get_vbat_voltage(), bq25896_get_vbat_current(),
bq25896_get_ntc_mpct() bq25896_get_ntc_mpct()