Neopixels, advices with the code.

Thread Starter

Xenon02

Joined Feb 24, 2021
500
Hello !

I've wanted to ask for advice and for question about code. I've bough lately some neopixels (8 leds in one strap), so I wanted to make a code, and decided to learn how it works from someones code. I wanted to ask for some help in understanding it.

My goal is to light up leds one after another when I click a button, so I click a button first leds lights up, and when I click again the button the second one lights up (first led is still on not off). The code I've been viewing was this one : https://www.thevfdcollective.com/blog/stm32-and-sk6812-rgbw-led
And here I had one problem the DMA callbacks ... first of all I know that callbacks should be short, but how measure if's its fast enough to read what is inside of the callback ?
Why I asked this question ? I've been having a dilemma lately, basically imagine this situation :

//A
// UART_Transmit B
//C
// UART Receive D
//E

If I called the function UART transmit and had transmitted all data then the device (slave) on the other side will now send data back to the (master) device, So in "A" nothing happens timing doesn't matter, in "B" as well because we send data in "C" it matters ! Because if it's to long the data will comeback before even the program will execute the "D" Receive function. But okey "c" is empty, then we have "D", it is also important because this function Receive is not empty it has plenty of lines of code which are translated into machine code ! Have in mind the device (slave) is sending back the data to the (master) device So data is coming while the Receive function is being executed (line of code after line of code), like imagine the data is coming and we are not ready to wait whether the data is fully received or not because the processor hasn't yet read the line of code (one of many in receive) that says to wait for a certain flag.


Well I've had many math thinking in low level like calculating the amount of instructions read per 10 bit of uart data in certain baud rate which sometimes lead to for 40 MHz 100 instructions to read before10 bit will be sent back to master from slave. So not much time to be honest. How do I know how many instructions it takes for single function to be executed fully !

Well that's my dilemma which I wasn't focusing on, maybe next time :)
This is just a thing I am very aware of although I shouldn't but I feel like either the function of receive or so are slow, because they have a lot of lines of code while something is being executed and they have to be fast enough ! And as a newbie in programming microprocessors I shouldn't think about it but I do somehow, same goes here !!
DMA callbacks ! How do I know that the thing in first callback is fast enough before the second callback is being triggered ? And what if I click the button which will also start the callback, then I have in total 3 callback and can be triggered 2 of them at the same time.

Second problem what I have in mind maybe not in the code of someone else but in concept of mine. The thing is that if I wait for to long 80us before clicking a button the reset cycle will happen and the first led diode instead of sending the data to the next diode it will take it as it's own. So yea I have to think of a way with that ... Because the from someone else is lighting all the leds.
 

BobTPH

Joined Jun 5, 2013
8,967
And here I had one problem the DMA callbacks ... first of all I know that callbacks should be short, but how measure if's its fast enough to read what is inside of the callback ?
Why I asked this question ? I've been having a dilemma lately, basically imagine this situation :
What does DMA callbacks and uart code have timo do with controlling neopixels?

When you look for an example code to do something, you want to look for code that does nothing else.
 

Thread Starter

Xenon02

Joined Feb 24, 2021
500
What does DMA callbacks and uart code have timo do with controlling neopixels?

When you look for an example code to do something, you want to look for code that does nothing else.
I just gave an example of timing I have been thinking of lately, it is just a dilemma nothing more.
Before executing the callback usually they have to do something before callback so it is IRQ stuff like receiving the data putting it into SRAM, checking the flags etc. usually as I saw the data is being stored at the end after checking many stuff. So I thought that DMA before executing the callback also has to do man stuff before executing the callback, and what is inside of that first callback of that DMA might slow down the execution hence the second DMA callback can be triggered before the first callback even finished executing what is inside of him.

As I've mentioned, only dilemma nothing more, and gave only a simple example.
 

Thread Starter

Xenon02

Joined Feb 24, 2021
500
I am sure the AdaFruit website will have examples you can understand. Look there.
They have for Arduino examples but not for STM. It wasn't the answer I was expecting.

I tried to use someone's code to understand it because of how fast the callback is being executed and the code before callback which are in IRQ. Is the callback to long or not etc.

So if it's not the answer to the question from the 1st post then please don't put random solutions. Thank you.
 

BobTPH

Joined Jun 5, 2013
8,967
Hello !

I've wanted to ask for advice and for question about code. I've bough lately some neopixels (8 leds in one strap), so I wanted to make a code, and decided to learn how it works from someones code. I wanted to ask for some help in understanding it.
I was replying to this first paragraph. You do not need to know anything about DMA callbacks to write code neopixels. You have chosen a poor example to look at if your goal is ti program neopixels.
 

Thread Starter

Xenon02

Joined Feb 24, 2021
500
I was replying to this first paragraph. You do not need to know anything about DMA callbacks to write code neopixels. You have chosen a poor example to look at if your goal is ti program neopixels.
I saw other neopixel programs that also used DMA.
I don't know exactly why even though the authors uses delays so the processor still waits for nothing, but wanted to understand the DMA and why it works even though the callbacks of this DMA is pretty long, so I wanted to measure how fast the processor executes the callbacks, sysTick measures in [ms] and I also didn't know where to place them to start with. Because I don't have the intuition of how short should be the callback sometimes even long codes can be very fast to execute and short code to be very long to execute, hence I just doubt the code although it probably works (I haven't tested it myself because it still requires some modifications for my STM) so that's why I used the UART example to manifest my concern or rather my dilemma in timings because in UART it is important and how function that is responsible to take data is executed (how fast it reads it's lines of machine code before the full data is received by master, because the data is coming from slave and master receives bit by bit while master is still reading lines of code to receive the data so here is sprint, who will be first overflow or master will read in time), function itself but what if something is inside of that function as well ? There are two callbacks instead so if the second one is triggered while the first one is still being processed, I think you know what I am trying to say, a sprint, who will be first.

I still have some problem with understanding fully the timings but well it is what it is.
 
Top