STM32 and DMX

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
rbarreiros
Posts: 27
Joined: Sat Mar 28, 2015 2:32 am

STM32 and DMX

Post by rbarreiros »

Hello,

I'm migrating some stuff I have from AVR to STM32, they're DMX dongles and/or converters, so I've been trying to investigate a little bit more about implementing the DMX protocol in STM32 and I've been having some problems with it by itself, and, I have a few doubts related to ChibiOS about it as well.

What is a common practice to generate the break signal, used to signal the start of the DMX stream, is to change baudrate to 100000 (and change the format to 8 bit + parity + 1 stop bit = 10 bit ~ 100usec break) and send a 0 byte, then switch back to the regular DMX baudrate which is 250k, by changing baud, we generate the MAB (Mark after break), then proceed to send the start byte which for DMX is 0 and then send 512 bytes which correspond to the 512 DMX channels.

The most efficient way by implementing this in AVR's was(is) :
- Set baud to 100k
- write byte 0
- set baud to 250k, enable tx enable int
- txc int triggers and send startbit disable tx complete int, enable udre int
- udre int triggers and send 512 bytes of data
- repeat

Now, I'm attempting to do the exact same thing in a STM32 (more specifically an STM32f103C8T6 the one sold in ebay from LC-Tech board) while using ChibiOS, the purpose is to have 3 DMX streams (for each usart) + 1 SPI (ENC28J60), yes, for those guessing, an ArtNet node with 3 DMX output ports, where each DMX stream is a thread, SPI (ENC28J60) another thread, and the main thread the one handling the USB connectivity, with a usb serial cdc mostly for debugging purposes, and this led me to the following questions I'd hope you guys could help me with (oh btw, it's open source, or better yet, will be as soon as I have an alpha working):

- First and most important, is the AVR method of generating a DMX stream the best one to do in a Cortex M3 such as this STM32F1 ?
- If it is, how do I change baudrate after I initialize the UART ? If not, how do you guys in your experience think it would be the best method to achieve the most stable stream ?
- Is my way of thinking regarding the plan for implementing the project with ChibiOS the right one ? (3 threads per USART + 1 thread for SPI + main thread for USB) ?
- What is the highest SPI speed that a STM32F1 (running ar 72Mhz) can achieve ? (72/2?)

Thank you very much for all the help.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32 and DMX

Post by Giovanni »

If I understood well this break is a sequence of zeros longer than a frame time, correct?

If you you can just program the pin in GPIO mode and set it to zero, wait an appropriate time, and then switch it back to USART mode.

The SPI maximum is 18MHz on the F1.

Giovanni
rew
Posts: 383
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 14 times

Re: STM32 and DMX

Post by rew »

Giovanni wrote:If I understood well this break is a sequence of zeros longer than a frame time, correct?
Yes, Correct.
If you you can just program the pin in GPIO mode and set it to zero, wait an appropriate time, and then switch it back to USART mode.
That's what I was thinking too. On the other hand, for efficiency you don't want to wait much longer than 100 microseconds at this point in time. So, using the uart for this timing-task is an option.

Changing the baud rate in chibios can be done with:

Code: Select all

SerialConfig wifiserial = {
  115200, // the baud rate;
  0,0,0
};

void chbaud (int baud)
{
  wifiserial.speed = baud;
  sdStart(&SD2, &wifiserial);
}
Possibly calling "sdStop" first is "nicer".

The STM32 should be able to transmit the whole 512byte sequence without any CPU intervention (i.e. DMA). Nice!
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32 and DMX

Post by Giovanni »

rew wrote:The STM32 should be able to transmit the whole 512byte sequence without any CPU intervention (i.e. DMA). Nice!


That would require the UART driver, the Serial driver does not use DMA.

Giovanni
Post Reply