imploding with the mbed src library...

02 Nov 2015

I am new to mbed :(

I was trying to detect a break on a serial stream using timer/timerout

not quite working , not sure why, reading reading...

I found this and had a look...

Erik Olieman :- The source code can be found here: http://developer.mbed.org/users/mbed_official/code/mbed-src/. The timer code is somewhere in targets/hal/freescale/[KLxx/KSDK]/us_ticker_api.c. And to answer it directly, The K64F uses four PIT timers for Timer/Ticker objects (Freescale MCUs aren't very efficient at implementing this, most NXP ones use a single timer for example), the KL46 uses two PIT timers and the LPTMR (PIT for Timer, LPTMR for ticker). From <https://developer.mbed.org/questions/7433/What-Timer-is-used/>

I don't really know my way around yet, I imported the library... not sure if that's a good thing or not...

now we don't compile...:(

Can I undo this ? or fix it ?

this is the error :

Error: "/extras/mbed_ba1f97679dad/TARGET_NUCLEO_F072RB/TOOLCHAIN_ARM_MICRO/stm32f072rb.sct", line 34 (column 9): Error: L6235E: More than one section matches selector - cannot all be FIRST/LAST.

02 Nov 2015

If you use mbed-src (or mbed-dev I think should be used now), delete your old mbed lib.

02 Nov 2015

Hi,

Thanks for looking in on my problem...

ok, I think I have done it, now it compiles... was it best to retain the project generated lib or run with the latest lib ? I can roll it back, if you think it is best

otherwise, but my previous problem still exists,

how can I get an interrupt if a serial port goes idle ?

should I start a new thread, ?

can I use something like this ?

int write (const uint8_t *buffer, int length, const event_callback_t &callback, int event=SERIAL_EVENT_TX_COMPLETE) Begin asynchronous write using 8bit buffer. int write (const uint16_t *buffer, int length, const event_callback_t &callback, int event=SERIAL_EVENT_TX_COMPLETE) Begin asynchronous write using 16bit buffer.

Nick.

02 Nov 2015

Nope, those functions won't help you. (They are not supported anyway by almost all boards).

It won't matter much which lib you use, using the source lib might help you when you want to try an alternative solution. For the timer option you don't need it. I guess you could connect the RX pin also to another pin, run an interruptin on it (or maybe run it on the RX pin itself, don't know if that will work), and start a timer at every falling edge, stop it at the rising edge, see how long it took.

Plan B, and for that you will need the source, is what if I recall correctly is the alternative way to do it, and that is to check for a frame error. So you would need to see if you can enable an interrupt on frame error (or just on receive, and add a check if a frameerror occured).

02 Nov 2015

Hi, Thanks again,

Yes, I think I need a more elaborate solution, so mbed.src is the right lib to use.. ??

Coming back to my problem, the IDLE condition on a serial port, how can we access it, and/or set an interrupt ?

(some of your comments went over my head, sorry)

02 Nov 2015

Do you want to have it on idle, or on break, those are two different situations. (Idle is a long high signal, break is a long low signal).

02 Nov 2015

Hi, Yes, IDLE thanks

I find the hardest part of this transition from 8bit assembler to mbed is the syntax of the new coding styles.

do you have some sample code to access / manage the IDLE bit ?

02 Nov 2015

Well first you would need to see if an idle bit (or something similar) exists in the hardware of your device, by looking through the reference manual. What is it exactly that you want your code to do?

02 Nov 2015

Hi, thanks again,

I believe that Modbus requires a minimum IDLE time between packets, I am not really sure what is currently accepted. These spec manuals are old now...

I like to run everything under interrupt control and check flags and process in the foreground. an IDLE interrupt would be excellent...

let me check the processor manual.. .Nucleo STM32F072RB

02 Nov 2015

The easiest way for that to me seems to be just running a Ticker/Timeout in the background, and ignore the hardware part: Time to transmit is 8 + 1 (startbit) + 1 (stopbit) + optional bits (second stopbit, parity, etc) divided by the baudrate. Then the idle time you want (+ some margin) can be added to this number, and you run a Ticker/Timeout at that period.

02 Nov 2015

Hi, Yes,

I have implemented something similar, but it loses sync after the first frame.

just seems to be lacking bandwidth,

ooo, I was ramping the 2 PWMs too often slowing us down....

now its going ballistic, I need to settle it down and come back to you.

Thanks for your support Erik, Nick

02 Nov 2015

Hi,

I have found the solution... but don't know how to adjust the Usart registers directly from within the mbed platform.

in the reference manual " RM0091 Ref manual STM32F0x1/STM32F0x2/STM32F0x8 advanced ARM®-based 32-bit MCU

" Modbus/RTU In this mode, the end of one block is recognized by a “silence” (idle line) for more than 2 character times. This function is implemented through the programmable timeout function. The timeout function and interrupt must be activated, through the RTOEN bit in the USARTx_CR2 register and the RTOIE in the USARTx_CR1 register. The value corresponding to a timeout of 2 character times (for example 22 x bit duration) must be programmed in the RTO register. when the receive line is idle for this duration, after the last stop bit is received, an interrupt is generated, informing the software that the current block reception is completed. "

from Universal synchronous asynchronous receiver transmitter (USART) RM0091 page 702/1008 DocID018940 Rev 8

if you could give me the syntax to adjust bits in the Usart registers, then I can work on it..

02 Nov 2015

That should indeed do the trick for you :).

The registers for your device are defined here: https://developer.mbed.org/users/mbed_official/code/mbed-dev/file/d797fbdad187/targets/cmsis/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F072RB/stm32f072xb.h

You access them like:

USART2->CR1 = USART_CR1_RTOIE;

or 

USART2->CR1 |= USART_CR1_RTOIE;

etc

All those are defined in that file. You don't actually need to use the bit definition, you can also just use (1<<20) (Don't use 20, I am too lazy to find the actual bitshift required, Freescale also defines the shift and more stuff, STM only the mask), but it is nice for readability.