cancel
Showing results for 
Search instead for 
Did you mean: 

Using USB and CAN controllers together

mohith
Associate II
Posted on September 23, 2009 at 02:45

Using USB and CAN controllers together

7 REPLIES 7
mohith
Associate II
Posted on May 17, 2011 at 13:24

Hello people,

I am using the STM32F103RB controller (in the LQFP64 package of course). Now my particular application requires both CAN and USB controllers to be used together. Is it possible?

I finished the CAN part first and all worked well. Now when I enable the USB part (as in the virtual COM port demo) it all goes crashing down, my laptop does not detect the hardware, even worse the controller goes into hardfault!!! I had no clue untill a few minute ago when I simply denied clock to the CAN controller, USB started working. Does it mean that I should forget about getting them to work together? Or am I making some stupid mistake whlie initialising them, like something in the NVIC initialisation?

Please help... I leave my life in your hands!!!

mbadanai
Associate II
Posted on May 17, 2011 at 13:24

Quote:

On 17-09-2009 at 22:01, Anonymous wrote:

Hello people,

I am using the STM32F103RB controller (in the LQFP64 package of course). Now my particular application requires both CAN and USB controllers to be used together. Is it possible?

I finished the CAN part first and all worked well. Now when I enable the USB part (as in the virtual COM port demo) it all goes crashing down, my laptop does not detect the hardware, even worse the controller goes into hardfault!!! I had no clue untill a few minute ago when I simply denied clock to the CAN controller, USB started working. Does it mean that I should forget about getting them to work together? Or am I making some stupid mistake whlie initialising them, like something in the NVIC initialisation?

Please help... I leave my life in your hands!!!

I report to you a sentences from STM32 Reference Manual (pag. 492):

''In Medium-density and High-density devices the USB and CAN share a dedicated 512-byte SRAM memory for data transmission and reception, and so they cannot be used concurrently (the shared SRAM is accessed through CAN and USB exclusively). The USB and CAN can be used in the same application but not at the same time''

So, if your device is a medium or high density you can't use USB and CAN concurrently....

mohith
Associate II
Posted on May 17, 2011 at 13:24

Thank you for the information. I just got the bad news from a development board maker in their data book (on the third page itself.. hehehe)

thank you once again for your time

mohith
Associate II
Posted on May 17, 2011 at 13:24

that being said, how about using them in the same application but not concurrently?

Say I start with CAN and when I am done with it, simply disable the clock to the CAN module and start the USB initialization. I tried this but looks like I am missing something. The controller hangs while initializing USB in this manner. These are the steps I follow

//For initialising CAN

1. Enable clock to CAN module, GPIOB and AFIO

2. Do a Pin remap for bring CAN out on GPIOB pins 8&9

3. Initialize GPIOB

4. Initialize NVIC for receiving interrupts

5. Initialize CAN cell

6. Initialize CAN filters

7. Enable CAN interrupt

....

//Do work with the CAN

....

//Disable CAN and enable USB

1. De-initialize CAN

2. Disable clock to CAN

3. Configure USB to run from a source of 48MHz

4. Enable clock to USB

5. Call USB library function USB_Init()

and this is where I get stuck....

Any ideas? please help.

Since I no longer use USB and CAN together, a workaround I thought about is to start with CAN, when the work is done, set a flag in a register (that can survive a software reset) and in my main function, I will check if this flag is set or not. If yes, I will go ahead with initializing USB. Is there a register that suits the description ?(I mean something that can survive a software reset).

clive2
Associate II
Posted on May 17, 2011 at 13:24

Quote:

Since I no longer use USB and CAN together, a workaround I thought about is to start with CAN, when the work is done, set a flag in a register (that can survive a software reset) and in my main function, I will check if this flag is set or not. If yes, I will go ahead with initializing USB. Is there a register that suits the description ?(I mean something that can survive a software reset).

Well the RAM, being static, survives a reset, pick an address outside the BSS/HEAP footprint of your application.

Assuming a 64KB RAM part

#define MAGIC (0xDEADBEEF)

*((unsigned *)0x2000FFF0) = MAGIC;

NVIC_GenerateSystemReset();

...

if (*((unsigned *)0x2000FFF0) == MAGIC)

{

*((unsigned *)0x2000FFF0) = ~MAGIC; // Invalidate

// Other stuff

}

Or use the BKP registers, which survive removal of the primary supply

// Enable BKP Element

BKP_WriteBackupRegister(BKP_DR1, MAGIC);

...

// Enable BKP Element

if (BKP_ReadBackupRegister(BKP_DR1) == MAGIC)

{

BKP_WriteBackupRegister(BKP_DR1, ~MAGIC);

// Other stuff

}

-Clive

miles
Associate II
Posted on May 17, 2011 at 13:24

Quote:

On 18-09-2009 at 08:54, Anonymous wrote:

Thank you for the information. I just got the bad news from a development board maker in their data book (on the third page itself.. hehehe)

thank you once again for your time

Are you aware of the STM32F105? It allows use of USB and CAN at the same time, and it's available in a 64-pin package, which is probably pin compatible with your STM32F103.

http://www.st.com/mcu/inchtml.php?fdir=pages&fnam=stm32_connectivity

mohith
Associate II
Posted on May 17, 2011 at 13:24

Hi Clive,

That was neat. I tried the backup domain and now it works like a charm. Thank you for your time.. by the way.. I loved the constant (deadbeef)

regards

mohith