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 Selector
tab 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
.ioc
configuration tool will open. If you go toSystem view
onlyDMA
,GPIO
,NVIC
andRCC
should appear. -
Go to
Categories > System Core > SYS
and set theDebug
toSerial Wire
. -
Go to
Categories > System > RCC
and set theHigh Speed Clock (HSE)
toCrystal/Ceramic Resonator
. -
Go to
Clock configuration
and choose whatever clock frequency combination you want, please note that for this project to work correctly theHCLK
frequency should be a multiple of25.175MHz
, otherwise you might experience issues. -
Go to
Project Manager > Advanced Settings
and set theGPIO
driver toLL
.
-
-
If you want USB support:
-
Go to
Categories > Conectivity > USB_OTG_HS
and set theInternal FS Phy
toHost_Only
. -
Go to
Categories > Middleware > USB_HOST
and set theClass For HS IP
option toHuman Interface Host Class (HID)
, and in the platform Settings set theDriver_VBUS_HS
toGPIO:Output
and select your pin (PC4 in my case) -
Go to
Categories > System > NVIC
and setPrioriy Group
to4 bits ...
and set theUSB On The Go HS Global Interrupt
priorities to the highest value [1]. -
Go to
Project Manager > Advanced Settings
and uncheck theGenerate Code
checkbox forMX_USB_HOST_Init
-
-
Open a terminal and navigate to the project
Middlewares
folder [2], once theregit clone
this repo. -
Add the
include
andexamples/include
folders to the include directories. -
Open the project with your OS Explorer and go to the
Drivers/STM32***_HAL_Driver
folder 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.c
file 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_DRIVER
definition 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.