Doing a very simple call to usbPrepareTransmit - the exact lines are:
Code: Select all
int ToHost(void *data, unsigned int len)
{
usbPrepareTransmit(&USBD1, 1, data, len);
I get a sigsegv when debugging which suggested a stack corruption so I doubled the main stack to 0x800 even though I've declared only 8 bytes of data!
Got to the stage where I was single stepping individual ARM instructions in the debugger rather than source lines and gdb comes up with this as the calling pattern:
Code: Select all
usbPrepareTransmit (usbp=0x8005e45 <chMtxLock+20>, ep=32 ' ', buf=0x0, n=536875184) at ../Common/ChiBIOS/os/hal/src/usb.c:427
Now this is clearly not right - looks like corruption of the calling parameters, fair enough. But how on earth is that happening with such a simple call fragment? Been trying to track this down for hours and can't for the life of me see what the issue is but it has to be something simple. I've checked the calling parameter types - pointer, int, pointer, int and they seem fine, so what is is? Hopefully someone will take a quick look, have a good laugh at my expense and point out the one-liner fix. Please?