USB on STM32L432 Driving Me NUTS!

This forum is dedicated to feedback, discussions about ongoing or future developments, ideas and suggestions regarding the ChibiOS projects are welcome. This forum is NOT for support.
avrhack
Posts: 140
Joined: Tue Dec 24, 2013 1:42 pm
Has thanked: 17 times
Been thanked: 3 times

USB on STM32L432 Driving Me NUTS!

Postby avrhack » Thu Mar 28, 2019 9:30 am

OK I'm sure I'm doing something stupid, but this is driving me nuts.

I have a perfectly working app on an STM32L432 when USB is connected and working. There's also an LED which flashes briefly every 5 seconds to show activity - it runs in the main loop. There are two other threads which cover reading from USB and one that also writes to USB.

As soon as I unplug from USB, everything stops - the LED doesn't flash any more. Plug it back in and everything resumes fine. Note THE PROCESSOR DOESN'T reset - it's definitely just suspended and resumed.

I'm not using CRS so there should be no dependency on the USB clocks. I'm checking in the read and write routines for the USB being 'ACTIVE' and I've even added a flag of my own that is 'off' when the USB_SUSPEND event is triggered, to make sure none of my read/write routines are paused on that. But even if they were, the main thread would surely be unaffected if one of the other threads stalled!

Any ideas because I'm utterly fed up with this stuff - it seems as if the USB SUSPEND is causing the whole processor to be suspended, but I can't see anything in the ChibiOS code to do that, nor of course is there anything in my code either........

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: USB on STM32L432 Driving Me NUTS!

Postby Giovanni » Thu Mar 28, 2019 9:41 am

Hi,

If the LED is no more flashing probably the system is halted.

Do you have debug options enabled in chconf.h? if so, what is the state after the CPU stops? please inspect the halt message (if any) and do a stack trace.

Giovanni

avrhack
Posts: 140
Joined: Tue Dec 24, 2013 1:42 pm
Has thanked: 17 times
Been thanked: 3 times

Re: USB on STM32L432 Driving Me NUTS!

Postby avrhack » Thu Mar 28, 2019 9:46 am

I can't debug it that way unfortunately - Blackmagic Probe no longer seems to work with the L4 series, tried loads of different versions and none of them work for me any more. Still great for the F0 and F3 but L4 is totally broken in terms of BMP.

And it can't be a halt with a ChibiOS debug assert as that would need a reset to restart things whereas as per my note, just plugging in USB causes everything to resume.

Any ideas what could cause a processor suspend on USB without any code? I'm going through all the data sheets to find out what's going on but so far nothing - in fact the USB section of the data sheet specifically says that you need code to stop the clocks / go into low power mode so I just don't see what's causing that pause......

I also wondered if it could be thread priorities ie one thread getting 'stuck' in the USB routines and then blocking the other threads, so I set them all to the same priority and enabled pre-emption / round-robin for same-priority threads; still no good.

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: USB on STM32L432 Driving Me NUTS!

Postby Giovanni » Thu Mar 28, 2019 9:52 am

Without knowing where it is stuck it is hard to tell, in addition, I don't know your code, this seems to not happen in normal demos and L432 uses the same driver used by all other devices.

I recommend getting a working debugger.

Giovanni

avrhack
Posts: 140
Joined: Tue Dec 24, 2013 1:42 pm
Has thanked: 17 times
Been thanked: 3 times

Re: USB on STM32L432 Driving Me NUTS!

Postby avrhack » Thu Mar 28, 2019 9:58 am

If I disable the thread that reads from USB and I immediately return from the thread that writes to USB everything works.

So there's something in either of those routines that blocks everything - all threads just stop. I'm going to narrow it down now to whether it's read or write then I'll share the ChibiOS calls I make in those routines as there's clearly something in one of the ChibiOS calls that's causing this to suspend all threads, which surely should never happen?

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: USB on STM32L432 Driving Me NUTS!

Postby Giovanni » Thu Mar 28, 2019 10:37 am

There is nothing that can suspend all other threads except a thread looping indefinitely at higher priority.

Giovanni

User avatar
alex31
Posts: 374
Joined: Fri May 25, 2012 10:23 am
Location: toulouse, france
Has thanked: 38 times
Been thanked: 61 times
Contact:

Re: USB on STM32L432 Driving Me NUTS!

Postby alex31 » Thu Mar 28, 2019 1:13 pm

Hi,

avrhack wrote:I can't debug it that way unfortunately - Blackmagic Probe no longer seems to work with the L4 series, tried loads of different versions and none of them work for me any more. Still great for the F0 and F3 but L4 is totally broken in terms of BMP.



Hum, i have no problem using BMP with L4, I even reflash stlink probe on nucleol432 board with BMP with no problems.

I have at this time 6 students working on nucleol432 board flashed with black magic probe.

If you want, i have a doc describing how to replace stlink by BMP on nucleo (in french).

Alexandre

avrhack
Posts: 140
Joined: Tue Dec 24, 2013 1:42 pm
Has thanked: 17 times
Been thanked: 3 times

Re: USB on STM32L432 Driving Me NUTS!

Postby avrhack » Thu Mar 28, 2019 3:07 pm

Giovanni wrote:There is nothing that can suspend all other threads except a thread looping indefinitely at higher priority.

Giovanni


Well the issue was a suspended thread causing all others to stop - even though they were all the same priority and I had set up pre-emptive scheduling round robin specifically to avoid that.

Unlikely to be a ChibiOS bug as that's a key part of the OS so surely someone else would have found it already; must be something in my configuration that is stopping pre-emptive scheduling for same-priority threads. My bet is that it's a locking issue somewhere in a critical zone......

avrhack
Posts: 140
Joined: Tue Dec 24, 2013 1:42 pm
Has thanked: 17 times
Been thanked: 3 times

Re: USB on STM32L432 Driving Me NUTS!

Postby avrhack » Thu Mar 28, 2019 3:10 pm

alex31 wrote:Hi,

avrhack wrote:I can't debug it that way unfortunately - Blackmagic Probe no longer seems to work with the L4 series, tried loads of different versions and none of them work for me any more. Still great for the F0 and F3 but L4 is totally broken in terms of BMP.



Hum, i have no problem using BMP with L4, I even reflash stlink probe on nucleol432 board with BMP with no problems.

I have at this time 6 students working on nucleol432 board flashed with black magic probe.

If you want, i have a doc describing how to replace stlink by BMP on nucleo (in french).

Alexandre


Thanks Alexandre - my French is from schooldays so might just get by ;)

However I wonder whether there's some issue with hardware. My BMP is a home-built v1 that I designed a PCB for myself and made a couple of modifications, rather than a 'real' one. That said, it has worked perfectly for me for F0, F1, F2, F3 and F4 series but not L4 which doesn't make any sense.

I guess I'll go and buy a real BMP and see if that works better - you can never have too many of them!

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: USB on STM32L432 Driving Me NUTS!

Postby Giovanni » Thu Mar 28, 2019 3:11 pm

Round robin is not supported in tick-less mode, if you need it then make sure to set the delta to zero and tick frequency to 1000.

In general it is not a good idea to rely on RR, the "granularity" is low.

Giovanni


Return to “Development and Feedback”

Who is online

Users browsing this forum: No registered users and 35 guests