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

Corrupted flash memory writes for Atmega328p with ISP interface #44

Open
araqioui opened this issue Apr 16, 2024 · 4 comments
Open

Corrupted flash memory writes for Atmega328p with ISP interface #44

araqioui opened this issue Apr 16, 2024 · 4 comments

Comments

@araqioui
Copy link

araqioui commented Apr 16, 2024

While trying to execute :

pymcuprog write  -f executable.hex --erase --verify -t atmelice -d atmega328p -i isp

The command always fails at flash memory verification step:

Connecting to any atmelice
Connected to Atmel-ICE CMSIS-DAP from ATMEL (serial number J42700040265)
Debugger firmware version 1.45.7
Debugger hardware revision 0
pymcuprog.nvm - WARNING - 
pymcuprog.nvm - WARNING - AVR-ISP/SPI stack is in Alpha state
pymcuprog.nvm - WARNING - Expect some features to be missing
pymcuprog.nvm - WARNING - 
Pinging device...
Ping response: 1E950F
Erasing device before writing from hex file...
Writing from hex file...
Writing flash...
Verifying flash...
pymcuprog.programmer - ERROR - Verify failed for flash memory:
pymcuprog.programmer - ERROR - Verify mismatch starting at location 0x000000: 0x0C vs 0xFF (is the memory section erased?)
Verification failed!

The mismatch location address is not always the same.

On the other hand, while trying to flash using MPLAB IPE with the same HW setup, and the same hex file, it always passes.

@xedbg
Copy link
Contributor

xedbg commented Apr 16, 2024

Logged internally as DSG-7318.
Thanks for reporting this and providing a fix!
We currently don't do pull-requests directly on github but the patch can be made on our git repo and the fix will be in place in the next release. We have just recently completed a release, so can't yet comment on when this might be done.

@araqioui
Copy link
Author

araqioui commented Apr 16, 2024

@xedbg Thank you for taking the time to look at this
You may have a look at this #PR for proposed fix.
Have a great day !

@xedbg
Copy link
Contributor

xedbg commented Apr 16, 2024

I think your fix works... interesting though, the tool protocol also has a delay argument which is not correctly used. This fix in pyedbglib's avrispprotocol.py could arguably be more "correct" when seen from the tool firmware:

Add parameter to write_flash_page:

# def write_flash_page(self, byte_address, data):
def write_flash_page(self, byte_address, data, delay_ms=5):

Then send in the delay to the tool firmware and set bit 6 to make use of it:

# command.extend([0x81])  # Page mode
# command.extend([0])  # Not used
command.extend([0x91])  # Write page with timed delay
command.extend([delay_ms])

@araqioui
Copy link
Author

araqioui commented Apr 17, 2024

@xedbg Thanks for the review and the proposed fix.
I can't help but agree with you on your suggested fix... Tested and worked just perfectly 💯
I opened a #PR to bring your suggested fix to life in the next release hopefully 😃

araqioui added a commit to smaders/pyedbglib that referenced this issue Apr 18, 2024
This MR is about fixing the AvrIspProtocol.write_flash_page() by using the delayed write command with an optional delay parameter.
A delayed write page flash is prefered over normal write command in terms of being in sync with MCU's flash memory timing constraints.
See this issue  for further details :  microchip-pic-avr-tools/pymcuprog#44

ref: https://smade.atlassian.net/browse/LC03T-477
araqioui added a commit to smaders/pyedbglib that referenced this issue Apr 18, 2024
This MR is about fixing the AvrIspProtocol.write_flash_page() by using the delayed write command with an optional delay parameter.
A delayed write page flash is prefered over normal write command in terms of being in sync with MCU's flash memory timing constraints.
See this issue  for further details :  microchip-pic-avr-tools/pymcuprog#44
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

2 participants