USB & STMF407 - Why does it stop?

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
freakuency
Posts: 4
Joined: Wed Aug 02, 2017 1:09 am

USB & STMF407 - Why does it stop?

Post by freakuency »

My first attempt with ChibiOS is the MEMS example for the disco board. It works and the LEDs changes and I can get the data out to my Qt interface over USB after some changes. Great, but, why does the OS freeze when I unplug the cable? I.e, the LEDs stops. I am calling the send function from the thread that reads with SPI. My guess is a buffer gets full for some reason. I cannot find a way to check IF I can send data before calling the send function, to avoid the freeze. Do you know how to?
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: USB & STMF407 - Why does it stop?

Post by Giovanni »

Hi,

Which OS version are you using? there should be a check in write functions to prevent exactly this.

Giovanni
freakuency
Posts: 4
Joined: Wed Aug 02, 2017 1:09 am

Re: USB & STMF407 - Why does it stop?

Post by freakuency »

Oh, ofc I left out that important information, it is 16.1.4.
freakuency
Posts: 4
Joined: Wed Aug 02, 2017 1:09 am

Re: USB & STMF407 - Why does it stop?

Post by freakuency »

Also, a soon as I reconnect the cable again, the system works fine again.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: USB & STMF407 - Why does it stop?

Post by Giovanni »

You should update to the latest version, that one is 2 years old.

Giovanni
freakuency
Posts: 4
Joined: Wed Aug 02, 2017 1:09 am

Re: USB & STMF407 - Why does it stop?

Post by freakuency »

This is what I did with an example that came with the latest version. The LED still stops. Apparently I am doing something incorrectly. It is not an issue though, as I could just request data from the MCU, and maybe that is the more preferable way to do it. So am just gonna do that and it will be good I guess.

Code: Select all

static THD_FUNCTION(blinker_thread, arg) {

  (void)arg;
  chRegSetThreadName("blinker");
  while (true) {
    systime_t time;

    time = serusbcfg.usbp->state == USB_ACTIVE ? 250 : 500;
    palClearLine(LINE_LED6);
    chThdSleepMilliseconds(time);
    palSetLine(LINE_LED6);
    chThdSleepMilliseconds(time);
    chprintf((BaseSequentialStream *)&SDU1, "Test\r\n");
  }
}
Post Reply