Regarding writing a bootloader which uses a micro SD card

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

Ok, I've read the AVR Bootloader FAQ. Very informative!

 

I have a few questions regarding my needs for an SD card bootloader.

 

1) If I understood correctly, whatever logic I can write in a standard program to read data from an SD card and get a file can be used in the bootloader (in a separate project without dependencies on the application) to get my firmware file. Is that right? I want to know so I can test my sd card reading code easily in an application then just move that code to a bootloader project.

 

2) The process I would need to do in such a bootloader would go as such. Do these steps make sense?

- Check if there is an sd card in the socket
- If yes, check if the firmware file expected is present
- If there is a file, continue to firmware upgrade
- Backup the current application to the sd card by reading the application memory
- Write the new firmware from the file in the SD card
- Verify the firmware written by comparing with the provided file on the sd card.
- Once all is honky dorry, call the watchdog to reset the micro
- If no firmware upgrade is available, process to start the application.

 

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

We have a member here that sometimes says "Everything that can be done already has been done". In this case he is correct.

 

Look here: https://spaces.microchip.com/gf/...

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

Oh wow. That looks good! Thanks Johan!!

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

Study that project in all its detail!  The project is by user "Orville Wilbur Wright", and it is no secret that that is nothing a pseudonym (or "alternate persona" if you like) used by Cliff Lawson with the more well known user name "clawson" here.

 

You're probably in great luck since one of the authorities on bootloaders is named "clawson". E.g. he is the one behind some of the material in the Bootloader FAQ, and frequently answers questions re bootloaders here.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

Yes, I've started to look up at the project, seems pretty slick and well done. It seems to do all I need. Hoping I can make it run just by tweaking the configurations for pins and difference for using it with xmega.

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

Once all is honky dorry, call the watchdog to reset the micro
 

That would be the usual approach, I think, for Megas and Tinies.

 

Many (All ? ) Xmegas also have a Software reset option.

 

JC 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1
case CMD_RESET_MCU:
    CCPWrite((void *)&WDT.CTRL, WDT_PER_128CLK_gc | WDT_WEN_bm | WDT_CEN_bm);	// watchdog will reset us in ~128ms
break;

by Paul Qureshi

via https://github.com/kuro68k/kboot/blob/master/xmega_usb_bootloader/xmega_usb_bootloader/bootloader.c

 

Edit: reset instead of jump

 

 

"Dare to be naïve." - Buckminster Fuller

Last Edited: Fri. Jan 26, 2018 - 11:51 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, I've been experimenting with the sd card bootloader project you pointed me out to. I first modified the target device to my Atxmega64a3u in the project setting in atmel studio 7. Then adapted the configuration in the configure.h

#define SD_PIN      5
#define SD_PORT	    PORTE
#define SD_DDR	    PORTE_DIR
#define CS_PIN	    4
#define SCLK_PIN    7
#define DI_PIN      5 //i(n to SD card that is)
#define DO_PIN      6

But I think there might be some gotchas with the xmega porting: I get this error at compilation: 

Severity Code Description Project File Line

Error operand out of range: 1664 pfboot K:\Dev\XMegaAvr\projects\SDBootloader\asmfunc.S 37 which points to this line:

    sbi	DDR_DI		; DI: output

I'm afraid this kind of thing appends because the Xmega uses addressing over what the current code is capable of. I'm afraid I'm stuck there unless someone is aware of a port version to the xmega.

Any ideas?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
    sbi	DDR_DI		; DI: output

That look weird. The SBI instruction takes two operands. Can you show the definition of DDR_DI ?

 


 

When you get the "operand out of range" on the SBI (or CBI) instruction(s) this is (almost?) always because the register operand (first operand) is out of range for the SBI instruction. It can only address registers in the 0 - 31 address range.

 

Google the error message text (in combination with "AVR") to get to the nitty-gritty of it.

 

There's an application note (whose number eludes me ATM) that has macros for dealing with this transparently.

 

I'm sure someone with a better memory than mine will toss in the details here eventually.

 

EDIT: See e.g. this: http://www.avrfreaks.net/forum/o... . The links in that thread to the app notes are old, and will only redirect to the Microchip landing page. Search the MC site for AVR001! (Yes, MC had their head up their * when they "migrated" the Atmel web site after the acquisition.)

 

EDIT: I was in luck so you are in luck. Found it immediately. Go here: http://www.microchip.com/wwwappn...

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

Last Edited: Sat. Jan 27, 2018 - 10:04 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just to say that I've rwad this thread but as I'm on a mobile it's difficult to provide full answers.

My SD bootloader project uses the core parts of EL Chan's PetitFs which includes the "soft SPI" that just bit bangs SPI on a few IO pins. That should actually make it more portable to Xmega than if "real" SPI were used but even for GPIO the Xmega is a little different so DDRx now becomes PORTx_DIR and so on (PINx also becomes PORTx_IN) so the code will need a little work for Xmega.
.
Also SPM is likely to be quite different.
.
Finally the design goal was to get a FAT aware bootloader into 2K or (with certain options disabled) even below 1K so it would fit in the bootloader of small AVRS. As such I never contemplated supporting micros that may require more than 16bit pointers. The 64K Xmega should be OK but above that you may have issues.

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

clawson wrote:
I've rwad this thread but as I'm on a mobile it's difficult to provide [..] answers

Amply demonstrated, right there.. ;-)

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]