This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

STM32F103 CAN to USB module problem

Hi folks

The general application is this
/*******************************/

a USB MSD bootloader lives in the bottom of the flash. If there is no USB lead plugged in, the bootloader finishs and the main application is started( starts in next flash block) . If a USB lead is detected the USB perpherial is configured and used to transfer a firmware update file to a SD card. Once the USB lead is removed the SD card is checked for a update file and if necessary applied.

Once the application is started the USB perpherial is deconfigured and the CAN perpherial is configured and the SD card is used to log CAN traffic.

Then when a USB lead is plugged in, the 5V from the USB is detected and the CAN module and its interrupts are deinited and then is the USB perpherial is configured again.

When the USB lead is removed it checks for firmware updates and applies them if needed and jumps to the restart vector.

or
stays in the application code applies new configuration files then the USB perpherial is deconfigured and the CAN perpherial configured again to start CAN comms.

The main application uses RTX the bootloader does not.

the problem - The USB functionailty fails once the application has been started (e.g. PC reports USB hardware has malfunctioed)
/********************************************************************************/
The USB class is MSD - code ST based

what is happening
******************

I have a task running detecting IO ( usb plus others) and once the lead is plugged in it sends an event to a task that oversees the hand over from CAN to USB ( e.g. files are closed the CAN tasks are stopped the CAN module is deinited) then the USB perpherial is configured.

Following the ST USB code the NVICs are set then the USB perpherial is configured

but the issues is
*****************

as soon as the NVIC are enabled a USB_ISR occurs. Its as if there is an uncleared ISR status flag set. There is a function in usb_pwr.c PowerOff() that supposidly clears the ISR's etc and puts the USB module into a safe state but this does not stop it happening.

solutions I have tried
**********************

1) de- init the CAN and the USB perpherial before either is configured. (On NVIC enable immediate ISR).
3) stopping the USB perpherial clock and restarting it after a delay as it suggests else where this can be used to reset the perpherial. (On NVIC enable immediate ISR)

2)jump to start of the Bootloader. (On NVIC enable immediate ISR)

what does seem to work
**********************
Set a watchdog to time out after the USB lead has been detected in the application and let the Bootloader deal with all USB MSD functionality.

The differenace is it seems that the USB hardware has had a hard reset and the USB_Isr flag is clear.

Has anyone else had this problem and if so can you give any suggestions on what I am missing

thanks