STM32F4 serial driver misses sometimes one or morecharacters

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

Moderator: RoccoMarco

Wafelijzer
Posts: 8
Joined: Mon Sep 21, 2015 9:09 am

Re: STM32F4 serial driver misses sometimes one or morecharac

Post by Wafelijzer »

Hi Giovanni,

I still have problems that the serial driver has a overrunning uart. My current setup:

* Receiver thread which waits for a CHN_INPUT_AVAILABLE event and has HIGHPRIO
* UART set at IRQ priority 2
* UART baudrate at 921600
* Some other threads with lower priority

I also tried by adding a "new" event ID to see if the serial driver buffer was overflowing or the UART register.
Which still resulted in the lowlevel UART register overflow, even with the thread at high priority and using the
event subsystem.

I also looked at direct UART access with DMA, and I have no clue if this will solve the issue.
viewtopic.php?f=16&t=2998
Receiver thread:

Code: Select all

/* Callback run from di_drv_hl854x_read */
static size_t modem_sd_read(void *buf, size_t nbyte)
{
        return sdReadTimeout(&DNCM_MODEM_DEV, buf, nbyte, TIME_IMMEDIATE);
}

static THD_WORKING_AREA(modem_recv_wa, 256);
static THD_FUNCTION(modem_recv_thd, arg)
{
        (void)arg;
        chRegSetThreadName("modem_reader");

        eventmask_t e;
        eventflags_t flags;
        event_listener_t l;

        chEvtRegisterMaskWithFlags(chnGetEventSource(&DNCM_MODEM_DEV),
                                   &l,
                                   EVENT_MASK(1),
                                   CHN_INPUT_AVAILABLE | SD_OVERRUN_ERROR);

        while (1) {
                e = chEvtWaitAny(EVENT_MASK(1));

                if (e & EVENT_MASK(1)) {
                        flags = chEvtGetAndClearFlags(&l);
                        if (flags & SD_OVERRUN_ERROR) {
                                chSysHalt("SD#OE");
                        }
                        if (flags & CHN_INPUT_AVAILABLE)
                                di_drv_hl854x_read(&ctx);
                }
        }
}

...
        chThdCreateStatic(modem_recv_wa, sizeof(modem_recv_wa), HIGHPRIO, modem_recv_thd, NULL);
...
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32F4 serial driver misses sometimes one or morecharac

Post by Giovanni »

Hi,

Probably the baud rate is just to high for a driver based on ISRs.

In the repository trunk now there is an improved UART driver with synchronous API, no callbacks required so it is easier to use. A callback is only required if you want to handle errors.

The driver uses DMA so it could solve your problem.

viewtopic.php?f=3&t=2989

Giovanni
mikemoretti
Posts: 12
Joined: Sun Nov 29, 2015 9:37 pm

Re: STM32F4 serial driver misses sometimes one or morecharac

Post by mikemoretti »

Does the "serial" driver use DMA by default? If so, which DMA? I just want to make sure its DMA doesn't conflict with the I2C DMA. I saw that you fixed I2C DMA in 3.0.4 so it can finally be turned off with a config define. I may end up doing this because I really don't need it for the small amount of data I send/receive and it just makes things too complicated to start,acquire then release,stop the i2c every time I want to write to it.

And is it proper to do an sdStart and sdStop whenever you want to use the serial port? I.e. I have a few threads where only one is active at a time based on the mode my device is in. For i2c i acquire and release each time i send a message. Should i do the same thing with sd?

Thanks!
-m
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32F4 serial driver misses sometimes one or morecharac

Post by Giovanni »

Hi,

The serial driver does not use DMAs, the UART driver does.

There is no acquire/release for the serial driver, the API is reentrant and can be called by multiple threads without issues. If you want mutual exclusion, for example because you need to sent large buffers atomically, then you can use a mutex.

Giovanni
mikemoretti
Posts: 12
Joined: Sun Nov 29, 2015 9:37 pm

Re: STM32F4 serial driver misses sometimes one or morecharac

Post by mikemoretti »

That is great news! Now I don't have to worry about DMA conflicts.
Post Reply