7 years, 1 month ago.

Combining Code dependent on OS and code not dependent on OS

Greetings , I'm really stuck with trying to integrate two separate functions that I can implement separately on my Nucleo F767ZI . I need the Ethernet functions provided with Mbed Os and at the same time I need to count a 20 MHz square signal on an input pin . I can do both separately but the moment I try to integrate the two It doesn't work, does anyone have a suggestion on how to do this I've been going at this for some time and I can't seem to find a solution.

1 Answer

7 years, 1 month ago.

Could you explain what is the problem you're seeing and what APIs you are using? Is it a compilation error or runtime error?

The aim of my application is to count pulses at 20 MHz as indicated earlier , and send the counts out to a pc via Ethernet. I successfully managed to send out information using the Ethernet Library provided for Mbed OS . I tried conducting my counting using interrupt functions in Mbed Os but they were too slow I tried the ticker and timer functions as well but they were too slow as well they all maxed out under 1 Mhz . So I implemented a counter in Atollic TrueStudio using the Systick handler and was hoping to port it to mbed (Which I had successfully done with another program) but the moment I port code and add the Mbed Os it just bugs out in certain areas(for example the print prints out the wrong Ascii characters). I do expect weird behaviour with the porting and mixing code , I was just trying to see if there was a way to use high level Mbed code and still be able to use lower level code to perform my counting.

posted by Anthony Mukuka Mwila 13 Oct 2017

Everything actually compiles fine so I don't get run time or compilation errors .

posted by Anthony Mukuka Mwila 13 Oct 2017

Trying to mush code generated in CubeMx or Atollic into mbed seems pretty tricky. Are you working with the mbed source files? All the low level HAL stuff is there. You could dig into the Atollic code and see how it works, then reimplement using the low level functions provided in mbed.

At 216MHz clock, trying to count pulses at 20MHz is tough because you only get 100 cycles to context switch and do other stuff between pulses. If you implement as an interrupt, you will end up spending all cpu time context switching. Seems like you will have to make use of peripheral hardware to handle the fast stuff for the cpu. I have not done this, but one idea would be to pick a Timer, say Timer 1 and set it for an external clock input with 1:1 scaling. So your timer register simply counts up by one every time an external pulse comes in. Then read it at a regular interval using, say, the ticker object and get the count. This would not verify the frequency of input signal at all, but merley count rising edges. Actually mbed describes this idea here https://os.mbed.com/users/4180_1/notebook/using-hardware-timers/ Can also check user projects, there are a couple libraries doing counting for STM32 parts, may give some ideas.

posted by Graham S. 14 Oct 2017