This is a feature creep that wouldn't just go away. This project is a CLI tool for GreenPAKs using the offical GreenPAK Serial Debugger.
To make the experience fit your profile, pick a username and tell us what interests you.
We found and based on your interests.
I've started working on an utils crate which will use the embedded hal i2c trait. This means that this crate will be usable on and with other devices.
The first functionality of this crate is to scan the I2C bus to find greenpaks Which is important if you load a gp file and want to program that, so we don't try to write to unknown device.
To that we have to know more about the addressing scheme greenpaks uses.
The standard 7-bit address is divided with the first 4 msb bits are called the control code and the remaining 3 least siginificant bits are the block address.
Just like an large eeprom can have several blocks for example 0x50 and 0x51, the greenpaks separate the different types of memory using the block address.
For example the SLG46826 with control code 0001
| Control code | Block address | Hex 7-bit I2C address | Memory |
| 0001 | 000 | 0x08 | RAM registers |
| 0001 | 001 | 0x09 | Reserved/ Not used |
| 0001 | 010 | 0x0A | NVM Configuration |
| 0001 | 011 | 0x0B | emulated-eeprom(NVM) |
When I do a full scan of the I2C bus which has only the SLG46824 connected I get responses from 4 addresses.
The datasheet for the SLG46824 says that it only uses 2 block addresses 000 and 010.
| Block address | Memory |
| 000 | RAM registers |
| 001 | Reserved / Not used |
| 010 | NVM configuration |
| 011 | Reserved / Not used |
I think this boils down to that the I2C macro cell is the same for all devices and some devices use all the blocks but most do not.
The SLG46826 uses block address 011 as an emulated eeprom, this is simply the unused NVM repurposed. However it can only do 1000 rewrite cycles.
If I remember correctly I've seen a greenpak that uses more than 1 block of 256 bytes for it's configuration which means that it uses the first two blocks as RAM and the other two blocks as the OTP(one time programmable) memory in this case.
So I did an experiment and read all the blocks of the SLG46824.
I got data from all of them, Block 000 and 001 got me the same data, which means that it points to the same RAM area I guess.
Block 010 gave me the internal settings of the device in the NVM.
Block 011 gave me all 0's.
The SLG46824 is not so much different than the SLG46826 it's only missing the high-speed analog and emulated-eeprom.
Could it be that all the SLG46826 silicon that fails the testing with the high-speed analog has those features removed and is sold as SLG46824?
Who knows?
Since NVM is read into ram when the device powers on reading the last page of the ram should get us the data we need.
So the scan function should only scan block address 000. With all control codes except 0000 and 1111 which are reserved. This leaves us 14 addresses to scan.
Possible greenpak RAM I2C addresses are thus 0x08, 0x10, 0x18, 0x20, 0x28, 0x30, 0x38, 0x40, 0x48, 0x50, 0x58, 0x60, 0x68 and 0x70.
Now with the utils scanning just these addresses, now we need to know how we can tell each greenpak type apart?
Looking in the In system programming guides for each device family, SLG47004 and the SLG46824/26.
According to the document FE~F7 are the service page bytes for the SLG47004V while FF~F0 is the service page bytes for the SLG46824/26.
So is there 2 formats? one using the full page and one only using half the page?
I'm just guessing here but I think there is a standard how it's done for all greenpaks which uses less than 8 bytes. Just have to figure out how it's done, preferable without having to decompile the official software.
When reading the NVM block I noticed that it has different data than the RAM for the last page. Could this be the device information data? It's not stored in the nvm but it's loaded into the ram in some other way?
I'll start by dumping all the blocks of all the devices I own. Including the non MTP devices.
The easiest way to do this is to flip the module over and connect wires to the VDD, GND, SCL, SDA. Connect these to the GSD and just run a dump program.
I'll make a program which simply scans and dumps it all...
Read more »I've made a new git project which contains all the related crates and the test crates. Having all the crates in the same workspace makes it easier to work on the project.
Porting all the tests to the new test crate, made me find some more bugs. With those fixed. The driver is almost ready to be used for the next step of development.
I've made a new test using a sht40 sensor to test the embedded-hal implementation.
The hardware test crate have 20 tests right now, which covers the API pretty well.
≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡[ Harware Test Results ]≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
[PASS] GSD: Status LED test (171 ms)
[PASS] GSD: Switch I2C bus mode test (17 ms)
[PASS] I2C: Write nack test (67 ms)
[PASS] I2C: Read nack test (64 ms)
[PASS] I2C: Write read nack test (64 ms)
[PASS] HAL: I2C write nack test (40 ms)
[PASS] HAL: I2C read nack test (64 ms)
[PASS] HAL: I2C write read nack test (64 ms)
[PASS] Power: Power ON test (68 ms)
[PASS] I2C: Write test (59 ms)
[PASS] I2C: Read test (68 ms)
[PASS] I2C: Set standard i2c bus speed (3 ms)
[PASS] I2C: Write read test (64 ms)
[PASS] I2C: Set fast i2c bus speed (3 ms)
[PASS] HAL: I2C Transaction ops test (116 ms)
[PASS] HAL: Unsupported I2C transaction ops test (48 ms)
[PASS] HAL: External crate test using sht40 sensor (82 ms)
[PASS] Power: Power OFF test (44 ms)
[PASS] ADC: Power sweep (1675 ms)
[PASS] Power: VBus 5 volt pass-through test (117 ms)
≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡[ Summary ]≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
[SUCCESS] : 20 tests (20 passed, 0 failed), total duration 2898 ms
Power sweep test, tests all settings of the target output voltage settings and reads it back using the ADC. I can probably shave some time off that test by reducing the grace time between each one.
The sht40 sensor can tolerate up to 5.5 volts in the spec so the 5 volts is no problem. So instead of making a seprate test crate and breadboard for it, I just plugged it into the same breadboard as the eeprom. They share the I2C bus.
I've not yet done any testing using an externally powered circuit.
The cli tool test board will include the SLG46824, SLG46826 and the SLG47004 which are all the Multi-time programmable devices. They will be powered externally and these are the devices that will be supported first.
I've wired up a 1Mbit eeprom on a breadboard to use for testing. It can be powered with 5 volts so it can endure the power output and ADC test sweep each hardware test cycle.
The test setup looks like this.
One of the LED's in the LED array lights up on power output from the GSD.
I've implemented support for embedded hal i2c. I managed to find some bugs that have to be fixed.
There is a bug in the i2c write read transaction function which does not check for nack which returns the wrong error message, it times out instead with a waiting for the read to complete instead of error on nack.
I didn't reimplement nack check test for it when I moved onto using the API layer for testing. Then I refactored some code and missed it.
With that bug fixed and the others marked with FIXME's for now as i've not implemented a good test for them. I clearly see the reason now why to do mocking. Setting hardware to do the error testing for all different types of failures is way more difficult and time consuming.
I'm testing the I2C code using the eeprom but I can do the I2C tests on the powerpak instead. I guess I'll have to make the muxing a hidden part of the API or something. I could then use that instead of the eeprom. This would make it possible for anyone with a GSD to just plug it in and run all the hardware tests.
This project takes a bit longer than the hacker thought due to the lack of time... and of course the inflated ego. When things go well and you have little to no problems the ego inflates until the hacker hit a wall, mountain or some obstacle and the ego baloon *pop* and the hacker falls crashing down back to earth *bam*.
Suddenly that overly optimistic estimate is years away from the hackers perspective. Do the hacker give up? No that is not what a hacker does! Hacker finds a way and gets some small wins in. Suddenly the hacker hits the equilibrium in the ego, the flatness, where everything makes sense and the hacker sees the truth. The estimate didn't match the hackers skill and time allocated.
The hacker of course always learns new things along the way and giving up is not an option. The hacker in this case is of course, me. So note to self multiply all estimates with at least 3 and readjust it later. Because making something that works and something that is robust is two different things. My perfectionism has a part of it as well. Why do something if you can't make to the best of your abilities, however what I think I can do, in my case doesn't reflect reality some times. At that point I study.
I've made headway and the device layer and the public API is almost complete. Which means that after the stress test of the I2C implementation. I can then start with the CLI tool. I'll see how good of a job I did with the driver, If I'll have to go back to it and make changes to it or not.
The other day I had some time to do some programming but I didn't have access to my hardware to do testing while programming. I ended up refactoring a lot of code and without testing it.
The next morning, tests failed, go figure ;)
I found the issue and I also found another bug in the code. A win, but fixing that cost me lab time, so tests are pretty important if you touch a lot of your code base. I was confident that the refactoring wouldn't break anything. I was wrong. Always run the tests while refactoring.
Having a computer connected to the hardware and run the code on that remotely. I could test it without the need of being in the lab at all.
Since the GSD uses the MCP2221A for I2C. I can expose that functionality using embedded hal I2C traits in the device layer API. This would make the GSD into a general purpose USB -> I2C device, that is not all since there is a controllable LDO you can supply power as well from 0.9 - 5 volts at max 50mA.
This would turn the GSD into a general purpose USB to I2C adapter with level shifting, power output and protection features. Pair that with a cable of your choice you can do a lot of things, a soic clip cable for reading eeproms, QWIIC cable for interfacing with that stuff and what not. Which is hopefully useful to someone other than myself.
I connected the GSD 2.0 to a SLG46824 and made a simple test firmware for it. Tested it using the offfical greenpak software using emulate mode.
Then I used my driver to set the OTP/RAM bytes so it shows up as a GSD 1.0, then I wrote the same firmware again using the offical software. I also did some read tests, no problems at all.
So I can probably confirm that both GSD 1.0 and 2.0 uses the same driver in the offical software, which means the hardware can be treated the same in mine as well.
With that out of the way, I can continue with the driver it self.
It's been a couple of busy months with little to no time working on any of my projects. Lately though I've been able to squeeze a few minutes in here and there.
In the dumps before it starts to communicate with the target, it reads register bytes 0xE5 and 0xE8.
0xE5 = 0x42 [ 0b0100_0010 ]
0xE8 = 0x52 [ 0b0101_0010 ]
Datasheet mentions this.
0xE5 = Protection Read Configuration
0xE8 = Silicon Identification Service Bits
This is probably part of the general purpose utils for greenpaks. It probably checks that what the protection status is. Then what device it is, so it knows the capabilities and so on. Probably something to put into my CLI software later.
It then reads 6 bytes from address 0xD8, which is part of the OTP/RAM bytes. It's memory that can be one time programmed with a value of your choice and then be used as general purpose ram if you want.
OTP/RAM Byte 0 = 0xA5
OTP/RAM Byte 1 = 0x04
OTP/RAM Byte 2 = 0x02
OTP/RAM Byte 3 = 0x02
OTP/RAM Byte 4 = 0x02
OTP/RAM Byte 5 = 0x5A
This could be what I'm looking for.
So I did an little experiment with my driver and the greenpak software. I used my driver to write to the RAM bytes. Any changes to any of the bytes individually or otherwise changes the version in the offical software to Hardware version 1.0 and Firmware version 1.7.
Further testing is required to see if the device behaves any differently. My hunch is that it's basically the same for both and it was just added so you can tell in the software which hardware you are running. The software probably doesn't care at all.
Since the RAM/OTP memory in the power pak keeps the version. I think firmware for the GSD 2.0 could have been redesigned, but it would cause the hardware to diverge and thus the driver needed be rewritten. Having two drivers to maintain just complicates things.
From what I can tell both devices function the same way.
I will do a test later where I change the ram bytes so the offical greenpak software think it's a rev 1.0 and try to read and program a SLG46826.
I tried dumping the PowerPak after I used it, but it didn't work so I checked the dumps in wireshark, and the mcp2221A GPIO is set to a different state after it's been used.
So I altered my program to set the sram to the same settings as before it's being used. That worked and I could dump the chip.
Doing a diff and analyzing what is different is the fastest way.
8c8 < :10007000000F939010FF7F000000000000000000C0 --- > :10007000010F939010FF7F000000000000000000BF 13c13 < :1000C000F80F01010F0860A800A800177715770442 --- > :1000C000F80F01010F08A0C000A8001777157704EA 16c16 < :1000F0004028100101010BC8A191A35A000008A5D6 --- > :1000F00040A8110101010BC8A191A35A000008A555
This is intel hex data so I'll remove the header and checksum footer. It leaves me with the binary data. There is 16 pages each have 16 bytes of memory, diffs are in pages 7, 12, and 15. Pages are numbered from 0 to 15.
000F939010FF7F000000000000000000 ->
010F939010FF7F000000000000000000
There is a diff in the first byte in page 7(0x70), byte 0x70.
Byte 0x70 (registers 903:896):
0b00000000 (0x00) -> 0b00000001 (0x01)
This byte is "CNT2 Counted Value for I2C read" so this have nothing to do with the design of the PowerPAK.
Its just a counter value.
F80F01010F0860A800A8001777157704 ->
F80F01010F08A0C000A8001777157704
There is diffs on page 12(0xC0), bytes 0xC6 and 0xC7.
Byte 0xC6 (registers 1591:1584):
0b01100000 (0x60) -> 0b10100000 (0xA0)
This byte contains registers for the minimum power selection and UVLO settings for LDO0 and LDO1.
Byte 0xC7 (registers 1599:1592):
0b10101000 (0xA8) -> 0b11000000 (0xC0)
This byte contains LDO0 settings, start-up ramping slope selection, and the output voltage.
4028100101010BC8A191A35A000008A5 ->
40A8110101010BC8A191A35A000008A5
On page 15(0xF0) there are 2 bytes that diff, byte 0xF1 and 0xF2.
Byte 0xF1 (registers 1935:1928):
0b00101000 (0x28) -> 0b10101000 (0xA8)
This byte contains the output values of LUTs or counters.
Byte 0xF2 (registers 1943:1936):
0b00010000 (0x10) -> 0b00010001 (0x11)
This byte also contains output values of LUTs or counters.
Looking at this the internal design have not changed from the one in the OTP memory.
I suspect they don't change the design in the PowerPAK. They just use the old design, and fix it in software. It would then be a disconnect between hardware, firmware and software. It's like a hardware engineer made a revision of the hardware and a software engineer did the software: They forgot or just left the firmware as is. It's a bit weird.
If this is the case, how do they tell the difference between GSD rev 1.0 and GSD rev 2.0 in software?
I checked dmesg when the GSD rev 2.0 was plugged in.
[748715.863239] usb 5-1: New USB device found, idVendor=2dcf, idProduct=d006, bcdDevice= 1.00
[748715.863253] usb 5-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[748715.863257] usb 5-1: Product: GreenPAK Serial Debugger
[748715.863261] usb 5-1: Manufacturer: Dialog Semiconductor
Does this mean the MCP2221A is also didn't have it's firmware updated?
bcdDevice= 1.00 <- This should have been bumped to 2.0 for rev 2.0. It would have made it so much easier to tell rev 1.0 and rev 2.0 apart.
The GreenPAK designer software clearly shows it in the information window.
Development Board:
Type: GreenPAK Serial Debugger
Hardware ID: 2.0 <--
Firmware ID: 2.0 <--
I'm pretty sure there is nothing in the MCP2221A so it must be in the SLG46582. But then why not change the internal design to match the hardware rev 2.0?
If they used preprogrammed SLG46582's from GSD rev 1.0, the OTP memory can not changed to add the information. Then it has to be done in software. Let's look at the internal design again for the SLG46582, the I2C level-shifter control.
Looking at the logic here SEL1 is just not used, it's a left over from the UART design before rev 1.0 probably. Only SEL0 is used to mux between I2C to PowerPAK or Target.
Since SEL0 will not turn the PowerPAK levelshifter on or off, this...
Read more »I rearranged the design so it's much more easy to see what is going on inside the SLG46582 PowerPAK.
Turned the I2C registers into network labels instead to remove a lot of lines, makes it a bit easier to see what is going on. The SEL0 and SEL1 logic was moved into its own area since it's logic is separated from the other logic.
The internal design is nothing like I expected, the NC pin has functionality to it. One of the I2C level shifter control pins are not set up as an NMOS. This can only mean one thing, is this preprogrammed design is an old one? Which is probably the design of GSD Rev 1.0. Quick search online for the user manual for GSD Rev 1.0 and it confirmed that this is probably true. It confirmed the error in the GSD Rev 2.0 manual I found before.
The SEL0, SEL1 and NC Logic
Now before analyzing I have to understand how the logic works inside the GSD PowerPAK. It's hard to reason what happens during analysis otherwise.
Since I want to know what SEL0 and SEL1 does, I'll start looking at the logic that is connected to these pins.
NC, SEL0 and SEL1 is connected to three 3-bit LUTs, 3-L3, 3-L1 and 3-L4.
NC pin is high when only SEL1 is high.
I2C_ON_PROG is only high when SEL0 is HIGH and SEL1 is LOW.
I2C_ON_LDO is HIGH if both SEL0 and SEL1 are low.
So since no more logic is connected is quite easy to reason about the default implementation we have here.
I2C_ON_PROG pin is set up as a open-drain NMOS. This means that if this pin is HIGH it will sink the VDD/EN of the target PCA9306, turning it off.
I2C_ON_LDO pin is set up as a normal output pin. Now we need to look at the schematics again.
The LDO level-shifter can not be turned off in this configuration? It shouldn't matter if I2C_ON_LDO is HIGH or LOW? It's powered through VDD anyway.
Looking at the GSD Rev 1.0 level-shifters
It fits the logic much better. Notice the level-shifter UART pins. NC is UART_ON.
Look at the output here.
There is a 6 pin header there. But with 2 extra GND. Probably where UTX and URX would have gone if they had added UART.
Here is a board view of the GSD Rev 1.0
The final design doesn't include the 2 UART level shifters. So the UART lines are probably not routed at all. The schematic is not updated to fit the final design which is weird. I guess the schematics, board design and documentation was managed by different people. It's only way to explain this.
Looking at this it confirms that the OTP memory logic of the SLG46582 on my GSD Rev 2.0 is the GSD Rev 1.0 design. They probably had a lot of preprogrammed chips to use. Now does this mean that the device is reconfigured by software before it's used?
The Error pin
This probably has the most logic connected to it. Let's start from the error pin and go backwards to the source of the logic.
The output of the Error LUT (3-L0) goes to the Error pin (Pin 4), Status LED LUT (2-L2) and the FET LUT (2-L1).
Let's look at the FET LUT (2-L1) First.
If there is an error, FET LUT output is turned off, FET LUT is controlled directly by the I2C Register 1957.
Next the Status LED.
Here an error turns off the Status LED.
Next is the Error LUT.
The Error LUT (3-L0). When an error is detected by the logic both the Power target LDO and Target power FET are turned off. The error signals comes from the LDO's themselves (IN0 and IN2) and the ACMPs (IN1). Both overvoltage (ACMP0) and the set temperature limit which is 75 °C (ACMP2).
The status LED control LUT (3-L6). The CNT/DLY2 signal controls the status LED blinking speed. There are two I2C registers connected to it 1958 and 1959.
The I2C register 1958: This controls if the status LED indicator should be on or not.
The I2C register 1959: It controls two things when it's turned on. It releases the powerdown of the OSC1 and enables blinking of the Status LED.
The rest
ACMP0 is use for overvoltage...
Read more »To know how the GSD really work we need to know all the unknowns of the hardware and capturing the communication between the GSD and the software can provide us with more information.
Instead of using wireshark directly to do the capture I decided to use dumpcap as it is. I wrote a script that is run as root that uses dumpcap on the usb interface the GSD uses, when the capture is over it will move the file over to my user, it renames and adjust the permissions. Then I'll analyze the dumps in wireshark.
Captured two dumps, one when reading a SLG46826V and a full programming cycle for my diavox SLG46826V.
Analyzing gets old pretty fast tabbing between the datasheets and wireshark to see what the bytes and bits does. So I decided to make a wireshark dissector for the MCP2221A.
After researching some more about it, I enlisted chatGPT to do the bulk of the work or so I thought... Cobbling together unfinished lua dissector script with chatGPT for help, got me some more information.
ACMP (mcp2221a GP3) is being used as ADC.
How do you get the ADC data from the MCP2221A?
According to the datasheet it's in the status command reply.
Byte 50, 51 = ADC channel 0
Byte 52, 53 = ADC channel 1
Byte 54, 55 = ADC channel 2
Pin out description it says ADC1, ADC2 and ADC3 while it also says "3 x (16-bit) little-endian ADC channel values (CH0 LSB, CH0 MSB, CH1 LSB, CH1 MSB, CH2 LSB, CH2 MSB)."
Here is the first status reply I found in one of the dumps.
Status reply
10 00 00 20 78 00 00 00 00 02 00 02 00 02 78 00 10 00 10 28 00 60 01 01 00 00 f1 79 f0 00 00 00 30 00 1b 00 02 27 13 45 03 00 00 26 90 1c 41 36 31 32 00 00 00 00 08 00 01 03 48 02 00 00 00 00
Since bytes 50-55 is the ADC channels we get this.
ADC1: 0x0000
ADC2: 0x0000
ADC3: 0x0008
I noticed this that both the Get SRAM reply and Status reply seems to contain the ADC values. Get SRAM command reply have most bytes including the last 32 bytes marked as "Don't care" in the datasheet. Going to have to deal with more don't care and any values later.
Get SRAM reply
61 00 12 04 78 12 88 1c cf 2d 06 d0 80 32 00 00 00 00 00 00 00 00 10 08 00 0a e1 75 f0 00 00 00 30 00 1b 00 02 27 13 27 00 00 00 26 90 1c 41 36 31 32 00 00 00 00 0a 00 00 03 65 02 00 00 00 00
ADC1: 0x0000
ADC2: 0x0000
ADC3: 0x000A
The values are little endian. So the data for ADC3 from status reply above here its has the value 0x0008 which is 8 in decimal. 0x000A is 9 in decimal so the values are close enough. More testing is required. Anyway let's continue.
To calculate the actual voltage we have to know a few things. How many bits the ADC can do, in this case it's 10-bits, the voltage divider k value and the voltage reference.
The maximum value a 10-bit ADC can get is 1023.
The voltage divider has k of 4.666.
The formula to get the voltage is
voltage = adc_value / max_adc_value * vref * k
I know from the captured data that the ADC3 is setup with 4.096 V as reference.
First status reply message.
( 8 / 1023) * 4.096 * 4.666 = 0.149 Volts
Status reply in the middle of the dump
(138 / 1023) * 4.096 * 4.666 = 2.57 Volts
For the last status replay message in the dump.
(74 / 1023) * 4.096 * 4.666 = 1.38 Volts
Not sure what is going on or if my calculations are correct. I'm sure I set the voltage to 3.3 volts in the greenpak software. Perhaps there is some calibration? I'll figure it out later with some more testing.
The maximum voltage the ADC in this case see handle is
(1023 / 1023) * 4.096 * 4.666 = 19.11 Volts.
Now why is the voltage divider set like this wasting precision?
There is no input protection before the voltage divider, so to protect the inputs of the MCP2221A and PowerPAK from overvoltage the voltage divider is set up like this.
The maximum voltage the PTC can handle is 16 volts.
So if you by accident feed 12Volts into the GSD VDD_OUT it will probably not release magic smoke. The zener will sink the current, the PTC trip and the device will most likely it...
Create an account to leave a comment. Already have an account? Log In.
Become a member to follow this project and never miss any updates
sjm4306
Anders Helgesson
Just Me NL
John Lonergan