This application note describes the demonstration firmware running on the STM3210CEVAL for the STM32F107VC to manage a smartplug network system.
An embedded graphical user interface (GUI) based on the “multi-input embedded GUI
library 2.0 for STM32F10xxx” described in the AN3128 application note, and working on an
LCD TFT 320 x 240 display and 5-position joystick, allows the user to interact with the
smartplug system made up of one coordinator and two smartplugs connected.
Section 1 describes the document and library rules.
Section 2 highlights the features of the ZigBee smartplug and explains its hardware
interface with a device microcontroller (STM32).
Section 3 describes briefly the “multi-input embedded GUI library”.
Section 4 describes the relevant blocks of the STM3210C-EVAL demonstration board.
Section 5 shows the demonstration firmware/board system setup.
Section 6 describes, in detail, how the “in-home display” firmware is structured, its
architecture and its exported APIs.
Section 7 explains how to get started with the system, how to configure and use the IAR
workspace, and contains an example application source code.
Section 8 illustrates how the “in-home display” GUI application works.
This document uses the conventions described in the sections below.
1.1 Acronyms
Ta bl e 1 lists the acronyms used in this document.
Table 1.List of acronyms
Acronym Meaning
API Application programming interface
HAL Hardware abstraction layer
MCU Microcontroller unit
I2C Inter-integrated circuit
SPISerial to parallel interface
OOP Object oriented programming
6/58Doc ID 18209 Rev 1
AN3311ZigBee smartplug
2 ZigBee smartplug
2.1 Smartplug description
The smartplug coordinator is connected via an SPI to the STM3210C-EVAL through an “AdHoc” adapter.
In Figure 1 it is possible to take a quick look at the STM3210C-EVAL board and a smartplug
node block diagram.
Figure 1.STM3210C-EVAL block scheme
An adapter is connected to the extended connectors CN8 and CN9 on the STM3210CEVAL (for more detailed information please refer to the UM0600 user manual), it allows the
connection of a ZigBee smartplug coordinator and the I
2
C/RF dual interface EEPROM
M24LR64-r. The Gerber files of the adapter board are included in the setup package of this
project.
The ZigBee smartplug board can be used as a guide to build a home/building automation
subsystem for energy management. In a typical application, the board is plugged into an
electrical wall socket and supplies an electrical load, monitoring the energy consumption;
using several smartplugs it is possible to monitor and control the home/building energy
consumption socket by socket. The board includes the following functions, shown in the
block diagram of Figure 2:
●Energy measurement
●Load differential current
●Load driving by relay or TRIAC (dimming)
●ZigBee communication capability.
Doc ID 18209 Rev 17/58
ZigBee smartplugAN3311
Figure 2.Block diagram
The STEVAL-IHP001V3 is a smartplug board based on an STM32F10x microcontroller, a
SPZB260 ZigBee module, and an STPM01 energy metering IC.
It implements a ZigBee metering node which allows the final user to monitor and manage
energy consumption.
The board has been developed as a guide to build a home/building automation subsystem
for energy management. In a typical home system implementation, the board is plugged into
an electrical wall socket and supplies a home appliance or other generic electrical load.
The current, power, energy, and other information, related to the electrical load connected to
the smartplug board, can be displayed locally on an LCD screen, and are sent to a ZigBee
data concentrator through the home/building ZigBee network.
2.2 ZigBee module
ZigBee smartplug communication is based on the SPZB260 module with a DIL adapter. The
module is FCC compliant (FCC ID:S9NZB260A). The module is based on the SN260
ZigBee network processor which integrates a 2.4 GHz, IEEE 802.15.4 compliant
transceiver, as well as IEEE 802.15.4 PHY and MAC. The main features are:
●0dBm nominal TX output power
●-92dBm RX sensitivity
●+2dBm TX output power in boost mode
●RX filtering for co-existence with IEEE 802.11g and Bluetooth
For further details please refer to the SPZB260 module and the SN260 network processor
datasheet.
Note:For more information, see the UM0608 user manual, STEVAL-IHP001V3 schematics
diagram, and AN2993 application note.
®
devices.
8/58Doc ID 18209 Rev 1
AN3311Multi-input embedded GUI library
3 Multi-input embedded GUI library
3.1 Description
This solution enables users, comfortable with the use of standard microcontrollers, to create
higher-end “look and feel” human interfaces by replacing conventional electromechanical
switches with touch-sensing controls.
Users can combine touch-sensing functions using multiple configurations (touchscreen,
joystick, and keys) with traditional MCU features (communication, beeper, LCD control, etc.).
The E-multi-input graphic library is part of the application firmware.
The graphic objects are a set of controls that can be printed on the screen and associated to
an action when pressed.
The library has been developed and tested on an LCD panel of QWGA resolution (320x240)
which is the default, but the library is independent of the LCD resolution, although it has not
been tested with others.
The library supports touchscreen features and includes a low level driver which handles the
analog input (for 12-bit ADC), and a function for the touchscreen calibration based on an
algorithm that uses 5 points.
The multi-input embedded GUI firmware library is fully developed in 'ANSI-C' following an
OOP approach. This means that the final application uses instances of page and graphic
objects according to their public methods and properties. In the end, the PageObj is a
structure containing public properties (data fields) and methods (functions pointers). The
OOP encapsulation feature is assured. The library has been developed and tested on the
“STM3210C” STMicroelectronics demonstration board.
The library can be included in the final application as a library file (multi-input embedded
GUI library.a) and used as a black box through its exported public API, or can be included in
the final application as source files (.c and .h), if the user wants to debug the library itself, or
to change the HAL functions in order to port the library on a different LCD (in model and
resolution) from the one attached to STM3210C-EVAL.
For more information on the graphic library see the AN3128, rev. 2, application note.
The calibration process is part of the post-processing layer. The touchscreen must be
calibrated at first power-on and/or upon user request.
Once the calibration is done, final adjustments on future power-on of the board are not
necessary because the calibration parameters are saved on the Flash memory.
The touchscreen and the joystick are controlled by the STMPE811 devices.
The STMPE811 has a simple 2-wire I
access the data in the touchscreen controller register at any time. It communicates via the
serial interface with a master controller.
Figure 3 shows how the STM32F10xxx microcontroller (master device) must be connected
to the STMPE811 device.
2
C digital serial interface which allows the user to
Refer to the STMPE811 datasheet for more information on the register concerning the data
of the touched points on the touchscreen.
Figure 3.I/O expander hardware configuration on the STM3210C-EVAL
+3V
C8
100n
IO_Expander_SCK
IO_Expander_SDA
IO_Expander_INT
VC
14
Vio
10
GN
SCLK
B1
R15
+3V
R160
10
+3V
+3V
R3
10
C9
100n
R164
10
+3V
SDAT
Data
A0/Data
Out
ST
devic
address:0x8
VC
14
Vio
10
GN
SCLK
SDAT
Data
A0/Data
Out
R5
ST
10
devic
address:0x8
16
15
13
12
11
16
15
13
12
11
TouchScreen_Y-
TouchScreen_XTouchScreen_Y+
TouchScreen_X+
EXP
EXP
EXP
EXP
R5
100
EXP
EXP
EXP
EXP
EXP
EXP
EXP
EXP
R5
100
AM08449v1
10/58Doc ID 18209 Rev 1
AN3311STM3210C-EVAL demonstration board
4 STM3210C-EVAL demonstration board
Figure 4.STM3210C-EVAL demonstration board
Doc ID 18209 Rev 111/58
STM3210C-EVAL demonstration boardAN3311
4.1 Features
●Three 5 V power supply options: power jack, USB connector, or daughterboard
●Boot from user Flash, system memory or SRAM
●I2S audio DAC, stereo audio jack
●512 MByte (or bigger) micro-SD cardTM
●Both type A and B smartcard support
2
●I
C compatible serial interface 64-Kbit EEPROM, MEMS and I/O expander
●RS-232 communication
●IrDA transceiver
●USB-OTG full speed, USB mini-AB connector
●IEEE-802.3-2002 compliant Ethernet connector
●Two channels of CAN2.0A/B compliant connection
●Inductor motor control connector
●JTAG and trace debug support
●3.2" 240x320 TFT color LCD with touchscreen
●Joystick with 4-direction control and selector
●Reset, wake-up, tamper, and user button
●4 color LEDs
●RTC with backup battery
●MCU consumption measurement circuit
●Extension connector for daughterboard or wrapping board.
4.2 STM32 peripherals mapping
The STM3210C-EVAL demonstration board is designed around the STM32F107VC in a
100-pin TQFP package. The hardware block diagram, Figure 5, illustrates the connection
between the STM32F107VC and peripherals (LCD, EEPROM, MEMS, USART, IrDA, USBOTG, Ethernet, audio, CAN bus, smartcard, micro-SD card, and motor control) and these
features can be located on the actual demonstration board in Figure 6.
For more details of calibration parameters, refer to the STPM01 datasheet on www.st.com.
Doc ID 18209 Rev 113/58
STM3210C-EVAL demonstration boardAN3311
Figure 6.STM3210C-EVAL demonstration board layout
&1&1%1&
&1
&$1
&1
&$1
&1&1([WHQVLRQKHDGHU
8
)9&7
670
&10RWRUFRQWURO
&1
5-
FRQQHFWRU
&1
56
&1
86%0LFUR$%
FRQQHFWRU
&1
9SRZHU
&1
$XGLR MDFN
&1
0LFUR6'FDUG
&1
6PDUWFDUG
%
5HVHW
4.3 Power supply
The STM3210C-EVAL demonstration board is designed to be powered by a 5 V DC power
supply and protected by PolyZen from a wrong power plug-in event. It is possible to
configure the demonstration board to use any of the following three sources for the power
supply:
●5 V DC power adapter connected to CN18, the power jack on the board (PSU on silk
screen for power supply unit)
●5 V DC power with 500 mA limitation from CN2, the USB mini-AB connector (USB on
silkscreen)
●5 V DC power from both CN8 and CN9, the extension connector for the daughterboard
(DTB for daughterboard on silkscreen).
%:DNHXS
%7DPSHU8-R\VWLFN
&1
7U D F H
&1
-7$*
&1
&RORU/&'
8
,U'$
59
3RWHQW LR PHWH
%
8VHUNH\
U
!-V
14/58Doc ID 18209 Rev 1
AN3311STM3210C-EVAL demonstration board
The power supply is configured by setting the related jumpers JP24 and JP25, as described
in Ta bl e 2 .
Table 2.Power related jumpers
JumperDescriptionConfiguration
JP25
selects one of the three possible power supply resources.
For power supply jack (CN18) to the STM3210C-EVAL only, JP25 is set as shown:
(Default)
For power supply from the daughterboard connectors (CN8 and CN9) to the
STM3210C-EVAL only, JP25 is set as shown:
JP25
For power supply from USB (CN2) to the STM3210C-EVAL only, JP25 is set as shown:
For power supply from power supply jack (CN18) to both the STM3210CEVAL
and daughterboard connected on CN8 and CN9, JP25 is set as
shown to the right (the daughterboard must not have its own power supply
connected):
bat is connected to 3.3 V power when JP24 is set as shown: (Default)
V
JP24
Vbat is connected to battery when JP24 is set as shown:
4.4 Boot option
The STM3210C-EVAL board is able to boot from:
●Embedded user Flash
●System memory with boot loader for ISP
●Embedded SRAM for debugging.
The boot option is configured by setting switches SW1 (BOOT1) and SW2 (BOOT0). The
BOOT0 can be configured also via the RS-232 connector CN6.
Doc ID 18209 Rev 115/58
STM3210C-EVAL demonstration boardAN3311
Table 3.Boot related switches
SwitchBoot fromConfiguration
STM3210C-EVAL boots from user Flash when SW2 is set as shown on
the right. SW1 setting does not matter in this configuration. (Default)
STM3210C-EVAL boots from system memory when SW1 and SW2 are
SW1 and SW2
set as shown:
STM3210C-EVAL boots from embedded SRAM when SW1 and SW2
are set as shown:
4.5 Clock source
Two clock sources are available on the STM3210C-EVAL demonstration board for
STM32F107VC, and RTC is embedded.
●X2, 32 kHz crystal for embedded RTC
●X3, 25 MHz crystal with socket for an STM32F107VC microcontroller, it can be
removed from the socket when an internal RC clock is used.
4.6 Reset source
The reset signal of the STM3210C-EVAL board is low active and the reset sources include:
●Reset button, B1
●Debugging tools from JTAG connector CN13 and trace connector CN12
●Daughterboard from CN9
●RS-232 connector CN6 for ISP.
Table 4.Reset related jumper
JumperDescription
JP20
Enables reset of the STM32F107VC embedded JTAG TAP controller each
time a system reset occurs. JP20 connects the TRST signal from the JTAG
connection with the system reset signal RESET#.
Default setting: not fitted.
16/58Doc ID 18209 Rev 1
AN3311STM3210C-EVAL demonstration board
4.7 Joystick
The joystick is four-directional and includes a selection key.
4.8 Pushbuttons
The following pushbuttons are provided:
●Key: user pushbutton
●Tamper: user pushbutton
●Wake-up: pushbutton used to wake up the processor from low-power mode.
4.9 Storage memory
The ZigBee adapter has a 64-Kbit I2C/RF dual interface memory (M24LR64-r) on board,
and it is connected to the I
2
The I
C address of the memory can be set by using the jumpers JP1 and JP2 on the ZigBee
adapter and must be different from the one already present on the STM3210C-EVAL (with
address 0xA0).
2
C1 peripheral of the MCU.
4.10 Development and debug support
The two debug connectors available on the STM3210C-EVAL demonstration board are:
1.CN13, standard 20-pin JTAG interface connector which is compliant with the debug
tools of ARM7 and ARM9
2. CN12, SAMTEC 20-pin connector FTSH-110-01-L-DV for both SWD and trace which is
compliant with ARM CoreSight
TM
debug tools
4.11 Display and input devices
The 3.2" TFT color LCD connected to SPI3 and 4 general purpose color LED's (LED 1, 2, 3,
4) are available as display devices.
A touchscreen connected to an I/O expander (U7), a 4-direction joystick with selection key, a
general purpose button (B3), a wake-up button (B2), and a tamper detection button (B4) are
available as input devices.
Table 5.LCD module
Pin on CN14DescriptionPin connection
1CSPB2
2RS-
3WR/SCLPC10
4RD -
3.2" TFT LCD with touchscreen
CN14 (default)
Doc ID 18209 Rev 117/58
STM3210C-EVAL demonstration boardAN3311
Table 5.LCD module (continued)
3.2" TFT LCD with touchscreen
CN14 (default)
Pin on CN14DescriptionPin connection
5RESETRESET#
22BL_GNDGND
23BL_Control+5 V
24VDD3.3 V
25VCI3.3 V
26GNDGND
27GNDGND
28BL_VDD+5 V
29SDOPC11
30SDIPC12
31XLI/O Expander
32XRI/O Expander
33YDI/O Expander
34YUI/O Expander
4.12 JTAG debugging connector CN13
Figure 7.JTAG debugging connector CN13 viewed from above the PCB
Table 6.JTAG debugging connector CN13
Pin numberDescriptionPin numberDescription
13.3 V power23.3 V power
3PB44GND
5PA156GND
7PA138GND
9PA1410GND
!-V
18/58Doc ID 18209 Rev 1
AN3311STM3210C-EVAL demonstration board
Table 6.JTAG debugging connector CN13 (continued)
Pin numberDescriptionPin numberDescription
11RTCK12GND
13PB314GND
15RESET#16GND
17DBGRQ18GND
19DBGACK20GND
4.13 Daughterboard extension connector CN8 and CN9
Two 50-pin male headers, CN8 and CN9, can be used to connect a daughterboard or
standard wrapping board to the STM3210C-EVAL demonstration board. All 80 GPIOs are
available on it. The space between these two connectors and the power position, GND and
RESET pin are defined as a standard, which allows to develop common daughterboards for
several demonstration boards. The standard width between CN8 pin1 and CN9 pin1 is 2700
mills (68.58mm). This standard was implemented on the majority of demonstration boards.
Each pin on CN8 and CN9 can be used by a daughterboard after disconnecting it from the
corresponding function block on the STM3210C-EVAL demonstration board.
Table 7.Daughterboard extension connector CN8
PinDescriptionAlternate function
1GND-
3PC7MC
5PC9USB power switch On Remove R36
7PA9USB VBUS Remove R78
9PA0MC/Ethernet/WKUP
11PC14 via SB132 kHz oscillator Remove R161, close SB1
13PA12 USB_DPRemove R43 or disconnect USB cable
15PC15 via SB2 32 kHz oscillatorRemove R59, close SB2
17PC10 SPI1_CLK
19GND-
21PC12 SPI1_MOSI
23PD1 CAN1_TX
25PD3 LD3Remove R96
How to disconnect with function block on STM3210C-
EVAL board
Disconnect STM3210C-EVAL board from motor power drive
board
Keep JP14 open. Disconnect STM3210C-EVAL board from
How to disconnect with function block on STM3210C-
EVAL board
Keep JP1 open
Disconnect STM3210C-EVAL board from motor power drive
board
Disconnect STM3210C-EVAL board from motor power drive
board
Disconnect STM3210C-EVAL board from motor power drive
board
32PB2 MCRemove R168
34PB0 MCRemove R167
36PC4 PotentiometerRemove R103
38PA6 IDD_MeasurementRemove R79
40PA5 MCRemove R84
42PA3 MC/EthernetKeep JP10 open
44PA1 EthernetKeep JP3 open
46PC2 EthernetRemove RS1
48PC0 MC/smartcardRemove R165
50GND
22/58Doc ID 18209 Rev 1
AN3311STM3210C-EVAL demonstration board
4.14 TFT LCD connector CN14
One 34-pin male header CN14 is available on the board to connect LCD module board
MB785.
4.15 Power connector CN18
The STM3210C-EVAL demonstration board can be powered from a DC 5 V power supply
via the external power supply jack (CN18) shown in Figure 8. The central pin of CN18 must
be positive.
Figure 8.Power supply connector CN18 viewed from the front
'&9
*1'
For more information on STM3210C-EVAL, please refer to the UM0600 user manual.
!-V
Doc ID 18209 Rev 123/58
Demonstration firmware system setupAN3311
5 Demonstration firmware system setup
5.1 Hardware requirements
a) ZigBee adapter board
b) ZigBee module SPZB260-PRO
c) VDC/2A isolated power supply is recommended
d) One JTAG programmer/debugger dongle (J-Link from SEGGER or IAR Systems™
is recommended). It is unnecessary if no modifications to the firmware code have
been performed.
5.2 STM3210C-EVAL demonstration board setup
Set up the STM3210C-EVAL board as follows:
●Close jumper JP19
●Keep JP15 open
●Remove R79, R84, and R169.
5.3 STM3210C-EVAL and ZigBee adapter with M24LR62-r
memory
Table 9.ZigBee adapter pin description
STM32 pin no. Pin name
-VDD3.3 VCN8 - Pin 48VCC_3V3
-VSSGNDCN9 - Pin 50GND
29PA4SPI1_NSSCN9 - Pin 41ZIG_SS
30PA5SPI1_CLKCN9 - Pin 40ZIG_SCLK
31PA6SPI1_MISOCN9 - Pin 38ZIG_MISO
32PA7SPI1_MOSICN9 - Pin 37ZIG_MOSI
92PB6CAN2_TX/I2C1_SCKCN8 - Pin 36I2C1_SCK
93PB7I2C1_SDACN8 - Pin 37I2C1_SDA
2PE3Trace_D0CN8 - Pin 42ZIG_HOST_INT
3PE4Trace_D1CN8 - Pin 43
4PE5Trace_D2CN8 - Pin 44ZIG_WAKE
5PE6Trace_D3CN8 - Pin 47ZIG_RSTB
STM3210C-EVAL I/O
assignment
Extension connector pin
no.
ZigBee adapter I/O
assignment
VCC-GPIO (for M24LR64-
r)
24/58Doc ID 18209 Rev 1
AN3311Demonstration firmware system setup
5.4 How to navigate the demo menu
Four basic elements constitute the hardware of the system user interface: a 320 x 240 TFT
LCD display, a resistive touchscreen, a 5-way (left, right, up, down, selection) micro-joystick
and a pushbutton “Key”.
The joystick is primarily used for navigating between the various menu screens, within a
screen and between screen items. In addition, the joystick allows the selection and editing of
item values.
Doc ID 18209 Rev 125/58
In-home display firmwareAN3311
p
{
ZigB
k
R
u
r
{
t
{
{
t
d
e
{
6 In-home display firmware
6.1 Firmware architecture
Figure 9.In-home display firmware architecture
InHome Display Firmware Architecture
on
F
r
e
e
T
O
S
licati
Ap
t
i-Inp
Mul
SmartPlug Coordinator
Layer
y
Multi-Input GUI Layer
Libra
GUI
LCD HAL
ee Stac
SPI
ZigBee Adapter and RF
Antenna for I2C Dual
Interface Memory
SPI
ware
nden
Har
Dep
This section describes the firmware implementation. The tasks/functions are described in
the following format:
Table 10.Function description format
Function name The name of the function
Function prototype Prototype declaration of the function
Behavior description Brief explanation of how the function is executed
Input parameter {x} Description of the input parameters
Output parameter {x} Description of the output parameters
Return value Value returned by the function
Required preconditions Requirements before calling the function
Called functions Other library functions called
LCD Libraries
STM32F10xx Libraries
I2C
AM08462v1
26/58Doc ID 18209 Rev 1
AN3311In-home display firmware
6.2 main.c
6.2.1 vSmartPlugSamplingTask
Ta bl e 1 1 describes the vSmartPlugSamplingTask task:
Table 11.vSmartPlugSamplingTask task
Function name vSmartPlugSamplingTask
Function prototype void vSmartPlugSamplingTask(void *pvParameters)
Behavior description Read and sample the plug consumption values
The application simulates the behavior of the system in a 24 hour period considering an
hour as equal to 20 seconds. After 24 hours (simulated), it resets the array values, so the
GraphCharts and the histograms show a maximum value set to zero.
6.2.2 vGraphicLibraryTask
Ta bl e 1 2 describes the vGraphicLibraryTask task:
Table 12.vGraphicLibraryTask task
Function name vGraphicLibraryTask
Function prototype void vGraphicLibraryTask(void *pvParameters)
Behavior description
Input parameter {x} None
Output parameter {x} None
Check if an input device has been stimulated (touchscreen or
joystick/button)
Return value None
Required preconditions None
Called functions No API/HAL layer functions;
This function checks if an input device has been stimulated (touchscreen or joystick/button)
and calls the graphic library relative function according to the object pressed.
/* Infinite main loop ------------------------------------------------------*/
while (1)
{
ProcessTouchScreenData();
/*Time out calculate for power saving mode*/
TimeOutCalculate();
#ifdef USE_STM3210C_EVAL
if (restart_calibration==1)
{
TS_Calibration();
restart_calibration = 0;
MENU_DeInit();
}
Behavior description Initialize the hardware peripheral of the STM3210C-EVAL board
Input parameter {x} None
Output parameter {x} None
Return value None
Required preconditions None
Called functions No API/HAL layer functions;
This function is intended to initialize the hardware peripheral of the STM3210C-EVAL board
and the graphic library hardware parameters.
Regarding the file menu.c, it just uses the API function of the graphic library and some
others of the “ZigBee stack for smartplug”, for more information please refer to the AN3128,
rev. 2, application note.
30/58Doc ID 18209 Rev 1
AN3311Getting started with the system
7 Getting started with the system
7.1 Configure IAR tool for building, debugging, and
programming the application
Together with the firmware library package, an example application is delivered in order to
provide the final user with a real example of “In-home display” application usage.
The delivered example application has been written and developed using IAR EWARM 5.40
IDE and can be built for both STM32F10xxx medium-density and high-density
microcontroller families.
The workspace is created using the IAR embedded Workbench 5.40 IDE, using the ARM
based 32-bit STM32F10xx firmware library (ver. 3.1.2) CMSIS compliant, and in C
language.
The tree structure of the project is organized separating and grouping the source files with
the header files, both for the project files and the library files, as shown in Figure 10.
Figure 10. Application project files
®
-
In order to load the project, click on File\Open\Workspace and in the window that appears
select, in \project folder\EWARM, the file “Project.eww”.
Doc ID 18209 Rev 131/58
Getting started with the systemAN3311
Figure 11. IAR embedded workbench main window
On the main node, where the program name located in the files window is shown, right click
the mouse button and select options. In the window which appears, select the debugger
item in the category list box, and select the proper debugging tool in the driver list box, then
press the Ok button. In the proposed example the J-Link dongle is used (Figure 12).
Press the Make icon or click on Project\Rebuild All. No error or warning should appear once
compiling has completed. Connect the J-Link tool to the USB port of the PC, and connect
the flat cable with the programming adapter. Plug the adapter into the dongle connector.
Press the debug icon, CTRL+D or click project\debug. The debugger starts to download the
firmware to the dongle through the J-Link debugger\programmer. Press the Go button, F5 or
click debug\go in order to execute the firmware in debug mode. To run the dongle in
standalone mode, press the stop debugging icon, CTRL+SHIFT+D or click debug\stop
debugging. Then remove the J-link adapter from the dongle and reset the board by
unplugging and plugging the power cable back in.
Figure 12. IAR embedded workbench debugger options
32/58Doc ID 18209 Rev 1
AN3311Getting started with the system
In order to use the In-home display application project, it is necessary to:
●Include all the firmware delivered in the In-home display package containing the
FreeRTOS core files. See Figure 10
●Create the desired menu application functions in the file menu.c
●Put inside “picture.c” the HEX dump of the pictures to be used with the application GUI
●Implement a main function as described in the following section.
7.2 Example application - main.c
An example of a main application is given below. The main function contains an example of
the In-home display application initialization/configuration and implements the classic
operations:
/* The time between cycles of the 'check' functionality (defined within the tick
hook. */
#define mainCHECK_DELAY ( ( portTickType ) 5000 / portTICK_RATE_MS )
/* The period of the system clock in nano seconds. This is used to calculate the
jitter time in nano seconds. */
#define mainNS_PER_CLOCK ((unsigned portLONG)((1.0 /
(double)configCPU_CLOCK_HZ)*1000000000.0))
/* Configure the hardware for the demo. */
static void prvSetupHardware( void );
/* Configure the board, LCD, Joystick, Button, GPIO and other peripherals as required
by the demo. */
static void vBoardInit( void );
/* Check Touchscreen, Joystick, Button in polling mode as required by the demo. */
static void vGraphicLibraryTask(void *pvParameters);
/* Check the SmartPlug Energy data as required by the demo. */
static void vSmartPlugSamplingTask( void *pvParameters);
Doc ID 18209 Rev 135/58
Getting started with the systemAN3311
/*
* Configures the high frequency timers - those used to measure the timing
* jitter while the real time kernel is executing.
*/
extern void vSetupHighFrequencyTimer( void );
/* Will only get here if there was insufficient memory to create the idle task. The
idle task is created within vTaskStartScheduler(). */
for( ;; );
}
The initialization process is charged with preparing the basic mechanism of the system:
●Hardware peripheral configuration and initialization
●ZigBee stack initialization
●FreeRTOS task creation
●Starting system.
36/58Doc ID 18209 Rev 1
AN3311Getting started with the system
The clock distribution and the interrupt settings are two components that are strongly
dependent on the target project. An example of clock rate may be 72 MHz as the maximum
speed of the current STM32 microcontroller. It can be decreased to reduce the power
consumption. The clock rate assumptions are:
●System HCLK - 72 MHz
●Low speed peripheral PCLK1 - 72 MHz
●High speed peripheral PCLK2 - 36 MHz
●Analog to digital converter ADCCLK - 36 MHz
The interrupt setting situation is very similar to clock distribution. The library functions
involved with interrupt managing do not take the priorities into account; they only perform
very necessary and absolutely common settings to make them serviceable.
Doc ID 18209 Rev 137/58
In-home display GUI applicationAN3311
8 In-home display GUI application
If the ZigBee dongle is not connected or the resistors R79, R84, and R169 have not been
removed from the STM3210C-EVAL, the following screen is shown:
Figure 13. ZigBee dongle connection problem
After a board reset, if the firmware is correctly loaded into the Flash memory and the board
power is correctly supplied, the main screen is displayed as shown in Figure 14.
Figure 14. Main menu
38/58Doc ID 18209 Rev 1
AN3311In-home display GUI application
If Search Plugs is selected, the coordinator scans for smartplug devices for a certain length
of time and the display shows the following screens in loop:
Figure 15. Searching plugs
After that, if some plugs are connected, it adds them to the smartplug list and then shows
the home screen.
Doc ID 18209 Rev 139/58
In-home display GUI applicationAN3311
If you click on Management two situations are possible:
●If no plug is connected to the smartplug coordinator, the following screen is shown:
Figure 16. No plug detected
●Once more plugs are detected, the following screen is shown:
Figure 17. Plugs detected
There are three main buttons: identify, modify, and control. They allow to manage the
smartplug device.
The Identify button is useful to activate the LED flashing on the relative plug, so this way the
user can easily identify which plug they are going to manage through the GUI.
If Modify is clicked, the user can change the label of the selected plug, through the screen
shown inFigure 18, choosing the new label from a list contained in a combobox.
40/58Doc ID 18209 Rev 1
AN3311In-home display GUI application
Figure 18. Label changing
The user should scroll the list of the labels and click on the Apply button in order to save the
information and set the label also in the plug device via ZigBee protocol.
When Control is clicked, it is possible to switch ON/OFF the smartplug, in case of relay type,
or regulate the output power, in case of TRIAC type. The following screens show both
possibilities:
Figure 19. TRIAC smartplug management
Doc ID 18209 Rev 141/58
In-home display GUI applicationAN3311
Figure 20. Relay smartplug management
In the home screen, by clicking on Statistics, it is possible to see the electrical consumption
of the single smartplug device or the total consumption related to all plugs connected to the
smartplug coordinator. The following screen is shown:
Figure 21. Smartplug statistics
42/58Doc ID 18209 Rev 1
AN3311In-home display GUI application
When Energy is clicked, the following screen, representing the energy consumption of the
selected smartplug device, is shown:
Figure 22. Energy consumption
When Global Energy is clicked, the following screen, representing the energy consumption
of the whole smartplug network, is shown:
Figure 23. Global energy consumption
Doc ID 18209 Rev 143/58
In-home display GUI applicationAN3311
When Power is clicked, the following screen, representing the power consumption of the
selected smartplug device, is shown:
Figure 24. Power consumption
When Global Power is clicked, the following screen, representing the power consumption of
the whole smartplug network, is shown:
Figure 25. Global power consumption
When the Refresh button is clicked, it is possible to make a refresh of the graph chart in
relation to the sampled points of the power consumption.
When the Home button is clicked, it returns to the home screen.
44/58Doc ID 18209 Rev 1
AN3311Schematics
9 Schematics
9.1 Smartplug board schematics and layout
Figure 26. ZigBee and dual interface EEPROM adapter schematic for STM3210C-EVAL
48R ev
o
meR -
)
KL
C_
1IPS(
5AP
PA6 (SPI1_MISO) - Remove R79
GND
ZIG_MISO
ZIG_SCLK
CN9
CN9
181920
10
8
14
56
12
34
9
7
111213
17
1516
2122
36
3334
35
3738
ZIG_MOSI
394041424344
9
6
SS_
1R
e
G
IZSS_GIZ
vo
meR - )IS
46
4950
45
4748
Header 25x2 (Female-Bottom)
Header 25x2 (Female-Bottom)
26
2324
2728
2930
3132
25
VCC_3V3
VCC_3V3
R3
4k7R34k7
2
Jumper
Jumper
1
R2
U1
3
GND
4k7R24k7
1
Jumper
Jumper
E1
VCC-GPIO
8
VCC
E01AC0
E0
JP2
JP2
3
JP1
JP1
2
I2C1_SDA
I2C1_SCK
5
7
6
E1
SCL
SDA
M24LR64U1M24LR64
VSS
AC1
3
2
4
GND
L1
4.7uHL14.7uH
SMD 7.8mm diameter, 5.3mm height
101112
CN8
CN8
12
34
56
78
9
1314
O
M_1I
P
S( 7AP
PA4 (SPI1_NSS) - Keep JP15 open
ZIG_SCLK
ZIG_MOSI
ZIG_MISO
VCC_3V3
VCC_3V3
VCC_3V3
1516
1718
1920
2122
23242526272829303132
MOSI
VBRDVBRD
1
23456
J2
J2
1
J4
J4
2
HOST_INT
ZIG_HOST_INT
R1
I2C1_SCK
36
3334
35
MISO
SCLK
nSSEL
345
WAKE
RSTB
GND
ZIG_WAKE
ZIG_RSTB
4k7R14k7
PE3
42
3940
3738
41
I2C1_SDA
GND
6
GNDVCC-GPIO
VCC_3V3
3V3
PE5
444546
43
4748
PE4
PE6
ZigBee - CONN1
ZigBee - CONN1
ZigBee - CONN2
ZigBee - CONN2
4950
ZIGBEE/SPZB260-PRO
Header 25x2 (Female-Bottom)
Header 25x2 (Female-Bottom)
Prior to using this adapter, remove the required
resistance from the STM3210C-Eval Board
AM08515v1
Doc ID 18209 Rev 145/58
SchematicsAN3311
9.2 ZigBee/RF adapter for smartplug and dual interface memory
Figure 27. ZigBee and dual interface EEPROM adapter layout for STM3210C-EVAL
9.11 LCD 3.2" module with SPI and 16-bit interface 1
Figure 36. LCD 3.2" module with SPI and 16-bit interface 1
CN1
CS
1
RS
2
WR
3
RD
4
#RESET
5
BLGND
SDO
SDI
22
23
24
25
26
27
28
29
30
3.2LCD_connector
BL_Control
VDD
BLVDD
LCD board connector to mother board
CS
RS
WR/SCL
RD
RESET
BL_GND
BL_Control
VDD
VCI
GND
GND
BL_VDD
SDO
SDI
BLVDD
BLGND
BL_Control
BLVDD
PD1
PD2
PD3
PD4
PD5
PD6
PD7
PD8
PD10
PD11
PD12
PD13
PD14
PD15
PD16
PD17
C2
2.2uF
PD1
6
PD2
7
PD3
8
PD4
9
PD5
10
PD6
11
PD7
12
PD8
13
PD10
14
PD11
15
PD12
16
PD13
17
PD14
18
PD15
19
PD16
20
PD17
21
31
XL
XL
32
XR
XR
33
YD
YD
YU
34
YU
The 34-pin connector to mother board for both
serial and 16- bit interface. Compatible with
MB694 with touch screen signals added on
pin 31-34.
4.7uH(1A)
R8
R5
0
do not t
L1
BLGND
U1
8
1
7
9
STLD40DPMR
Z1
STPS1L40M
SW
Vi
EN
GND3FB
PGND
Soldered for i80-system 16-bit interface
R1
10K
VDD
R2
PD16
PD14
PD12
PD10
PD8
PD6
PD4
PD2
PD9
PD0
RS
RD
PD17
PD15
PD13
PD11
PD7
PD5
PD3
PD1
4K7
R3
4K7
R4
0
RP1
10K
RP2
10K
RP3
10K
RP4
10K
RP5
10K
SDO
SDI
Soldered for Serial interface only
CN2
36
VSYNC
HSYNC
DotClk
Enable
CS
WR
RD
RS
SDO
SDI
#RESET
VDD
A
C1
4.7uF/50V
6
Vo
NC
Rset
BLGND
5
4
2
R7
R6
10
100K
BLGND
K
VSYNC
37
HSYNC
38
DOTCLK
39
ENABLE
11
NC
31
CS
34
WR/SCL
35
RD
33
RS
10
SDO
12
SDI
32
RESET
40
VCC
41
VCC
44
LED_A
43
LED_K
6
VSS
42
VSS
45
VSS
1
VSS
FF0245SS1
AM-240320D4TOQW-T00H(R)
RP6
HSYNC
Enable
VSYNC
DotClk
10K
IM0/ID
8
IM1
9
IM3
7
YU
5
YU
YD
XR
XL
D0
D1
D2
D3
D4
D5
D6
D7
D8
D9
D10
D11
D12
D13
D14
D15
D16
D17
VDD
YD
4
XR
3
XL
2
PD0
30
PD1
29
PD2
28
PD3
27
PD4
26
PD5
25
PD6
24
PD7
23
PD8
22
PD9
21
PD10
20
PD11
19
PD12
18
PD13
17
PD14
16
PD15
15
PD16
14
PD17
13
C3
1uF/50V
AM08509v1
Doc ID 18209 Rev 155/58
ReferencesAN3311
10 References
1.AN3128 application note
2. RM0008 reference manual
3. STM32F10xFWLib 3.2.1 help file
4. STM811 datasheet
5. TN0074 technical note
6. UM0608 user manual
7. STEVAL-IHP001V3 schematics diagram
8. AN2993 application note
9. M24LR64-r datasheet
10. AN2972 application note.
56/58Doc ID 18209 Rev 1
AN3311Revision history
11 Revision history
Table 16.Document revision history
DateRevisionChanges
14-Dec-20101Initial release.
Doc ID 18209 Rev 157/58
AN3311
Please Read Carefully:
Information in this document is provided solely in connection with ST products. STMicroelectronics NV and its subsidiaries (“ST”) reserve the
right to make changes, corrections, modifications or improvements, to this document, and the products and services described herein at any
time, without notice.
All ST products are sold pursuant to ST’s terms and conditions of sale.
Purchasers are solely responsible for the choice, selection and use of the ST products and services described herein, and ST assumes no
liability whatsoever relating to the choice, selection or use of the ST products and services described herein.
No license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted under this document. If any part of this
document refers to any third party products or services it shall not be deemed a license grant by ST for the use of such third party products
or services, or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoever of such
third party products or services or any intellectual property contained therein.
UNLESS OTHERWISE SET FORTH IN ST’S TERMS AND CONDITIONS OF SALE ST DISCLAIMS ANY EXPRESS OR IMPLIED
WARRANTY WITH RESPECT TO THE USE AND/OR SALE OF ST PRODUCTS INCLUDING WITHOUT LIMITATION IMPLIED
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE (AND THEIR EQUIVALENTS UNDER THE LAWS
OF ANY JURISDICTION), OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT.
UNLESS EXPRESSLY APPROVED IN WRITING BY AN AUTHORIZED ST REPRESENTATIVE, ST PRODUCTS ARE NOT
RECOMMENDED, AUTHORIZED OR WARRANTED FOR USE IN MILITARY, AIR CRAFT, SPACE, LIFE SAVING, OR LIFE SUSTAINING
APPLICATIONS, NOR IN PRODUCTS OR SYSTEMS WHERE FAILURE OR MALFUNCTION MAY RESULT IN PERSONAL INJURY,
DEATH, OR SEVERE PROPERTY OR ENVIRONMENTAL DAMAGE. ST PRODUCTS WHICH ARE NOT SPECIFIED AS "AUTOMOTIVE
GRADE" MAY ONLY BE USED IN AUTOMOTIVE APPLICATIONS AT USER’S OWN RISK.
Resale of ST products with provisions different from the statements and/or technical features set forth in this document shall immediately void
any warranty granted by ST for the ST product or service described herein and shall not create or extend in any manner whatsoever, any
liability of ST.
ST and the ST logo are trademarks or registered trademarks of ST in various countries.
Information in this document supersedes and replaces all information previously supplied.
The ST logo is a registered trademark of STMicroelectronics. All other names are the property of their respective owners.