STM32F4 Discovery Part1 - Touch Buttons


Introduction: STM32F4 Discovery Part1 - Touch Buttons

Hi !

Today I want to show you simple application using touch screen. The idea of the programme is quite easy, but it will be great start for bigger apps. I was programming AVR for over 1 year and I didn't realize how great the ARMs could be. When I bought the Discovery board I did my best to start using touch LCD. In step 1 I'll give You links which really helped me to get start with stm32.

Step 1: CoIDE, HalCube, Segger

Download and install CoIDE

Download the HALCube (on the bottom of the page)

Segger will help you in creating widgets

In HalCube pack you have examples for all peripherials of stm32 Discovery. There ale also datasheets for discovery board, stm32, segger, and everything You need. Check out these files !

Step 2: Writting a Programme Buttons.h

Writting a programme on ARM microcontrollers are quite harder then AVR. I will show you how to create your first widget in easy way.


As you see, firstly you have to define elements you will need. In this case it is Framewin, Button1 and Button2.

In static const GUI_WIDGET_CREATE_INFO _MainWindow[] you create your widget. We have to write the type of the widget to create (FRAMEWIN_CreateIndirect), Text to be visibled on it ("Instructables !"), X-start(10) Y-start(10), X-end(220), Y-end(180).

The Buttons() function is the main function for touch screen routine.

#ifndef __BUTTONS_H
#define __BUTTONS_H

#include "WM.h" #include "BUTTON.h" #include "TEXT.h" #include "FRAMEWIN.h" #include "PROGBAR.h" #include "GRAPH.h" #include "GUIDEMO.h"

#define ID_W1 (GUI_ID_USER + 1) #define ID_W1_BUTTON0 (GUI_ID_USER + 2) #define ID_W1_BUTTON1 (GUI_ID_USER + 3) // // Dialog resource // static const GUI_WIDGET_CREATE_INFO _MainWindow[] = { {FRAMEWIN_CreateIndirect , "Instructables !", ID_W1 , 10 , 10 , 220 , 180 , 0 , 0 , 0 }, {BUTTON_CreateIndirect , "LIGHT ON" , ID_W1_BUTTON0 , 10 , 10 , 190 , 40 , 0 , 0 , 0 }, {BUTTON_CreateIndirect , "LIGHT OFF" , ID_W1_BUTTON1 , 10 , 70 , 190 , 40 , 0 , 0 , 0 }, };

void Buttons(void);

#endif /* __BUTTONS_H */

Step 3: Writting a Programme Buttons.c


The buttons() is called in main before infinite loop ! Using GUI_Exec() provides staying in the buttons() function. If you want to create more windows just add a global flag.

#include <stdio.h>
#include "buttons.h"
#include "stm32f429i_discovery.h"
#include "WM.h"
*       _cbMainWindow
*   Callback function of the WELCOME dialog
static void _cbMainWindow(WM_MESSAGE * pMsg)
	WM_HWIN hItem; 					// Universal handler for all widgets
	int Id; 						// Id of source widget
	int NCode = pMsg -> Data.v; 	// Code of message
	WM_HWIN hDlg = pMsg -> hWin;
	switch (pMsg->MsgId)
		hItem = WM_GetDialogItem(hDlg, ID_W1_BUTTON0);	// LIGHT ON button
		BUTTON_SetFont(hItem, GUI_FONT_24_ASCII);	// set button text size
		hItem = WM_GetDialogItem(hDlg, ID_W1_BUTTON1);	// LIGHT OFF button
		BUTTON_SetFont(hItem, GUI_FONT_24_ASCII);	// set button text size
		FRAMEWIN_SetTitleHeight(hDlg, 30);		// set title bar height
		FRAMEWIN_SetTextColor(hDlg, GUI_DARKRED);	// set framewin text color
		FRAMEWIN_SetFont(hDlg, GUI_FONT_20_ASCII);	// set framewin text size
		FRAMEWIN_SetTextAlign(hDlg, GUI_TA_CENTER);	// set framewin text align
		WM_SetDesktopColor(GUI_DARKRED);		// background color
	Id = WM_GetId(pMsg -> hWinSrc);
	switch (Id)
		case ID_W1_BUTTON0:
			switch (NCode)
				case WM_NOTIFICATION_RELEASED:  //button released reaction
					BSP_LED_On(LED3);	// leds on
		case ID_W1_BUTTON1:
			switch (NCode)
				case WM_NOTIFICATION_RELEASED:	//button released reaction
					BSP_LED_Off(LED3);	// leds off
*       WelcomeButtons();
*   Main Window of this file
void Buttons(void)
     BUTTON_SetDefaultSkin(BUTTON_SKIN_FLEX);	// create buttons with default skin
     FRAMEWIN_SetDefaultSkin(FRAMEWIN_SKIN_FLEX);    // create framewin with default skin
GUI_CreateDialogBox(_MainWindow, GUI_COUNTOF(_MainWindow), &_cbMainWindow, WM_HBKWIN, 0, 0);
     while (1)

Step 4: Watch the Results !

Now You can see how it works.

GUI_CURSOR_Show() called in main will show the cursor.

That's quite simple programme.

P.S. Enjoy and Sorry for my english :)



    • Casting Contest

      Casting Contest
    • Make it Move Contest

      Make it Move Contest
    • Woodworking Contest

      Woodworking Contest

    We have a be nice policy.
    Please be positive and constructive.




    HI,i'm a begginger for the LCD control the LED light ,when i compiler the code,the question is occurred, the WM.h I can't not found anywhere

    Are you asking about discovery board ?