# HG changeset patch # User heinrichsweikamp # Date 1582531117 0 # Node ID 6c824f902934cd91575e3ec8656c97c9e64e7e21 # Parent 2b4440f75434b2e05c436bef5801931214e8f9a9# Parent 079f32a8e68c5bf43331c8b1572af88cf5c2e89c Merged in Ideenmodellierer/ostc4/Improve_BatteryGasGauge (pull request #40) Improve BatteryGasGauge diff -r 2b4440f75434 -r 6c824f902934 Discovery/Src/data_exchange_main.c --- a/Discovery/Src/data_exchange_main.c Tue Feb 18 12:41:45 2020 +0100 +++ b/Discovery/Src/data_exchange_main.c Mon Feb 24 07:58:37 2020 +0000 @@ -416,14 +416,6 @@ settingsHelperButtonSens_keepPercentageValues(settingsGetPointerStandard()->ButtonResponsiveness[3], settings->ButtonResponsiveness); setButtonResponsiveness(settings->ButtonResponsiveness); - - // hw 160720 new lastKnownBatteryPercentage - if(!wasUpdateNotPowerOn) - { -// dataOut.data.newBatteryGaugePercentageFloat = settingsGetPointer()->lastKnownBatteryPercentage; - dataOut.data.newBatteryGaugePercentageFloat = 0; - dataOut.setBatteryGaugeNow = 1; - } } } diff -r 2b4440f75434 -r 6c824f902934 Discovery/Src/tComm.c --- a/Discovery/Src/tComm.c Tue Feb 18 12:41:45 2020 +0100 +++ b/Discovery/Src/tComm.c Mon Feb 24 07:58:37 2020 +0000 @@ -106,6 +106,7 @@ #define BYTE_DOWNLOAD_MODE (0xBB) #define BYTE_SERVICE_MODE (0xAA) +#define UART_OPERATION_TIMEOUT (500u) /* Timeout for common read / write operations (ms) */ #define UART_TIMEOUT_SECONDS (120u) /* Timeout for keeping connection open and waiting for data */ #define UART_TIMEOUT_LARGE_BLOCK (6000u) /* Timeout (ms) for reception of an 16K data block (typical RX time ~4,5seconds) */ @@ -444,7 +445,7 @@ do { HAL_Delay(200); - if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferEscapeSequence, 3, 1000)== HAL_OK) + if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferEscapeSequence, 3, UART_OPERATION_TIMEOUT)== HAL_OK) { answer = tComm_CheckAnswerOK(); } @@ -455,13 +456,13 @@ if(answer == HAL_OK) { answer = HAL_ERROR; - if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxDisconnect,sizeDisconnect , 1000)== HAL_OK) + if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxDisconnect,sizeDisconnect , UART_OPERATION_TIMEOUT)== HAL_OK) { answer = HAL_ERROR; if(tComm_CheckAnswerOK() == HAL_OK) { answer = HAL_ERROR; - if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferEnd, 4, 1000) == HAL_OK) /* exit terminal mode */ + if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferEnd, 4, UART_OPERATION_TIMEOUT) == HAL_OK) /* exit terminal mode */ { answer = tComm_CheckAnswerOK(); } @@ -536,7 +537,7 @@ while((answer == prompt4D4C(receiveStartByteUart)) && (timeoutCounter < UART_TIMEOUT_SECONDS)) /* try receive once a second */ { - if(HAL_UART_Receive(&UartHandle, (uint8_t*)&localRx, 1, 1000)!= HAL_OK) + if(HAL_UART_Receive(&UartHandle, (uint8_t*)&localRx, 1, UART_OPERATION_TIMEOUT)!= HAL_OK) { timeoutCounter++; get_globalStateList(&status); @@ -666,7 +667,7 @@ #endif case 0xC1: // Start low-level bootloader - if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, 1, 1000)!= HAL_OK) + if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, 1, UART_OPERATION_TIMEOUT)!= HAL_OK) return 0; break; default: @@ -1926,7 +1927,7 @@ uint8_t answer; memset(aRxBuffer,0,UART_CMD_BUF_SIZE); - if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, sizeAnswer, 1000) == HAL_OK) + if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, sizeAnswer, UART_OPERATION_TIMEOUT) == HAL_OK) { do { @@ -2098,7 +2099,7 @@ { if(BmTmpConfig == BM_CONFIG_ECHO) /* echo is not yet turned off => read and discard echo */ { - HAL_UART_Receive(&UartHandle, (uint8_t*)TxBuffer, CmdSize, 1000); + HAL_UART_Receive(&UartHandle, (uint8_t*)TxBuffer, CmdSize, UART_OPERATION_TIMEOUT); } result = tComm_CheckAnswerOK(); diff -r 2b4440f75434 -r 6c824f902934 Discovery/Src/tMenuEditSystem.c --- a/Discovery/Src/tMenuEditSystem.c Tue Feb 18 12:41:45 2020 +0100 +++ b/Discovery/Src/tMenuEditSystem.c Mon Feb 24 07:58:37 2020 +0000 @@ -1521,8 +1521,8 @@ text[1] = TXT2BYTE_WarnBatteryLow; text[2] = 0; snprintf(&text[2],10,": %01.2fV",stateRealGetPointer()->lifeData.battery_voltage); - write_label_var( 30, 800, ME_Y_LINE4, &FontT42, text); - + write_label_var( 30, 800, ME_Y_LINE5, &FontT42, text); + snprintf(&text[0],30,"Code: %X",getLicence()); write_label_var( 30, 800, ME_Y_LINE6, &FontT42, text); break; diff -r 2b4440f75434 -r 6c824f902934 Small_CPU/CPU2-RTE.ld --- a/Small_CPU/CPU2-RTE.ld Tue Feb 18 12:41:45 2020 +0100 +++ b/Small_CPU/CPU2-RTE.ld Mon Feb 24 07:58:37 2020 +0000 @@ -181,7 +181,15 @@ *(.heap*) __HeapLimit = .; } > RAM - + + /* .noinit section contains data which will not be change during startup */ + .noinit : + { + . = ALIGN(4); + *(.noinit*) + _end = . ; + } > RAM + /* .stack_dummy section doesn't contains any symbols. It is only * used for linker to calculate size of stack sections, and assign * values to stack symbols later */ diff -r 2b4440f75434 -r 6c824f902934 Small_CPU/Src/baseCPU2.c --- a/Small_CPU/Src/baseCPU2.c Tue Feb 18 12:41:45 2020 +0100 +++ b/Small_CPU/Src/baseCPU2.c Mon Feb 24 07:58:37 2020 +0000 @@ -151,6 +151,8 @@ #include "stm32f4xx_hal.h" #include +uint8_t coldstart __attribute__((section (".noinit"))); + uint8_t hasExternalClock(void) { if ((TM_OTP_Read(0, 0) > 0) && (TM_OTP_Read(0, 0) < 0xFF)) return 1; @@ -181,7 +183,9 @@ /* for safety reasons and coming functions */ .magic[0] = FIRMWARE_MAGIC_FIRST, .magic[1] = FIRMWARE_MAGIC_SECOND, .magic[2] = FIRMWARE_MAGIC_CPU2_RTE, /* the magic byte for RTE */ - .magic[3] = FIRMWARE_MAGIC_END }; + .magic[3] = FIRMWARE_MAGIC_END +}; + uint8_t firmwareVersionHigh(void) { return cpu2_FirmwareData.versionFirst; @@ -339,7 +343,11 @@ init_battery_gas_gauge(); HAL_Delay(10); battery_gas_gauge_get_data(); -// battery_gas_gauge_set(0); + if(coldstart != 0xA5) + { + coldstart = 0xA5; + battery_gas_gauge_set(0); + } global.lifeData.battery_voltage = get_voltage(); global.lifeData.battery_charge = get_charge(); diff -r 2b4440f75434 -r 6c824f902934 Small_CPU/Src/batteryGasGauge.c --- a/Small_CPU/Src/batteryGasGauge.c Tue Feb 18 12:41:45 2020 +0100 +++ b/Small_CPU/Src/batteryGasGauge.c Mon Feb 24 07:58:37 2020 +0000 @@ -64,7 +64,7 @@ buffer[0] = 0x01; // F8 = 11111000: - // Vbat 3.0V (11) + // ADC auto mode (11) // Prescale M = 128 (111) // AL/CC pin disable (0) // Shutdown (0) @@ -127,8 +127,8 @@ // max/full: 0.085 mAh * 1 * 65535 = 5570 mAh battery_f_charge_percent_local = (float)(bufferReceive[2] * 256); battery_f_charge_percent_local += (float)(bufferReceive[3]); - battery_f_charge_percent_local -= BGG_BATTERY_OFFSET; - battery_f_charge_percent_local /= BGG_BATTERY_DIVIDER; + battery_f_charge_percent_local -= BGG_BATTERY_OFFSET; /* Because of the prescalar 128 the counter assumes a max value of 5570mAh => normalize to 3350mAh*/ + battery_f_charge_percent_local /= BGG_BATTERY_DIVIDER; /* transform to percentage */ if(battery_f_charge_percent_local < 0) battery_f_charge_percent_local = 0;