cancel
Showing results for 
Search instead for 
Did you mean: 

How can I interface an LCD with an STM32L412RBT6P microcontroller using SPI and DMA?

Zaim01
Associate III

Hi,

I have an STM32L412RBT6P microcontroller and a CFAG12864T3-NFH LCD which uses an ST7565 controller. I want to use SPI to communicate with the LCD and leverage DMA to efficiently transfer data with lowest current consumption possible. Could someone provide an example code or any helping notes on how to set this up? Specifically, I'm looking for:

1. Initializing the SPI peripheral on the STM32L412RBT6P for communication with the ST7565 controller.

2. Configuring DMA to handle data transfers from memory to the SPI peripheral.

3. Sending initialization commands and data to the LCD with ST7565.

Any help would be greatly appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions

1. I mean no SPI clock is based on PCLK2 then in transfer time PCLK must be 2x SPI speed. After transfer can swith down...

MM1_0-1723562170654.png

2. Too NO.

3. Use partial update method for screen and switch to low power after transfer changes.

By energy law is irelevant if you use low SPI speed with low current long time vs high speed short time. Avoid animation at all.

L4 is SPI 1.3.x hw

Specific handling of autonomous SPI operation in low power modes is out of this document scope. Version 2.x.x
is capable to drive serial bus clocking in stop mode while raising asynchronous interrupts to handle data
exchange. Version 3.x.x, additionally, can handle the data exchange between the peripheral and memory via
smart DMA if implemented in the product. This is done without need for system wake-up, due to temporal
domain's clock requests handled by the peripheral while the data transfers can be synchronized with other
peripherals by internal triggers. Refer to documents targeting LPBAM control, such as AN5645 "STM32U5 Series
power optimization using LPBAM" Guidelines for enhanced SPI communication on STM32 MCUs and MPUs - Application note

View solution in original post

9 REPLIES 9

It is probably possible to do something, either in a circular manner, or processing a linked-list or scatter-gather type mechanism.

ST doesn't really have a slick way of managing the Chip Select pin, which complicates general purpose solutions.

It's perhaps unrealistic to expect others to do your work and analysis and furnish you with a solution for a pair of parts you've chosen.

There should be SPI+DMA examples amongst the CubeL4 code trees for the assorted DISCO or EVAL boards. The mechanics and associativity is covered in the Reference Manuals

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Hi Tesla DeLorean,

I appreciate your response, but I’d like to clarify a few points. Firstly, while I understand the theoretical concepts like circular or scatter-gather mechanisms, I'm looking for concrete examples specific to the STM32L4xx and ST7565. Practical guidance is more helpful than theoretical suggestions.

Regarding the management of the Chip Select (CS) pin, I agree it can be tricky. However, many in the community have likely faced and solved this issue. Sharing specific advice or examples would be valuable.

I want to address the assumption that I expect others to do my work. That is not the case. This community is here to help each other, and many members have similar questions and benefit from shared solutions. My question is in line with the community's purpose.

The ST7565 LCD controller is quite common, and I believe others have interfaced it with STM32 MCUs. Sharing practical experiences and solutions is what this community is about.

While I’m looking into CubeL4 examples, specific guidance on adapting them to my setup would still be highly appreciated. This community exists for ST product users to support each other. If someone has experience with this setup, sharing practical examples or detailed steps would help many of us.

Thanks

AScha.3
Chief III

Hi,

here an example, just set your pins and spi you use...

https://github.com/ArsalanAliMujtaba/ST7565-ST7565P-COG-3-Inch-LCD-Library-for-STM32Cube-IDE

 

+ DMA for such small display ? ...at first get it running without DMA.

 

If you feel a post has answered your question, please click "Accept as Solution".

Thank you for your recommendations.

 

Actually, I have used this library before and successfully got the LCD working with the MCU, and it's still functioning well with a CPU clock of 16 MHz. However, my application is focused on low power consumption, which is why I am trying to reduce the clock frequency to 1 MHz or even lower. 

 

When I lower the clock speed, the system continues to operate correctly, but the text on the LCD becomes difficult to read and lacks fluency. After some research, I found that using DMA to handle the LCD could allow the CPU to enter low-power modes while the DMA manages the display updates. This approach seems like it could help maintain the performance of the display even at reduced clock speeds.

 

Do you have any further insights on implementing DMA for this purpose, or suggestions on other methods to optimize the display performance for low-power applications?

As first in normal run mode create display flush with SPI and DMA. After this work handle switch into low power modes with SPI ... supported is only Sleep , LP Run and LP Sleep. Read STM32L4 and STM32L4+ ultra-low-power features overview

Dor_RH
ST Employee

Hello @Zaim01,

Here are some links from STMicroelectronics that can help you write code to configure and use SPI with DMA on STM32 microcontrollers, as well as specific examples for LCD screens using the ST7565 controller:

  • AN4776 Application Note: This document explains in detail how to configure and use the DMA controller on STM32 microcontrollers.
  • AN5050 Application Note: This guide helps you get started with STM32CubeMX to configure peripherals and generate initialization code.
  • STM32CubeL4 Firmware Package: This package contains code examples, libraries, and demonstration projects for STM32L4 microcontrollers. You can find specific examples for SPI and DMA.

Additionally, here are some corrected and verified links for articles on STM32 SPI and using DMA with STM32:

I hope my answer has helped you. When your question is answered, please select this topic as solution that answered you, it will help others find that answer faster.

Thanks for your contribution.

Dor_RH

Thank you all for your helpful suggestions and insights! I appreciate the time and effort you’ve taken to assist me.

I’ve been referring to the RM0394 Reference Manual, particularly section 6.2 on Clocks (page 178), but I noticed it doesn’t specifically mention SPI. In my configuration, I’m unable to directly adjust the SPI clock. While I can reduce the clock frequencies for other peripherals like I2C, the SPI clock appears to be fixed and non-adjustable.

 

WhatsApp Image 2024-08-13 at 3.48.44 PM.jpeg

WhatsApp Image 2024-08-13 at 3.49.38 PM.jpeg

My primary goal is to reduce the CPU clock to the lowest possible value while ensuring the LCD screen operates within a suitable clock range. I attempted to lower the overall MCU clock to 1 MHz, but this significantly slowed down the screen refresh rate, making it less practical.

Here are my questions:

  1. Is it possible to reduce the MCU clock and still keep the SPI clock high? If so, how can I achieve this configuration?

  2. Can I use an external clock source specifically for the SPI peripheral while reducing the main MCU clock? Would this approach be effective in balancing low power consumption with acceptable display performance?

  3. Considering my goal of minimal power consumption, what would be the best strategy to drive the LCD using the STM32L412? I plan to use an SMPS for VDD12, so any advice on optimizing power usage while maintaining screen performance would be valuable.

Thank you again for your guidance!
@MM..1 @Dor_RH 

1. I mean no SPI clock is based on PCLK2 then in transfer time PCLK must be 2x SPI speed. After transfer can swith down...

MM1_0-1723562170654.png

2. Too NO.

3. Use partial update method for screen and switch to low power after transfer changes.

By energy law is irelevant if you use low SPI speed with low current long time vs high speed short time. Avoid animation at all.

L4 is SPI 1.3.x hw

Specific handling of autonomous SPI operation in low power modes is out of this document scope. Version 2.x.x
is capable to drive serial bus clocking in stop mode while raising asynchronous interrupts to handle data
exchange. Version 3.x.x, additionally, can handle the data exchange between the peripheral and memory via
smart DMA if implemented in the product. This is done without need for system wake-up, due to temporal
domain's clock requests handled by the peripheral while the data transfers can be synchronized with other
peripherals by internal triggers. Refer to documents targeting LPBAM control, such as AN5645 "STM32U5 Series
power optimization using LPBAM" Guidelines for enhanced SPI communication on STM32 MCUs and MPUs - Application note

Thank you for your valuable insights and assistance! I’ll be reading the mentioned application notes and applying your suggestions. If I have any further concerns, I’ll reach out again. Marking this as solved—thanks again