What compiler or Atmel Studio IDE settings are needed for Bootloader to Application Code jump?

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

I am working on USB device drivers where device gets detected as HID. I'm facing problem in compiler settings for address offset in case of HID and integrating my code with bootloader. I managed to find some leads on how how to do address offsetting in Atmel Studio 6.2. After spending some time on blogs and going through comments somehow I have got it working. I don't know though if this is the right way to do so. All I have done is

 

  1. Project -> Project Properties ->Tool Check the 'Override Vector Table Offset Register' and edit that field to '&exception_table'
  2. In Project -> Project Properties ->Toolchain -> ARM/GNU Linker -> Memory Settings I have added .text=0x00004100 In 'FLASH segment'. After making these changes, I was able to do address offsetting and code works fine. I checked .hex file too and verified it's starting from 0x00004100.

Bootloader code has reserved space 0x00000000 to 0x00004000.

 

So after programming the chip with bootloader code, device enters in CDC mode (COM Port) and allows you to load the firmware from there. I have c# utility to do so.

Hence after programming the chip with BL, I put lock on those memory locations by setting up fuse in Atmel Studio->Tools->Device Programming->Fuses.

Then when I try to load the firmware, instead of going into application code (Where it should enter in HID mode), it just sits there as CDC device (COM Port). I don't know where exactly I'm going wrong.

 

I know that there's no problem in BL code because, I'm doing the same thing for my other project where code jumps from BL to Application code (Test & Measurement Instrument in this case) and everything is working good. Similarly, here should not be any issue with Application Code (in case of HID device) because without BL, my application code (HID) works properly.

 

Hence I'm sure that there are some compiler settings or Atmel Studio IDE settings must for Address Offsetting & BL compatibility I'm missing in case of this project.

 

The other working project (BL to TMI) which I mentioned above is set up in Eclipse IDE and selection of IDE is the only difference here. There are some IDE issues where HID, Eclipse IDE, WDT & BL can't go together that's why I set up this project in Atmel Studio instead of Eclipse.

 

Help in this matter is really appreciated. It's been long since I'm trying to figure out the solution of this issue. The code I'm using to jump from Bootloader to Application code is -

#define APP_START_ADDRESS  ((uint32_t)0x00004100)
#define APP_START_RESET_VEC_ADDRESS (APP_START_ADDRESS+(uint32_t)0x00000004)

/* Pointer to the Application Section */
  void (*application_code_entry)(void);

  /* Rebase the Stack Pointer */
  __set_MSP(*(uint32_t *) APP_START_ADDRESS);

  /* Rebase the vector table base address */
  SCB->VTOR = ((uint32_t) APP_START_ADDRESS & SCB_VTOR_TBLOFF_Msk);

  /* Load the Reset Handler address of the application */
  application_code_entry = (void (*)(void))(unsigned *)(*(unsigned *)(APP_START_RESET_VEC_ADDRESS));

  /* Jump to user Reset Handler in the application */
  application_code_entry();

I have checked that there's no problem at all in jumping from BL to Application code (CDC to TMI) but it fails to work in CDC to HID case.

Last Edited: Wed. Dec 2, 2015 - 04:06 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Which AVR has:

SCB->VTOR = ((uint32_t) APP_START_ADDRESS & SCB_VTOR_TBLOFF_Msk);

??

 

This looks like UC3 or ARM to me so is probably off-topic for the "Atmel Studio (AVR related)" forum.

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

@clawson I'm using SAMD series uc. SAMD21E18A.

 

[OK, thread moved]

Last Edited: Wed. Dec 2, 2015 - 04:10 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, just wanted to update that I got this issue fixed. The problem was with watchdog timer. 
I was actually configuring and starting my watchdog timer once hw gets configured as HID device by udc_start() function from ASF(thinking that if Windows takes lot time to configure it as HID, it shouldn't reset my uc if wdt is started before). Since I was having no leads on why my application code is not working with BL, I just resumed 'trial and error' method and started my wdt before udc_start() and boooommm!! It worked. Now BL->HID flow is at its best. I literally have no idea why it's working now but I'm curious to know why this is happening. Any help in this matter is really appreciated.

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

One suggest could be to change the watchdog timeout to be longer and set the early warning interrupt at the previous watchdog timeout value. Then change the starting point back of the wdt to that which caused your issue and set a breakpoint in the WDT_Handler. Run your code and see if the interrupt consistently occurs in the same area of code execution to help understand why. 

Last Edited: Fri. Dec 4, 2015 - 03:13 AM