Firmware works when programmed with Flip- GUI, but not with BatchISP - Page 1
Forum section: electronics / general

author: Electr0nicus
author_rank: Regular Contributor
timestamp: March 10, 2020, 09:38:20 pm
content: HiI'm using an AT90CAN32 CAN- equipped microcontroller for a current project. In fact there are 16 AT90CAN32 connected on one CAN- Bus. Although my board has testpads and a custom programming adapter which I made and which connects to those testpads, the process of firmware update should be done completly over the CAN interface.I've downloaded and adapted the CAN- 4K Bootloader from Microchip, which can be accessed through the device page on their website.https://www.microchip.com/wwwAppNotes/AppNotes.aspx?appnote=en591223The bootloader also works fine to me. Although I have a slight problem, which is not severe, but annoys the hell out of me.If I program my firmware hex- file with the Atmel Flip utility, and then click on "Start Application" after it has programmed, the firmware starts up fine. This i can observe, as then there is a communication over the CAN- Bus and the AT90CAN32 writes out my sensor- data, as it should.If I use the batchisp utility, as intended in the final product, a thing happens which I can't explain, nor I have the slightest idea what is causing it. Maybe some of you can help me out with his wisdom.I get all green in the batchisp- commandline, although the firmware does not start up at all. There is no communication (as it should, as mentioned above) over the CAN bus. Even when cycling the power the chip continues to keep silent.Here is my Commandline for BatchISP:Code:batchisp -device AT90CAN32 -hardware kvaser -canbitrate 500 -operation CANOPEN 0x02 LOADBUFFER "Firmware.hex" MEMORY FLASH ERASE f BLANKCHECK PROGRAM VERIFY READ SAVEBUFFER "Firmware_read.hex" hex386 START NORESET 0 CANCLOSE 0x02And the output of the batchisp commandline tool:Code:C:\Program Files (x86)\Atmel\Flip 3.4.7\bin>batchisp -device AT90CAN32 -hardware kvaser -canbitrate 500 -operation CANOPEN 0x02 LOADBUFFER "Firmware.hex" MEMORY FLASH ERASE f BLANKCHECK PROGRAM VERIFY READ SAVEBUFFER "Firmware_read.hex" hex386 START NORESET 0 CANCLOSE 0x02Running batchisp 1.2.5 on Sat Mar 07 00:43:26 2020AT90CAN32 - KVASER - 500KbitDevice selection....................... PASSHardware selection..................... PASSOpening port........................... PASSOpening CAN Node....................... PASS 0x02 0x00Reading Bootloader version............. PASS 1.0.4Parsing HEX file....................... PASS Firmware.hexSelecting FLASH........................ PASSErasing................................ PASSBlank checking......................... PASS 0x00000 0x05fffProgramming memory..................... PASS 0x00000 0x05fffVerifying memory....................... PASS 0x00000 0x05fffReading memory......................... PASS 0x00000 0x05fffSaving buffer to HEX file.............. PASS Firmware_read.hex HEX386Starting Application................... PASS NORESET 0Closing CAN Node....................... PASS 0x02Summary: Total 15 Passed 15 Failed 0C:\Program Files (x86)\Atmel\Flip 3.4.7\bin>As you can see, I also read out the Flash after programming. I've also compared the source- hex file and the read- hex file with notepad++'s compare utility, and they are both exactly the same to the last byte. So the machine code in the device is the exact same as in the source- hex file. So the firmware should work perfectly.So my only idea is, that there need to be some extra configuration in the CAN- Bootloader, so that the firmware is correctly executed. I've read something of a BootStatusByte which needs to be set to 0x00 elsewhere on the internet. Although the RBSB and WBSB commands don't seem to work in batchisp with my bootloader.Code:AT90CAN32 - KVASER - 500KbitDevice selection....................... PASSHardware selection..................... PASSOpening port........................... PASSOpening CAN Node....................... PASS 0x02 0x00Reading Bootloader version............. PASS 1.0.4Reading Boot Status Byte............... FAIL Command does not exist.(A)bort, (R)etry, (I)gnore ? aISP done.As documentation for the inner workings of batchisp is really sparse in my opinion, even after 6h of debugging, I didn't go further.Maybe someone of you has the final piece of the puzzle to make this work.Followup:Obviously BatchISP corrupts the hex data while programming, so it doesn't work.I've programmed the same unchanged hex- file with FLIP and then read it using a Atmel ICE via ISP.Then I programmed the same unchanged hex- file with batchisp and read it using a Atmel ICE via ISP.Now I expect, that both hex files are the same, but they aren't. And there are not minor differences, literally the complete hex code programmed with batchisp is different from the hex code programmed with FLIP. Also mostly two bytes are different per line.And not on the same position in the line, but distributed randomly.I made a diff from both files with notepad++'s compare utility.Let's take the following line in the hex file:FLIP above, Batchisp below:10009000 0C 94 67 00 11 24 1F BE CF EFD8 E0DE BF CD BFA8:10009000 0C 94 67 00 11 24 1F BE CF EFD0 E1DE BF CD BFAFInterestingly, if I open the hex file, which BatchISP reads back and saves, then they match perfectly. But obviously in reality thats not the case, because I thrust the hex data read with the Atmel ICE more than the hex read back by Batch-ISPAnyone an idea. Do I need some switch in the commandline, so that the source hex is parsed correctly?That's my new commandline:Code:batchisp -device AT90CAN32 -hardware kvaser -canbitrate 500 -operation CANOPEN 0x0F LOADBUFFER "E0390_Firmware.hex" MEMORY FLASH ERASE f BLANKCHECK PROGRAM VERIFY READ SAVEBUFFER "E0390_Firmware_read.hex" hex386 START NORESET 0 CANCLOSE 0x0FThanks in advance,Gregor

author: ajb
author_rank: Super Contributor
timestamp: March 10, 2020, 09:53:43 pm
content: So Flip and BatchISP are both talking to the same bootloader over CAN? If so, the problem is presumably in the commands (and possibly timing of those commands) sent to the BL. Can you capture the CAN traffic and compare between the two?In your sample of the differences between the two hex files, note that the last pair of hex digits is the checksum, so these are just indicating that the data in the two lines is different, which you already know. The differences between the lines do not suggest something like an incomplete erase. Do you notice a difference in programming time between the two? Maybe BatchISP is sending the next command before the device is ready to process it and the BL does not have adequate protection against this condition? Maybe the programming parameters, if any, sent by BatchISP are wrong for the device (flash timing etc?)