Page 2 of 2

Re: STM32F4 serial driver misses sometimes one or morecharac

Posted: Mon Nov 23, 2015 5:04 pm
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);
...

Re: STM32F4 serial driver misses sometimes one or morecharac

Posted: Mon Nov 23, 2015 5:18 pm
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

Re: STM32F4 serial driver misses sometimes one or morecharac

Posted: Mon Dec 21, 2015 2:00 am
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

Re: STM32F4 serial driver misses sometimes one or morecharac

Posted: Mon Dec 21, 2015 9:11 am
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

Re: STM32F4 serial driver misses sometimes one or morecharac

Posted: Tue Dec 22, 2015 12:13 am
by mikemoretti
That is great news! Now I don't have to worry about DMA conflicts.