This is a port of Tilen Majerle's Nokia 3310/5110 LCD library, which can be used with the STM32 HAL functions and STM32CubeMX's auto-generated code.
The biggest advantage of this SPI-based library compared to Adafruit's more famous GPIO-based library, is its noticeably higher speed.
Settings in STM32CubeMX: Activate an SPI, set the mode to "Transmit only Master" (since we don't need to recieve anything from the LCD), and set the data size to "8 bits". Then activate three GPIO_Output pins for the reset, DC and CE pins of the LCD.
After setting up SPI and three GPIO_Output pins, go to the "stm32f4_pcd8544.h" file and edit these lines on top of the file with the handle struct of your SPI, and the three GPIO pins that you have set up for the reset, DC and CE pins of the LCD. In the original files and the example below I have set up hspi3 as SPI handle, and the D7, D5 and D3 pins as the GPIO pins.
//SPI used
extern SPI_HandleTypeDef hspi3;
#define PCD8544_SPI hspi3
//Default pins used
//Default RST pin
#define PCD8544_RST_PORT GPIOD
#define PCD8544_RST_PIN GPIO_PIN_7
//Default CE pin
#define PCD8544_CE_PORT GPIOD
#define PCD8544_CE_PIN GPIO_PIN_5
//Default DC pin
#define PCD8544_DC_PORT GPIOD
#define PCD8544_DC_PIN GPIO_PIN_3
#include "stm32f4_pcd8544.h"
...
int main()
{
...
PCD8544_Init(0x38); //LCD initializing function, the input is the contrast value
PCD8544_Puts("Hello World!", PCD8544_Pixel_Set, PCD8544_FontSize_5x7);
PCD8544_Refresh(); //Don't forget to refresh to see your text on screen
while(1)
{ ... }
}