Code Monkey home page Code Monkey logo

stm32-argb-dma's Introduction

STM32-ARGB-DMA

Fastest and simplest library for ARGB LEDs: WS28xx and SK68xx Series RGB or RGBW for STM32 Series.
Uses DMA Interrupts and PWM to control LED Strip

Banner

Features:

  • Can be used for addressable RGB and RGBW LED strips
  • Uses double-buffer and half-ready DMA interrupts, so RAM consumption is small
  • Uses standard neopixel's 800/400 KHz protocol
  • Supports RGB and HSV color models
  • Timer frequency auto-calculation

Limitations

  • Only supports APBx frequency >32 MHz. It's timers' limitations.

Lib settings

#define WS2812       // Family: {WS2811S, WS2811F, WS2812, SK6812}
// WS2811S — RGB, 400kHz;
// WS2811F — RGB, 800kHz;
// WS2812  — GRB, 800kHz;
// SK6812  — RGBW, 800kHz

#define NUM_PIXELS 5 // Pixel quantity

#define USE_GAMMA_CORRECTION 1 // Gamma-correction should fix red&green, try for yourself

#define TIM_NUM	   2  // Timer number
#define TIM_CH	   TIM_CHANNEL_2  // Timer's PWM channel
#define DMA_HANDLE hdma_tim2_ch2_ch4  // DMA Channel
#define DMA_SIZE_WORD     // DMA Memory Data Width: {.._BYTE, .._HWORD, .._WORD}
// DMA channel can be found in main.c / tim.c

Function reference (from .h file):

// API enum status
typedef enum ARGB_STATE {
    ARGB_BUSY = 0,      // DMA Transfer in progress
    ARGB_READY = 1,     // DMA Ready to transfer
    ARGB_OK = 2,        // Function execution success
    ARGB_PARAM_ERR = 3, // Error in input parameters
} ARGB_STATE;

void ARGB_Init(void);   // Initialization
void ARGB_Clear(void);  // Clear strip

void ARGB_SetBrightness(u8_t br); // Set global brightness

void ARGB_SetRGB(u16_t i, u8_t r, u8_t g, u8_t b);  // Set single LED by RGB
void ARGB_SetHSV(u16_t i, u8_t hue, u8_t sat, u8_t val); // Set single LED by HSV
void ARGB_SetWhite(u16_t i, u8_t w); // Set white component in LED (RGBW)

void ARGB_FillRGB(u8_t r, u8_t g, u8_t b); // Fill all strip with RGB color
void ARGB_FillHSV(u8_t hue, u8_t sat, u8_t val); // Fill all strip with HSV color
void ARGB_FillWhite(u8_t w); // Fill all strip's white component (RGBW)

ARGB_STATE ARGB_Ready(void); // Get DMA Ready state
ARGB_STATE ARGB_Show(void); // Push data to the strip

Connection

Connection

Instructions for use:

  • Use CubeMX to configure clocks and peripheral.
  • Enable PWM Generation for your preferred timer channel.
  • PWM Mode 1, OC Preload: Enable, Fast Mode: Disable, CH Polarity: High
  • Enable DMA for your timer channel with "Memory To Peripheral" direction.
  • Set DMA mode to Circular, Data Width to Word/Byte, Increment Address checkbox only for Memory.
  • Set GPIO Speed to the Maximum, use Open Drain or Push Pull Mode - details in Troubleshooting.
  • Save CubeMX .ioc file and generate code.
  • Add library to your source destination and add #include in your code.
  • In main.c file search for your DMA Handler
/* Private variables */
TIM_HandleTypeDef htim2;
DMA_HandleTypeDef hdma_tim2_ch2_ch4;  <-- THIS
  • Add this handler in ARGB.h file in DMA HANDLE define.
  • Set other defines with your settings.
  • Now we're ready to go!

TROUBLESHOOTING

  • IF STRIP DOESN'T WORK

    • You should convert logic levels
      • In Push Pull GPIO Mode use SN74LVC Translator
      • In Open Drain GPIO Mode use 1K PullUp Resistor
    • Check HAL DMA Generation order. DMA_Init should be higher than TIM_Init DMA_Order
  • COLOR NOISE

    • Use Logic Analyzer or Oscilloscope to measure the signal, or just play with values
      • Correct timer values in .c file 152 string
  • ANY OTHER

Suggestions

Special thanks

NarodStream, VFD

Donate options

stm32-argb-dma's People

Contributors

crazy-geeks avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

stm32-argb-dma's Issues

STM32F030K6T6 What I'm doing wrong?

Hi!

I'm trying to run this library on STM32F030K6T6, but I have a trouble with it.
All configs are correctly set, but the frequency is 4 times slower than that supposed to.

Screens:
obraz
obraz
obraz
obraz

Of course I added the TIM_NUM 17 to ARGB.c and hard-coded frequency, which should not effect on performance:
void ARGB_Init(void) { u32_t APBfq = 48000000; // Clock freq #ifdef WS2811S

ARGB.h:
`#define WS2812 ///< Family: {WS2811S, WS2811F, WS2812, SK6812}
// WS2811S — RGB, 400kHz;
// WS2811F — RGB, 800kHz;
// WS2812 — GRB, 800kHz;
// SK6812 — RGBW, 800kHz

#define NUM_PIXELS 100 ///< Pixel quantity

#define USE_GAMMA_CORRECTION 1 ///< Gamma-correction should fix red&green, try for yourself

#define TIM_NUM 17 ///< Timer number
#define TIM_CH TIM_CHANNEL_1 ///< Timer's PWM channel
#define DMA_HANDLE hdma_tim17_ch1_up ///< DMA Channel
#define DMA_SIZE_WORD ///< DMA Memory Data Width: {.._BYTE, .._HWORD, .._WORD}`

Where we can took libraries

where to get

#include "stm32_dma.h"
#include "pwm.h"
#include "math.h"

??

this is not a part of HAL package

Stuck in busy HAL_DMA_STATE_BUSY

Hello Crazy-Geeks,

Thank you for this lib. I try to add it to my Nucleo G0B1RE project but I have several problems.

First of all I had to change APBfq init because of "implicit declaration of function" :
image

Unfortunatlly, I the execution get stuck in the second ARGB_show() call. Whane checking DMA_HANDLE.State it is HAL_DMA_STATE_BUSY.

Please find my configs :
image

image

image

image

image

I use a picoscope for debugging which is directly connected to the TIM4_CHANNEL1 pin and the it stays low.

Do you think the problem comes from the APBfq changes ? Could you please help me find out where does the problem comes from ?

Thank you for your time.

antoi-q

Work frequency

Now strip works only when APB frequency is 72 MHz. I tried to set it to 8 MHz and change counter to 9 (8x10^6/8x10^5 = 10), but strip didn't work at all. In several weeks I'll buy logic analizator to watch what happens at GPIO pin.

Incorrect signals on STM32F411

Hi there,

Thanks for all the work in putting this together, very clear code & instructions. I am trying to use this lib on an STM32F411 (Nucleo STM32F411RE) and the output signal is incorrect:

image

This is the signal supposed to be sent for to clear a strip of one pixel:

ARGB_Init();  // Initialization

  ARGB_Clear(); // Clear strip
  while (ARGB_Show() != ARGB_OK); // Update - Option 1

  //ARGB_SetBrightness(100);  // Set global brightness to 40%

  //ARGB_SetRGB(2, 0, 255, 0); // Set LED №3 with 255 Green
  //while (!ARGB_Show());  // Update - Option 2

  //ARGB_SetHSV(0, 0, 255, 255); // Set LED №1 with Red
  //while (!ARGB_Ready()); // Update - Option 3
  //ARGB_Show();

  //ARGB_FillWhite(230); // Fill all white component with 230
  //while (ARGB_Ready() == ARGB_BUSY); // Update - Option 4
  //ARGB_Show();

  //ARGB_FillRGB(200, 0, 0); // Fill all the strip with Red
  //while (!ARGB_Show());

I have checked all the CubeMX configuration which is as per your instructions and really don't understand what's happening. Any idea?

For reference, here is my clock configuration:

image

Timer configuration:

image

RCC configuration:

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.