Serial Driver flush buffer

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
vrollei
Posts: 163
Joined: Sun Nov 13, 2016 8:44 am
Been thanked: 26 times

Re: Serial Driver flush buffer

Postby vrollei » Wed Mar 22, 2017 5:30 am

Hi,

the problem was in calling chEvtRegisterMaskWithFlags and chEvtWaitAny from different threads.

Thanks!
Vitaly

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: Serial Driver flush buffer

Postby Giovanni » Wed Mar 22, 2017 8:45 am

No, the caller thread registers itself on the event source.

Giovanni

vrollei
Posts: 163
Joined: Sun Nov 13, 2016 8:44 am
Been thanked: 26 times

Re: Serial Driver flush buffer

Postby vrollei » Wed Mar 22, 2017 2:25 pm

Hi, Giovanni!

So I need to call chEvtRegisterMaskWithFlags for every thread. Right?
In initial implementation there was only one call chEvtRegisterMaskWithFlags during logger initialisation and event listener declared as static global variable in c file.

There is no problem with event processing in new implementation of logLock and logUnlock:
bool logLock(void) {
if (logInited) {
chMtxLock(&logMtx);
sdStart(&LOG_SD, sdConf);
chEvtRegisterMaskWithFlags(&LOG_SD.event, &logListener, EVENT_MASK(0),
CHN_TRANSMISSION_END);
return true;
} else {
return false;
}
}

void logUnlock(void) {
do {
chEvtWaitAny(EVENT_MASK(0));
} while ((chEvtGetAndClearFlags(&logListener) & CHN_TRANSMISSION_END ) == 0);
chEvtUnregister(&(STDOUT_SD.event), &logListener);
sdStop(&LOG_SD);
chMtxUnlock(&logMtx);
}


But there is strange behaviour of Serial Driver after exit from low power sleep mode.
Output is completely broken. Something like this: 00:0���12����" U�main.c���253 - Blinking��

Does it enough to do these steps after low power sleep mode to make Serial Driver works properly (btw spi driver works fine with the same steps):

1. Enable APB1 with rccEnableAPB1
2. Restore pins AF: palSetLineMode
3. Start Serial Driver with sdStart

Thanks a lot in advance!
Vitaly

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: Serial Driver flush buffer

Postby Giovanni » Wed Mar 22, 2017 5:08 pm

Each thread that needs to wait for events must register using a separate listener.

Exiting low power modes probably requires a clock reinitialization, see the STM32 RM, without that the baud rate is not correct. It is something I never personally used, be alert.

Giovanni

vrollei
Posts: 163
Joined: Sun Nov 13, 2016 8:44 am
Been thanked: 26 times

Re: Serial Driver flush buffer

Postby vrollei » Wed Mar 22, 2017 5:58 pm

Giovanni,

Ok, no more questions about events ) thanks a lot!

I will check RM.

BTW: I implemented simple Power Driver for STM32L1,
it supports:
- low power sleep mode with active chibios ST timer (tickless mode)
- switching between HSI in run mode and MSI in LP sleep mode
- configurable MSI clock source for LP sleep mode
- configurable VOS for LP
- automatic clock switching to MSI for LP mode, timer prescaler modification and back to HSI for run mode
- hooks for disable/enable periphs
- chibios drivers state checking - activate LP sleep mode if all drivers are in stop state

result: about 5uA in LP deep sleep mode @ 65kHz MSI

so I would like to discuss high level driver interface, some chibios modification (MSI values at least, and new feature: bit field for all drivers state) and share the source code.

What do you think?
Vitaly

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: Serial Driver flush buffer

Postby Giovanni » Wed Mar 22, 2017 6:30 pm

Just open a topic in the development forum about it.

Giovanni


Return to “ChibiOS/HAL”

Who is online

Users browsing this forum: No registered users and 9 guests