USB secondary bootloader for LPC1788
I am attempting to port from the Keil AN10866 app note, to CW so the LPC1788 can execute the IAP. So I have made a stab at this but not quite succeeded yet. I have some issues with the code and I wanted to see what others folks on this forum thought. The overview of these issues are the __packed keyword, a confusing cast and some inline assembly in the Keil C code. Here are the detailed questions:
Firstly there are numerous typdef'd structs which have the __packed attribute. i.e.:
typedef struct __packed USB_COMMON_CONFIGURATOR
which I substituted
#pragma pack(1)
typedef struct USB_COMMON_CONFIGURATOR.
This satisfied the compiler and I believe the __packed keyword defaults to 1. So related to this question is the c expression where the __packed keyword again is used ie:
LPC_USB->USBTxData = *((__packed uint32 *)pData);
not sure how to use the pragma directive here, so I can remove the __packed directive and the compiler is happy, but it looks like the __packed tells the compiler this data was initially packed and needs to be treated as aligned to byte boundaries. Not sure here, just guessing...!
Next, there is a C expression which I do not get:
the declaration:
USB_COMMON_DESCRIPTOR *pD;
the initialization:
pD = (USB_COMMON_DESCRIPTOR *)USB_ConfigDescriptor;
The Keil compiler builds fine, but Crossworks bitches on this statement:
(uint8_t *)pD += ((USB_CONFIGURATION_DESCRIPTOR *)pD)->wTotalLength;
with the message
"lvalue required as left operand of assignment"
if I remove the pointer cast to uint8_t *, the compiler builds without error. Just not sure if the original author intended the pD pointer to increment by wTotalLength, just seems a little unsafe. I would have thought pD += sizeof(USB_CONFIGURATION_DESCRIPTOR); would have been safer if the intent was to get to the next pD object. So this is just something I will have to test, but I thought I would see if anyone else has an opinion.
Lastly, there is a function call
__asm void boot_jump( uint32_t address ){
LDR SP, [R0] ;Load new stack pointer address
LDR PC, [R0, #4] ;Load new program counter address
}
From my experience with the MSP compiler, I remember you cannot mix c and assembly. I got the following messages from this small .s file:
.global boot_jump
.section text
boot_jump:
ldr sp, [r0]
ldr pc, [r0, #4]
Building “USB_Bootloader” in configuration “THUMB Flash Debug”
Assembling BootJump.s
bootjump.s
lo register required -- `ldr sp,[r0]'
lo register required -- `ldr pc,[r0,#4]'
Build failed
Anyway that is as far as I have dug into this, as an ARM newbie, hoping there would be some sage advice out there. Certainly not looking for others to do this work, but just need some pointers...
Thanks
-Bill
-
Yes, I took the path of least resistance. I used some modules from a company in the US called dzx designs (www.dzxdesigns.com). Apart from the fact their stuff worked out of the box, they also had a messaging model builder, which auto-generated the enumerations and exchanges for both the LPC1788 firmware and the host-side PC. In all, I would say they saved me a good 4-6 weeks of work! So if you are doing a home project, this is all free, if it is a commercial development, it is a one-time license of $500 per product. Money well spent believe me...
-Bill
-
I think it required I build from scratch, could not use their demo projects. As it is all in C, it was fairly painless. There are some config setups, like editing the xml memory map to indicate the entry point for the code. I would be happy to send a build to you, but you should probably work with DZX. The guy who is the programmer there (Tyler) was extremely helpful. You should mention we spoke, I have had a lot of dialog with Tyler as I did uncover some early bugs. Right now, everything is rock solid. Good Luck!
-Bill
-
Thanks again. Will be happy to get the build file from you, and Tyler email. Will contact them tomorrow.
My email is j@agrologic.com
Johanan
Please sign in to leave a comment.
Comments
6 comments