Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing a small portion of the non-contiguous .hex file on dsPIC33CH256MP508 #9

Closed
aBarilCatalys opened this issue Sep 6, 2023 · 7 comments

Comments

@aBarilCatalys
Copy link

aBarilCatalys commented Sep 6, 2023

Using mcbootflash version 5.1.1 I am not able to properly flash a dsPIC33CH256MP508 with MCC bootloader. Downloading using mcbootflash doesn't generate any error but the program is not functionnal.
I am able to flash it properly using Microchip Unified Bootloader Host Application v1.19.1. The program works.

Using MPLAB and SNAP debugger, I was able to read back the downloaded .hex file with both programs but mcbootflash missed a section at the end of the program. I suspect this missing section explains why the program doesn't work with mcbootflash. The hex file I want to download is not contiguous. I have attached both the Java application downloaded hex and the mcbootflash downloaded hex so you can see the difference if you diff those two files.
I suspect this a is problem with the initial hex file parsing of mcbootflash but I may be wrong too...

If you need further clarification or debug data I would be happy to provide it!
Thank you and good luck.
python_mcbootflash_read.txt
java_unified_bootloader_read.txt

@mathieugalle
Copy link

mathieugalle commented Sep 7, 2023 via email

@bessman
Copy link
Owner

bessman commented Sep 8, 2023

You are most likely right that the problem is due to the file being non-continuous. I hadn't considered that possibility, so it's probably not handled correctly.

Thanks for the readbacks, I'll take a look and try to fix it.

@bessman
Copy link
Owner

bessman commented Sep 8, 2023

Could you also share the hex-file itself, i.e. the file you gave to mcbootflash to flash to your MCU?

It would also be useful to have the output of mcbootflash run with the --verbose flag active. The output will be large, so you should redirect it to a logfile.

@bessman
Copy link
Owner

bessman commented Sep 8, 2023

Looking at the code, it looks like this should work already. As long as all segments are fully within the writable memory area as reported by MCC, it shouldn't matter whether they are contiguous.

At present, my guess as to what is happening is that mcbootflash thinks the missing segment does not fit within the program memory range. That could mean one of a few things:

  1. mcbootflash subtly miscalculates the segment's space requirements, incorrectly surmising that it does not fit when in fact it does. Possible off-by-one error somewhere?
  2. The segment does in fact not fit in the program memory, but should be flashed anyway. Not sure how to handle that, would need to try and figure out what UBHA is doing differently.

A verbose output from mcbootflash should shed some light on the situation.

@aBarilCatalys
Copy link
Author

aBarilCatalys commented Sep 8, 2023

Hello M. Bessman,
First of all, thank you for taking the time to look at this issue so quickly.
Here is the .hex file that I want to program, sorry for leaving it out in my first post:
app_to_be_programmed .txt
Here is the verbose output. I am not able to fully understand it, but it looks like everything is correct?
output.txt

The dsPIC33CH seems to have a unique memory scheme with the master and slave cores. If you take a look at figure 1.1 of the dsPIC33CH data sheet (https://ww1.microchip.com/downloads/aemDocuments/documents/MCU16/ProductDocuments/DataSheets/dsPIC33CH512MP508-Family-Data-Sheet-DS70005371D.pdf) you will see that the slave core program is included in the flash memory (hex file) after the end of the master core program. The linker script that MCC generates seems to put the slave program at the end of the memory creating the gap in the hex.file and making it non-contiguous.

@bessman
Copy link
Owner

bessman commented Sep 9, 2023

I've looked over the hexfile and the missing data is part of a segment which just barely does not fit within the program memory range, by just three bytes. Therefore, mcbootflash ignores it.

At some point during development, I decided to not flash contiguous data segments unless the whole segment fit. I can't recall why I did that. Thinking about it now, it seems wrong. Any data within the program memory range should be flashed. I can't see any downside; at worst any additional data would just be unreachable from the rest of the program.

I've made a prerelease, v5.1.2b1, which should fix your problem. You can install it from here or from pypi with pip install --pre -U mcbootflash. Let me know if it works and I'll promote it to a proper release.

@bessman
Copy link
Owner

bessman commented Sep 13, 2023

Since I'm pretty sure the new behavior is correct, I've included it in the recent v6.0.0 release. I'm tentatively closing this as fixed; let me know if the problem persist. If it is indeed fixed, I would appreciate a confirmation 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants