PROBLEM SOLVED - Can I program a W25Q80DV in circuit? - Page 1
Forum section: electronics / general

author: Phil1977
author_rank: Frequent Contributor
timestamp: August 12, 2024, 08:38:41 am
content: Hi,I have a device (a FNIRSI SG04 process calibrator) that does not start anymore after a failed firmware upgrade.Obviously the code is stored in a W25Q80DC chip from winbond in an accessible SOIC8 form factor. I have different firmware revisions as a .bin file.Does anyone know if it´s possible to flash this device with a SOIC8-test-clip in circuit? Can anyone recommend a tool or Raspi-code or anything else to flash via SPI?I´d desolder the chip only as a measure of last resort. The SG04 has quite a lot of analogue blocks and I don't want to thermally stress them if it´s not the only alternative to discarding.Thanks in advance!

author: amyk
author_rank: Super Contributor
timestamp: August 13, 2024, 03:20:48 am
content: You can try to apply a current-limited voltage to see if it attempts to power up the rest of the system; if it does, you will need to lift the Vcc pin on the IC before using a chip clip.

author: HwAoRrDk
author_rank: Super Contributor
timestamp: August 13, 2024, 07:53:26 am
content: If you can find a way to hold the SPI master (i.e. MCU) in reset state, then you should be able to do it in-circuit. This way the master will not make any attempts to communicate and will also have all its connected pins hi-Z. Maybe if you can find a programming header for the MCU that features reset, you can jump it to ground.Assuming the flash is operating at 3.3V, you can do the flash programming using a Raspberry Pi with its native SPI interface and theflashromutility. You need to specify which SPI interface to use with-p linux_spi:dev=/dev/spidevX.Y. See man page for details.I would advise putting some series resistors on the SPI connections just in case. Nothing too large, 1k is good. And you can turn down the SPI clock speed by adding the optionalspispeedparameter to the above arg, to avoid problems due to janky temporary wiring.(IIRC the default is something like 10 MHz.)

author: HwAoRrDk
author_rank: Super Contributor
timestamp: August 13, 2024, 01:04:51 pm
content: I looked into this a bit more. It would seem FNIRSI have made it easy to control the reset line of the MCU.In looking for teardown pictures, I found a YouTube review and teardown byKerry Wongof the SG-003A, which seems to be fairly similar to the SG-004A. In that, you can see the NRST pin of the MCU (GeehyAPM32F103VCT6in LQFP100) - right next to the two crystal oscillator pins - is connected to an unpopulated button footprint on the top edge of the circuit board.Looking at another YouTube review and teardown byDiodeGoneWildof the SG-004A, it appears that while they are using a different MCU (ArteryAT32F403A), it shares the same (or very similar) LQFP100 pin-out, so the NRST pin is in the same place. As there is a similar unpopulated button footprint on the board edge, it follows that even though the exact route of the trace coming from the NRST pin is obscured by passing to another layer through a via, it's highly likely it connects to this button just like on the SG-003A.So, to hold the MCU in reset during flash SPI programming, you can likely simply short the two pads of this button footprint.Here's also some more details from notes I made when I did a similar thing - programming an SPI flash chip in-circuit from a Raspberry Pi - a while ago:If not already present, install flashrom utility:sudo apt install flashromEnable SPI0 bus on Raspberry Pi:1. Edit /boot/config.txt.2. Uncomment (or add) line with "dtparam=spi=on".3. Reboot Pi.4. Confirm that /dev/spidev0.0 and /dev/spidev0.1 exist.Connect SPI flash chip to Raspberry Pi GPIO header as follows:Flash PinPi GPIO Pin1 (CS)24 (GPIO8, SPI0 CE0)2 (SO)21 (GPIO9, SPI0 MISO)3 (WP)[Jumper to VCC]4 (GND)20 (GND)5 (SI)19 (GPIO10, SPI0 MOSI)6 (SCK)23 (GPIO11, SPI0 SCLK)7 (HOLD)[Jumper to VCC]8 (VCC)17 (3V3)Writing ROM image to chip:1. Check chip responds to communication:sudo flashrom -p linux_spi:dev=/dev/spidev0.02. Write data:sudo flashrom -p linux_spi:dev=/dev/spidev0.0 -w <filename.bin>3. Verify data (optional):sudo flashrom -p linux_spi:dev=/dev/spidev0.0 -v <filename.bin>Note that flashrom requires data file size to match size of flash. If ROM image is not big enough, pad with 0xFF bytes to required size:srec_cat <filename.bin> -binary -fill 0xFF 0 <size> -o <filename-padded.bin> -binaryChange device argument to "linux_spi:dev=/dev/spidev0.0,spispeed=NNN" to set SCK speed (value N in kHz).I mis-remembered before about default SCK speed - it's 2 MHz, but that's still rather fast, so you'll probably want to slow it down to a few hundred kHz.

author: abyrvalg
author_rank: Frequent Contributor
timestamp: August 13, 2024, 01:35:01 pm
content: These APM32/AT32 MCUs run firmware from internal flash, so perhaps W25Q is a wrong target.

author: Phil1977
author_rank: Frequent Contributor
timestamp: August 13, 2024, 01:51:24 pm
content: Thousand thanks for the detailed descriptions!Currently I´m trying to find out if I can still get a warranty repair/exchange of the failed unit - but I do not have realistic hopes, I didn't get the device from the manufacturers store but somewhere else.Prior to the failed update the device appeared as a flash-drive in Windows so you can easily program the firmware. I also would suspect that the bootloader for the flash-drive is in the MCU but not in the external flash. Anyhow, I´d give it a try to read the W25Q, compare it roughly to the .bin files and if there are any similarities I´d try to reprogram it. Even if it doesn't work you learn a lot about repairing modern stuff in general.I´ll keep you updated.

author: HwAoRrDk
author_rank: Super Contributor
timestamp: August 13, 2024, 02:51:55 pm
content: Quote from: abyrvalg on August 13, 2024, 01:35:01 pmAh, yes, that's right. That fact passed me by - should have looked more closely at the MCU datasheet.Quote from: Phil1977 on August 13, 2024, 01:51:24 pmI was going to say that the size of the .bin firmware image file you already have will be a hint as to where its home is, but given that the W25Q80DV has a capacity of 1 MB, and (assuming your unit is identical) the AT32F403AVGT7alsohas an on-chip flash capacity of 1 MB ('G' in part number = 1 MB flash), that is not a good lead.The AT32F403A datasheet does say it features "SPIM interface: Extra interfacing up to 16 Mbytes of the external SPI Flash (as instruction/data memory)", so it appears the MCU is actually capable of running code from SPI flash, so the bootloader on internal flash hypothesis is feasible. But having 1 MB of MCU flash would be rather overkill for just a bootloader...Given that the SG-004A has a "History Record" feature, I am thinking the SPI flash might only be used for this data.

author: ebastler
author_rank: Super Contributor
timestamp: August 13, 2024, 03:04:08 pm
content: Quote from: HwAoRrDk on August 13, 2024, 02:51:55 pmI haven't looked at the datasheet of this particular MCU. Does it have BOOT0/BOOT1 pins which define where it boots from? Can the connections to those be traced, or the voltage levels upon boot be measured?

author: pcprogrammer
author_rank: Super Contributor
timestamp: August 13, 2024, 04:20:21 pm
content: To solely target the W25Q80DV, I would suggest to look closely to the parts near the chip. It might be that they added a diode in series with the VCC pin of the W25Q80DV. I have seen this in the FNIRSI 1013D and 1014D for both the FLASH chips used in these devices.If that is the case it is possible to use a clip and power only the W25Q80DV itself. But be careful and make sure the programmer being used is 3.3V on not only the VCC pin, but also on the SPI pins. I say this from experience having blown the FLASH in one of my 1013D's. The programmer used 5V on the SPI lines.

author: HwAoRrDk
author_rank: Super Contributor
timestamp: August 13, 2024, 04:53:01 pm
content: Quote from: ebastler on August 13, 2024, 03:04:08 pmThe datasheet says it has both BOOT0 (pin 94) and BOOT1 (pin 37). You can see in the screenshots I posted earlier that the resistor at a 45-deg angle above the chip is connected to BOOT0, for a pull-up or pull-down, but does not appear to go anywhere else. BOOT1 seems to have a trace disappearing away to the LCD screen. (Edit: actually, BOOT1 has no other function apart from GPIO PB2, so not 'XMC' LCD interface.) So, whatever those pins define as the boot mode appears to be fixed.From the MCUreference manual:QuoteAnd from the datasheet:QuoteI'm not sure exactly what it means when it talks about memory banks. But the internal flash memory is segmented into two areas: one 256 KB 'ZW' (zero wait state) memory, and one 768 KB 'NZW' (non-zero wait state) memory. I have a feeling it is talking about that, with "bank 3" being external SPI flash memory.

author: abyrvalg
author_rank: Frequent Contributor
timestamp: August 13, 2024, 07:46:16 pm
content: OP, would you mind posting your .bin file? It should be quite easy to find out from which memory it should run by looking at vector table.

author: Phil1977
author_rank: Frequent Contributor
timestamp: August 14, 2024, 06:20:58 am
content: You can get the latest firmware (the one that destroyed my device) here:https://www.fnirsi.com/cdn/shop/files/SG-004A_V2.11.zip?v=18145067921082521464I can also send you a link to the previous version per PM.

author: abyrvalg
author_rank: Frequent Contributor
timestamp: August 14, 2024, 03:14:33 pm
content: This .bin is built for 0x08005800 start address which fits MCU's internal flash. But you can't just erase the MCU and write this bin, it is not a complete image, there should be some bootloader at 0x08000000-0x08005800. Try reading out the flash if it is not protected. In any case, W25Q is wrong target.

author: Phil1977
author_rank: Frequent Contributor
timestamp: August 14, 2024, 04:18:07 pm
content: If the bootloader is not in the provided file then it seems there must be broken more than just the program area. Of course I don't know FNIRSIs programming secrets, but isn't usually the USB-drive code in the bootloader - to just prevent the device from getting bricked if something goes wrong in the program area?

author: abyrvalg
author_rank: Frequent Contributor
timestamp: August 15, 2024, 09:25:55 am
content: We can’t be sure here, in the worst case the bootloader cold be damaged, or it just can’t detect some kind of damaged firmware and jumps straight to it, who knows. Try reading out the full flash to see what can be salvaged.In the worst case (damaged boot or read protection set) here is a trick to fake the bootloader: cut first 0x5800 bytes of the main firmware and paste (insert, not overwrite) it at the beginning - this will duplicate fw’s vector table in the bootloader area and the CPU will jump straight into the fw upon reset. You’ll loose the bootloader functionality (whatever it was), but the main fw could work in some cases (if it doesn’t use code/data from boot).

author: HwAoRrDk
author_rank: Super Contributor
timestamp: August 15, 2024, 10:23:07 am
content: Can't imagine why they would have their own bootloader when the MCU has its own USB bootloader.There is a UART header (three pins, RX, TX, GND) next to the MCU. Could try connecting to that (with a USB-UART adapter - note it'll probably need to run at 3.3V, not 5V) and see if any code that is managing to run is spitting out any messages that might be informative. I would imagine a custom bootloader might do so. They obviously didn't put that header there for no reason.

author: abyrvalg
author_rank: Frequent Contributor
timestamp: August 15, 2024, 09:32:42 pm
content: Quote from: HwAoRrDk on August 15, 2024, 10:23:07 amTheir custom bootloader emulates a mass storage device, simplifying the update process significantly.

author: Phil1977
author_rank: Frequent Contributor
timestamp: August 28, 2024, 07:57:23 am
content: Good news everyone (TM): The SG-004A is running again without any solder activities.After a long and unsuccessful discussion with the seller, I started to further disassemble the unit. Unexplainably but true, the bootloader showed me the flash drive again after disconnecting the display. Maybe the code skips some initialization routines if the display is not connected, but obviously it enabled the firmware flashing procedure.After copying the old FW 2.9 back to the device it was alive again. Also the update to FW 2.11 was flawless this time.Now I just have to check the calibration before it get´s back into the toolbox.Thanks anyhow for all the help! Some inner child of mine nearly hoped for some worse problem, this nearly was too easy.

author: Mike1233
author_rank: Newbie
timestamp: September 22, 2024, 12:06:23 am
content: Did you find any problems with the version 2.11?Is it better that if i update my SG-004A first with 2.9 and then version 2.11?Thanks.

author: Phil1977
author_rank: Frequent Contributor
timestamp: September 22, 2024, 06:02:37 am
content: Yes, as written in the other thread dedicated to the SG-04 I´ve heard from one other guy who bricked his device by skipping V2.9 and flashing directly to V2.11.If V2.11 is running then it seems to be running fine. But I don't have a changelog and only noticed a corrected typo so far.

author: Mike1233
author_rank: Newbie
timestamp: September 24, 2024, 08:05:02 pm
content: Thank you for the reply. I first did the update with 2.9 and then i did use 2.11.My device is still alive so i think everything is fine.This is what i just saw in the folder of the 2.11 firmware.SG-004A V2.9 2023/05/111.修复 设置 输出24V中工程量上限显示0问题SG-004A V2.10 2023/05/181.修改热电偶输入显示问题SG-004A V2.11 2023/06/121.更新热电偶输出问题----------------------------SG-004A V2.9 2023/05/111. Fix the problem that the upper limit of engineering quantity in "Settings" output 24V shows 0SG-004A V2.10 2023/05/181. Modify the thermocouple input display problemSG-004A V2.11 2023/06/121. Update thermocouple output problem