[F4] Neopixel driver using hardware timers

What are you developing?
flyboy74
Posts: 31
Joined: Fri Jan 03, 2020 10:12 am

[F4] Neopixel driver using hardware timers

Post by flyboy74 »

I have created an addressable RGB LED driver using the hardware timers on the STM32F4 to create the critical timing pulse train needed to transmit the data to the the LED strip.

My understanding is other drivers use the SPI peripheral and also use lots of RAM for a small umber of LEDs and is limited to max number of LEDs. The big advantage of my driver is it only uses 3 bytes/LED and doesn't have a limit of number of LEDs

see my driver here https://github.com/OutOfTheBots/STM32_NEOpixels_timer
stas2z
Posts: 131
Joined: Mon Feb 24, 2020 8:17 pm
Answers: 8

Re: Neopixel driver using hardware timers

Post by stas2z »

it's nice you shared it here, but it's not a proper place for code like yours imho, most users here will not be able to use your driver (no matter how fast and brilliant your code is)
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: Neopixel driver using hardware timers

Post by mrburnette »

Ah, nice share. It;s F4 code, so relevant, IMO. Admin will likely move to "Projects" and edit the title to "F4 Neopixel driver ..."

Keep up the effort!


Ray
flyboy74
Posts: 31
Joined: Fri Jan 03, 2020 10:12 am

Re: Neopixel driver using hardware timers

Post by flyboy74 »

stas2z wrote: Sat Apr 25, 2020 11:34 pm it's nice you shared it here, but it's not a proper place for code like yours imho, most users here will not be able to use your driver (no matter how fast and brilliant your code is)
Although not technically Ardunio code it is standard C code. I have rarely used Ardunio so am not familiar with it's inner working and don't know how to implement this in Arudnio but I have followed this forum since starting with STM32 as it has the most knowledge place about STM32 I can find anywhere. There is no shortage of people on this forum that can take the code I posted and port it to Ardunio considering it is the people on this forum that created STMdunio (ported STM32 C to STM32 Ardunio) in the first place.
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: Neopixel driver using hardware timers

Post by mrburnette »

flyboy74 wrote: Sun Apr 26, 2020 1:05 am ...
Although not technically Ardunio code it is standard C code. I have rarely used Ardunio so am not familiar with it's inner working ...
Arduino is both an experience and a programming syntax. The ArduinoIDE is the default code editor, the wrapper for the compiler & linker, and the upload to device enabler... an environment. The programming syntax is listed here:
https://www.arduino.cc/reference/en
In many ways, the language looks like BASIC (no flames, please!) Of course, there are lots of functionality provided from the "core" libraries (some bloat and speed concerns, too.)

You can use any editor and run the Arduino build system from the command line:
https://github.com/arduino/arduino-cli

You can use traditional C make files:
https://forum.arduino.cc/index.php?topic=591748.0


Ray
stas2z
Posts: 131
Joined: Mon Feb 24, 2020 8:17 pm
Answers: 8

Re: Neopixel driver using hardware timers

Post by stas2z »

flyboy74 wrote: Sun Apr 26, 2020 1:05 am
stas2z wrote: Sat Apr 25, 2020 11:34 pm it's nice you shared it here, but it's not a proper place for code like yours imho, most users here will not be able to use your driver (no matter how fast and brilliant your code is)
Although not technically Ardunio code it is standard C code. I have rarely used Ardunio so am not familiar with it's inner working and don't know how to implement this in Arudnio but I have followed this forum since starting with STM32 as it has the most knowledge place about STM32 I can find anywhere. There is no shortage of people on this forum that can take the code I posted and port it to Ardunio considering it is the people on this forum that created STMdunio (ported STM32 C to STM32 Ardunio) in the first place.
First, as it written with HAL, it will never compile with roger's/libmaple core ever, but also it will difficult to use it with HAL based core. It contains SytemClock_Config for exact f407 mcu and timer init hadcoded with registers (what for? escpecially as your gpio and pll are still inited with HAL routines, what the purpose of this?), irq handler hardcoded with regs and to exact timer, also it written with C, but arduino code is C++ by default, so at least irq handler and clock conwig will not be properly defined without extern "C" {} and will not be called, but with it irq handler will conflict with built-in hardwaretimer library... so it's not portable at all. It also cannot be "driver" for standalone HAL based project cuz most of the code is mcu specific.

So,finally im not trying to say your code is bad, but as a code you wanna share for other ppl it's useless.
flyboy74
Posts: 31
Joined: Fri Jan 03, 2020 10:12 am

Re: Neopixel driver using hardware timers

Post by flyboy74 »

stas2z wrote: Sun Apr 26, 2020 5:38 am
flyboy74 wrote: Sun Apr 26, 2020 1:05 am
stas2z wrote: Sat Apr 25, 2020 11:34 pm it's nice you shared it here, but it's not a proper place for code like yours imho, most users here will not be able to use your driver (no matter how fast and brilliant your code is)
Although not technically Ardunio code it is standard C code. I have rarely used Ardunio so am not familiar with it's inner working and don't know how to implement this in Arudnio but I have followed this forum since starting with STM32 as it has the most knowledge place about STM32 I can find anywhere. There is no shortage of people on this forum that can take the code I posted and port it to Ardunio considering it is the people on this forum that created STMdunio (ported STM32 C to STM32 Ardunio) in the first place.
First, as it written with HAL, it will never compile with roger's/libmaple core ever, but also it will difficult to use it with HAL based core. It contains SytemClock_Config for exact f407 mcu and timer init hadcoded with registers (what for? escpecially as your gpio and pll are still inited with HAL routines, what the purpose of this?), irq handler hardcoded with regs and to exact timer, also it written with C, but arduino code is C++ by default, so at least irq handler and clock conwig will not be properly defined without extern "C" {} and will not be called, but with it irq handler will conflict with built-in hardwaretimer library... so it's not portable at all. It also cannot be "driver" for standalone HAL based project cuz most of the code is mcu specific.

So,finally im not trying to say your code is bad, but as a code you wanna share for other ppl it's useless.
The HAL only sets up the clocks, it is generated by CubeMX. Ardunio has it's own automatic wrapper to setup the clocks, so for Ardunio all that code just needs to be deleted.

All of the code that drives the Neopixels doesn't use any HAL libraries but rather writes directly to the registers and will compile with the ardunio compiler u just need to #include "stm32f4xx.h" for all the macros I use to address the registers Ardunio has no problem using pointers to write to RAM addresses.
irq handler will conflict with built-in hardwaretimer library
Well of course but I would expect that anyone porting this to Ardunio would simply copy the code in the C irq handler to the ardunio ISR handler then delete the C irq handler. Mind I assume that the Ardunio ISR is just a wrapper for the C irq that is certain how the HAL interrupt handlers work.

Much the same way I don't know the wrapper that Ardunio uses I don't know the wrapper that STM HAL uses so outside the setup code generated by CubeMX I don't use the HAL and write all my code just in C.

In the end I put up my code MIT for anyone to use and posted it here because I know the draw backs (heavy RAM use and limit on number of of LEDs) with the current method of using SPI to drive Neo pixels on the STM32dunio port and I know there are plenty of people on this forum that won't have the slightest problem porting this to STMdunio due to the such simple nature of the code.

I am surprised everyone is so offended by me sharing this code
Last edited by flyboy74 on Sun Apr 26, 2020 7:09 am, edited 1 time in total.
flyboy74
Posts: 31
Joined: Fri Jan 03, 2020 10:12 am

Re: Neopixel driver using hardware timers

Post by flyboy74 »

mrburnette wrote: Sun Apr 26, 2020 4:02 am
Arduino is both an experience and a programming syntax. The ArduinoIDE is the default code editor, the wrapper for the compiler & linker, and the upload to device enabler... an environment.
Ray
This is correct I just haven't spent the time to learn the wrapper that Ardunio is, much the same way I haven't spent the time to learn the wrapper that STM HAL is. For most of what I do it is just quicker for me to to write low level code than learn the higher level wrapper.
stas2z
Posts: 131
Joined: Mon Feb 24, 2020 8:17 pm
Answers: 8

Re: Neopixel driver using hardware timers

Post by stas2z »

flyboy74 wrote: Sun Apr 26, 2020 6:22 am All of the code that drives the Neopixels doesn't use any HAL libraries but rather writes directly to the registers and will compile with the ardunio compiler u just need to #include "stm32f4xx.h" for all the macros I use to address the registers Ardunio has no problem using pointers to write to RAM addresses.
Ok, stm32f4xx.h is a part of CMSIS, and, __surprise__, libmaple/roger's/steeve's cores are not based on HAL/CMSIS. So it will not compile without porting reg defines.
flyboy74 wrote: Sun Apr 26, 2020 6:22 am
irq handler will conflict with built-in hardwaretimer library
Well of course but I would expect that anyone porting this to Ardunio would simply copy the code in the C irq handler to the ardunio ISR handler then delete the C irq handler.
Nope, handlers, as it implemented in the HAL based core don't work like this. Library redefine all possible handlers to it's own all-in-one handler which call basic handlers on request, just copying code will not work cuz it will conflict.
flyboy74 wrote: Sun Apr 26, 2020 6:22 am Much the same way I don't know the wrapper that Ardunio uses I don't know the wrapper that STM HAL uses so outside the setup code generated by CubeMX I don't use the HAL and write all my code just in C.
CubeMX also generates timer init for you, and this init will be some kind portable at least across f4 series (not arduino, but at least for HAL), but you've chosen to init it bare metal way, dropping any kind of portability, but except some tiny code size improvement (for F407 with at least 512K flash, really?) you got nothing. It's ok for your own projects as it's your code and you know every byte of it, but...
Probably, much better, if you kept HAL, will be using LL driver instead of pure registers. LL is a mostly macros around registers and register operations, but it become a bit more portable while keeping size and speed.
Also you've hardcoded it to TIM4, but i don't see any reason why not to choose any of basic timers like TIM6/7 for f407
flyboy74 wrote: Sun Apr 26, 2020 6:22 am In the end I put up my code MIT for anyone to use and posted it here because I know the draw backs (heavy RAM use and limit on number of of LEDs) with the current method of using SPI to drive Neo pixels on the STM32dunio port and I know there are plenty of people on this forum that won't have the slightest problem porting this to STMdunio due to the such simple nature of the code.

I am surprised everyone is so offended by me sharing this code
Again, again and again, i have nothing against you and your code, probably it will be useful for someone. I just don't see any byte of reusable code here, especially for stm32duino comminity. Adaptation will waste much more time than writing it from scratch.
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: [F4] Neopixel driver using hardware timers

Post by stevestrong »

I think we have to thank to @flyboy74 because he shared his code.
On the other hand, a short description of the environment limitations (which core, with or w/o HAL) under the code works to be included in the readme would be helpful for the reader.
Post Reply

Return to “Projects”