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:
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:
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:
- If I did anything wrong to solve the problem with casting as shown above?
- Have anyone successfully compiled the code in IAR workbench?