SAM-BA Bootloader NVM/Flash Write Routines

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm a bit embarrassed to post since I figure I must be missing something here, but I'm writing a bootloader for a product containing a SAML21G18B. It looked like the SAM-BA application from Atmel was a good place to start. I figured I'd just modify its flash-handling routines for my needs (AES decryption and reading HEX file from external SD). However, for the life of me I can't find any 'flash-handling routines'...

 

Looking at the source, it appears the program just writes to memory using pointers like it's RAM. I thought maybe it only worked on RAM, but I can change the address in the Windows GUI to the Flash area at 0x2000 and write there, read it back out over SWD, and verify. In the source, I don't see any logic to erase, buffer pages, or actually write to NVM like I would expect. Atmel even provides an NVM driver for writing to flash on SAM parts which would seem to confirm there's no 'magic' way to do it with nothing but pointers...

 

Can anyone point out what I'm missing?

 

Thanks as always.

This topic has a solution.
Last Edited: Sun. Sep 25, 2016 - 05:46 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The mechanism used by SAM-BA to program a non-volatile memory is based on the principle of an applet running on the target, and that handles the programming algorithm.

 You can find source for the flash handling applet in the sam-ba installation. It might be simpler to look at the i2c boot loader example project (at least SAMD21 has that), it just uses nvm_erase_row() and nvm_write_buffer() from the mentioned nvm driver.

/Lars

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the reply. That's just what I needed to hear. I had a suspicion it was something like that - when looking at the GUI it prints out 'XXXX bytes written by applet..." when you program. I just couldn't find any evidence of an 'applet'. I don't think I have the 'proper' SAM-BA source. I have a folder called 'sam-ba_monitor' that just seems to have the serial/USB interface code that calls the applet, but no applet. I'll probably take a look at the I2C example you mentioned. At this point I might just write it using the nvm driver, but anything to speed up this project...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The applet file for flash programming will be available at the following location C:\Program Files (x86)\Atmel\sam-ba_2.16\applets\samd21j18a\sam-ba_applets\flash