Spark Logic

IRlib on STM32?

Cmustard Sun Apr 10, 2016 1:13 pm

Did anyone have some degree of success to get an infrared library working in send and recieve mode yet?

I found this nice initiative https://github.com/petoknm/STM32_NEC_Decode
but that’s only focussing on the Decode piece and not the sending part.

As IRlib has done a great job in decoupling the HW related timer things from the decoding and sending logic I thought it might be a nice project to sink my teeth in.
maybe it’s fairly easy to just focussing on the hardware specific parts in the library.

Although I’m not as seasoned as most of you guys out here on the board,
An I think it might be overly ambitious for me, but still may be worth a try.

Best regards,

Paul

Replies

Just4Fun Fri Apr 29, 2016 6:34 pm

Last version 2.1.0 of IRremote library (https://github.com/z3t0/Arduino-IRremote) can be used with Teensy 3.0/3.1, that uses a 32bit ARM Cortex M4 MCU @72MHz, and Teensy-LC with a Cortex M0+ ARM. So the distance “may” be not so much… (anyway on Teensy 3.x CMT timer is used, that is a specialized timer in the Freescale MPU. Just a 2 minutes search…)

rexnanet Tue May 10, 2016 10:07 am

Just4Fun wrote:Last version 2.1.0 of IRremote library (https://github.com/z3t0/Arduino-IRremote) can be used with Teensy 3.0/3.1, that uses a 32bit ARM Cortex M4 MCU @72MHz, and Teensy-LC with a Cortex M0+ ARM. So the distance “may” be not so much… (anyway on Teensy 3.x CMT timer is used, that is a specialized timer in the Freescale MPU. Just a 2 minutes search…)

Cmustard Fri May 13, 2016 10:02 am

The timer specific thingies on the STMs are not so easy.

If you have the STM32 variety that can do AND gate operations on 2 output clocks then it’s much easier..
set the 38Khz signal as a base freq. and then turn the signal on and off on the 2nd timer to get the right output.
I could do it that way by combining two timers on separate pins but that would consume two pins and needs two extra transistors on the outside for F103.type boards which is probably what the majority of hobby bobs are using.
but that’s a HW hack to get things right.

another way would be to build a mini timer circuit for the base freq. (e.g. 38Khz) using a 555 timer IC and a few resistors but again that’s a HW hack I’d like to avoid if possible as it is a bit besides the point of a SW library.
but then again it would simplify the problem considerably :D

The reason I looked at IR lib is because the signal generation (protocol specific) and hardware part are split in the library itself.
and all is housed in separate functions which is great.
This makes IRlib pretty portable but the HW part proved more difficult to me than initally expected (due to the points mentioned above).
In the current library there is a lot of low level AVR stuff going on to get the timings right
(stop interrupts, register pusing and shoving enabling interrupts again etc.)
In the STM’s this could be done similar but that might have a huge impact on the interrups and thus possibly on other libraries/functions in a project.
so I’m not too fond of that method and am looking for alternatives.
It looks like I’ll not be having something working soon BTW.
Also becaue I’m struggling in how to combine HAL stuff with the duino IDE I’m not sure how much I end up in conflict with the core libs by doing so.

And especially as I’m not a seasoned programmer things take extra time :-(
but still it’s good time spent !

Paul

ahull Tue Jan 17, 2017 10:52 pm

You can cheat a bit if you want to send and receive serial data over IR. -> http://www.ebay.com/itm/5V-IR-Infrared- … SwGYVXBLQW

For what its worth, here is ST’s take on the problem -> http://www.st.com/content/ccc/resource/ … 053084.pdf

It would be good to get a software only solution of course, either based on ST”s approach or perhaps using DMA to shift out a 1010101 bit stream at 36 38 or 40kHz in to which we inject our data. Getting the timing right is of course the big trick with IR, but from personal experience (my day job involves software development for set TV top boxes for Hotels), once you have your that nailed, the rest is relatively trivial.

victor_pv Wed Jan 18, 2017 12:05 am

I was looking at that last year, and have intention to continue when i have time to dig the files and then continue with it.

I was using the ST application note linked by Andy in the previous post. That AN is for F0 and F3 chips that include an internal circuit to connect 2 timer outputs, in a way that they will provide an output with the 56Khz, 48Khz, or whatever needed for the IR receiver used in the application.
The F1 lacks that internal circuit, but nothing prevents you from using 2 timer outputs and implementing the circuit on the PCB with a couple of transistors and little more. That was my approach.

I had the code half way translated from the STM std peripheral library to mostly libmaple, but like I said that was last year and I had to put it aside for a long time, so I don’t remember how close I was to getting it to work. I remember I had to order IR leds and put it aside and started working on a wav player using a timer to generate a PCM output. I got that working, and I didn’t feel the IR stuff was much more complex, but then didn’t have time to back to it.
It can definitely use DMA, and I planned to turn to DMA as soon as I had it working, to reduce the CPU load.

I do not think it’s complicated. Anyone with a bit of experience in C and the STM32F1 timers should be able to complete it faster than me.

GrumpyOldPizza Wed Jan 18, 2017 10:27 pm

victor_pv wrote:I was looking at that last year, and have intention to continue when i have time to dig the files and then continue with it.

I was using the ST application note linked by Andy in the previous post. That AN is for F0 and F3 chips that include an internal circuit to connect 2 timer outputs, in a way that they will provide an output with the 56Khz, 48Khz, or whatever needed for the IR receiver used in the application.
The F1 lacks that internal circuit, but nothing prevents you from using 2 timer outputs and implementing the circuit on the PCB with a couple of transistors and little more. That was my approach.

I had the code half way translated from the STM std peripheral library to mostly libmaple, but like I said that was last year and I had to put it aside for a long time, so I don’t remember how close I was to getting it to work. I remember I had to order IR leds and put it aside and started working on a wav player using a timer to generate a PCM output. I got that working, and I didn’t feel the IR stuff was much more complex, but then didn’t have time to back to it.
It can definitely use DMA, and I planned to turn to DMA as soon as I had it working, to reduce the CPU load.

I do not think it’s complicated. Anyone with a bit of experience in C and the STM32F1 timers should be able to complete it faster than me.

victor_pv Thu Jan 19, 2017 12:11 am

GrumpyOldPizza wrote:

Interesting note. Would one want a generic library, or something that can emit RC5 directly ?

KaraWin Sat Apr 15, 2017 7:35 pm

Thanks! I was posting it on the forum and realized you already had done it :)
Have to test it ASAP! :)

Ok, let me know.

VadimEL Mon May 01, 2017 8:18 pm

https://github.com/karawin/irmp-master
can not compile :( Maple mini (STM32F103CBT6)

In file included from C:\Documents and Settings\Vadim\Мои документы\Arduino\hardware\Arduino_STM32\STM32F1\libraries\irmp-master-master/irmp.h:18:0,

from C:\HELP\07ELECTRONIK\09MK\20MY\40shpagi\05LCD touch\00progr\24ver\PVS\PVS.ino:165:

C:\Documents and Settings\Vadim\Мои документы\Arduino\hardware\Arduino_STM32\STM32F1\libraries\irmp-master-master/irmpsystem.h:98:22: fatal error: avr/io.h: No such file or directory

# include <avr/io.h>

^

compilation terminated.

exit status 1
Ошибка компиляции для платы Maple Mini.

KaraWin Mon May 01, 2017 10:10 pm

Something is wrong in your board selection.
You are in
#if defined(ATMEL_AVR)
case.

I made the modification for
#elif defined(BOARD_generic_stm32f103c)

Please change all BOARD_generic_stm32f103c to your mapple mini definition or better, add an ifdef or elif case.
Probably
if defined(ARDUINO_MAPLE_MINI)

They are at
Search “stm32duino” (3 hits in 3 files)
C:\Users\jp\Documents\Arduino\libraries\irmp-master\irmpconfig.h (1 hit)
Line 162: * Change hardware pin here for STM32Duino
C:\Users\jp\Documents\Arduino\libraries\irmp-master\irmpsystem.h (1 hit)
Line 44: #elif defined(BOARD_generic_stm32f103c) // STM32DUINO
C:\Users\jp\Documents\Arduino\libraries\irmp-master\irsndconfig.h (1 hit)
Line 170: * generic_stm32f103c(STM32duino, see IRSEND.ino)

VadimEL Tue May 02, 2017 1:19 am

KaraWin
Thanks, it compile now. I change all to ARDUINO_MAPLE_MINI

Image

Ok found irmpconfig.h and change IN PIN to PA8
* Change hardware pin here for STM32Duino
*---------------------------------------------------------------------------------------------------------------------------------------------------
*/
#elif defined(ARDUINO_MAPLE_MINI)
# define IRMP_BIT_NUMBER PA8 // use C15 pin

KaraWin Tue May 02, 2017 7:59 am

Yes, you may delete the comment, it is a test to learn many way to implement a timer.

and it WORK!!! :mrgreen: everyone laughs are all happy :mrgreen: :mrgreen: :mrgreen: Thanks for library =)

Great. Enjoy.

ouzcckl Thu Sep 07, 2017 1:28 pm

i do what you said but i get compile error.

\Arduino\libraries\TimerOne/TimerOne.h:301:17: error: conflicting declaration 'TimerOne Timer1'

extern TimerOne Timer1;

Sign in to reply