stm32 bluetooth usb integration RFC

This forum is about you. Feel free to discuss anything is related to embedded and electronics, your awesome projects, your ideas, your announcements, not necessarily related to ChibiOS but to embedded in general. This forum is NOT for support.
Post Reply
vitaly
Posts: 8
Joined: Mon Jan 02, 2012 11:24 am

stm32 bluetooth usb integration RFC

Post by vitaly »

Hi!

I recently successfully coded usb bluetooth demo for stm32f4-discovery, based on ST usb lib and the btstack project.

Now I'd like it to be integrated with ChibiOS, but to my understanding, ST usb lib code size is considerable and it is not feasible to rewrite it from scratch, so I'm thinking of sort of weak integration. For instance, may be it's possible to just wrap relevant usb ISR into OS with minimal effort for the time being.

What do you think?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: stm32 bluetooth usb integration RFC

Post by Giovanni »

Hi,

It is possible for sure, one user already integrated the ST USB library with ChibiOS in the past (see GNUK project). Just take care to rewrite (or wrap) interrupt handlers using ChibiOS macros if you plan invoking OS APIs from ISRs or callbacks.

Giovanni
vitaly
Posts: 8
Joined: Mon Jan 02, 2012 11:24 am

Re: stm32 bluetooth usb integration RFC

Post by vitaly »

Thank you very much for your prompt responce and good starting point link, Giovanni.

Now I've faced another issue: contrary to ST usb device lib, used in GNUK, current OTG/host usb lib version frivolously uses long (I've found 200ms at least) delays from inside ISR. I tried to emulate them using gptPolledDelay() (yes, I've read ChibiOS docs, but it was just an experiment anyway) with very limited success: it hangs after few successful stages.

Have you any idea how to fix it in a least intrusive way? I'd implemented it using spinlocks or something similar, but I don't want to convert ISR into state machine.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: stm32 bluetooth usb integration RFC

Post by Giovanni »

200mS loops inside an interrupt handler? LOL, great design there.

Anyway, yesterday I added a RT counter feature to the STM32 HAL driver, you may checkout the current trunk and use that for delays. In hal.h there are examples. Note, it is still untested but very simple code.

Giovanni
vitaly
Posts: 8
Joined: Mon Jan 02, 2012 11:24 am

Re: stm32 bluetooth usb integration RFC

Post by vitaly »

Thank you, I'll give it a try.
vitaly
Posts: 8
Joined: Mon Jan 02, 2012 11:24 am

Re: stm32 bluetooth usb integration RFC

Post by vitaly »

Apparently it was not so scary: huge delays were present in a single ISR branch (usb reset). So, I have managed to integrate my code with ChibiOS/RT as we discussed above, now it works (possibly not very stable yet, but anyway). Thank you for your support and great OS, it looks truly fantastic to me. Keep going good work.

BTW, in case anybody interested, my code (although in very early stage) is available at https://github.com/byly/uubt
Post Reply