1 (edited by GregRob 2015-03-30 02:21:45)

Topic: Flashing Senoko PVT board

So I had been trying to follow the DVT instructions for flashing my battery board that I had acquired from mclein, but it turns out there is a difference with the PVT design.  So after some irc input from xobs here is the process I think I followed.  During this process the battery board is connected to the mainbaord, but there is no battery or anything else connected to the battery board.

1) Get and make the stm32flash software

git clone https://github.com/xobs/stm32flash 
cd stm32flash/
make
cd ..

2) Get and make the senoko board software image

git clone https://github.com/xobs/senoko-chibios-3
cd senoko-chibios-3
cd senoko
make -j4

Very close to the end of the make it should say, "Creating build/senoko.hex"

3) get the reset.sh script from the DVT repository, https://github.com/xobs/senoko-chibios/ … o/reset.sh
or just paste the following into reset.sh and make it executable:

#!/bin/bash

# Bring board out of "program" mode
sudo /bin/sh -c 'echo 148 > /sys/class/gpio/export 2> /dev/null'
sudo /bin/sh -c 'echo out > /sys/class/gpio/gpio148/direction 2> /dev/null'
sudo /bin/sh -c 'echo 0 > /sys/class/gpio/gpio148/value 2> /dev/null'


# Bring the board out of reset
sudo /bin/sh -c 'echo 149 > /sys/class/gpio/export 2> /dev/null'
sudo /bin/sh -c 'echo out > /sys/class/gpio/gpio149/direction 2> /dev/null'
sudo /bin/sh -c 'echo 0 > /sys/class/gpio/gpio149/value 2> /dev/null'
sleep 0.1
sudo /bin/sh -c 'echo 1 > /sys/class/gpio/gpio149/value 2> /dev/null'
chmod a+x reset.sh

4) Put the board into reflash mode
-Press and hold the reflash button on the battery board

./reset.sh

-release the reflash button

5) Flash the senoko.hex image onto the board

sudo ../../stm32flash/stm32flash -b 115200 -w build/senoko.hex /dev/ttymxc3

the output during step 5 should look something like:

stm32flash - http://stm32flash.googlecode.com/

Using Parser : Intel HEX
Serial Config: 115200 8E1
Version      : 0x22
Option 1     : 0x00
Option 2     : 0x00
Device ID    : 0x0410 (Medium-density)
RAM          : 20KiB  (512b reserved by bootloader)
Flash        : 128KiB (sector size: 4x1024)
Option RAM   : 15b
System RAM   : 2KiB

Wrote
Wrote s 0x08000100 (0.55%)
Wrote s 0x08000200 (1.10%)
Wrote s 0x08000300 (1.65%)
Wrote s 0x08000400 (2.20%)
Wrote s 0x08000500 (2.75%)
Wrote s 0x08000600 (3.30%)
Wrote s 0x08000700 (3.85%)
Wrote s 0x08000800 (4.40%)
Wrote s 0x08000900 (4.95%)
Wrote s 0x08000a00 (5.50%)
Wrote s 0x08000b00 (6.05%)
Wrote s 0x08000c00 (6.60%)
Wrote s 0x08000d00 (7.15%)
Wrote s 0x08000e00 (7.70%)
Wrote s 0x08000f00 (8.25%)
Wrote s 0x08001000 (8.80%)
Wrote s 0x08001100 (9.35%)
Wrote s 0x08001200 (9.90%)
Wrote s 0x08001300 (10.45%)
Wrote s 0x08001400 (11.00%)
Wrote s 0x08001500 (11.55%)
Wrote s 0x08001600 (12.10%)
Wrote s 0x08001700 (12.65%)
Wrote s 0x08001800 (13.20%)
Wrote s 0x08001900 (13.75%)
Wrote s 0x08001a00 (14.30%)
Wrote s 0x08001b00 (14.85%)
Wrote s 0x08001c00 (15.40%)
Wrote s 0x08001d00 (15.95%)
Wrote s 0x08001e00 (16.49%)
Wrote s 0x08001f00 (17.04%)
Wrote s 0x08002000 (17.59%)
Wrote s 0x08002100 (18.14%)
Wrote s 0x08002200 (18.69%)
Wrote s 0x08002300 (19.24%)
Wrote s 0x08002400 (19.79%)
Wrote s 0x08002500 (20.34%)
Wrote s 0x08002600 (20.89%)
Wrote s 0x08002700 (21.44%)
Wrote s 0x08002800 (21.99%)
Wrote s 0x08002900 (22.54%)
Wrote s 0x08002a00 (23.09%)
Wrote s 0x08002b00 (23.64%)
Wrote s 0x08002c00 (24.19%)
Wrote s 0x08002d00 (24.74%)
Wrote s 0x08002e00 (25.29%)
Wrote s 0x08002f00 (25.84%)
Wrote s 0x08003000 (26.39%)
Wrote s 0x08003100 (26.94%)
Wrote s 0x08003200 (27.49%)
Wrote s 0x08003300 (28.04%)
Wrote s 0x08003400 (28.59%)
Wrote s 0x08003500 (29.14%)
Wrote s 0x08003600 (29.69%)
Wrote s 0x08003700 (30.24%)
Wrote s 0x08003800 (30.79%)
Wrote s 0x08003900 (31.34%)
Wrote s 0x08003a00 (31.89%)
Wrote s 0x08003b00 (32.44%)
Wrote s 0x08003c00 (32.99%)
Wrote s 0x08003d00 (33.54%)
Wrote s 0x08003e00 (34.09%)
Wrote s 0x08003f00 (34.64%)
Wrote s 0x08004000 (35.19%)
Wrote s 0x08004100 (35.74%)
Wrote s 0x08004200 (36.29%)
Wrote s 0x08004300 (36.84%)
Wrote s 0x08004400 (37.39%)
Wrote s 0x08004500 (37.94%)
Wrote s 0x08004600 (38.49%)
Wrote s 0x08004700 (39.04%)
Wrote s 0x08004800 (39.59%)
Wrote s 0x08004900 (40.14%)
Wrote s 0x08004a00 (40.69%)
Wrote s 0x08004b00 (41.24%)
Wrote s 0x08004c00 (41.79%)
Wrote s 0x08004d00 (42.34%)
Wrote s 0x08004e00 (42.89%)
Wrote s 0x08004f00 (43.44%)
Wrote s 0x08005000 (43.99%)
Wrote s 0x08005100 (44.54%)
Wrote s 0x08005200 (45.09%)
Wrote s 0x08005300 (45.64%)
Wrote s 0x08005400 (46.19%)
Wrote s 0x08005500 (46.74%)
Wrote s 0x08005600 (47.29%)
Wrote s 0x08005700 (47.84%)
Wrote s 0x08005800 (48.38%)
Wrote s 0x08005900 (48.93%)
Wrote s 0x08005a00 (49.48%)
Wrote s 0x08005b00 (50.03%)
Wrote s 0x08005c00 (50.58%)
Wrote s 0x08005d00 (51.13%)
Wrote s 0x08005e00 (51.68%)
Wrote s 0x08005f00 (52.23%)
Wrote s 0x08006000 (52.78%)
Wrote s 0x08006100 (53.33%)
Wrote s 0x08006200 (53.88%)
Wrote s 0x08006300 (54.43%)
Wrote s 0x08006400 (54.98%)
Wrote s 0x08006500 (55.53%)
Wrote s 0x08006600 (56.08%)
Wrote s 0x08006700 (56.63%)
Wrote s 0x08006800 (57.18%)
Wrote s 0x08006900 (57.73%)
Wrote s 0x08006a00 (58.28%)
Wrote s 0x08006b00 (58.83%)
Wrote s 0x08006c00 (59.38%)
Wrote s 0x08006d00 (59.93%)
Wrote s 0x08006e00 (60.48%)
Wrote s 0x08006f00 (61.03%)
Wrote s 0x08007000 (61.58%)
Wrote s 0x08007100 (62.13%)
Wrote s 0x08007200 (62.68%)
Wrote s 0x08007300 (63.23%)
Wrote s 0x08007400 (63.78%)
Wrote s 0x08007500 (64.33%)
Wrote s 0x08007600 (64.88%)
Wrote s 0x08007700 (65.43%)
Wrote s 0x08007800 (65.98%)
Wrote s 0x08007900 (66.53%)
Wrote s 0x08007a00 (67.08%)
Wrote s 0x08007b00 (67.63%)
Wrote s 0x08007c00 (68.18%)
Wrote s 0x08007d00 (68.73%)
Wrote s 0x08007e00 (69.28%)
Wrote s 0x08007f00 (69.83%)
Wrote s 0x08008000 (70.38%)
Wrote s 0x08008100 (70.93%)
Wrote s 0x08008200 (71.48%)
Wrote s 0x08008300 (72.03%)
Wrote s 0x08008400 (72.58%)
Wrote s 0x08008500 (73.13%)
Wrote s 0x08008600 (73.68%)
Wrote s 0x08008700 (74.23%)
Wrote s 0x08008800 (74.78%)
Wrote s 0x08008900 (75.33%)
Wrote s 0x08008a00 (75.88%)
Wrote s 0x08008b00 (76.43%)
Wrote s 0x08008c00 (76.98%)
Wrote s 0x08008d00 (77.53%)
Wrote s 0x08008e00 (78.08%)
Wrote s 0x08008f00 (78.63%)
Wrote s 0x08009000 (79.18%)
Wrote s 0x08009100 (79.73%)
Wrote s 0x08009200 (80.27%)
Wrote s 0x08009300 (80.82%)
Wrote s 0x08009400 (81.37%)
Wrote s 0x08009500 (81.92%)
Wrote s 0x08009600 (82.47%)
Wrote s 0x08009700 (83.02%)
Wrote s 0x08009800 (83.57%)
Wrote s 0x08009900 (84.12%)
Wrote s 0x08009a00 (84.67%)
Wrote s 0x08009b00 (85.22%)
Wrote s 0x08009c00 (85.77%)
Wrote s 0x08009d00 (86.32%)
Wrote s 0x08009e00 (86.87%)
Wrote s 0x08009f00 (87.42%)
Wrote s 0x0800a000 (87.97%)
Wrote s 0x0800a100 (88.52%)
Wrote s 0x0800a200 (89.07%)
Wrote s 0x0800a300 (89.62%)
Wrote s 0x0800a400 (90.17%)
Wrote s 0x0800a500 (90.72%)
Wrote s 0x0800a600 (91.27%)
Wrote s 0x0800a700 (91.82%)
Wrote s 0x0800a800 (92.37%)
Wrote s 0x0800a900 (92.92%)
Wrote s 0x0800aa00 (93.47%)
Wrote s 0x0800ab00 (94.02%)
Wrote s 0x0800ac00 (94.57%)
Wrote s 0x0800ad00 (95.12%)
Wrote s 0x0800ae00 (95.67%)
Wrote s 0x0800af00 (96.22%)
Wrote s 0x0800b000 (96.77%)
Wrote s 0x0800b100 (97.32%)
Wrote s 0x0800b200 (97.87%)
Wrote s 0x0800b300 (98.42%)
Wrote s 0x0800b400 (98.97%)
Wrote s 0x0800b500 (99.52%)
address 0x0800b5e0 (100.00%) Done.

Resetting device... done.

6) Take the board out of programming mode

./reset.sh

7) Now you can connect to the board and run the factory test

sudo screen /dev/ttymxc3 115200

From step 7 you should get a, "ch>" prompt

And the following is cut and paste from the factory test script:

tests.append(new SenokoScript(QStringList()
                << "power on"               /* Ensure board is powered up */
                    << "Powering on... Ok"
                << "chg"                    /* Check for charger manufacturer ID */
                    << "Manufacturer ID:  0x0040"
                << "chg"                    /* Check for charger device ID */
                    << "Device ID:        0x0007"
                << "stats"                  /* Check for gas gauge product ID */
                    << "Part name:          bq20z95"
                << "gg cells 3"             /* Batteries have three cells */
                    << "Set 3-cell mode"
                << "gg capacity 3 5000"     /* Set a 5 Ah capacity */
                    << "Setting capacity... Set capacity of 3 cells to 5000 mAh"
                << "gg current 5000"        /* Fastcharge current at 5Ah */
                    << "Setting fastcharge curent... Set fastcharge current to 5000 mA"
                << "gg tempsource greater"  /* Use TS1 or TS2 */
                    << "Set tempsource to greater"
                << "gg deadband 16"          /* Set the 0 mV deadband to +/- 16 mA */
                    << "Ok"
                << "gg it"                  /* Start ImpedenceTrack */
                    << "Starting ImpedenceTrackTM algorithm... Ok"
                ));

EDIt (Mar 29, 2015): noticed the wget in step 3 doesn't actually work from a git repository, put the actual code inline.

2 (edited by GregRob 2015-01-30 22:43:59)

Re: Flashing Senoko PVT board

EDIT Jan 30: replaced stats command output with one that wasn't full of errors.

Here is my output from the factory tests, got some errors during the "gg" commands but then most of them go away after trying the command again.

ch> power on
Power status: on
ch> chg
Charger information:
        Charge thread:    running
        Manufacturer ID:  0x0040
        Device ID:        0x0007
        Current:          0 mA
        Voltage:          0 mV
        Input:            3328 mA
Command usage:
  chg set [c] [v] [[i]]  Set charge current to c mA @ v mV
  chg input [i]          Set max input AC current to [i] mA
  chg pause              Pause charge control
  chg resume             Resume charge control
ch> stats
Manufacturer:       Texas Inst.
Part name:          bq20z95
Firmware version:   0x5009
Charge FET:         off
Discharge FET:      off
State:              battery failure
Time until full:    65535 minutes
Time until empty:   65535 minutes
Chemistry:          LION
Serial number:      0x0001
Charge:             0%
Max capacity:       3648 mAh
Design capacity:    4400 mAh
Temperature:        -37.25075 C
Voltage:            18 mV
Current:            -5 mA
Average current:    0 mA
Target voltage:     0 mV
Target current:     0 mA
Number of cells:    4 cells
Cell 1 voltage:     0 mV
Cell 2 voltage:     5 mV
Cell 3 voltage:     12 mV
Cell 4 voltage:     0 mV
Charge status:      0x1
    Charging allowed?   yes
    Can suspend?        no
    Can precharge?      no
    Can maintenance?    no
    Temperature limit?  no
    Temperature limit?  no
    Can fastcharge?     no
    Pulse charging?     no
    Pulse disable CHG?  no
    Cell balancing?     no
    Precharge timeout?  no
    Fastcharge timeout? no
    Overcharge OV?      no
    Overcharge OC?      no
    Overcharge?         no
    Battery empty?      yes
Alarms:
    TERMINATE CHARGE ALARM
    TERMINATE DISCHARGE ALARM
    REMAINING CAPACITY ALARM
Charge state:
    Battery initialized
    Battery discharging/relaxing
    Battery fully discharged
No errors detected
No safety alerts
Safety status:
    Pack undervoltage condition
    Cell undervoltage condition
ch> gg cells 3
Unable to set 3 cells: 0xFFFFFFFE
ch> gg cells 3
Set 3-cell mode
ch> gg capacity 3 5000
Setting capacity... Unable to set capacity: 0xFFFFFFFE
ch> gg capacity 5000
Usage: gg capacity [cells] [capacity in mAh]
ch> gg capacity 3 5000
Setting capacity... Unable to set capacity: 0xFFFFFFFE
ch> gg current 5000
Setting fastcharge curent... Set fastcharge current to 5000 mA
ch> gg tempsource greater
Unable to set temp source: 0x1000000
ch> gg tempsource greater
Unable to set temp source: 0x1000000
ch> gg tempsource greater
Unable to set temp source: 0x1000000
ch> gg tempsource greater
Set tempsource to greater
ch> gg deadband 16
Error
ch> gg it
Starting ImpedenceTrackTM algorithm... Ok
ch>

Re: Flashing Senoko PVT board

Just recalled and issue I had during step 2, not sure if it will occur for you, but just in case here is some additional detail.

During the make process I got an error that stubs-soft.h was missing, but everything should be hard float so this was odd.  I ended up modifying /usr/include/arm-linux-gnueabihf/gnu/stubs.h so that both entries in it referred to stubs-hard.h and then the make ran fine.

There may be a difference with the PVT repository and DVT repository with this problem, I originally had the trouble while using the DVT repository, but didn't bother to undo my change before running "make" on the PVT repository code.

Re: Flashing Senoko PVT board

The errors you're seeing seem to indicate the gas gauge isn't responding, possibly because there isn't a battery attached.  Your charger is, however, responding.

"stats" should always return valid data.  E.g.:

ch> stats
Manufacturer:       Texas Inst.
Part name:          bq20z95
Firmware version:   0x5009
Charge FET:         off
Discharge FET:      on
State:              normal discharge
Time until full:    65535 minutes
Time until empty:   65535 minutes
Chemistry:          LION
Serial number:      0x0001
Charge:             100%
Max capacity:       55140 mWh
Design capacity:    63360 mWh
Temperature:        23.57114 C
Voltage:            12449 mV
Current:            0 mA
Average current:    0 mA
Target voltage:     12600 mV
Target current:     0 mA
Number of cells:    3 cells
Cell 1 voltage:     4148 mV
Cell 2 voltage:     4152 mV
Cell 3 voltage:     4148 mV
Cell 4 voltage:     0 mV
Charge status:      0x0
    Charging allowed?   yes
    Can suspend?        no
    Can precharge?      no
    Can maintenance?    no
    Temperature limit?  no
    Temperature limit?  no
    Can fastcharge?     no
    Pulse charging?     no
    Pulse disable CHG?  no
    Cell balancing?     no
    Precharge timeout?  no
    Fastcharge timeout? no
    Overcharge OV?      no
    Overcharge OC?      no
    Overcharge?         no
    Battery empty?      no
Alarms:
    TERMINATE CHARGE ALARM
Charge state:
    Battery initialized
    Battery discharging/relaxing
    Battery fully charged
No errors detected
No safety alerts
No safety status messages
ch> 

5 (edited by GregRob 2015-01-30 22:43:01)

Re: Flashing Senoko PVT board

My stats command normally does return information.  I had not noticed that when I was cutting and pasting examples that the one I used was full of errors.  I have edited post 2 above to show a correct stats command, with no battery attached.

I seem to generally have an issue talking to the gas gauge.  I'd say the gg commands are only working about 75% of the time, for example, from my previous post, when I tried to set the number of cells, it took 2 tries:

ch> gg cells 3
Unable to set 3 cells: 0xFFFFFFFE
ch> gg cells 3
Set 3-cell mode

I'm at the moment waiting for somebody else to confirm that they have gotten their mclein produced board working, so I'll know whether I have an individual problem, or we have a general problem, as at the moment mine would have clearly failed your factory test. 

I have plugged in a battery and the stats command still think I'm using a 4 cell battery and thus won't start the charger as the 4th cell is 0volts.

ch> stats
Manufacturer:       Texas Inst.
Part name:          bq20z95
Firmware version:   0x5009
Charge FET:         off
Discharge FET:      off
State:              battery failure
Time until full:    65535 minutes
Time until empty:   0 minutes
Chemistry:          LION
Serial number:      0x0001
Charge:             0%
Max capacity:       2071 mAh
Design capacity:    4400 mAh
Temperature:        -37.25075 C
Voltage:            11476 mV
Current:            -5 mA
Average current:    -5 mA
Target voltage:     0 mV
Target current:     0 mA
Number of cells:    4 cells
Cell 1 voltage:     3827 mV
Cell 2 voltage:     3825 mV
Cell 3 voltage:     3824 mV
Cell 4 voltage:     0 mV
Charge status:      0x0
    Charging allowed?   yes
    Can suspend?        no
    Can precharge?      no
    Can maintenance?    no
    Temperature limit?  no
    Temperature limit?  no
    Can fastcharge?     no
    Pulse charging?     no
    Pulse disable CHG?  no
    Cell balancing?     no
    Precharge timeout?  no
    Fastcharge timeout? no
    Overcharge OV?      no
    Overcharge OC?      no
    Overcharge?         no
    Battery empty?      no
Alarms:
    TERMINATE CHARGE ALARM
    TERMINATE DISCHARGE ALARM
    REMAINING CAPACITY ALARM
    REMAINING TIME ALARM
Charge state:
    Battery initialized
    Battery discharging/relaxing
    Battery fully discharged
No errors detected
No safety alerts
Safety status:
    Cell undervoltage condition

Setting it to 3 cells doesn't take:

ch> gg capacity 3 5000
Setting capacity... Set capacity of 3 cells to 5000 mAh
ch> gg current 5000
Setting fastcharge curent... Set fastcharge current to 5000 mA
ch> gg cells 3
Set 3-cell mode

ch> stats
Manufacturer:       Texas Inst.
Part name:          bq20z95
Firmware version:   0x5009
Charge FET:         off
Discharge FET:      off
State:              battery failure
Time until full:    65535 minutes
Time until empty:   0 minutes
Chemistry:          LION
Serial number:      0x0001
Charge:             0%
Max capacity:       2071 mAh
Design capacity:    4400 mAh
Temperature:        -37.25075 C
Voltage:            11475 mV
Current:            -5 mA
Average current:    -5 mA
Target voltage:     0 mV
Target current:     0 mA
Number of cells:    4 cells
Cell 1 voltage:     3826 mV
Cell 2 voltage:     3825 mV
Cell 3 voltage:     3824 mV
Cell 4 voltage:     0 mV
Charge status:      0x0
    Charging allowed?   yes
    Can suspend?        no
    Can precharge?      no
    Can maintenance?    no
    Temperature limit?  no
    Temperature limit?  no
    Can fastcharge?     no
    Pulse charging?     no
    Pulse disable CHG?  no
    Cell balancing?     no
    Precharge timeout?  no
    Fastcharge timeout? no
    Overcharge OV?      no
    Overcharge OC?      no
    Overcharge?         no
    Battery empty?      no
Alarms:
    TERMINATE CHARGE ALARM
    TERMINATE DISCHARGE ALARM
    REMAINING CAPACITY ALARM
    REMAINING TIME ALARM
Charge state:
    Battery initialized
    Battery discharging/relaxing
    Battery fully discharged
No errors detected
No safety alerts
Safety status:
    Cell undervoltage condition
ch>

6 (edited by raziel 2015-02-22 04:54:12)

Re: Flashing Senoko PVT board

I'm also trying to get the mclien board to work, with little success.
I added a little debug code to see what values get read/written to/from the gas gauge and the chip does not seem to keep the values.
Debug code in gg.c looks like this and I added an extra gg_getflash after writing the number of cells.

ret = gg_getflash(64, 0, cfg_a, sizeof(cfg_a));
chprintf(stream, "Got cfgA: 0x%x 0x%x\r\n ", cfg_a[0], cfg_a[1]);

The output looks like this:

ch> gg cells 3
Got cfgA: 0xF 0x29
 Set cfgA: 0xE 0x29
Got cfgA: 0xF 0x29
 Set 3-cell mode 0x0
ch> gg cells 4
Got cfgA: 0xF 0x29
 Set cfgA: 0xF 0x29
Got cfgA: 0xF 0x29
 Set 4-cell mode
ch> gg cells 2
Unknown cell count: 2
ch> gg cells 3
Got cfgA: 0xF 0x29
 Set cfgA: 0xE 0x29
Got cfgA: 0xF 0x29
 Set 3-cell mode 0x0

The difference between 0x0E and 0x0F is the bit CC0 of the CC1,CC0 combination that says how many cells there are in series (2,3 or 4).

Edit:
After reading more of the technical reference, the chip could be in one of the failure modes where write access to the flash is disabled.
That would explain the unchanged values, but not the fact that there is no error on writing.

Re: Flashing Senoko PVT board

Mine is behaving broadly similarly. Trying a few times to set the capacity, for example, gives:
ch> gg capacity 3 5000
Setting capacity... Unable to set capacity: 0xFFFFFFFE
ch> gg capacity 3 5000
Setting capacity... Set capacity of 3 cells to 5000 mAh
ch> gg capacity 3 5000
Setting capacity... Set capacity of 3 cells to 5000 mAh
ch> gg capacity 3 5000
Setting capacity... Unable to set capacity: 0xFFFFFFFE
ch> gg capacity 3 5000
Setting capacity... Unable to set capacity: 0xFFFFFFFE
ch> gg capacity 3 5000
Setting capacity... Set capacity of 3 cells to 5000 mAh


similarly, stats gives:
Manufacturer:       error 0xFE000000
Part name:          error 0xFE000000
Firmware version:   error 0xFE000000
State:              error 0xFE000000
Time until full:    error 0xFE000000
Time until empty:   error 0xFE000000
Chemistry:          error 0xFE000000
Serial number:      error 0xFE000000
Charge:             error 0xFE000000
Max capacity:       error 0xFE000000
Design capacity:    error 0xFE000000
Temperature:        2184.5 C
Voltage:            error 0xFE000000
Current:            error 0xFE000000
Average current:    error 0xFE000000
Target voltage:     error 0xFE000000
Target current:     error 0xFE000000
Number of cells:    error 0x1000000
Cell 1 voltage:     error 0xFE000000
Cell 2 voltage:     error 0xFE000000
Cell 3 voltage:     error 0xFE000000
Cell 4 voltage:     error 0xFE000000
Charge status:      0x5555
    Charging allowed?   yes
    Can suspend?        suspended
    Can precharge?      no
    Can maintenance?    yes
    Temperature limit?  no
    Temperature limit?  yes
    Can fastcharge?     no
    Pulse charging?     yes
    Pulse disable CHG?  no
    Cell balancing?     in-progress
    Precharge timeout?  no
    Fastcharge timeout? yes
    Overcharge OV?      no
    Overcharge OC?      yes
    Overcharge?         no
    Battery empty?      yes
Alarms:
    TERMINATE CHARGE ALARM
    OVER TEMP ALARM
    REMAINING TIME ALARM
Charge state:
    Battery discharging/relaxing
    Battery fully discharged
STATUS ERROR CODE: 0x5
Unable to read safety alerts
Unable to read safety status

Re: Flashing Senoko PVT board

Oh, I'm an idiot. There's no battery attached so no power to the GG chip. Tap the prime button to give it a little juice and it's happy. smile

Re: Flashing Senoko PVT board

I tried hitting the prime button before trying the gg commands and it still does not take.  I even tried attaching a battery, pressing prime, and then trying the gg commands, and it does not take. 

James, what does the stats commands say about the number of cells after you sent "gg cells 3"  I get the following:

ch> gg cells 3
Set 3-cell mode
ch> stats
Manufacturer:       Texas Inst.
Part name:          bq20z95
Firmware version:   0x5009
Charge FET:         off
Discharge FET:      off
.
.
.
Target current:     0 mA
Number of cells:    4 cells
Cell 1 voltage:     3824 mV
.
.
.

Re: Flashing Senoko PVT board

It appears I lied - it's happy only in the sense that it'll talk to me willingly, but it does the same as everyone else's and won't save the gg cells 3 command.

I actually tried DIYing up and connecting a four-cell battery (having removed R305 first!) and managed to get the stats command to report no safety alarms. However, even in this state, and with no "bad" numbers or statuses showing, it never seems to write the number of cells back (although the command completes successfully). I get much the same results for every other command to the gas gauge - the command completes fine but doesn't appear to write to the data flash of the gas-gauge chip.

I can't quite work out which condition is causing the data flash to lock out, unfortunately, and I'm not at home for the next two weeks, so I'm severely constrained for equipment to poke at it further.

Re: Flashing Senoko PVT board

There is an undervoltage lockout on the gas gauge that prevents it from modifying the values if the cell voltage is too low.  3V should be enough.

You might also want to try attaching a 10k resistor to TP1, though the temperature shouldn't matter if it's too low, only if it's too high.

Re: Flashing Senoko PVT board

From the stats command my Safety Satus is reporting Cell undervoltage.  But the cells are reporting 3.8 volts.  Al lexcept the 4th non-existent cell.

ch> stats
.
.
.
Temperature:        -37.25075 C
Voltage:            11448 mV
.
.
.
Number of cells:    4 cells
Cell 1 voltage:     3817 mV
Cell 2 voltage:     3816 mV
Cell 3 voltage:     3815 mV
Cell 4 voltage:     0 mV
.
.
.
Safety status:
    Cell undervoltage condition

I assumed the undervoltage was being reported because the 4th cell was reporting 0 volts. 

I'll try the resistor in any case since that is easy.

Re: Flashing Senoko PVT board

Ok, so to insert the 10K resistor, Bunnie was thinking ahead in the hardware design, you just need to short the T and X pins on the P302 header, and that connects the pre-wired resistor to TS1.  My stats command now reports 25 degrees instead of -37, and from xobs feedback on IRC that will certainly help with some future FET issues.

Regretfully the resistor didn't solve my problem with the GG commands not sticking.  Maybe a newly charged battery would make a difference?

Re: Flashing Senoko PVT board

Does it say there's a Permanent Failure?  Try "gg pfreset" to clear that.

You might also try restarting the gas gauge, which I believe "gg reboot" will do.

Re: Flashing Senoko PVT board

The Stats command doesn't say there is a permanent failure.  Maybe I should probe SAFE to see what voltage showing up there.  I tried the gg pfreset and the gg reboot, as well as just a plain old reboot, I followed each of these as quickly as possible with a gg cells 3, and another time with a gg capacity 3 5000 to see if they would take since the permanent failure mode is supposed to take at least a couple seconds to be invoked.  But still no luck.

16 (edited by pelrun 2015-03-22 01:00:40)

Re: Flashing Senoko PVT board

Exactly the same issues here with my mclien board - I haven't seen any errors when I run gg commands, though, just the inability to get them to stick.

Edit: spent a day banging against this to no avail. I'm at the point now where I'm talking directly to the gas gauge directly from the novena instead of uploading modified senoko firmware constantly; I've got a raw dump of the dataflash taken from BootROM mode, which I'm hoping I can import into the TI configuration app to edit.

Re: Flashing Senoko PVT board

Well there's one whole weekend gone banging against this...

I faked a 4-cell battery with a resistor divider on the balance connector input and a full 3s lipo; that easily gives >3000mV on all the cell voltage inputs, and the 12600mV is above the "Charger present" voltage, but the dataflash is still locked. As far as I can tell from the TI forums, I've satisfied every requirement for unlocking the dataflash, but it's still stubbornly read-only.

Dear god, the TI software is awful, and is incapable of doing anything useful if not connected to their stupid expensive proprietary usb-smbus cable. In any case, it appears to access dataflash via the same mechanism we are, so it's not much use anyway. And all the damn firmware update files are encrypted, so I can't easily take a default firmware file and flash it myself.

Soon I'll have the code written to read and write both firmware and dataflash; one option is to get xobs or someone else with a working battery board to dump their chip and we can upload that.

Additionally, there's been a bunch of work done on disassembling and reverse engineering the firmware on a chip in the same family, so I'm going to take those tools and damn well figure out why the dataflash updates are locked from the inside: http://www.accuvant.com/labs/research/b … re-hacking

Re: Flashing Senoko PVT board

perlrun, I'm happy to help you by giving you a dump of my flash.  I don't have those routines written yet, though.

One thing to note: The endianess of the chip is... not really well-defined.  SBS seems to have one endianess, and the values stored in flash have a swapped endianess.

Re: Flashing Senoko PVT board

Thanks for that. I'm writing the code at the moment, it'll be up at http://github.com/pelrun/novena-gg-tools soon.

I've noticed the endianness issue; it's really quite awful. That and how easy it is to hardbrick the chip, which is something that shouldn't be permitted in this day and age. I'm taking some pointers from the guy who did the macbook battery hack and being *very* paranoid about it - he bricked 7-8 $130 batteries!

Re: Flashing Senoko PVT board

Well, to be fair, most batteries ship in the "Sealed" mode, where these commands aren't available.  The only people who ever have a chance to brick their batteries are large corporations doing development on them.

It's still pretty awful.

You should be very careful when talking to the chip.  Already the Linux kernel is talking to it as an SBS device, and Senoko is talking to it to charge things.  To take Senoko out of the picture, hold down the "Programming" button while wiggling the Reset pin (e.g. echo 0 > /sys/class/gpio/gpio149/value; echo 1 > /sys/class/gpio/gpio149/value).  Make sure you do your reads via a single ioctl to lock out the kernel, too.

Re: Flashing Senoko PVT board

Nothing else is getting in my way: I took the sbs-battery driver out of the device tree to stop it interfering smile (I'll switch to disabling it from sysfs now that I know how to do that.) Also, the code does a lot of repeated reads and comparisons to ensure that any corruption is caught and handled, I'm not trusting the bus.

There's nothing stopping a program from screwing with the gauge from a userspace program; I'll add gg seal/unseal commands to senoko to close off that vulnerability.

22 (edited by pelrun 2015-03-25 09:04:04)

Re: Flashing Senoko PVT board

xobs, I've got a working firmware dump utility in the github repo if you would like to give it a shot; of course, look at the code first to make sure it won't do anything untoward on your system. Let me know if there's anything more you need me to do for you to be comfortable running the code on your machine.

I'm quite confident that the worst case for the current code is if the dumper dies partway through the dump the chip may need to be powercycled to get it out of bootrom mode.

You'll need to disable the sbs-battery driver and senoko as discussed earlier, then a "make && ./dump" will create gg.ifi and gg.dfi files, which are the instruction and data flash dumps respectively. It'll take a few minutes, because I read each word multiple times to ensure it's correct.

23 (edited by pelrun 2015-03-26 09:59:34)

Re: Flashing Senoko PVT board

Also it seems like there's at least one route to unbrick a chip; there's a pin on the package that will force the chip to start up in BootROM if it's grounded at powerup. It's disabled on end-user products, but as long as we don't do that (it's independent of the seal/unseal state. EDIT: but the seal command also disables it! Good thing I spotted that in the firmware!) we should have a way back if something goes horribly wrong.

Re: Flashing Senoko PVT board

I'm having issues as well, though mine have the added bonus of possibly being hardware related...]

Anyway, some salient output:

ch> stats
Manufacturer:       Texas Inst.
Part name:          bq20z95
Firmware version:   0x5009
Charge FET:         on
Discharge FET:      on
State:              normal discharge
Time until full:    65535 minutes
Time until empty:   0 minutes
Chemistry:          LION
Serial number:      0x0001
Charge:             0%
Max capacity:       5670 mAh
Design capacity:    6000 mAh
Temperature:        25.-121 C
Voltage:            10654 mV
Current:            -297 mA
Average current:    -145 mA
Target voltage:     0 mV
Target current:     0 mA
Number of cells:    3 cells
Cell 1 voltage:     3551 mV
Cell 2 voltage:     3553 mV
Cell 3 voltage:     3551 mV
Cell 4 voltage:     0 mV
Charge status:      0x8000
    Charging allowed?   no
    Can suspend?        no
    Can precharge?      no
    Can maintenance?    no
    Temperature limit?  no
    Temperature limit?  no
    Can fastcharge?     no
    Pulse charging?     no
    Pulse disable CHG?  no
    Cell balancing?     no
    Precharge timeout?  no
    Fastcharge timeout? no
    Overcharge OV?      no
    Overcharge OC?      no
    Overcharge?         no
    Battery empty?      no
Alarms:
    TERMINATE DISCHARGE ALARM
    REMAINING TIME ALARM
Charge state:
    Battery initialized
    Battery fully discharged
No errors detected
No safety alerts
No safety status messages
ch> chg
Charger information:
        Charge thread:    running
        Error getting manufacturer: 0x80000000
        Device ID:        0x0000
        Current:          0 mA
        Voltage:          0 mV        Input:            13312 mA
Command usage:
  chg set [c] [v] [[i]]  Set charge current to c mA @ v mV
  chg input [i]          Set max input AC current to [i] mA
  chg pause              Pause charge control
  chg resume             Resume charge control

When I press the "level" button on the Senoko, LED D306 just blinks a couple times. The board seems to refuse to charge- maybe due to the aforementioned error reading manufacturer? Bad soldering job somewhere?

I've also had problems with the RTOS crashing, when just sitting idle:

ch> 
Starting Senoko (Ver 2.0, git version f4ba2b6e82fc4c5e6b90ffeae0326ce5c918a6a6)
Possibly crashed in senoko-i2c.c:223
Assertion on last boot: 
Before reboot, PC was at: 0x08000B63 in thread 0x20000F18
Previous thread PC was at: 0x08001589 in thread 0x20000D30

Other than that, the board seems to run just fine from Senoko power (aside from not charging, that is). I can turn off the discharge FET with "gg dsg -", but that kills power to my Novena, regardless of where the adapter is plugged (eg, even if it goes straight to the Novena mainboard). "gg chg -" doesn't seem to do anything.

I've tried "gg pfreset" with no luck. It seems weird that the listed current is negative (from "stats"), and that the Charge status is 0x8000 (no charging allowed).

Thoughts? It kind of seems like a hardware issue to me, between the strange charging state and the apparent i2c failure, but I don't know enough of how the software works to know where to start looking (and asking here is easier than poking around on my own).

I can move this discussion to my senoko debugging thread if it's irrelevant to the current topic.

25 (edited by pelrun 2015-03-25 10:25:44)

Re: Flashing Senoko PVT board

This thread is as good as any for battery board issues. smile

Your gas gauge IC is responding to i2c, but the charger IC isn't, so I'd start by checking the soldering of that chip.

The charger IC is U200, which is the one you soldered backwards initially, isn't it? Perhaps it's damaged and needs replacing.