81
October 2012 Doc ID 022809 Rev 2 1/81 AN4049 Application note In-Home Display with HTTP gateway Introduction In this period of energy optimization and metering, there is an ever increasing demand for the possibility to perform in-house monitoring and management of energy use. For this reason, STMicroelectronics offers a system which allows the monitoring and management of home energy consumption. This system, “In-Home Display gateway”, is made up of three main components: The STM322xG-EVAL demonstration board connected to an Ethernet network The STEVAL-IDZ001V1 adapter board connected on top of the STM322xG-EVAL board Remote web server. Through this infrastructure, the system has the ability to publish the home automation device (i.e. smartplugs) energy data to a remote web server. The user can consult the energy consumption data on the web server from wherever they are, and at home, they can manage the entire system directly through an LCD touch panel. This application note describes a smartplugW network system managed through the STM322xG-EVAL board. The firmware and board allow the possibility to manage a ZigBee ® network system, collecting ZigBee device information, and managing it through the LCD, touchscreen, pushbutton and joystick, and publishing the collected data to a HTTP server over the Internet by means of an Ethernet interface. Section 1 describes the document and library rules. Section 2 highlights the features of the ZigBee smartplug and explains its hardware interface with the microcontroller (STM32). Section 3 describes briefly the “Multi-Input Embedded GUI Library”. Section 4 describes the relevant blocks of the STM322xG-EVAL demonstration board. Section 5 shows the demonstration firmware/board system setup. Section 6 describes how the “In-Home Display” firmware is structured, its architecture and its exported APIs in detail. Section 7 explains how to get started with the system, how to configure and use the IAR workspace, and it contains an example application source code. Section 8 illustrates how the “In-Home Display” GUI application works. Section 10 illustrates the hardware schematics. www.st.com

In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

Embed Size (px)

Citation preview

Page 1: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

October 2012 Doc ID 022809 Rev 2 1/81

AN4049Application note

In-Home Display with HTTP gateway

IntroductionIn this period of energy optimization and metering, there is an ever increasing demand for the possibility to perform in-house monitoring and management of energy use.

For this reason, STMicroelectronics offers a system which allows the monitoring and management of home energy consumption.

This system, “In-Home Display gateway”, is made up of three main components:

■ The STM322xG-EVAL demonstration board connected to an Ethernet network

■ The STEVAL-IDZ001V1 adapter board connected on top of the STM322xG-EVAL board

■ Remote web server.

Through this infrastructure, the system has the ability to publish the home automation device (i.e. smartplugs) energy data to a remote web server. The user can consult the energy consumption data on the web server from wherever they are, and at home, they can manage the entire system directly through an LCD touch panel.

This application note describes a smartplugW network system managed through the STM322xG-EVAL board.

The firmware and board allow the possibility to manage a ZigBee® network system, collecting ZigBee device information, and managing it through the LCD, touchscreen, pushbutton and joystick, and publishing the collected data to a HTTP server over the Internet by means of an Ethernet interface.

■ Section 1 describes the document and library rules.

■ Section 2 highlights the features of the ZigBee smartplug and explains its hardware interface with the microcontroller (STM32).

■ Section 3 describes briefly the “Multi-Input Embedded GUI Library”.

■ Section 4 describes the relevant blocks of the STM322xG-EVAL demonstration board.

■ Section 5 shows the demonstration firmware/board system setup.

■ Section 6 describes how the “In-Home Display” firmware is structured, its architecture and its exported APIs in detail.

■ Section 7 explains how to get started with the system, how to configure and use the IAR workspace, and it contains an example application source code.

■ Section 8 illustrates how the “In-Home Display” GUI application works.

■ Section 10 illustrates the hardware schematics.

www.st.com

Page 2: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

Contents AN4049

2/81 Doc ID 022809 Rev 2

Contents

1 Document and library rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

1.1 Acronyms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

2 System description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

3 ZigBee smartplug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

3.1 Smartplug description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

3.2 ZigBee module SPZB32W1x2.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

4 Multi-Input Embedded GUI Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

4.1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

5 STM3220G-EVAL demonstration board . . . . . . . . . . . . . . . . . . . . . . . . . 11

5.1 Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

5.2 Hardware layout and configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

5.3 Power supply . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

5.4 Boot option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

5.5 Clock source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

5.6 Reset source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

5.7 EEPROM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

5.8 Ethernet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

5.9 SRAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

5.10 Development and debug support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

5.11 Display and input devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

5.12 Daughterboard extension connector CN1, 2, 3 and CN4 . . . . . . . . . . . . . 22

5.13 Ethernet RJ45 connector CN7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

5.14 JTAG debugging connector CN14 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

5.15 Power connector CN18 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

5.16 TFT LCD connector CN19 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

6 In-Home Display with HTTP gateway firmware . . . . . . . . . . . . . . . . . . . 31

6.1 Firmware structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

6.2 main.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

Page 3: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049 Contents

Doc ID 022809 Rev 2 3/81

6.2.1 demo_initTask . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

6.3 web_client.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

6.3.1 Web_Get_Task . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

6.4 tasks_misc.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

6.4.1 GraphicLibTask . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

6.4.2 ZigNetMgmtTask . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

6.4.3 CalendarTask . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

6.4.4 SPSamplingTask . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

6.4.5 ToggleLed Task . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

7 Getting started with the system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

7.1 Hardware requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

7.2 STM322xG-EVAL demonstration board setup . . . . . . . . . . . . . . . . . . . . . 47

7.3 STM322xG-EVAL and ZigBee adapter pins mapping . . . . . . . . . . . . . . . 47

7.4 Program/update dual interface EEPROM with network parameters . . . . 48

7.5 Configure IAR tool for building, debugging, and programming application 49

7.6 Example application - main.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51

8 In-Home Display with HTTP gateway GUI application . . . . . . . . . . . . . 56

8.1 Application user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56

9 Web server hosting energy consumption data . . . . . . . . . . . . . . . . . . 65

9.1 Features overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65

9.2 Accessing the website . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65

9.3 Browsing reporting data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66

10 Schematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68

11 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79

12 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80

Page 4: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

List of tables AN4049

4/81 Doc ID 022809 Rev 2

List of tables

Table 1. List of acronyms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6Table 2. Power related jumpers and solder bridges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16Table 3. Boot related switch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17Table 4. EEPROM related jumper and solder bridge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18Table 5. Ethernet related jumpers and solder bridges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18Table 6. SRAM related jumpers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19Table 7. LCD modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21Table 8. Daughterboard extension connector CN1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22Table 9. Daughterboard extension connector CN2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24Table 10. Daughterboard extension connector CN3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25Table 11. Daughterboard extension connector CN4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27Table 12. Ethernet connector pinout. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29Table 13. JTAG debugging connector CN14 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29Table 14. Function description format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32Table 15. demo_initTask task. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33Table 16. Web_Get_Task task . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35Table 17. GraphicLibTask task . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37Table 18. ZigNetMgmtTask task. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38Table 19. CalendarTask task . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39Table 20. SPsamplingTask task . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42Table 21. ToggleLed Task . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45Table 22. ZigBee adapter pinout description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47Table 23. Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80

Page 5: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049 List of figures

Doc ID 022809 Rev 2 5/81

List of figures

Figure 1. STM322xG-EVAL board and a smartplug node block diagram . . . . . . . . . . . . . . . . . . . . . . 7Figure 2. Block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8Figure 3. STM3220G-EVAL board. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11Figure 4. STM3220G-EVAL board hardware block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13Figure 5. STM3220G-EVAL demonstration board layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14Figure 6. ZigBee adapter layout description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15Figure 7. Ethernet RJ45 connector CN7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28Figure 8. JTAG debugging connector CN14 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29Figure 9. Power supply connector CN18 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30Figure 10. Firmware architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31Figure 11. System architecture and hardware block interaction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32Figure 12. M24LRxx application software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49Figure 13. Application project files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50Figure 14. IAR embedded workbench main window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50Figure 15. IAR embedded workbench debugger options. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51Figure 16. Home screen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56Figure 17. Home screen after ZigBee network initialization done . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56Figure 18. No plug detected. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57Figure 19. Setup ZigBee network . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57Figure 20. Setting ZigBee network up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58Figure 21. Reinitializing ZigBee network . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58Figure 22. Plug detected . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59Figure 23. Label changing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59Figure 24. Smartplug management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60Figure 25. Identify . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60Figure 26. Smartplug statistics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61Figure 27. Energy consumption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61Figure 28. Global energy consumption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62Figure 29. Power consumption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62Figure 30. Global power consumption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63Figure 31. Demo scenario . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63Figure 32. Set timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64Figure 33. Activate timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64Figure 34. Login page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65Figure 35. Device selection page. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66Figure 36. Energy data table page. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66Figure 37. Export data page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67Figure 38. Plotting data page. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67Figure 39. ZigBee and dual Interface EEPROM adapter for STM322xG-EVAL . . . . . . . . . . . . . . . . . 68Figure 40. STM3220-21-45-46G-EVAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69Figure 41. STM3220-21-45-46G-EVAL_MCU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70Figure 42. STM3220-21-45-46G-EVAL_Ethernet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71Figure 43. STM3220-21-45-46G-EVAL_LCD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72Figure 44. LCD module with both SPI and 16-bit interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73Figure 45. STM3220-21-45-46G-EVAL I/O peripherals. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74Figure 46. STM3220-21-45-46G-EVAL I/O_Expander . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75Figure 47. STM3220-21-45-46G-EVAL JTAG and trace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76Figure 48. STM3220-21-45-46G-EVAL_Power . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77Figure 49. STM3220-21-45-46G-EVAL_Extension connector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78

Page 6: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

Document and library rules AN4049

6/81 Doc ID 022809 Rev 2

1 Document and library rules

This document uses the conventions described in the sections below.

1.1 AcronymsTable 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

SPI Serial to parallel interface

UART Universal asynchronous receiver-transmitter

HTTP HyperText transfer protocol

Page 7: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049 System description

Doc ID 022809 Rev 2 7/81

2 System description

The network configuration parameters (IP address, subnet mask, and default gateway) of the board as well as the IP address of the web server are stored in the dual interface EEPROM “M24LR64r” onboard, accessible from both the STM32W108CB and the STM32F2x7x via the I2C interface and remotely by means of an RF reader. Therefore, it is possible to read and update parameters from inside (I²C) and outside (RF) the application. In this way, an operator can easily change the network configuration of the board without any programming skills, and using just an RF reader.

In order to use the STM322xG-EVAL board to interface with the ZigBee coordinator, a specific adapter has been developed. The ZigBee coordinator is connected to the demonstration board through the adapter that allows the UART communication. The two peers use a serial protocol to exchange data and commands.

The STM32W108CB is used as a co-processor of the STM32F2x7x, so the STM32F2x7x runs the application while the STM32W108CB runs the ZigBee stack and protocol. The two microcontrollers communicate by means of a UART interface.

An embedded graphical user interface (GUI) based on the “Multi-Input Embedded GUI Library 2.1" described in the document AN3128, and working on an LCD TFT 320 x 240 display and 5-position joystick, allows the user to interact with the smartplugW system made up of one coordinator and two smartplugs connected.

In Figure 1 it is possible to take a quick look of the STM322xG-EVAL board and a smartplug node block diagram.

Figure 1. STM322xG-EVAL board and a smartplug node block diagram

Page 8: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

ZigBee smartplug AN4049

8/81 Doc ID 022809 Rev 2

3 ZigBee smartplug

3.1 Smartplug descriptionThe smartplug coordinator is connected via UART to the STM322xG-EVAL through an “ad-hoc” adapter. The adapter is connected to the extended connectors CN2, CN3 and CN4 on the STM322xG-EVAL (for more detailed information, please refer to the UM1065 user manual); it allows the connection of a ZigBee coordinator and the I2C/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.

Figure 2. Block diagram

The STEVAL-IHP004V1 is a smartplug board based on an STM32W108CB microcontroller, a SPZB32W1x2.1 module, and an STPM10 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 to provide 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.

Page 9: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049 ZigBee smartplug

Doc ID 022809 Rev 2 9/81

3.2 ZigBee module SPZB32W1x2.1ZigBee communication is based on the SPZB32W module. The SPZB32W is a low power consumption ZigBee module optimized for embedded applications. It enables OEMs to easily add wireless capability to electronic devices.

The module is FCC compliant (FCC ID: S9NZB32C2) and it is based on the STM32W108CB MCU which integrates a 2.4 GHz IEEE 802.15.4-compliant SMD module based on the ST single-chip STM32W108CB featuring:

● Integrated 2.4 GHz transceiver

● PHY and MAC IEEE 802.15.4 features

● Integrated ARM® Cortex-M3 core

● Integrated 128 kB embedded Flash and 8 kB embedded RAM

● Integrated encryption (AES-128) accelerator

● +3 dBm output power (+8 dBm in Boost mode)

● -99 dBm receiver sensitivity.

The module is controlled by means of a standard serial interface (SPI) allowing connection to a variety of host microcontrollers.

For further details, please refer to the SPZB32W module and the STM32W108CB datasheet.

For more information, see the user manual, the STEVAL-IHP004V1 schematics diagram, and the ZigBee smartplug firmware user manual.

Page 10: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

Multi-Input Embedded GUI Library AN4049

10/81 Doc ID 022809 Rev 2

4 Multi-Input Embedded GUI Library

4.1 DescriptionThis 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.

The user can combine touch-sensing functions using multiple configurations (touchscreen, joystick, and keys) with traditional MCU features (communication, LED control, 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 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 STMicroelectronics demonstration boards.

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 if they want to change the HAL functions in order to port the library on a different LCD (in model and resolution) from the one attached to the ST demonstration board.

For more information on the graphic library, see the AN3128 rev.4 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.

Page 11: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049 STM3220G-EVAL demonstration board

Doc ID 022809 Rev 2 11/81

5 STM3220G-EVAL demonstration board

Figure 3. STM3220G-EVAL board

The STM3220G-EVAL demonstration board is a complete evaluation and development platform for the STM32 F-2 series and includes an embedded in STM32F207IGH6 high-performance ARM® Cortex™-M3 32-bit microcontroller.

The full range of hardware features on the board is provided to help the user evaluate all peripherals (USB OTG HS, USB OTG FS, Ethernet, motor control, CAN, MicroSD card, smartcard, USART, audio DAC, RS-232, IrDA, SRAM, MEMS, EEPROM… etc.) and develop their own applications. Extension headers make it possible to easily connect a daughterboard or wrapping board for specific applications.

The in-circuit ST-LINK tool can be easily used for JTAG and SWD interface debugging and programming.

Page 12: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

STM3220G-EVAL demonstration board AN4049

12/81 Doc ID 022809 Rev 2

5.1 Features● STM32F207IGH6 microcontroller

● 16 Mbit SRAM

● 1 GByte or more MicroSD card

● Boot from user Flash, system memory or SRAM

● Both ISO/IEC 14443 type A and B smartcards support

● I2C compatible serial interface 8 Kbytes EEPROM, MEMS and I/O expander

● IEEE 802.3-2002 compliant Ethernet connector

● Two CAN 2.0 A/B channels on the same DB connector

● RS-232 communication

● IrDA transceiver

● USB OTG (HS and FS) with Micro-AB connector

● Inductor motor control connector

● I2S audio DAC, stereo audio jack for headset

● 3.2" 240x320 TFT color LCD with touchscreen

● 4 color LEDs

● Camera module and extension connector for ST camera plug-in

● Joystick with 4-direction control and selector

● Reset, wakeup, tamper and user button

● RTC with backup battery

● Extension connector for daughterboard or wrapping board

● JTAG, SW and trace debug support

● Embedded ST-LINK/V2

● Five 5 V power supply options: Power jack, USB FS connector, USB HS connector, ST-LINK/V2 or daughterboard

● MCU consumption measurement circuit.

5.2 Hardware layout and configurationThe STM3220G-EVAL demonstration board is designed around the in STM32F207IGH6 microcontroller in the UFBGA176 package. The hardware block diagram, Figure 2, illustrates the connection between the in STM32F207IGH6 and peripherals (camera module, LCD, SRAM, EEPROM, MEMS, USART, IrDA, USB OTG HS, USB OTG FS, Ethernet, audio, CAN bus, smartcard, MicroSD card and motor control) and Figure 3 helps to locate these features on the actual demonstration board.

Page 13: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049 STM3220G-EVAL demonstration board

Doc ID 022809 Rev 2 13/81

Figure 4. STM3220G-EVAL board hardware block diagram

Page 14: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

STM3220G-EVAL demonstration board AN4049

14/81 Doc ID 022809 Rev 2

Figure 5. STM3220G-EVAL demonstration board layout

Page 15: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049 STM3220G-EVAL demonstration board

Doc ID 022809 Rev 2 15/81

Figure 6. ZigBee adapter layout description

5.3 Power supplyThe STM322xG-EVAL demonstration board is designed to be powered by a 5 V DC power supply and to be protected by PolyZen from a wrong power plug-in event. It is possible to configure the demonstration board to use any of the following five sources for the power supply:

● 5 V DC power adapter connected to JP18, the power jack on the board

● 5 V DC power with 500 mA limitation from CN8, the USB OTG FS Micro-AB connector

● 5 V DC power with 500 mA limitation from CN9, the USB OTG HS Micro-AB connector

● 5 V DC power with 500 mA limitation from CN21, the ST-LINK/V2 USB connector

● 5 V DC power from both CN1 and CN3, the extension connector for the daughterboard (DTB for daughterboard on silkscreen).

The power supply is configured by setting the related jumpers JP4, JP32, JP18 and JP19, as described in Table 1.

Page 16: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

STM3220G-EVAL demonstration board AN4049

16/81 Doc ID 022809 Rev 2

Table 2. Power related jumpers and solder bridges

Jumper Description

JP4Jumper reserved for future use (RFU).Default setting: fitted

JP32MCU_VDD is connected to 3.3 V power when JP32 is closed and MCU current consumption measurement can be done manually by multi-meter when JP32 is open.Default setting: fitted

JP18

JP18 is used to select one of the four possible power supply sources.To select the ST-LINK/V2 USB connector (CN21) power supply, set JP18 as shown:(default setting)

For power supply jack (CN18) to the STM322xG-EVAL, JP18 is set as shown on the right: (default setting)

To select daughterboard connector (CN1 and CN3) powersupply, set JP18 as shown:

To select USB OTG FS (CN8) power supply, set JP18 as shown:

To select USB OTG HS (CN9) power supply, set JP18 as shown:

To select power supply jack (CN18) power supply to both STM322xG-EVAL and daughterboard connected on CN1 and CN3, set JP18 as shown

Warning: daughterboard must not have its own power supply connected

Page 17: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049 STM3220G-EVAL demonstration board

Doc ID 022809 Rev 2 17/81

Note: The LED LD9 is lit when the STM322xG-EVAL demonstration board is powered by the 5 V correctly.

5.4 Boot optionThe STM322xG-EVAL demonstration 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 switch SW1 (BOOT1) and SW2 (BOOT0). The BOOT0 can be configured also via RS232 connector CN16.

5.5 Clock sourceFour clock sources are available on the STM3220G-EVAL demonstration board for the STM32F207IFT6 and RTC embedded.

● X1, 25 MHz crystal for Ethernet PHY with socket. It can be removed when clock is provided by the MCO pin of the MCU

● X2, 26 MHz crystal for USB OTG HS PHY

● X3, 32 kHz crystal for embedded RTC

● X4, 25 MHz crystal with socket for the in STM32F207IGH6 microcontroller (it can be removed from socket when internal RC clock is used).

JP19

To connect Vbat to the battery, set JP19 as shown:

To connect Vbat to 3.3 V power, set JP19 as shown:(default setting)

Table 2. Power related jumpers and solder bridges (continued)

Jumper Description

Table 3. Boot related switch

BOOT BOOT1 Boot source

0 Do not care STM322xG-EVAL boots from user Flash (default setting)

1 1 STM322xG-EVAL boots from embedded SRAM

1 0 STM322xG-EVAL boots from system memory

Page 18: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

STM3220G-EVAL demonstration board AN4049

18/81 Doc ID 022809 Rev 2

5.6 Reset sourceThe reset signal of the STM322xG-EVAL demonstration board is low active and the reset sources include:

● Reset button B1

● Debugging tools from JTAG connector CN14 and trace connector CN13

● Daughterboard from CN3

● RS232 connector CN16 for ISP

● ST-LINK/V2.

5.7 EEPROMA 64 KBit EEPROM is connected to the I2C1 bus of the in STM32F207IGH6.

5.8 EthernetThe STM322xG-EVAL demonstration board supports 10M/100M Ethernet communication by a PHY DP83848CVV (U5) and integrated RJ45 connector (CN7). Both MII and RMII interfaces can be selected by setting jumpers JP5, JP6 and JP8, as listed below:

Table 4. EEPROM related jumper and solder bridge

Jumper Description

JP24The EEPROM is in Write Protection mode when JP24 is fitted.

Default setting: not fitted

Table 5. Ethernet related jumpers and solder bridges

Jumper Description

JP8

JP8 is used to select MII or RMII interface mode.To enable MII, JP8 is not fitted.

To enable RMII interface mode, JP8 is fitted.Default setting: not fitted

JP6

To enable MII interface mode, set JP6 as shown (default setting):

To enable RMII interface mode, set JP6 as shown:

Page 19: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049 STM3220G-EVAL demonstration board

Doc ID 022809 Rev 2 19/81

Note: 1 A test point (TP2) is available on the board for the PTP_PPS feature test.

2 The Ethernet PHYU5 can be powered down by regulating PB14.

3 In RMII mode it is not possible to use MCO to output the 50 MHz clock to PHY due to the PLL limitation explained in chapter 2.6.5 of STM32F2x7x and STM32F2x7x errata sheet (ES0005). In such a case it is possible to provide the 50 MHz clock by soldering a 50 MHz oscillator (ref SM7745HEV-50.0M or equivalent) on the U3 footprint located under CN3 and also removing jumper on JP5. This oscillator is not provided with the board.

5.9 SRAMThe 16 Mbit SRAM is connected to the FSMC bus of the in STM32F207IGH6 which shares the same I/Os with the CAN1 bus. JP3 and JP10 must not be fitted for SRAM and LCD application.

JP5

To provide 25 MHz clock for MII or 50 MHz clock for RMII byMCO at PA8, set JP5 as shown (default setting):

To provide 25 MHz clock by external crystal X1 (for MII interfacemode only) set JP5 as shown:

When clock is provided by external oscillator U3, JP5 must not be fitted

(default setting).

SB1

SB1 is used to select clock source only for RMII mode.

To connect the clock from MCO to RMII_REF_CLK, close SB1.The resistor R212 must be removed in this case.Default setting: open

Table 5. Ethernet related jumpers and solder bridges (continued)

Jumper Description

Table 6. SRAM related jumpers

Jumper Description

JP1

Connect PE4 to SRAM as A20 by setting JP1 as shown (default setting):

Connect PE4 to trace connector CN13 as TRACE_D1 by setting JP1 as shown:

Page 20: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

STM3220G-EVAL demonstration board AN4049

20/81 Doc ID 022809 Rev 2

5.10 Development and debug supportThe version 2 of the ST-LINK, called ST-LINK/V2, is embedded on the board. This tool allows onboard program loading and debugging of the STM32F using the JTAG or SWD interface.

Third-party debug tools are also supported by the JTAG (CN14) or trace (CN13) connectors.

To communicate with the embedded ST-LINK/V2, a specific driver needs to be installed on the PC. To download and install this driver, refer to the software and development tools page for the STM32F family available on www.st.com (the install shield is called ST-LINK_V2_USBdriver.exe).

The embedded ST-LINK/V2 connects to the PC via a standard USB cable from connector CN21. The bicolor LED LD10 (COM) indicates the status of the communication as follows:

● Slow blinking red/off: at power-on before USB initialization

● Fast blinking red/off: after the first correct communication between PC and ST-LINK/V2 (enumeration)

● Red LED on: when initialization between PC and ST-LINK/V2 is successfully finished

● Green LED on: after successful target communication initialization

● Blinking red/green: during communication with target

● Green on: communication finished and OK

● Orange on: communication failure.

Note: It is possible to power the board via CN21 (embedded ST-LINK/V2 USB connector) even if an external tool is connected to CN13 (trace) or CN14 (external JTAG and SWD).

5.11 Display and input devicesThe 3.2" TFT color LCD connected to the FSMC bus and 4 general purpose color LEDs (LED 1, 2, 3, 4) are available as display devices. A touchscreen connected to an I/O expander (U24), 4-direction joystick with selection key, general purpose button (B4), wakeup button (B2) and tamper detection button (B3) are available as input devices.

JP2

Connect PE3 to SRAM as A19 by setting JP2 as shown (default setting):

Connect PE3 to trace connector CN13 as TRACE_D0 by setting JP2 as shown:

Table 6. SRAM related jumpers (continued)

Jumper Description

Page 21: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049 STM3220G-EVAL demonstration board

Doc ID 022809 Rev 2 21/81

Table 7. LCD modules

3.2” TFT LCD with touchscreen (CN19)

Pin on CN19 Pin name Pin connection

1 CS FSMC_NE3 (PG10)

2 RS FSMC_A0

3 WR/SCL FSMC_NWE

4 RD FSMC_NOE

5 RESET RESET#

6 PD1 FSMC_D0

7 PD2 FSMC_D1

8 PD3 FSMC_D2

9 PD4 FSMC_D3

10 PD5 FSMC_D4

11 PD6 FSMC_D5

12 PD7 FSMC_D6

13 PD8 FSMC_D7

14 PD10 FSMC_D8

15 PD11 FSMC_D9

16 PD12 FSMC_D10

17 PD13 FSMC_D11

18 PD14 FSMC_D12

19 PD15 FSMC_D13

20 PD16 FSMC_D14

21 PD17 FSMC_D15

22 BL_GND GND

23 BL_Control +5 V

24 VDD +3.3 V

25 VCI +3V3

26 GND GND

27 GND GND

28 BL_VDD +5V

29 SDO NC

30 SDI NC

31 XL IO expander U24

32 XR IO expander U24

Page 22: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

STM3220G-EVAL demonstration board AN4049

22/81 Doc ID 022809 Rev 2

5.12 Daughterboard extension connector CN1, 2, 3 and CN4Four male headers CN1, 2, 3 and CN4 can be used to connect the daughterboard or the standard wrapping board to the STM322xG-EVAL demonstration board. A total number of 140 GPIOs is available on the board.

Each pin on CN1, 2, 3 and 4 can be used by a daughterboard after disconnecting it from the corresponding function block on the STM322xG-EVAL demonstration board.

The ZigBee adapter is connected to the extended connectors CN2 and CN4 on the STM322xG-EVAL (for more detailed information, please refer to Table 8 to Table 10), it allows the communication between the STM32F2x7x on the eval board, the ZigBee smartplug coordinator (STM32W108CB) and the I2C/RF dual interface EEPROM M24LR64-r on the ZigBee adapter.

33 YD IO expander U24

34 YU IO expander U24

Table 7. LCD modules (continued)

3.2” TFT LCD with touchscreen (CN19)

Pin on CN19 Pin name Pin connection

Table 8. Daughterboard extension connector CN1

Pin Description Alternative functionHow to disconnect with function block on STM322xG-EVAL board

1 GND - -

3 PE3 Trace_D0 and FSMC_A19 Keep JP2 on 2<->3

5 PE5 Trace_D2

7 PI8 LCD_HSYNC -

9 PC14 OSC32_IN Remove R84, SB4 closed

11 PC15 OSC32_OUT Remove R85, SB5 closed

13 PI10 MII_RX_ER Remove RS3

15 PF0 FSMC_A0 -

17 PF2 FSMC_A2 -

19 GND - -

21 PF5 FSMC_A5 -

23 PF7 SmartCard_RST -

25 PF9 Potentiometer Remove R151

27 PH0 OSC_IN SB6 open

29 PC0 ULPI_STP -

31 PC1 MII_MDC SB11 open

33 PC3 MII_TX_CLK Remove R51

Page 23: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049 STM3220G-EVAL demonstration board

Doc ID 022809 Rev 2 23/81

35 PA0 WakeUP Remove R139

37 PA2 MII_MDIO -

39 GND - -

41 PH4 ULPI_NXT Remove R61

43 NC - -

45 NC - -

47 EMU_3V3 - -

49 EMU_5V - -

2 PE2 Trace_CLK -

4 PE4 Trace_D1 & FSMC_A20 Keep JP1 on 2<->3

6 PE6 Trace_D3 -

8 PC13 Anti-Tamper Remove R143

10 GND - -

12 PI9 LED3 Remove R141

14 PI11 ULPI_DIR Remove R62

16 PF1 FSMC_A1 -

18 PF3 FSMC_A3 -

20 PF4 FSMC_A4 -

22 PF6 SmartCard_OFF Remove R126

24 PF8 LCD_CS

26 PF10 Audio_IN Remove R196

28 PH1 OSC_OUT Remove R86, SB7 closed

30 GND - -

32 PC2 MII_TXD2 & MC SB12 open

34 VREF+ - -

36 PA1 MII_RX_CLK JP6 open

38 PH2 MII_CRS Remove RS3

40 PH3 MII_COL Remove RS3

42 PH5 OTG_FS_PowerSwitchOn Remove R18

44 NC - -

46 NC - -

48 APP_3V3 - -

50 GND - -

Table 8. Daughterboard extension connector CN1 (continued)

Pin Description Alternative functionHow to disconnect with function block on STM322xG-EVAL board

Page 24: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

STM3220G-EVAL demonstration board AN4049

24/81 Doc ID 022809 Rev 2

Table 9. Daughterboard extension connector CN2

Pin Description Alternative functionHow to disconnect with function block on STM322xG-EVAL board

1 GND - -

3 PA3 ULPI_D0 -

5 PA5 ULPI_CLK Remove R69

7 PA7 MII_RX_DV Remove RS2, JP8 open

9 PC5 MII_RXD1 Remove R58

11 PB0 ULPI_D1 -

13 PB2 BOOT1 -

15 PF12 FSMC_A6 -

17 PF14 FSMC_A8 -

19 GND - -

21 PG1 FSMC_A11 -

23 PE8 FSMC_D5 -

25 PE10 FSMC_D7 -

27 PE12 FSMC_D9 -

29 PE14 FSMC_D11 -

31 PE15 FSMC_D12 -

33 PB11 ULPI_D4 -

35 PH7 MII_RXD3 Remove RS3

37 PH9 DCMI_D0 Remove camera module from CN15

39 GND - -

2 APP_VCC - -

4 PA4 Audio_DAC_OUT Remove R115

6 PA6 DCMI_PIXCK Remove camera module from CN15

8 PC4 MII_RXD0 Remove RS2

10 GND - -

12 PB1 ULPI_D2 -

14 PF11 OTG_FS_Overcurrent Remove R15

16 PF13 FSMC_A7 -

18 PF15 FSMC_A9 -

20 PG0 FSMC_A10 -

22 PE7 FSMC_D4 -

24 PE9 FSMC_D6 -

26 PE11 FSMC_D8 -

Page 25: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049 STM3220G-EVAL demonstration board

Doc ID 022809 Rev 2 25/81

28 PE13 FSMC_D10 -

30 GND - -

32 PB10 ULPI_D3 -

34 PH6 MII_RXD2 Remove RS5

36 PH8 DCMI_HSYNC & MCRemove camera module from CN15.

Disconnect motor control board from CN5

38 PH10 DCMI_D1 &MCRemove camera module from CN15.Disconnect motor control board from

CN5

40 PH11 DCMI_D2 &MCRemove camera module from CN15.Disconnect motor control board from

CN5

Table 10. Daughterboard extension connector CN3

Pin Description Alternative functionHow to disconnect with function block on

STM322xG-EVAL board

1 GND - -

3 PI1 I2S_CK -

5 PH15 SmartCard_3/5 V & MC Disconnect motor control board from CN5

7 PH13 MicroSDCard_defect & MCRemove MicroSD card from CN6.

Disconnect motor control board from CN5

9 PC13 Anti-Tamper Remove R143

11 RESET# Reset button -

13 PA11 OTG_FS_DM Remove R17

15 PA9 VBUS_FSRemove USB cable from CN8

Remove R18

17 PC9MicroSDCard_D1 &

I2S_CKINKeep JP16 on open

19 EMU_5V - -

21 PC6I2S_MCK &

SmartCard_IOJP21 open

23 PG7 SmartCard_CLK -

25 PG5 FSMC_A15 -

27 PG3 FSMC_A13 -

29 PD15 FSMC_D1 -

31 PD14 FSMC_D0 -

Table 9. Daughterboard extension connector CN2 (continued)

Pin Description Alternative functionHow to disconnect with function block on STM322xG-EVAL board

Page 26: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

STM3220G-EVAL demonstration board AN4049

26/81 Doc ID 022809 Rev 2

33 PD12 FSMC_A17 SB15 open

35 PD10 FSMC_D15 -

37 PD8 FSMC_D13 -

39 GND - -

41 PB13ULPI_D6 &

CAN2_TX-

43 PH12 DCMI_D3 & MCRemove camera module from CN15.

Disconnect motor control board from CN5

45 NC - -

47 EMU_3V3 - -

49 EMU_5V - -

2 PI2 IO_Expandor_INT Remove R136

4 PI0 I2S_CMD -

6 PH14 DCMI_D4 & MCRemove camera module from CN15.

Disconnect motor control board from CN5

8 PA13 TMS/SWDIO -

10 GND - -

12 PA12 OTG_FS_DP Remove R19

14 PA10 OTG_FS_ID Remove R21

16 PA8 MCO JP5 open

18 PC8 MicroSDCard_D0 & MCRemove MicroSD card from CN6

disconnect motor control board from CN5

20 PC7 LED4 Remove R140

22 PG8 LED2 Remove R154

24 PG6 LED1 Remove R155

26 PG4 FSMC_A14 -

28 PG2 FSMC_A12 -

30 GND - -

32 PD13 FSMC/MCSB14 open.

Disconnect motor control board from CN5.

34 PD11 FSMC_A16 -

36 PD9 FSMC_D14 -

38 PB15 OneNAND_INT Remove R53

40 PB14 MII_INT Remove R41

42 PB12 ULPI_D5 -

Table 10. Daughterboard extension connector CN3 (continued)

Pin Description Alternative functionHow to disconnect with function block on

STM322xG-EVAL board

Page 27: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049 STM3220G-EVAL demonstration board

Doc ID 022809 Rev 2 27/81

44 NC - -

46 NC - -

48 APP_3V3 - -

50 GND - -

Table 11. Daughterboard extension connector CN4

Pin Description Alternative functionHow to disconnect with function block on

STM322xG-EVAL board

1 GND - -

3 PI6 DCMI_D6 & MCRemove camera module from CN15

Disconnect motor control board from CN5

5 PI4 DCMI_D5 & MCRemove camera module from CN15

SB16 open

7 PE0 FSMC_BL0 -

9 PB8 MII_TXD3 & MCRemove RS5SB10 open

Disconnect motor control board from CN5

11 BOOT0 BOOT0 -

13 PB6 I2C1_SCK Remove R103

15 PB4 TRST -

17 PG15 User button Remove R150

19 GND - -

21 PG12Smartcard_CMDVCC &

CLD_VSYNCRemove R128

23 PG10 FSMC_NE3 Remove LCD board MB785 from CN19

25 PD7 FSMC_NE1 Remove R52

27 PD5 FSMC_NWE -

29 PD3 FSMC_CLK -

31 PD2 MicroSDCard_CMD -

33 PD0 FSMC_D2 & CAN1_RX JP10 open

35 PC11MicroSDCard_D3 &

RS232/IrDA_RXJP22 open.

Remove MicroSD card from CN6

37 PA15 TDI -

39 GND - -

Table 10. Daughterboard extension connector CN3 (continued)

Pin Description Alternative functionHow to disconnect with function block on

STM322xG-EVAL board

Page 28: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

STM3220G-EVAL demonstration board AN4049

28/81 Doc ID 022809 Rev 2

5.13 Ethernet RJ45 connector CN7

Figure 7. Ethernet RJ45 connector CN7

2 PI7 DCMI_D7 & MCRemove camera module from CN15.

Disconnect motor control board from CN5

4 PI5 DCMI_VSYNC & MCRemove camera module from CN15.

Disconnect motor control board from CN5

6 PE1 FSMC_BL1 -

8 PB9 I2C1_SDA Remove R111

10 GND - -

12 PB7 FSMC_NL -

14 PB5 ULPI_D7 & CAN2_RX JP10 open

16 PB3 TDO/SWO -

18 PG14 MII_TXD1 Remove RS6

20 PG13 MII_TXD0 Remove RS6

22 PG11 MII_TX_EN Remove RS6

24 PG9 FSMC_NE2 Remove R47

26 PD6 FSMC_NWAIT Remove R54

28 PD4 FSMC_NOE -

30 GND - -

32 PD1 FSMC_D3 &CAN1_TX JP3 open

34 PC12 MicroSDCard_CLK Remove MicroSD card from CN6

36 PC10MicroSDCard_D2 &

RS232/IrDA_TXRemove MicroSD card from CN6

38 PA14 TCK/SWCLK -

40 PI3 I2S_DIN -

Table 11. Daughterboard extension connector CN4 (continued)

Pin Description Alternative functionHow to disconnect with function block on

STM322xG-EVAL board

Page 29: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049 STM3220G-EVAL demonstration board

Doc ID 022809 Rev 2 29/81

5.14 JTAG debugging connector CN14

Figure 8. JTAG debugging connector CN14

Table 12. Ethernet connector pinout

Pin number Description Pin number Description

1 TxData+ 2 TxData-

3 RxData+ 4 Shield

5 Shield 6 RxData-

7 Shield 8 Shield

Table 13. JTAG debugging connector CN14

Pin number Description Pin number Description

1 3.3 V power 2 3.3 V power

3 PB4 4 GND

5 PA15 6 GND

7 PA13 8 GND

9 PA14 10 GND

11 RTCK 12 GND

13 PB3 14 GND

15 RESET# 16 GND

17 DBGRQ 18 GND

19 DBGACK 20 GND

Page 30: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

STM3220G-EVAL demonstration board AN4049

30/81 Doc ID 022809 Rev 2

5.15 Power connector CN18The STM322xG-EVAL demonstration board can be powered from a DC 5 V power supply via the external power supply jack (CN18) shown in Figure 6. The central pin of CN18 must be positive.

Figure 9. Power supply connector CN18

5.16 TFT LCD connector CN19One 34-pin male header CN19 is available on the board for connecting the LCD module board MB785. Please refer to Section 5.11 for details.

Page 31: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049 In-Home Display with HTTP gateway firmware

Doc ID 022809 Rev 2 31/81

6 In-Home Display with HTTP gateway firmware

6.1 Firmware structureFigure 10 shows the layers architecture of the firmware implementation.

Figure 10. Firmware architecture

Figure 11 describes the system architecture and the hardware block interaction.

Page 32: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

In-Home Display with HTTP gateway firmware AN4049

32/81 Doc ID 022809 Rev 2

Figure 11. System architecture and hardware block interaction

This section describes the firmware implementation. The tasks/functions are described in the following format:

Table 14. 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

Page 33: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049 In-Home Display with HTTP gateway firmware

Doc ID 022809 Rev 2 33/81

6.2 main.c

6.2.1 demo_initTask

Table 15 describes the demo_initTask task:

Example:

static void demo_initTask (void *pvParameters)

{

#if TOUCH_SCREEN_CAPABILITY

/* Check if Calibration has been done*/

TS_CheckCalibration();

#endif

CursorInit(GL_NULL);

/* Set the LCD Back Color */

GL_SetBackColor(GL_White);

/* Set the Font Text Color */

GL_SetTextColor(GL_Black);

GL_Clear(GL_White);

GL_DrawButtonBMP( 210, 110,

(LCD_Height/10)*2 + 100,

(LCD_Height/10)*2,

(uint8_t*) STM32Logo);

GL_DisplayAdjStringLine(3*(LCD_Height/5),(LCD_Width/3)*2 + 6,

"Loading.", GL_FALSE);

GL_Delay(30);

Table 15. demo_initTask task

Function name demo_initTask

Function prototype void demo_initTask (void *pvParameters)

Behavior description Initialize the visualization environment, the RTC and check the touchscreen for the calibration

Input parameter {x} None

Output parameter {x} None

Return value None

Required preconditions None

Called functions No API/HAL layer functions;

Page 34: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

In-Home Display with HTTP gateway firmware AN4049

34/81 Doc ID 022809 Rev 2

GL_DisplayAdjStringLine(3*(LCD_Height/5), (LCD_Width/3)*2 + 6,

"Loading..", GL_FALSE);

GL_Delay(30);

GL_DisplayAdjStringLine(3*(LCD_Height/5), (LCD_Width/3)*2 + 6,

"Loading...", GL_FALSE);

GL_Delay(30);

GL_DisplayAdjStringLine(3*(LCD_Height/5), (LCD_Width/3)*2 + 6,

"Loading. ", GL_FALSE);

GL_Delay(30);

GL_DisplayAdjStringLine(3*(LCD_Height/5), (LCD_Width/3)*2 + 6,

"Loading..", GL_FALSE);

GL_Delay(30);

GL_DisplayAdjStringLine(3*(LCD_Height/5), (LCD_Width/3)*2 + 6,

"Loading...", GL_FALSE);

GL_Delay(20);

RTC_Settings();

CursorShow(195, 50);

vTaskResume(xGraphLibTaskHandle);

while(!RTC_ClockIsSet)

vTaskDelay(25);

vTaskResume(xWEB_GetTaskHandle);

vTaskResume(xZigNetMgmtHandle);

vTaskResume(xCalendarTaskHandle);

vTaskResume(xSmartPlugSamplingHandle);

vTaskResume(xLedTaskHandle);

vTaskSuspend(NULL);

}

Page 35: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049 In-Home Display with HTTP gateway firmware

Doc ID 022809 Rev 2 35/81

6.3 web_client.c

6.3.1 Web_Get_Task

Table 16 describes the Web_Get_Task task:

Example:

void Web_Get_Task(void *pvParameters)

{

struct netconn *conn;

int ret = 0;

int len = 0;

int nErr = 0;

vTaskSuspend( NULL );

/* Create a new connection identifier. */

conn = netconn_new(NETCONN_TCP);

/* Bind the connection to WEB server port */

ret = netconn_connect(conn, &WEB_SERVER_IP, WEB_SERVER_PORT);

/* Infinite main loop ------------------------------------------------------*/

while (1)

{

if(SendToWeb == 1)

{

/* Check if the conn allocation has been successed */

if (conn == 0)

{

/* Delete the current session data */

netconn_delete(conn);

/* Create a new connection identifier. */

Table 16. Web_Get_Task task

Function name Web_Get_Task

Function prototype void Web_Get_Task (void *pvParameters)

Behavior description Start the WEB GET task: Upload the smartplug sampling data on the web server where they are stored in an SQL database.

Input parameter {x} None

Output parameter {x} None

Return value None

Required preconditions None

Called functions No API/HAL layer functions;

Page 36: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

In-Home Display with HTTP gateway firmware AN4049

36/81 Doc ID 022809 Rev 2

conn = netconn_new(NETCONN_TCP);

/* Start the connection */

do

{

/* Bind the connection to WEB server port */

ret = netconn_connect(conn, &WEB_SERVER_IP, WEB_SERVER_PORT);

/* Check if the Connection Binding has been successed */

if (ret == ERR_MEM || ret == ERR_BUF || ret == ERR_VAL || ret == ERR_ARG )

{

/* Delete the current session data */

netconn_delete(conn);

/* Create a new connection identifier. */

conn = netconn_new(NETCONN_TCP);

vTaskDelay(700);

}

}while(ret!=0);

}

/* Write the GET request to the buffer to be sent to WEB server */

len = strlen((char*)buf);

/* Send application data to be encrypted */

ret = netconn_write(conn, buf, len, NETCONN_NOFLAG);

if(ret < 0)

{

/* Write to WEB server failed */

/* Bind the connection to WEB server port */

ret = netconn_connect(conn, &WEB_SERVER_IP, WEB_SERVER_PORT);

/* Check if the Connection Binding has been successes */

if ( ret < 0 )

{

/* Delete the current session data */

netconn_delete(conn);

/* Create a new connection identifier. */

conn = netconn_new(NETCONN_TCP);

do{

/* Bind the connection to WEB server port */

ret = netconn_connect(conn, &WEB_SERVER_IP, WEB_SERVER_PORT);

/* Send application data to be encrypted */

ret = netconn_write(conn, buf, len, NETCONN_NOFLAG);

}while(ret<0);

Page 37: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049 In-Home Display with HTTP gateway firmware

Doc ID 022809 Rev 2 37/81

}

}

SendToWeb = 0;

}

/* Insert 10 s delay */

vTaskDelay(700);

}

}

6.4 tasks_misc.c

6.4.1 GraphicLibTask

Table 17 describes the GraphicLibTask task:

Example:

void GraphicLibTask( void *pvParameters)

{

vTaskSuspend( NULL );

/* Infinite main loop ---------------------------------------*/

while (1)

{

/* Catching touch events */

if ( TS_IsCalibrationDone() == SET )

{

/* Catch the user input through Touchscreen/Joystick */

ProcessInputData();

}

/*Timeout calculate for power saving mode*/

Table 17. GraphicLibTask task

Function name GraphicLibTask

Function prototype void GraphicLibTask (void *pvParameters)

Behavior description Manage the graphic library layer and input events

Input parameter {x} None

Output parameter {x} None

Return value None

Required preconditions None

Called functions No API/HAL layer functions;

Page 38: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

In-Home Display with HTTP gateway firmware AN4049

38/81 Doc ID 022809 Rev 2

TimeOutCalculate();

CatchInputEvents();

vTaskDelay(3);

}

}

6.4.2 ZigNetMgmtTask

Table 18 describes the ZigNetMgmtTask task:

Example:

void ZigNetMgmtTask( void *pvParameters)

{

vTaskSuspend( NULL );

uint8_t NewDevFlag = 1;

/* Load Device List stored into the Dual Interface EEPROM */

if( Load_HA_DevList() == 0 && HA_DeviceCount > 0)

{

ZigBeeNet_InitDone = 1;

ShowNetworkStatus();

CursorShow(195, 50);

vTaskResume(xWEB_GetTaskHandle);

}

/* Infinite main loop ---------------------------------------*/

while (1)

{

USART_ITConfig(HA_USART, USART_IT_RXNE, ENABLE);

while( (HA_DevAnn == 1) && (ZigBeeNet_InitDone == 1) )

Table 18. ZigNetMgmtTask task

Function name ZigNetMgmtTask

Function prototype void ZigNetMgmtTask (void *pvParameters)

Behavior description Initialize ZigBee network add nodes sending DeviceAnnounce request

Input parameter {x} None

Output parameter {x} None

Return value None

Required preconditions None

Called functions No API/HAL layer functions;

Page 39: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049 In-Home Display with HTTP gateway firmware

Doc ID 022809 Rev 2 39/81

{

NewDevFlag = 1;

for(uint8_t i=0; i<HA_DeviceCount; i++)

if(ppHAdeviceList[i]->NetworkID == HA_NodeID)

{

NewDevFlag = 0;

break;

}

/* Adding the new device to the device list */

if(NewDevFlag == 1)

{

ppHAdeviceList[HA_DeviceCount++] = NewHA_Device(0, HA_NodeID);

Add_HA_DeviceToCombo(GL_FALSE,0);

}

HA_DevAnn = 0; /* Reset the FLAG to accept new device join */

}

vTaskDelay(20);

}

}

6.4.3 CalendarTask

Table 19 describes the CalendarTask task:

Example:

void CalendarTask( void *pvParameters)

{

Table 19. CalendarTask task

Function name CalendarTask

Function prototype void CalendarTask (void *pvParameters)

Behavior description Simulate the scenario over 24 hours switching on/off the devices according to their timer

Input parameter {x} None

Output parameter {x} None

Return value None

Required preconditions None

Called functions No API/HAL layer functions;

Page 40: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

In-Home Display with HTTP gateway firmware AN4049

40/81 Doc ID 022809 Rev 2

vTaskSuspend( NULL );

uint8_t * NodePower[16];

uint8_t NodeLabel[20];

/* Infinite main loop ---------------------------------------*/

while (1) {

if(HA_TimerActivated == 1){

if(ppHAdeviceList[0]->Timer == HA_TIMER_ON)

{

if((ppHAdeviceList[0]->StartTime == HA_HourCounter) && (ppHAdeviceList[0]->Status == 0))

{

SwitchDeviceON(ppHAdeviceList[0]->NetworkID);

ppHAdeviceList[0]->Status = 1;

}

if((ppHAdeviceList[0]->StopTime <= HA_HourCounter) && (ppHAdeviceList[0]->Status == 1))

{

SwitchDeviceOFF(ppHAdeviceList[0]->NetworkID);

ppHAdeviceList[0]->Status = 0;

}

if(ppHAdeviceList[0]->Status == 1)

{

sprintf((char*)NodeLabel, "%s", ppHAdeviceList[0]->Label);

if(strcmp((char*)NodeLabel, "WASHING_MACHINE") == 0)

sprintf((char*)NodeLabel, "WashMach Status ON ");

else

sprintf((char*)NodeLabel, "%s Status ON ", NodeLabel);

Set_Label( &pageS1E, 0x68, NodeLabel );

sprintf((char*)NodePower, "Power %d Watt ", ppHAdeviceList[0]->Power);

}

else

{

sprintf((char*)NodeLabel, "%s", ppHAdeviceList[0]->Label);

if(strcmp((char*)NodeLabel, "WASHING_MACHINE") == 0)

sprintf((char*)NodeLabel, "WashMach Status OFF");

else

sprintf((char*)NodeLabel, "%s Status OFF", NodeLabel);

Set_Label( &pageS1E, 0x68, NodeLabel );

sprintf((char*)NodePower, "Power 0 Watt ");

Page 41: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049 In-Home Display with HTTP gateway firmware

Doc ID 022809 Rev 2 41/81

}

Set_Label( &pageS1E, 0x71, (uint8_t*)NodePower );

RefreshPageControl( &pageS1E, 0x68 );

RefreshPageControl( &pageS1E, 0x71 );

}

if(ppHAdeviceList[1]->Timer == HA_TIMER_ON)

{

if((ppHAdeviceList[1]->StartTime == HA_HourCounter) && (ppHAdeviceList[1]->Status == 0))

{

SwitchDeviceON(ppHAdeviceList[1]->NetworkID);

ppHAdeviceList[1]->Status = 1;

}

if((ppHAdeviceList[1]->StopTime <= HA_HourCounter) && (ppHAdeviceList[1]->Status == 1))

{

SwitchDeviceOFF(ppHAdeviceList[1]->NetworkID);

ppHAdeviceList[1]->Status = 0;

}

if(ppHAdeviceList[1]->Timer == HA_TIMER_ON)

{

if(ppHAdeviceList[1]->Status == 1)

{

sprintf((char*)NodeLabel, "%s", ppHAdeviceList[1]->Label);

if(strcmp((char*)NodeLabel, "WASHING_MACHINE") == 0)

sprintf((char*)NodeLabel, "WashMach Status ON ");

else

sprintf((char*)NodeLabel, "%s Status ON ", NodeLabel);

Set_Label( &pageS1E, 0x69, NodeLabel );

sprintf((char*)NodePower, "Power %d Watt ", ppHAdeviceList[1]->Power);

}

else

{

sprintf((char*)NodeLabel, "%s", ppHAdeviceList[1]->Label);

if(strcmp((char*)NodeLabel, "WASHING_MACHINE") == 0)

sprintf((char*)NodeLabel, "WashMach Status OFF");

else

sprintf((char*)NodeLabel, "%s Status OFF", NodeLabel);

Set_Label( &pageS1E, 0x69, NodeLabel );

sprintf((char*)NodePower, "Power 0 Watt ");

}

Page 42: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

In-Home Display with HTTP gateway firmware AN4049

42/81 Doc ID 022809 Rev 2

Set_Label( &pageS1E, 0x72, (uint8_t*)NodePower );

RefreshPageControl( &pageS1E, 0x69 );

RefreshPageControl( &pageS1E, 0x72 );

}

}

RTC_TimeStampShow();

}

vTaskDelay(90);

}

}

6.4.4 SPSamplingTask

Table 20 describes the SPsamplingTask task:

Example:

void SPsamplingTask( void *pvParameters )

{

uint8_t i=0, j=0, f=0, g=0;

uint8_t index = 0;

vTaskSuspend( NULL );

/* Infinite main loop ------------------------------------------------------*/

while (1)

{

if(HA_ReportReceived)

{

HA_ReportReceived = 0;

for(; index < HA_DeviceCount; index++)

{

Table 20. SPsamplingTask task

Function name SPsamplingTask

Function prototype void SPsamplingTask (void *pvParameters)

Behavior description Read and sample the plug consumption values

Input parameter {x} None

Output parameter {x} None

Return value None

Required preconditions None

Called functions No API/HAL layer functions;

Page 43: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049 In-Home Display with HTTP gateway firmware

Doc ID 022809 Rev 2 43/81

if(HA_NodeID == ppHAdeviceList[index]->NetworkID)

break;

}

if(index == 0)

{

if ( ppHAdeviceList[0]->Status == 1 )

{

if(HA_Attribute == 0x0000) /* Type of data = Energy */

{

smart_points1[i%N_SAMPLES] = ppHAdeviceList[0]->Energy;

i++;

}

else if(HA_Attribute == 0x0400)/* Type of data = Power */

{

smart_points1B[i%N_SAMPLES] = ppHAdeviceList[0]->Power;

j++;

}

sendData_ToWeb(ppHAdeviceList[0]->NetworkID, ppHAdeviceList[0]->Label, ppHAdeviceList[0]->Power, ppHAdeviceList[0]->Energy);

}

else

{

smart_points1[i%N_SAMPLES] = 0;

smart_points1B[j%N_SAMPLES] = 0;

i++;

j++;

}

}

else if(index == 1)

{

if ( ppHAdeviceList[1]->Status == 1 )

{

if(HA_Attribute == 0x0000) /* Type of data = Energy */

{

smart_points2[f%N_SAMPLES] = ppHAdeviceList[1]->Energy;

f++;

}

else if(HA_Attribute == 0x0400)/* Type of data = Power */

{

smart_points2B[g%N_SAMPLES] = ppHAdeviceList[1]->Power;

Page 44: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

In-Home Display with HTTP gateway firmware AN4049

44/81 Doc ID 022809 Rev 2

g++;

}

sendData_ToWeb(ppHAdeviceList[1]->NetworkID, ppHAdeviceList[1]->Label,

ppHAdeviceList[1]->Power, ppHAdeviceList[1]->Energy);

}

else

{

smart_points2[f%N_SAMPLES] = 0;

smart_points2B[g%N_SAMPLES] = 0;

f++;

g++;

}

}

else if(ppHAdeviceList[index] && HA_NodeID == ppHAdeviceList[index]->NetworkID)

sendData_ToWeb(ppHAdeviceList[index]->NetworkID,ppHAdeviceList[index]->Label, ppHAdeviceList[index]->Power, ppHAdeviceList[index]->Energy);

if((i == N_SAMPLES) || (j == N_SAMPLES) || (f == N_SAMPLES) || (g == N_SAMPLES))

{

i=0;

j=0;

f=0;

g=0;

for(uint8_t k=0; k<N_SAMPLES; k++)

{

smart_points1[k] = 0;

smart_points1B[k] = 0;

smart_points2[k] = 0;

smart_points2B[k] = 0;

}

}

}

index = 0;

USART_ITConfig(HA_USART, USART_IT_RXNE, ENABLE);

vTaskDelay(100);

}}

Page 45: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049 In-Home Display with HTTP gateway firmware

Doc ID 022809 Rev 2 45/81

6.4.5 ToggleLed Task

Table 21 describes the ToggleLed Task:

Example:

void ToggleLed( void *pvParameters)

{

vTaskSuspend( NULL );

portTickType xLastWakeTime;

const portTickType xFrequency = 200;

/* Initialize the xLastWakeTime variable with the current time */

xLastWakeTime = xTaskGetTickCount();

/* Infinite loop */

for( ;; )

{

STM_EVAL_LEDToggle(LED1);

/* Insert 12 ms delay */

vTaskDelay(12);

STM_EVAL_LEDToggle(LED1);

/* Insert 12 ms delay */

vTaskDelay(12);

STM_EVAL_LEDToggle(LED2);

/* Insert 10 ms delay */

vTaskDelay(12);

STM_EVAL_LEDToggle(LED2);

/* Insert 12 ms delay */

Table 21. ToggleLed Task

Function name ToggleLed

Function prototype void ToggleLed (void *pvParameters)

Behavior description Start toggle Led task: Toggle LED 1, 2 and 3 every 200 ms

Input parameter {x} None

Output parameter {x} None

Return value None

Required preconditions None

Called functions No API/HAL layer functions

Page 46: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

In-Home Display with HTTP gateway firmware AN4049

46/81 Doc ID 022809 Rev 2

vTaskDelay(12);

STM_EVAL_LEDToggle(LED3);

/* Insert 12 ms delay */

vTaskDelay(12);

STM_EVAL_LEDToggle(LED3);

/* Insert 12 ms delay */

vTaskDelay(12);

STM_EVAL_LEDToggle(LED2);

/* Insert 12 ms delay */

vTaskDelay(12);

STM_EVAL_LEDToggle(LED2);

vTaskDelayUntil(&xLastWakeTime, xFrequency);

}

}

Page 47: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049 Getting started with the system

Doc ID 022809 Rev 2 47/81

7 Getting started with the system

7.1 Hardware requirements● ZigBee adapter board with the ZigBee module SPZB32W onboard

● STM322xG-EVAL board with the jumpers set as described in Section 7.2

● VDC / 2 A isolated power supply is recommended

● 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.

7.2 STM322xG-EVAL demonstration board setupSet up the STM322xG-EVAL board as follows:

● Keep jumper JP16, JP21 and JP22 not fitted

● Set JP5 in 1-2 position, and JP6 in 2-3 position

● Disconnect motor control board from CN5

● Remove MicroSD card from CN6

● Remove R115 and R140.

Set up the STEVAL-IDZ001V1 adapter as follows:

● Place the adapter on the STM322xG-EVAL board so that it is well fixed on connectors CN2, CN3 and CN4

● Set JP3 and JP4 in 1-2 position in order to set the communication between STM32W108CB and STM32F2x7x via UART

● Set JP1 and JP2 in position 1-2 to assign 0xA6 as I2C address for the dual interface EEPROM (M24LR64r).

7.3 STM322xG-EVAL and ZigBee adapter pins mappingThe connections between the MCU and the ZigBee module + EEPROM dual interface are shown in Table 12.

Table 22. ZigBee adapter pinout description

STM32 pin name

STM322xG-EVAL I/O assignment Extension connector

pin. no

ZigBee adapter I/O assignment

- APP_3V3 CN3 VCC_3V3

- GND CN3 GND

PA4 Audio_DAC_OUT (remove R115) CN2 -Pin 4 ZIG_SS (SPI3)

PC10 MicroSDCard_D2 & RS232-IrDA_TX (remove MicroSD

card from CN6) CN4 ZIG_SCLK (SPI3)

PC11 MicroSDCard_D3 & RS232-IrDA_RX (JP22 open, remove

MicroSD card from CN6) CN4 -Pin 35 ZIG_MISO (SPI3)

Page 48: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

Getting started with the system AN4049

48/81 Doc ID 022809 Rev 2

7.4 Program/update dual interface EEPROM with network parametersThe dual interface EEPROM M24LR64-r stores the network parameters of the STM322xG-EVAL board inside the first 3 blocks of the sector 1 and the IP address of the web server at the fourth block of the sector 1, where each block is 4 bytes. The schema is the following:

● Block 0000: IP address

● Block 0001: subnet mask

● Block 0002: default gateway

● Block 0003: web server IP address.

Figure 12 shows a screenshot of the “M24LRxx application software”, the GUI application that allows the user to program the M24LR64-r memory through an RF reader (i.e. FEIG) included in the demo kit (USB based) of the dual interface EEPROM:

PC12 MicroSDCard_CLK (remove MicroSD card from CN6) CN4 -Pin 34 ZIG_MOSI (SPI3)

PA8 MCO (JP5 open) CN3 I2C3_SCK

PC9 MicroSDCard_D1 & I2S_CKIN (keep JP16 on open) CN3 I2C3_SDA

PD2 MicroSDCard_CMD CN4 ZIG_HOST_INT

PC8 MicroSDCard_D0 & MC (remove MicroSD card from CN6,

disconnect motor control board from CN5) CN3 -Pin 18 ZIG_RSTB

PH13 MicroSDCard_detect & MC (remove MicroSD card from

CN6, disconnect motor control board from CN5) CN3 ZIG_WAKE

PH15 SmartCard_3/5V & MC (disconnect motor control board

from CN5) CN3 -Pin 5

VCC-GPIO (for M24LR64-r)

PC6 I2S_MCK & SmartCard_IO (JP21 open) CN3 USART6_TX

PC7 LED4 (Remove R140) CN3 USART6_RX

Table 22. ZigBee adapter pinout description (continued)

STM32 pin name

STM322xG-EVAL I/O assignment Extension connector

pin. no

ZigBee adapter I/O assignment

Page 49: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049 Getting started with the system

Doc ID 022809 Rev 2 49/81

Figure 12. M24LRxx application software

For more information on the M24LRxx application software, see the UM0853 user manual, the GUI application is available from the ST website: http://www.st.com/internet/com/SOFTWARE_RESOURCES/SW_COMPONENT/SW_FUNCTION/m24lr_application_software.zip.

7.5 Configure IAR tool for building, debugging, and programming applicationTogether with the firmware library package, an example application is delivered in order to provide the final user with a real example of the “In-Home Display with HTTP gateway” application usage.

The delivered example application has been written and developed using IAR EWARM 6.30 IDE and can be built for the STM32F2x7x microcontroller.

The workspace is created using the IAR embedded workbench 6.30 IDE, using the ARM®-based 32-bit STM32F2x7x firmware library (ver. 1.0.0), 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 13.

Page 50: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

Getting started with the system AN4049

50/81 Doc ID 022809 Rev 2

Figure 13. 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”.

Figure 14. IAR embedded workbench main window

On the main node, where the program name located in the files window is shown, right click 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 15).

Press the “Make” icon or click on “Project \ Rebuild All”. Any error or warning should appear once the 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

Page 51: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049 Getting started with the system

Doc ID 022809 Rev 2 51/81

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 15. IAR embedded workbench debugger options

In order to use the application project, it is necessary to:

● Include all the firmware delivered in the In-Home Display with HTTP gateway package containing the FreeRTOS core files, see Figure 13.

● 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.6 Example application - main.cAn example of a main application is reported below. The main function contains an example of the In-Home Display with HTTP gateway application initialization/configuration and implements the classic operations:

/* Includes ----------------------------------------------------*/

#include "main.h"

#include "touchscreen.h"

#ifdef USE_FREERTOS

#include "FreeRTOS.h"

#include "task.h"

#endif

/* Private typedef ----------------------------------------------*/

/* Private define -----------------------------------------------*/

Page 52: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

Getting started with the system AN4049

52/81 Doc ID 022809 Rev 2

/*--------------- Tasks Priority -------------*/

#define WEB_TASK_PRIO ( configMAX_PRIORITIES - 3 )

#define LED_TASK_PRIO ( tskIDLE_PRIORITY + 1 )

/* Private macro ------------------------------------------------*/

/* Private variables --------------------------------------------*/

/* Task Handles */

xTaskHandle xSmartPlugSamplingHandle, xWEB_GetTaskHandle, xGraphLibTaskHandle, xLedTaskHandle, xCalendarTaskHandle, xZigNetMgmtHandle;

/* Static IP Address */

uint8_t IP_ADDR0;

uint8_t IP_ADDR1;

uint8_t IP_ADDR2;

uint8_t IP_ADDR3;

/* Subnet Mask */

uint8_t NETMASK_ADDR0;

uint8_t NETMASK_ADDR1;

uint8_t NETMASK_ADDR2;

uint8_t NETMASK_ADDR3;

/* Default Gateway */

uint8_t GW_ADDR0;

uint8_t GW_ADDR1;

uint8_t GW_ADDR2;

uint8_t GW_ADDR3;

/* Web Server Static IP Address */

uint8_t WEB_SERVER_IP_ADDR0;

uint8_t WEB_SERVER_IP_ADDR1;

uint8_t WEB_SERVER_IP_ADDR2;

uint8_t WEB_SERVER_IP_ADDR3;

extern uint8_t RTC_ClockIsSet;

/* Private function prototypes ----------------------------------*/

static void demo_initTask( void *pvParameters );

extern void (*pDelayFunc)(uint32_t nTime);

extern void (*pSysTickFunc)(void);

Page 53: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049 Getting started with the system

Doc ID 022809 Rev 2 53/81

extern void DelayCounter(uint32_t nTime);

extern void DelayRTOS(uint32_t nTime);

#ifdef __GNUC__

/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf

set to 'Yes') calls __io_putchar() */

#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)

#else

#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)

#endif /* __GNUC__ */

/* Private functions -------------------------------------------*/

/**

* @brief Main program.

* @param None

* @retval None

*/

int main(void)

{ pDelayFunc = DelayCounter;

/*!< At this stage the microcontroller clock setting is already configured to

120 MHz, this is done through SystemInit() function which is called from

startup file (startup_stm32f2xx.s) before to branch to application main.

To reconfigure the default setting of SystemInit() function, refer to

system_stm32f2xx.c file

*/

/* Setup STM32 system (USART, RNG, HASH, CRYP) and STM322xG-EVAL resources */

System_Setup();

EEprom_NetConfigReadFunc();

/* Configure Ethernet (GPIOs, clocks, MAC, DMA) */

ETH_BSP_Config();

/* Initialize the LwIP stack */

LwIP_Init();

portBASE_TYPE res = xTaskCreate(demo_initTask, "DEMO_INIT", configMINIMAL_STACK_SIZE*12, NULL, configMAX_PRIORITIES-1, NULL);

Page 54: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

Getting started with the system AN4049

54/81 Doc ID 022809 Rev 2

/* Start the WEB GET task: Update the SmartPlug data on the WebServer */

res = xTaskCreate(Web_Get_Task, "WEB_GET", configMINIMAL_STACK_SIZE*22, NULL, tskIDLE_PRIORITY+4, &xWEB_GetTaskHandle);

/* Start the Graphic Library task: Check the Touchscreen, Joystick, Button user interaction */

res = xTaskCreate(GraphicLibTask, (signed portCHAR *) "GraphicLibrary", configMINIMAL_STACK_SIZE*16, NULL, tskIDLE_PRIORITY+6, &xGraphLibTaskHandle);

/* Start the ZigBee Network Management task: manage the whole ZigBee network and keep trace of the alive Nodes */

res = xTaskCreate(ZigNetMgmtTask, (signed portCHAR *) "ZigNetMgmt", configMINIMAL_STACK_SIZE*4, NULL, tskIDLE_PRIORITY+2, &xZigNetMgmtHandle);

/* Start the Calendar task: Update the date/time and show it on the LCD */

res = xTaskCreate(CalendarTask, (signed portCHAR *) "Calendar",

configMINIMAL_STACK_SIZE*4, NULL, tskIDLE_PRIORITY+2,

&xCalendarTaskHandle);

/* Start the SmartPlug Measurement Sampling task: Sample the measured power/energy

of each Node */

res = xTaskCreate(SPsamplingTask, (signed portCHAR *) "SmartPlugSampling",

configMINIMAL_STACK_SIZE*6, NULL, tskIDLE_PRIORITY+3,

&xSmartPlugSamplingHandle);

/* Start toggleLed task: Toggle LED 1, 2 and 3 every 200ms */

res = xTaskCreate(ToggleLed,"LED",configMINIMAL_STACK_SIZE/4, NULL, LED_TASK_PRIO, &xLedTaskHandle);

pDelayFunc = DelayRTOS;

/* Start the scheduler */

vTaskStartScheduler();

/* We should never get here as control is now taken by the scheduler */

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.

The clock distribution and the interrupt settings are two components which are strongly dependent on the target project. An example of clock rate may be 72 MHz as the maximum

Page 55: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049 Getting started with the system

Doc ID 022809 Rev 2 55/81

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.

Page 56: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

In-Home Display with HTTP gateway GUI application AN4049

56/81 Doc ID 022809 Rev 2

8 In-Home Display with HTTP gateway GUI application

8.1 Application user interfaceAfter 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 16.

Figure 16. Home screen

If the network has already been set up in the past, after some seconds, when the ZigBee network initialization is complete, the home screen looks like that in Figure 17.

Figure 17. Home screen after ZigBee network initialization done

At this point, the ZigBee nodes can be switched on and joined to the ZigBee network just created. The default channel is 16, so set it on the ZigBee nodes accordingly.

Page 57: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049 In-Home Display with HTTP gateway GUI application

Doc ID 022809 Rev 2 57/81

If “Management” is chosen, two situations are possible:

a) If no plug is connected to the smartplug coordinator, the following screen is shown:

Figure 18. No plug detected

From this screen it is possible to run the ZigBee network setup by which a new ZigBee network is formed. The screen in Figure 19 is shown:

Figure 19. Setup ZigBee network

Page 58: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

In-Home Display with HTTP gateway GUI application AN4049

58/81 Doc ID 022809 Rev 2

If no network already exists with the current coordinator, the screen in Figure 20 is shown:

Figure 20. Setting ZigBee network up

If a ZigBee network had already been set up, it must be reinitialized, so the screen in Figure 21 is shown:

Figure 21. Reinitializing ZigBee network

Page 59: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049 In-Home Display with HTTP gateway GUI application

Doc ID 022809 Rev 2 59/81

b) If one or more plugs are detected the following screen is shown:

Figure 22. Plug detected

There are three main buttons: modify, control and identify. They allow the management of the smartplug device.

If “Modify” is chosen, the user can change the label of the selected plug, through the screen shown in Figure 23, choosing the new label from a list contained in a combobox.

Figure 23. Label changing

The user should scroll the list of the labels and select the “Apply” button in order to save the information and set the label also in the plug device via ZigBee protocol.

Page 60: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

In-Home Display with HTTP gateway GUI application AN4049

60/81 Doc ID 022809 Rev 2

When “Control” is chosen, it is possible to switch on/off the smartplug device. The following screen shows the scenario:

Figure 24. Smartplug management

When “Identify” is chosen, the system shows the network ID of the selected node, which is a 16-bit number shown in hexadecimal format. Figure 25 below shows the respective screen:

Figure 25. Identify

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.

Page 61: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049 In-Home Display with HTTP gateway GUI application

Doc ID 022809 Rev 2 61/81

The following screen is shown:

Figure 26. Smartplug statistics

When energy is chosen, the following screen, representing the energy consumption of the selected smartplug device, is shown:

Figure 27. Energy consumption

Page 62: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

In-Home Display with HTTP gateway GUI application AN4049

62/81 Doc ID 022809 Rev 2

When global energy is chosen, the following screen, representing the energy consumption of the whole smartplug network, is shown:

Figure 28. Global energy consumption

When power is chosen, the following screen, representing the power consumption of the selected smartplug device, is shown:

Figure 29. Power consumption

Page 63: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049 In-Home Display with HTTP gateway GUI application

Doc ID 022809 Rev 2 63/81

When global power is chosen, the following screen, representing the power consumption of the whole smartplug network, is shown:

Figure 30. Global power consumption

When the refresh button is chosen, 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 chosen, it returns to the home screen.

On the home screen, by clicking on “Demo Scenario” it is possible to set a configuration for the nodes in order to enable automatic timers.

Only the first two nodes can be configured for the demo scenario.

The following screen is shown:

Figure 31. Demo scenario

When the “Set Timer” button is chosen, a new screen is shown where the user can set up the parameter for the timer related to a smartplug node.

Page 64: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

In-Home Display with HTTP gateway GUI application AN4049

64/81 Doc ID 022809 Rev 2

Figure 32. Set timer

After setting up the parameters, the user must choose “Save Parameters” in order to apply the changes. Then, the user must choose “Back”, bringing up the previous screen so that the timer can be activated with the respective button. Before activating the timer, the user can set it for another smartplug, so that the timer scenario is activated for 2 devices (the maximum allowed for the demo).

Clicking on the “Activate” button, the following screen is shown:

Figure 33. Activate timer

In this way, the demo scenario is running and the node for which the timer is activated is switched on and off according to the timer parameters set in the previous screen. In this screen the user can visualize the current date and time, the node status (off or on) and the instant power consumption. If the timer is activated also for a second node, its status and power consumption are shown after those of the first node.

When the home button is selected, it returns to the home screen.

Page 65: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049 Web server hosting energy consumption data

Doc ID 022809 Rev 2 65/81

9 Web server hosting energy consumption data

9.1 Features overviewEach time a smartplug node joins the network and its load type is configured through the GUI interface, it starts reporting power and energy consumption measured values.

These data are received from the coordinator board and routed via Ethernet to the web server.

The user can browse these data from another PC connecting to the web server and logging in with a username and password. Then, the user can look at the reporting table, export data to an Excel file or plot them to graphical charts.

9.2 Accessing the websiteThe following image shows the login page of the web server:

Figure 34. Login page

For example, the user can log in using “guest” as both username and password.

Page 66: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

Web server hosting energy consumption data AN4049

66/81 Doc ID 022809 Rev 2

9.3 Browsing reporting dataAfter login, the browser is redirected to the following page where the user can choose the smartplug of which they want to query the reporting data. It can be selected from a combobox containing a list of all the smartplugs that have sent reports. From this page on, the user can always return using the specific “Back” button.

Figure 35. Device selection page

After selecting the smartplug device, the following page is displayed:

Figure 36. Energy data table page

Page 67: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049 Web server hosting energy consumption data

Doc ID 022809 Rev 2 67/81

At this point, the user can:

1. Export the table of data to an Excel file, clicking on the “Export to Excel” button. See the following image:

Figure 37. Export data page

2. Plot the data to graphical charts, where the user can select the day for which to plot the data, as shown from the following screen:

Figure 38. Plotting data page

3. Return in order to select another smartplug device using the “Back” button.

Page 68: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

Schematics AN4049

68/81 Doc ID 022809 Rev 2

10 Schematics

Figure 39. ZigBee and dual Interface EEPROM adapter for STM322xG-EVAL

AM12005v1

ZIG

BE

E/S

PZ

B32W

PA

4

PH

13

PC

8

Prio

r to

use

this

ada

pter

, ope

n JP

5, J

P16

, JP

21 a

nd J

P22

,re

mov

e M

icro

SD

car

d, re

mov

e re

sist

ores

R11

5 an

d R

140,

di

scon

nect

Mot

orC

ontro

l boa

rd fr

om S

TM32

2xG

-Eva

l Boa

rd

PH

15

PA

8P

C9

PC

6P

C7

PC

11P

C12

PC

10

PD

2

SC

2_S

DA

SC

2_S

CL

GN

D

nRE

SE

T

ZIG

_SS

I2C

_SD

A

VC

C-G

PIO

ZIG

_WA

KE

SC

1-U

AR

T_R

XD

/SC

1-M

OS

IJT

-TC

KJT

-TD

OJT

-TD

IJT

-TM

S

JT-T

MS

JT-T

DI

JT-T

DO

JT-T

CK

nRE

SE

T

PA6

PA7

ZIG

_WA

KE

UA

RT_

TXD

UA

RT_

RX

D

PA7

PA6

nRE

SE

T

ZIG

_MIS

O

ZIG

_HO

ST_

INT

ZIG

_MO

SI

ZIG

_SC

LK

E1

GN

D

I2C

_SD

A

I2C

_SC

K

GN

D

VC

C-G

PIO

E0

ZIG

_SC

LKZI

G_S

SU

AR

T_TX

D

ZIG

_MO

SI

UA

RT_

RX

D

ZIG

_MIS

O

I2C

_SC

K

I2C

_SD

AI2

C_S

CK

SC

1-U

AR

T_TX

D/S

C1-

MIS

O

VC

C_3

V3

VC

C_3

V3

VC

C_3

V3

VC

C_3

V3

VC

C_3

V3

VC

C_3

V3

VC

C_3

V3

VC

C_3

V3

VC

C_3

V3

CN

2

Hea

der 2

0x2

(Fem

ale-

Bot

tom

)

CN

2

12

34

56

78

910

1112

1314

1516

1718

1920

2122

2324

2526

2728

2930

3132

3334

3536

3738

3940

J1

Min

i-JTA

G C

onn

(10

Pin

s)

J1

Min

i-JTA

G C

onn

(10

Pin

s)

12

34

56

78

910

CN

4

Hea

der 2

0x2

(Fem

ale-

Bot

tom

)

CN

4

12

34

56

78

910

1112

1314

1516

1718

1920

2122

2324

2526

2728

2930

3132

3334

3536

3738

3940

R8

470

R8

470

C1

100n

C1

100n

12

R6

4.7k

R6

4.7k

R12

4.7k

R12

4.7k

D1

LED

D1

LED

SW

1R

ES

ET

SW

1R

ES

ET

R9

470

R9

470

Ant

enna

U2

SP

W32

_MO

DU

LE

U2

PA2

10

GN

D11

VD

D12

PC

113

PB

014

PB

115

PB

216

JTC

K17

PC

218

PC

319

PC

420

PC

021

PB

722

PA7

25P

C5

26

PA4

3

PA3

4

nRE

SE

T5

PB

36

PB

47

PB

51

PA0

8

PB

623

PA1

9

PA6

24

PA5

2

R4

10k

R4

10k

JP4

Jum

per

231

R7

4.7k

R7

4.7k

CN

3

Hea

der 2

5x2

(Fem

ale-

Bot

tom

)

CN

3

12

34

56

78

910

1112

1314

1516

1718

1920

2122

2324

2526

2728

2930

3132

3334

3536

3738

3940

4142

4344

4546

4748

4950

R1

4.7k

R1

4.7k

D2

LED

D2

LED

JP1

Jum

per

JP1

Jum

per 2

31

JP3

Jum

per

JP3

231

R5

4.7k

R5

4.7k

U1 M

24LR

64

U1

E0

1

AC

02

AC

13

E1

7

SD

A5

SC

L6

VC

C8

VS

S4

R2

4.7k

R2

4.7k

R3

4.7k

R3

4.7k

R11

4.7k

R11

4.7k

C2

100n

C2

100n

12JP

2

Jum

per

JP2

Jum

per

231

Page 69: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049 Schematics

Doc ID 022809 Rev 2 69/81

Figure 40. STM3220-21-45-46G-EVAL

AM12006v1

Page 70: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

Schematics AN4049

70/81 Doc ID 022809 Rev 2

Figure 41. STM3220-21-45-46G-EVAL_MCU

AM12007v1

PA[0

..15

]PA

[0..1

5]

PB[0

..15

]PB

[0..1

5]

PC[0

..15

]PC

[0..1

5]

PD[0

..15

]PD

[0..1

5]

PE[0

..15

]PE

[0..1

5]

1 432

B1

RE

SE

T

R1

37

do

no

t fi

t

+3

V3C

12

3

10

0nF

C7

32

0p

FC

72

20

p F

X4 25

MH

z (w

ith

so

cke

t)

R8

63

90

R8

91

0 K

+3

V32

31

SW

20

9.0

32

90

.01

RE

SE

T#

R8

81

0K

+3

V3

231

SW

1

09

.03

29

0.0

1

41

32

X3

MC

30

6-G

-06

Q-3

2.7

68

(m

an

ufa

ctu

rer

J F V

NY)

C7

16

.8p

FC

70

6.8

p F

R8

50

R8

40

TP2

PTP

_PP

S

Bo

otl

oa

de

r_B

OO

T0

Bo

otl

oa

de

r_R

ES

ET

DC

MI

_PI

XCK

DC

MI

_V

SY

NC

DC

MI

_D

[0..7

]

DC

MI

_H

SY

NC

MC

O

ULP

I_

D[0

..7]

ULP

I_

CL

K

ULP

I_

DIR

ULP

I_

NXT

ULP

I_

ST

P

RS

23

2/I

rDA

_T

X

RS

23

2/I

rDA

_R

X

OTG

_FS

_Po

we

rSw

itch

On

OTG

_FS

_O

verC

urr

en

t

OTG

_FS

_D

MO

TG_

FS_

DP

OTG

_FS

_I

D

I2S

_W

S

I2S

_S

D

I2S

_S

CK

I2S

_M

CK

Au

dio

_D

AC

_O

UT

CA

N1

_T

X

CA

N1

_R

X

CA

N2

_T

X

CA

N2

_R

X

MII

_T

XD

0

MII

_T

X_

EN

MII

_T

X_

CLK

MII

_R

XD

0

MII

_R

X_

ER

MII

_R

X_

DV

/RM

II_

CR

SD

V

MII

_R

X_

CLK

/RM

II_

RE

F_

CL

K

MII

_C

OL

MII

_C

RS

MII

_M

DC

MII

_M

DIO

MII

_T

XD

1M

II_

TX

D2

MII

_T

XD

3

MII

_R

XD

1

MII

_R

XD

2M

II_

RX

D3

MII

_IN

T

LE

D 4

LED3

LED1

LED2

Pote

nti

om

ete

r

An

ti_

Tam

pe

r

WA

KE

UP

Use

r_B

utt

on

I2C

1_

SC

L

I2C

1_

SD

A

IO_

Exp

an

do

r_IN

T

TD

I

TR

AC

E_

D3

TR

AC

E_

D2

TR

AC

E_

D1

TR

AC

E_

D0

TR

AC

E_

CK

TR

ST

TM

S/S

WD

IOTC

K/S

WC

LK

TD

O/S

WO

D[0

..15

]

A[0

..20

]

FSM

C_

NE

3

Mic

roS

DC

ard

_C

LK

Mic

roS

DC

ard

_C

MD

Mic

roS

DC

ard

_D

0

Mic

roS

DC

ard

_D

1

Mic

roS

DC

ard

_D

2

Mic

roS

DC

ard

_D

3

Mic

roS

DC

ard

_D

ete

ct

MC

_E

me

rge

ncy

STO

P

MC

_C

urr

en

tA

MC

_C

urr

en

tB

MC

_C

urr

en

tC

MC

_P

FC

sy

nc1

MC

_P

FC

sy

nc2

MC

_W

L

MC

_V

H

MC

_V

L

MC

_U

H

MC

_U

L

MC

_W

H

MC

_N

TC

MC

_D

issi

pa

tiv

eB

rake

MC

_P

FC

pw

m

MC

_E

nA

MC

_E

nB

MC

_H

ea

tsin

kTe

mp

era

ture

MC

_B

usV

olt

ag

e

MC

_E

nI

nd

ex

Sma

rtC

ard

_3

/5V

Sma

rtC

ard

_IO

Sma

rtC

ard

_R

ST

Sma

rtC

ard

_C

LK

Sma

rtC

ard

_O

FF

Sma

rtC

ard

_C

MD

VC

C

FSM

C_

NE

1

FSM

C_

NE

2

FSM

C_

NW

EFS

MC

_N

OE

FSM

C_

BL

N0

FSM

C_

BL

N1

FSM

C_

NW

AIT

FSM

C_

CL

K

FSM

C_

NL

On

eN

AN

D_

INT

PE0

PE1

PE2

PE3

PE4

PE5

PE6

PE7

PE8

PE9

PE1

0PE

11PE

12

PE1

3PE

14

PE1

5

PI0

PI1

PI2

PI3

PI4

PI5

PI6

PI7

PI8

PI9

PI1

0PI

11

PC0

PC1

PC2

PC3

PC4

PC5

PC6

PC7

PC8

PC9

PC1

0PC

11PC

12

PC1

3

PC1

4PC

15

PF0

PF1

PF2

PF3

PF4

PF5

PF6

PF7

PF8

PF9

PF1

0PF

11PF

12

PF1

3PF

14

PF1

5

A0

A1

A2

A3

A4

A5

PA0

PA1

PA2

PA3

PA4

PA5

PA6

PA7

PA8

PA1

0PA

11PA

12

PA1

3PA

14

PA1

5

PH0

PH1

PH2

PH3

PH4

PH5

PH6

PH7

PH8

PH9

PH1

0PH

11PH

12

PH1

3PH

14

PH1

5

ULP

I_

D0

ULP

I_

D1

ULP

I_

D2

PB0

PB1

PB2

PB3

PB4

PB5

PB6

PB7

PB8

PB9

PB1

0PB

11PB

12

PB1

3PB

14

PB1

5

A6

A7

A8

A9

PG0

PG1

PG2

PG3

PG4

PG5

PG6

PG7

PG8

PG9

PG1

0PG

11PG

12

PG1

3PG

14

PG1

5

A1

0A

11

ULP

I_

D3

DC

MI

_D

0D

CM

I_

D1

DC

MI

_D

2D

CM

I_

D3

PD0

PD1

PD2

PD3

PD4

PD5

PD6

PD7

PD8

PD9

PD1

0PD

11PD

12

P D

13

PD1

4P

D1

5

D1

3D

14

D1

5

D4

D5

D6

D7

D8

D9

D1

0D

11D

12

A1

6A

17

D0

D1

A1

2A

13

A1

4A

15

DC

MI

_D

4D

2D

3

DC

MI

_D

5

DC

MI

_D

6D

CM

I_

D7

DC

MI

_D

[0..7

]

A[0

..20

]

D[0

..15

]

ULP

I_

D[0

..7]

VB

US

_F

S

PF[0

..15

]PF

[0..1

5]

PG[0

..15

]PG

[0..1

5]

PH[0

..15

]PH

[0..1

5]

PI[0

..11

]PI

[0..1

1]

JP2

1

BT1

CR

12

20

ho

lde

r

L3 BE

AD

C7

41

uF

C6

91

00

n F

R8

7

47

VD

DA

VD

D_

MC

U

VR

EF+

C6

81

00

nF

TP 5

VR

EF

1

2

3 J

P1

9

+3

V3

VD

D_

MC

U

C6

01

00

n F

VD

D_

MC

U

C5

02

.2u

FC

33

2.2

u F

C4

81

00

n FC

37

10

0n F

C3

51

00

n FC

54

10

0n F

C6

71

00

n F

C3

41

00

n F

C5

71

00

n F

VD

D_

MC

U

C5

61

00

n FC

36

10

0n F

C6

11

00

n FC

66

10

0n

FC

53

10

0n

FC

49

10

0n F

C6

51

00

n F

IOs

Mu

ltip

lexe

dIO

s M

ult

iple

xed

ULP

I_

D4

ULP

I_

D5

ULP

I_

D6

ULP

I_

D7

R7

11

0K

C7

51

uF

BO

OT

0B

OO

T0

D1

BAT

60

JFIL

M

J P

29

D2

BAT

60

JFIL

M

TP1

4

MC

O1

TP1

6

CPU

CK

TP1

5

MC

O2

A1

8

A1

9A

20

Au

dio

_IN

J P3

4

SB

10

SB

11

SB

12

SB

14

SB

15

SB

16

R3 4

0

R2

04

[N/A

]

R58

0

R2

05

[N/A

]

12

3

JP1 1

23

JP2

PE2

A2

PE3

A1

PE4

B1

PE5

B2

PE6

B3

PI8

D2

PC1

3D

1

PC1

4E

1

PC1

5F1

PI9

D3

PI1

0E

3PI

11E

4

PF0

E2

PF1

H3

PF2

H2

PF3

J2PF

4J3

PF5

K3PF

6K2

PF7

K1PF

8L3

PF9

L2PF

10

L1

PH0

G1

PH1

H1

NR

ST

J1

PC0

M2

PC1

M3

PC2

M4

PC3

M5

PA0

N3

PA1

N2

PA2

P2

PH2

F4PH

3G

4PH

4H

4PH

5J4

PA3

R2

PA4

N4

PA5

P4

PA6

P3

PA7

R3

PC4

N5

PC5

P5

PB0

R5

PB1

R4

PB2

M6

PF11

R6

PF1

2P6

PF1

3N

6PF

14

R7

PF1

5P7

PG0

N7

PG1

M7

PE7

R8

PE8

P8PE

9P9

PE1

0R

9PE

11P1

0PE

12

R1

0PE

13

N11

PE1

4P1

1PE

15

R11

PB1

0R

12

PB11

R1

3

PH6

M11

PH7

N1

2PH

8M

12

PH9

M1

3PH

10

L1

3PH

11L

12

PH1

2K

12

PB1

2P1

2

PB1

3P1

3

PB1

4R

14

PB1

5R

15

PD8

P15

PD9

P14

PD1

0N

15

PD11

N1

4

PD1

2N

13

PD1

3M

15

PD1

4M

14

PD1

5L

14

PG2

L1

5PG

3K

15

PG4

K1

4PG

5K

13

PG6

J15

PG7

J14

PG8

H1

4PC

6H

15

PC7

G1

5

PC8

G1

4

PC9

F14

PA8

F15

PA9

E1

5

PA1

0D

15

PA11

C1

5

PA1

2B

15

PA1

3A

15

PH1

3E

12

PH1

4E

13

PH1

5D

13

PI0

E1

4PI

1D

14

PI2

C1

4PI

3C

13

PA1

4A

14

PA1

5A

13

PC1

0B

14

PC11

B1

3

PC1

2A

12

PD0

B1

2

PD1

C1

2

PD2

D1

2

PD3

D11

PD4

D1

0

PD5

C11

PD6

B11

PD7

A11

PG9

C1

0PG

10

B1

0PG

11B

9PG

12

B8

PG1

3A

8PG

14

A7

PG1

5B

7

PB3

A1

0

PB4

A9

PB5

A6

PB6

B6

PB7

B5

BO

OT

0D

6

PB8

A5

PB9

B4

PE0

A4

PE1

A3

PI4

D4

PI5

C4

PI6

C3

PI7

C2

U1

6A

ST

M3

2F

20

7IG

H 6

VB

AT

C1

VS

SF2

VD

DF3

VS

SG

2

VD

DG

3V

RE

F-N

1

VS

SA

M1

VR

EF+

P1

VD

D A

R1

BY P

AS

S_

RE

GL4

VD

DK4

VS

SM

8

VD

DN

8

VS

SM

9

VD

DN

9

VC

AP

M1

0

VD

DN

10

VS

SH

12

VD

DJ1

2

VS

S_

SA

D5

VD

DJ1

3V

SS

G1

2V

D D

H1

3

VC

AP

F13

VS

SF1

2

VD

DG

13

VS

SD

9

VD

DC

9

VS

SD

8

VD

DC

8

VS

SD

7

VD

DC

7

RFU

C6

VD

D_

SA

C5

U1

6 B

ST

M3

2F

20

7IF

T6

LCD

_H

SY

NC

LCD

_V

SY

NC

LCD

_C

S

R8

11

0KJP 4

+3

V3

12

3

JP1

6

I2S

_C

KIN

R51

0R

66

[N/A

]

C5

84

.7u

F

ST

M3

2F

21

7IG

H 6

ST

M3

2F

45

7IG

H 6

ST

M3

2F

46

7IG

H 6

Op

tio

na

l

- R

F U

me

an

s R

ese

rve

d f

or

Futu

re U

se.

- A

s a

n o

pti

on

, R

FU c

ou

ld b

e ti

ed

to

VD

D o

r V

SS

fo

r fo

rwa

rd

com

pa

tib

ility

wit

h f

utu

re S

TM

32

F p

rod

uct

s. H

ow

ev

er,

use

r m

ay l

eav

e

R FU

pin

co

nn

ect

ed

to V

DD

, o

r V

SS

, o

r N

C fo

r S

TM

32

F

ev i

sul

cx

e xx

2u

se.

- J P

4 sh

ou

ld b

e fi

tte

d f

or

futu

re b

ack

wa

rd c

om

pa

tib

ility

wit

h s

TM

32

F2xx

.

Page 71: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049 Schematics

Doc ID 022809 Rev 2 71/81

Figure 42. STM3220-21-45-46G-EVAL_Ethernet

MII

_T

XD

0M

II_

TX

_E

N

MII

_T

X_

CLK

MII

_R

XD

0

MII

_R

X_

ER

MII

_R

X_

DV

/RM

II_

CR

SD

V

MII

_R

X_

CLK

/RM

II_

RE

F_

CL

K

MII

_C

OL

MII

_C

RS

MII

_M

DC

MII

_M

DIO

X1 25

MH

z (w

ith

so

cke

t)C

14

22

pF

C1

52

2p

F

12

3JP5

MCO

EN1

GND

2O

UT

3V

CC4

U3

SM

77

45

HE

V-5

0.0

M (

do

no

t fi

t)

+3

V3

R2

61

0 K

RE

SE

T# R2

4

0

JP8

R4

0

2K

2

+3

V3

+3

V 3

R2

5

4.8

7K

R3

02

K2

+3

V 3

R3

32

K2

C2

10

.1u

FC

17

0.1

u F

C1

90

.1u

F

C1

31

0u

F

R4

2

2K2

MII

_T

XD

1

MII

_T

XD

2M

II_

TX

D3

MII

_R

XD

1

MII

_R

XD

2M

II_

RX

D3

TX

_C

LK1

TX

_E

N2

TX

D_

03

TX

D_

14

TX

D_

25

TX

D_

3/S

NI_

MO

DE6

PWR

_D

OW

N/IN

T7

NC

8N

C9

NC

10

NC

11N

C1

2 R

D-

13

RD +

14

AG

ND

15

TD

-1

6T

D+

17

PFB

IN

11

8

AG

ND

19

NC

20

NC

21

AV

DD

33

22

P FB

OU

T2

3

RB

IA

S2

4

25

MH

z_O

UT

25

LE

D_

AC

T/C

OL/

AN

_EN

26

LED

_SP

EE

D/A

N1

27

LE

D_

LIN

K/A

N0

28

RE

SE

T_

N2

9

MD

IO3

0M

DC

31

IOV

DD

33

32

X23

3

X13

4

IOG

ND

35

DG

ND

36

PFB

IN

23

7

RX

_C

LK3

8R

X_

DV

/MII

_M

ODE

39

CR

S/C

RS

_D

V/L

ED_

CF

G4

0

RX

_E

R/M

DIX

_E

N4

1

CO L

/PH

YAD0

42

RX

D_

0/P

HYA

D14

3

RX

D_

1/P

HYA

D24

4

RX

D_

2/P

HYA

D34

5

RX

D_

3/P

HYA

D44

6

IOG

ND

47

IOV

DD

33

48

U5

DP

83

84

8C

VV

+3

V 3

C1

60

.1u

FC

27

0.1

u F

C2

00

.1u

F

+3

V3

R4

31

.5K

12

3

JP6

TP1

25

MH

z

TD

+1

TCT

4

TD

-2

RD +

3

RC

T5

R D -

6

NC

7

CH

S G

N D

8

LE

D(g

ree

n)_

A9

LE

D(g

ree

n)_

K1

0

LE

D(Y

ello

w)_

A1

2

LE

D(Y

ello

w)_

K11

Sh

ield

13

Sh

ield

14

CN

7

J00

11D

21

B

R2

22

40

R1

24

0

+3

V3

C7

0.1

u F

C6

0.1

u F

+3

V3M

II_I

NT

R41

0

R44

0S

eco

nd

so

urc

e:

S I -

60

116

-F

RS

55

1R

S3

51

RS

6

51

+3

V3Un

use

d in

RM

II m

od

e

RS

1

2K

2

RS

45

1

RS

2

51

PI1

0

PC1

PC2

PC3

PA1

PA2

PH2

PH3

PA7

PC4

PC5

PG11

PH6

PH7

PG1

3PG

14

PB1

4

PB8

PA8

SB

1

R2

08

51

R2

12

15

0

AM12008v1

Page 72: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

Schematics AN4049

72/81 Doc ID 022809 Rev 2

Figure 43. STM3220-21-45-46G-EVAL_LCD

Tou

ch

Sc

ree

n_

X+

Tou

ch

Scre

en

_X

-

Tou

ch

Sc

ree

n_

Y+

Tou

ch

Scre

en

_Y-

CS

1

RS

2

WR

/SC

L3

RD

4

RE

SE

T5

VD

D2

4

VC

I2

5

GN

D2

6

GN

D2

7

BL

_V

DD

28

BL

_C

on

tro

l2

3B

L_

GN

D2

2

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

SD

O2

9

SD

I3

0X

L3

1

XR

32

YD3

3

YU3

4

CN

19

3.2

" LC

D_

co

nn

ec

tor

(M

B7

85

wit

h A

M-2

40

32

0D

4T

OQ

W-T

00

H(R

))

+3

V3

+5

V

To I/O expandor

RE

SE

T#

D[0

..15

]

A[0

..20

]A

[0..2

0]

D[0

..15

]

FSM

C_

NW

EFS

MC

_NO

E

FSM

C_

NE3

D0

D1

D2

D3

D4

D5

D6

D7

D8

D9

D10

D11

D12

D13

D14

D15

A0

PD

5P

D4

PG

10

R1

70

15

0R

17

11

50

R1

72

15

0R

17

31

50

R1

74

15

0R

17

51

50

R1

76

15

0R

17

71

50

R8

21

50

R1

61

15

0R

16

31

50

R1

65

15

0R

16

61

50

R1

67

15

0R

16

81

50

R1

69

15

0

R7

81

50

R11

91

50

R1

62

15

0R

16

41

50

C1

48

10

uF

L2 BE

AD

C1

53

10

0n

F

L1 BE

AD

LCD

_H

SY

NC

LCD

_V

SY

NC

LCD

_C

S

12

34

56

CN

22

He

ade

r 3

X2

H

PC[0

..15

]PC

10PC

11PC

12

PC[0

..15

]

Re

serv

ed

fo

r LC

D c

on

ne

cto

r

R6

70

+3

V3

R6

8[N

/A]

AM12009v1

Page 73: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049 Schematics

Doc ID 022809 Rev 2 73/81

Figure 44. LCD module with both SPI and 16-bit interface

AM12004v1

Ena

ble

Dot

Clk

HS

YN

CV

SY

NC

CS

RS

WR

RD

#RE

SE

T

SD

OS

DI

VD

D

PD0

PD1

PD2

PD3

PD4

PD5

PD6

PD7

PD8

PD9

PD10

PD11

PD12

PD13

PD14

PD15

PD16

PD17

YU

YD

XR

XL

VS

S1

XL

2X

R3

YD

4Y

U5

VS

S6

IM0/

ID7

IM1

8

IM3

9

SD

O10

NC

11

SD

I12

D17

13D

1614

D15

15D

1416

D13

17D

1218

D11

19D

1020

D9

21D

822

D7

23D

624

D5

25D

426

D3

27D

228

D1

29D

030

CS

31

RE

SE

T32

RS

33

WR

/SC

L34

RD

35

VS

YN

C36

HS

YN

C37

DO

TC

LK38

EN

AB

LE

39

VC

C40

VC

C41

VS

S42

LE

D_K

43L

ED

_A44

VS

S45

CN

2

FF02

45S

S1

R4

0

R1

10K

VD

D

RP1

10K

RP2

10K

RP4

10K

PD0

PD2

PD4

PD6

PD8

PD9

PD10

PD11

PD12

PD13

PD14

PD15

PD16

PD17

Ena

ble

Dot

Clk

HS

YN

C

VS

YN

C

VD

D

C3

1uF/

50V

R3

4K7

R2

4K7

SD

IS

DO RD

RS

Sol

dere

d fo

r S

eria

l in

terfa

ce o

nly

Sol

dere

d fo

r i8

0-sys

tem

16-b

it in

terfa

ce

The

34-

pin

conn

ecto

r to

mot

her

boar

d fo

r bo

th

seria

l &

16b

it in

terfa

ce.

Com

patib

le w

ith

MB

694

with

Tou

ch s

cree

n si

gnal

s ad

ded

on

Pin

31-34

.

CS

RS

WR

RD

#RE

SE

T

VD

D

BL

GN

D

BL

VD

D

BL

_Con

trol

PD1

PD2

PD3

PD4

PD5

PD6

PD7

PD8

PD10

PD11

PD12

PD13

PD14

PD15

PD16

PD17

SD

OS

DI

A K

Z1

ST

PS1L

40M

C1

4.7u

F/50

V

L1

4.7u

H(1

A)

R7

10

BL

GN

D

BL

VD

D

R6

100K

C2

2.2u

F R5

0

R8 do

not

fit

BL

VD

D

BL

_Con

trol

BL

GN

D

BL

GN

D

BL

GN

D

AM

-240

320D

4TO

QW

-T00

H(R

)

Vi

1

Rse

t2

GN

D3

FB4

NC

5V

o6

EN

7

SW

8

PGN

D9

U1

ST

LD40

DPM

R

CS

1

RS

2

WR

/SC

L3

RD

4

RE

SE

T5

VD

D24

VC

I25

GN

D26

GN

D27

BL

_VD

D28

BL

_Con

trol

23B

L_G

ND

22

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

SD

O29

SD

I30

XL

31

XR

32

YD

33

YU

34

CN

1

3.2L

CD

_con

nect

or

YU

YD

XR

XL

LC

D b

oard

con

nect

or t

o M

othe

r bo

ard

RP3

10K

RP6

10K

RP5

10K

PD1

PD3

PD5

PD7

Page 74: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

Schematics AN4049

74/81 Doc ID 022809 Rev 2

Figure 45. STM3220-21-45-46G-EVAL I/O peripherals

AM12010v1

R147

10K

R146

10K

R145

10K

R144

10K

R149

10K

+2V8

C11

91

00

nF

C128

10

0n

F

C120

10

0n

F

C129

10

0n

F

C121

10

0n

FR159

100COMMON

5

Selection2

DWON3

LEFT1

RIGHT4

UP6

U32

MT008-A

JOY_SELJOY_DOWNJOY_LEF TJOY_RIGHTJOY_UP

To IO expandor

EEP ROM_SCLEEP ROM_SD A

E01

E12

E23

VSS4

SDA5

SCL6

WC7

VCC8

U18

M24C64- RMN6TP

+3V3

R10210K

JP24

C81

100nF

PB9PB6

R153220K

143 2

B2WK UP

C124do not fit

+3V3

R138

100R1484K7

1 432

B4USER C130

100n F

+3V3

R160

100

R1424K7

1 432

B3Tamper C118

100n F

+3V3

R156

100

R139

330

R150

0

R1430

Anti_Tamper

WAKEUP

User_ButtonPC13

PA0

PG15

31

2 RV13386P-103H[10%]

R151

0

+3V3

Potentiometer

C12210nF

R152

1K

PF9

1 2

LD3Red

1 2

LD2Orange

1 2

LD4Blue

1 2

LD1Green

R155

510

R154

680

R141

680

R140

680LED4

LED3

LED1

LED2

PG6

PG8

PI9

PC7

MEMS_SCLMEMS_SDA

MEMS_I NT1MEMS_I NT2

VDD_IO1

GND2

Reserved3

GND4

GND5

VD D6

CS7

INT18

INT29

GND10

Reserved11

SDO12

SDA13

SCL14

U20

LI S302D L

+2V8R10710 K

+2V8

C89

100nF

To I O expandor

PB9PB6

Page 75: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049 Schematics

Doc ID 022809 Rev 2 75/81

Figure 46. STM3220-21-45-46G-EVAL I/O_Expander

AM12011v1

Y-1

INT2

A0/Data Out3

SCL K4

SDA T5

VCC6

Data in7

IN08

IN19

GND10

IN211

IN312

X+13

Vio14

Y+15

X-16

U24

STMP E811Q T R

Y-1

INT2

A0/Data Out3

SCLK4

SDA T5

VCC6

Data in7

IN08

IN19

GND10

IN211

IN312

X+13

Vio14

Y+15

X-16

U29

STMP E811Q T RR13510K

+2V 8

I2C device address:0x82

I2C device address:0x88

+2V8

+2V8

R116100K

R132100K

IO_Expandor_SCKIO_Expandor_ SDAIO_Expandor_INT

TouchScreen_X+

TouchScreen_X-TouchScreen_Y+

TouchScreen_Y-

EXP _IO2EXP _IO3EXP _IO4EXP _IO5EXP _IO6EXP _IO7EXP _IO8

EXP _IO 9EXP _IO10EXP _IO11EXP _IO12

EXP _IO1

R12110K

R136 0

+2V8

R11710K

R13110K

+2V8

C99100nF

C115100n F

PB9PB6

PI2

Page 76: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

Schematics AN4049

76/81 Doc ID 022809 Rev 2

Figure 47. STM3220-21-45-46G-EVAL JTAG and trace

AM12012v1

1 2 3 4 5 6 7 8 9 10

11 12

13

14

15

16

17

18

19

20

+3

V3

R97

[N/A

]

R96

[N/A

]

R1

01

[N/A

]

R95

[N/A

]

R9

8d

o n

ot

fit

+3

V3

1 2 3 4 5 6 7 8 9 10

11 12

13

14

15

16

17

18

19

20

+3

V3

+3

V3

R1

05

10

K

R1

06

10

K

R99

10K

R92

[N/A

]

R1

04

0R

10

0do

no

t fi

tR

940

R91

do

no

t fi

t

TRA

CE_

D3

TRA

CE_

D2

TRA

CE_

D1

TRA

CE_

D0

TRA

CE_

CK

PA13

PA14

PB3

PA15

PB4

PE6

PE5

PE4

PE3

PE2

TDI

RES

ET#

TRST

TMS/

SWD

IOTC

K/S

WC

LK

TDO

/SW

O

D8 Z5V1

RS7

22

D3 Z5V1

D4 Z5V1

D5 Z5V1

D6 Z5V1

D7 Z5V1

Page 77: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049 Schematics

Doc ID 022809 Rev 2 77/81

Figure 48. STM3220-21-45-46G-EVAL_Power

AM12013v1

Vin3

GN

D1

Vout2

U22LD1086D2M33TR

C113220uF

C8310uF

C82100nF

+5V3V3

+3V3

Vin3

Vout2

1

U21LD1117S25TR+5V

C9110uF

+2V 5

TP 62V 5

C96220uF

Vin3

Vout2

1

U30LD1117S18TR

C11610uF

+1V8

1V8

+3V3 VDD_ MCUJP32

SV1

SG2

CV3

CG14

CG25

CG36

U25

BNX002-01

C10610uF

E5 V1

32

CN18

DC- 10BZ1SMAJ5.0A-TR C112

100nF

1

2

3

U28ZEN056V130A24LS

TP 85V

+5V

R931K

12

LD 9red

TP13Ground

D5VE5V

VBUS_FS

VBUS_H S

Vin3

Vout2

1

U26LD1117STR+5V

C11010u F

+2V8

TP 92V 8

R114120

C10010uF

R120150

1 23 45 67 89 10

JP18

Header 5X2

U5V_ST_LIN K

Page 78: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

Schematics AN4049

78/81 Doc ID 022809 Rev 2

Figure 49. STM3220-21-45-46G-EVAL_Extension connector

AM12014v1

RE

SE

T#

RE

SE

T#

12

34

56

78

91

011

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

CN4

21

N2

25

64

- 40

S1

0B

1 23 45 67 89 1011 1213 1415 1617 1819 2021 2223 2425 2627 2829 3031 3233 3435 3637 3839 4041 4243 4445 4647 4849 50

CN121N22564 -50S10B

12

34

56

78

91

011

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

CN2

21

N2

25

64

-40

S1

0B

1 23 45 67 89 1011 1213 1415 1617 1819 2021 2223 2425 2627 2829 3031 3233 3435 3637 3839 4041 4243 4445 4647 4849 50

CN321N22564- 50S10B

1AP0APPA2

PA3

P A

4PA

5PA

6PA

7

PA8PA10PA11PA12

PA13

P A

14P

A15

PB0

PB1

PB2

PB3

P B

4PB

5P

B 6

PB7

P B

8P

B 9

PB10

PB11

PB12PB13PB14PB15

PC02CP1CP

PC3

PC4

P C

5

PC6PC7PC8PC9

P C

10

P C

11P

C12

PC13EXT_PC14EXT_PC15

PD0

P D

1P

D2

P D

3P

D4

P D

5P

D6

P D

7

PD8PD9PD10PD11PD12PD13PD14

PD15

P E 0

P E

1

PE24EP3EP6EP5EP

PE7

PE8

PE9

PE1

0PE

11PE

12PE

13PE

14PE

15

1FP0FP3FP2FP

PF4PF5 PF6PF7 PF8

01FP9FP

PF11

PF1

2PF

13

PF1

4PF

15

PG0

PG1

PG2PG3PG4PG5PG6PG7PG8

P G

9P

G1

0P

G11

P G

12P

G13

P G

14P

G 1

5

EXT_PH0 EXT_PH1

PH2PH3

5HP4HP

PH6

PH7

PH8

PH9

PH10

PH11

PH12

PH13PH14PH15PI0PI1PI2

PI3

P I

4 6I

P5I

P P I7

PI8

PI911IP01IP

VR

EF+

EM

U_

3V

3

EM

U_

5V

APP

_3

V3

APP

_VCC

PC13RESET #

EM

U_

5V

EM

U_

3V

3

EM

U_

5V

APP

_3

V3

BO

OT

0

(Le

ft)

(Rig

ht)

(Buttom) (Top)

PA[0

..15

]PA

[0..1

5]

PB[0

..15

]PB

[0..1

5]

PC[0

..15

]PC

[0..1

5]

PD[0

..15

]PD

[0..1

5]

PE[0

..15

]PE

[0..1

5]

PF[0

..15

]PF

[0..1

5]

PG[0

..15

]PG

[0..1

5]

PH[0

..15

]PH

[0..1

5]

PI[0

..11

]PI

[0..1

1]

APP

_3

V3

AP

P_V

CC

EM

U_

5V

D5

V

+3

V3

SB

6

SB

7

SB

4

SB

5

PH0

PH1

PC1

4

PC15

EX

T_

PH

0

EX

T_

PH

1

EX

T_

PC

14

EX

T_

PC

15

Clo

se t

o cr

yst

al o

n

PC

B

BO

OT0

BO

OT0

VB

US

_F

S

Page 79: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049 References

Doc ID 022809 Rev 2 79/81

11 References

1. STEVAL-IHP004V1 schematics diagram

2. M24LR64, datasheet

3. STM322xG-EVAL evaluation board - UM1057, user manual

4. AN3128, application note

5. ZigBee-Dual IFs EEPROM Adapter for STM322xG-EVAL - UM1519, user manual

6. SPZB32W1A2.1 module, datasheet

7. UM0853, user manual

Page 80: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

Revision history AN4049

80/81 Doc ID 022809 Rev 2

12 Revision history

Table 23. Document revision history

Date Revision Changes

24-Jul-2012 1 Initial release.

12-Oct-2012 2 Modified: code in the Section 6.3.1

Page 81: In-Home Display with HTTP gateway - Farnell · PDF fileIn-Home Display with HTTP gateway ... “In-Home Display gateway”, is made up of three main ... plugged into an electrical

AN4049

Doc ID 022809 Rev 2 81/81

Please Read Carefully:

Information in this document is provided solely in connection with ST products. STMicroelectronics NV and its subsidiaries (“ST”) reserve theright to make changes, corrections, modifications or improvements, to this document, and the products and services described herein at anytime, 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 noliability 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 thisdocument 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 productsor services, or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoever of suchthird 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 IMPLIEDWARRANTY WITH RESPECT TO THE USE AND/OR SALE OF ST PRODUCTS INCLUDING WITHOUT LIMITATION IMPLIEDWARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE (AND THEIR EQUIVALENTS UNDER THE LAWSOF ANY JURISDICTION), OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT.

UNLESS EXPRESSLY APPROVED IN WRITING BY TWO AUTHORIZED ST REPRESENTATIVES, ST PRODUCTS ARE NOTRECOMMENDED, AUTHORIZED OR WARRANTED FOR USE IN MILITARY, AIR CRAFT, SPACE, LIFE SAVING, OR LIFE SUSTAININGAPPLICATIONS, 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 "AUTOMOTIVEGRADE" 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 voidany warranty granted by ST for the ST product or service described herein and shall not create or extend in any manner whatsoever, anyliability 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.

© 2012 STMicroelectronics - All rights reserved

STMicroelectronics group of companies

Australia - Belgium - Brazil - Canada - China - Czech Republic - Finland - France - Germany - Hong Kong - India - Israel - Italy - Japan - Malaysia - Malta - Morocco - Philippines - Singapore - Spain - Sweden - Switzerland - United Kingdom - United States of America

www.st.com