STM32F407 and USB / UART goes into idle thread forever

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

Moderators: RoccoMarco, barthess

kb1gtt
Posts: 41
Joined: Sat Jul 09, 2016 11:29 am
Has thanked: 11 times
Been thanked: 2 times

Re: STM32F407 and USB / UART goes into idle thread forever

Postby kb1gtt » Wed Feb 03, 2021 9:39 pm

Per the below link I see the non-blocking function sdWriteTimeout. However I see that chprintf uses sdWrite and I do not see any version of chprintf which includes the sdWriteTimeout variant.
https://www.playembedded.org/blog/stm32 ... os-serial/

Am I correct that there is no chprintf (or equivalent) function with timeout? If it does not exist, then I would have to create it which would be a fair bit of work for me. I was preventing a printf as an alternative to using sdWriteTimeout.

Also does sdWriteTimeout go to an idle state while it waits to timeout? It was unclear to me if it would remain idle until timeout, or if I could use those CPU cycles for other tasks while it waits.

User avatar
FXCoder
Posts: 384
Joined: Sun Jun 12, 2016 4:10 am
Location: Sydney, Australia
Has thanked: 180 times
Been thanked: 130 times

Re: STM32F407 and USB / UART goes into idle thread forever

Postby FXCoder » Thu Feb 04, 2021 1:45 am

Hi,
For listening to SDU events you need to create an event listener which masks in the CHN_CONNECTED and CHN_DISCONNECTED events from SDU and posts an event (of your definition) for the output thread.
The output thread will get the event, analyse the event flags from the SDU channel and enable/disable writing to the channel accordingly.

Below is a simplified general way of doing this (incomplete code).
--
Bob

Code: Select all

  #define CONSOLE_CHANNEL_EVT         EVENT_MASK(0)
  /* Event listener objects. */
    event_listener_t con_el;
   
  /* Clear any prior event and attach event listener to serial channel. */
  (void)chEvtGetAndClearEvents(CONSOLE_CHANNEL_EVT);
  chEvtRegisterMaskWithFlags(
                      chnGetEventSource((BaseAsynchronousChannel *)chp),
                      &con_el, CONSOLE_CHANNEL_EVT,
                      CHN_CONNECTED | CHN_DISCONNECTED);

  /* Flush any channel events prior to running channel. */
  (void)chEvtGetAndClearFlags(&con_el);
 
    do {
       eventmask_t evt = chEvtWaitAnyTimeout(CONSOLE_CHANNEL_EVT, TIME_IMMEDIATE);
        eventflags_t evtf = chEvtGetAndClearFlags(&con_el);
       if (evt != 0) {
          /* Set flag or clear flag to control writing to channel depending on evtf values. */
          if (evtf & CHN_CONNECTED != 0) {
             /* Set flag to enable writing to channel. */
          }
          else {
             /* Set flag to disable writing to channel. */
          }
       }
       else {
          /* Do regular processing. Write to channel only if enabled . */
       }
    } while (true);
 


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 20 guests