This package provides a toolkit for developing applications with multimedia features using STM32 boards. It implements a VGA driver, a basic primitive drawing library, a very basic audio driver and a basic USB input device driver.
This is an adaptation of an old project that I developed in 2014.
The driver generates a VGA signal with 256 colors RGB 2-3-3
A minimal DAC is needed to convert the 8 bit signal to the 3 channel VGA analog signals. This DAC can be easily built with only resistors. The following picture describes how to build the DAC and how to connect it to the VGA adapter:
By default, the video output on the board uses the following pins:
- B0 -> PC8
- B1 -> PC9
- B2 -> PC10
- G0 -> PC11
- G1 -> PC12
- G2 -> PC13
- R0 -> PC14
- R1 -> PC15
But in the future this will be a configurable option.
If you don't want to build the DAC, it is still possible to generate the output without it, but the color combinations will be reduced to 8. Just pick 3 pins and place a 260 Ohm resistor between each one and the corresponding color pin on the VGA connector. You can also use a single pin if you want monochrome video. There's a wide option range!
Here is a basic example which demonstrates how to initialize the video driver.
#include <stdio.h>
#include <stm32f4xx.h>
#include "mdt/graphics.h"
#include "mdt/text.h"
void example(void) {
MDT_GRAPHICS_InitTypeDef graphicsCfg = {
.useHardwareAcceleration = true,
.useSDRAM = false,
.mainCtxHeight = 200,
.mainCtxWidth = 320,
.videoDriver = VIDEO_DRIVER_VGA,
};
MDT_GRAPHICS_Init(&graphicsCfg);
while (1) {
MDT_Clear(0x00);
MDT_DrawText("Hello world!", 10, 10, 0xFF);
MDT_WaitForVSync();
MDT_SwapBuffers();
}
}-
Open STM32CubeIDE and create a new project: File > New > STM32 Project.
-
Click on
Board Selectortab and select yours, then click next. -
Give your project a name, use default options (
C,Executable,STM32Cube) and click Finish. -
When prompted to initialize all peripherals to default mode choose
No.The
.iocconfiguration tool will open. If you go toSystem viewonlyDMA,GPIO,NVICandRCCshould appear. -
Go to
Categories > System Core > SYSand set theDebugtoSerial Wire. -
Go to
Categories > System > RCCand set theHigh Speed Clock (HSE)toCrystal/Ceramic Resonator. -
Go to
Clock configurationand choose whatever clock frequency combination you want, please note that for this project to work correctly theHCLKfrequency should be a multiple of25.175MHz, otherwise you might experience issues. -
Go to
Project Manager > Advanced Settingsand set theGPIOdriver toLL.
-
-
If you want USB support:
-
Go to
Categories > Conectivity > USB_OTG_HSand set theInternal FS PhytoHost_Only. -
Go to
Categories > Middleware > USB_HOSTand set theClass For HS IPoption toHuman Interface Host Class (HID), and in the platform Settings set theDriver_VBUS_HStoGPIO:Outputand select your pin (PC4 in my case) -
Go to
Categories > System > NVICand setPrioriy Groupto4 bits ...and set theUSB On The Go HS Global Interruptpriorities to the highest value [1]. -
Go to
Project Manager > Advanced Settingsand uncheck theGenerate Codecheckbox forMX_USB_HOST_Init
-
-
Open a terminal and navigate to the project
Middlewaresfolder [2], once theregit clonethis repo. -
Add the
includeandexamples/includefolders to the include directories. -
Open the project with your OS Explorer and go to the
Drivers/STM32***_HAL_Driverfolder and copy the missing drivers.You should add your MCU's drivers, for example: for the STM32F4xx family you can find them here.
-
Edit
main.cfile and modify it according to this snippet:
//...
/* USER CODE BEGIN Includes */
#include "mdt/examples/all.h"
/* USER CODE END Includes */
//...
void main(void) {
//...
/* USER CODE BEGIN 2 */
MDT_EXAMPLE_term(); //or whatever example you want to run
/* USER CODE END 2 */
//...
}-
Enabling any other peripherals could make the system unstable, please do it carefully.
-
In
Project Properties > C/C++ Build > Settings > MCU GCC Compiler > Preprocessor, theUSE_FULL_LL_DRIVERdefinition should be set.
In NVIC priority settings, lower value means higher priority.
Actually you can clone this repo anywhere within the project. Middlewares just seemed the appropiate place, but in case it does not exist you can put it into any folder, just make sure the folder is a Source Folder so its contents get compiled.