How to Compile?? SAM BA Bootloader for SAM D21 in IAR Workbench

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

I want to modify SAM BA bootloader for SAM D21 and adapt it for my project. My target device is ATSAMD21J18A and I would use USB CDC for bootloading. I referred the application note "Atmel AT07175: SAM-BA Bootloader for SAM D21" and downloaded source files from here.

Now, when I tried to compile the source code in IAR workbench (IAR Embedded Workbench for ARM v7.40.5.9739) for testing (without any changes to source code), I get the following errors:

sam_ba_errors_in_iar

 

after this, I tried to remove errors and I managed to get rid of errors by casting like this:
from this (you can refer to the line numbers on which the error occurred):

USB->DEVICE.CTRLB.bit.SPDCONF = USB_DEVICE_CTRLB_SPDCONF_0_Val;         //line no: 279
pCdc->pUsb->DEVICE.INTFLAG.bit.EORST = true;                            //line no: 315
pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.bit.TRCPT0 = true;    //line no: 376
pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.bit.TRCPT0 = true;    //line no: 406
pUsb->DEVICE.DeviceEndpoint[ep_num].EPINTFLAG.bit.TRCPT1 = true;        //line no: 442
pUsb->DEVICE.DeviceEndpoint[0].EPINTFLAG.bit.TRCPT1 = true;             //line no: 471
pUsb->DEVICE.DeviceEndpoint[0].EPINTFLAG.bit.RXSTP = true;              //line no: 505

to this:

USB->DEVICE.CTRLB.bit.SPDCONF = 0;         //line no: 279
*(uint16_t*)pCdc->pUsb->DEVICE.INTFLAG.bit.EORST = true;                        //line no: 315
*(uint8_t*)pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.bit.TRCPT0 = true; //line no: 376
*(uint8_t*)pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.bit.TRCPT0 = true; //line no: 406
*(uint8_t*)pUsb->DEVICE.DeviceEndpoint[ep_num].EPINTFLAG.bit.TRCPT1 = true;     //line no: 442
*(uint8_t*)pUsb->DEVICE.DeviceEndpoint[0].EPINTFLAG.bit.TRCPT1 = true;          //line no: 471
*(uint8_t*)pUsb->DEVICE.DeviceEndpoint[0].EPINTFLAG.bit.RXSTP = true;           //line no: 505

and then compiling the code again I get this:

compiling after resolving the errors in IAR code


At this point, the errors are gone and binary file ("samd21_sam_ba.hex") has been generated in the debug folder.

Now when I program my ATSAMD21J18A and connect it to computer, I get an "UNKNOWN DEVICE" error. But at the same time if I program ATSAMD21J18A with pre-compiled binary files (which came along with source code zip file) then it works absolutely fine.

 

I have made sure that the target device in IAR workbench is Atmel ATSAMD21J18A. Questions are:

  1. If I did anything wrong to solve the problem with casting as shown above?
  2. Have anyone successfully compiled the code in IAR workbench?

BR / Yasir Qureshi

Last Edited: Thu. Oct 15, 2015 - 11:31 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yasir wrote:
I have made sure that the target device in IAR workbench is Atmel ATSAMD21J18A.

1. Questions are: If I did anything wrong to solve the problem with casting as shown above?

2. Have anyone successfully compiled the code in IAR workbench?

 

Change

    before:

USB->DEVICE.CTRLB.bit.SPDCONF = USB_DEVICE_CTRLB_SPDCONF_0_Val;         //line no: 279

after:

USB->DEVICE.CTRLB.bit.SPDCONF = USB_DEVICE_CTRLB_SPDCONF_FS_Val;         //line no: 279

      Maybe:  _FS_  or _LS_ or _HS_

 

For errors:

Error[Pe137]: expression must be a modifiable lvalue \drivers\cdc_enumerate.c 315
Error[Pe137]: expression must be a modifiable lvalue \sambamonitor\drivers\cdc_enumerate.c 376
Error[Pe137]: expression must be a modifiable lvalue \sambamonitor\drivers\cdc_enumerate.c 406
Error[Pe137]: expression must be a modifiable lvalue \drivers\cdc_enumerate.c 442
Error[Pe137]: expression must be a modifiable lvalue \drivers\cdc_enumerate.c 471
Error[Pe137]: expression must be a modifiable lvalue \drivers\cdc_enumerate.c 505 

Need enter into defined structure and remove IAR extension (__I) for defined bit setting in row (where we receive error in file cdc_enumerate.c, line 315,376 etc.)

 

 

After this all project full compile without error.

 

Last Edited: Tue. Jan 24, 2017 - 09:55 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Are you quoting to re-ask the questions or what?
Check here https://community.atmel.com/foru...

/Lars

 

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

Lajon wrote:

Are you quoting to re-ask the questions or what?
Check here https://community.atmel.com/foru...

/Lars

solution :)

 

When writefirmware from SAM-BA 2.16 I'm have error:

Bootloader: samd21_sam_ba_usbcdc

address for upload firmware: 0x1000

firmware: LED_Toggle_0x1000.bin

 

Why not possible upload firmware ?

Last Edited: Tue. Jan 24, 2017 - 11:26 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Does it work if you build the version with both interfaces and start address 0x2000? Reason I ask is that is the only one I tested and it did work for me (it was also SAMD21).

/Lars

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

No. When build with both interfaces and with start address 0x2000 also not downloaded. But executed commands (erase etc.) and may save file from memory.

OS: Win 10 x64. 

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

I used version 2.15

  C:\Program Files (x86)\Atmel\sam-ba_2.15\applets\samd21j18a\sam-ba_applets\flash\flash_app_main.c(88):#define MONITOR_SIZE (0x2000)

while 2.16 has

  C:\Program Files (x86)\Atmel\sam-ba_2.16\applets\samd21j18a\sam-ba_applets\flash\flash_app_main.c(88):#define MONITOR_SIZE (0x6000)

This limit looks hard coded, i.e., the LED_Toggle_0x1000.bin is not going to work with with any version, while LED_Toggle_0x2000.bin can work with 2.15, without rebuild the applets and/or application that is. 

A quick test with sam_ba 2.16 (I did not build any application, just writing in flash): the first address I can write is 0x6000

/Lars

 

 

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

Hey Lajon and everyone,

 

What u said at is correct. I'm running LED_0x2000 in 2.15 version of sam-ba,  but not able to run LED_0x1000 in sam-ba 2.15 or 2.16.

Kindly let me know how to run LED_0x1000 as this is my requirement.

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

Hey everyone,

 

 

Now when I program my ATSAMD21J18A and connect it to computer, I get an "UNKNOWN DEVICE" error.

But at the same time if I program ATSAMD21J18A with pre-compiled binary files (which came along with source code zip file) then it works absolutely fine.

 

How can I solve it?

 

 

please help me~

thanks~

 

Last Edited: Tue. Mar 26, 2019 - 09:35 AM