JN UG 3028 CodeBlocks 1v8
JN UG 3028 CodeBlocks 1v8
JN UG 3028 CodeBlocks 1v8
Jennic
Jennic 2008
JN-UG-3028 v1.8
Jennic
4
4 5 5 5 5
Contents
About this Manual
Organisation Conventions Acronyms and Abbreviations Related Documents Feedback Address
7 9
9 10
11
11 12 17 18 18 20 21
23
23 23 24 26
27
27 28 31 32 35 36 37 39
Appendices
A The Integrated Debugger Explained B Installing the USB-to-Serial Cable Driver C Identifying PC Communications Port Used D Setting the Comms Port for the Flash Programmer E Using Code::Blocks to Build Custom Libraries
41
41 43 44 45 47
JN-UG-3028 v1.8
Jennic 2008
Jennic
About this Manual
This User Guide is designed to help you use the Code::Blocks IDE (Integrated Development Environment) to develop applications for devices in the Jennic wireless microcontroller family. The guide focuses on tasks required to implement applications on Jennic devices and does not cover all the features and functionality of Code::Blocks.
Caution: This User Guide refers to Jennics version of Code::Blocks. It should not be used in conjunction with any other version of Code::Blocks.
Organisation
This manual consists of five chapters and five appendices, as follows: Chapter 1 provides a brief overview of using the Code::Blocks IDE. Chapter 2 provides a quick start to using Code::Blocks by describing how to use the IDE to open and build example applications supplied by Jennic. Chapter 3 describes how to create and build your own Code::Blocks projects, and provides advice on dealing with compilation errors. Chapter 4 describes how to download your executable code to the Flash memory of the Jennic wireless microcontroller. Chapter 5 explains how to debug your application with the help of Code::Blocks. The appendices describe the operation of the integrated debugger, how to install the USB-to-serial cable driver, how to identify the PC communications port allocated to a network connection, how to set the PC communications port for the integrated Flash programmer and how to build a custom library in Code::Blocks.
Note: Once you have installed and configured Code::Blocks, you are advised to practise using the IDE with the example applications (as described in Chapter 2) before creating and building your own projects.
Jennic 2008
JN-UG-3028 v1.8
Jennic
Conventions
Files, folders, functions and parameter types are represented in bold type. Function parameters are represented in italics type. Code fragments are represented in the Courier typeface.
Related Documents
[1] [2] Jennic Software Developers Kit Installation Guide (JN-UG-3035) Jennic JN51xx Flash Programmer Application User Guide (JN-UG-3007)
Feedback Address
If you wish to comment on this manual, or any other Jennic user documentation, please provide your feedback by writing to us (quoting the manual reference number and version) at the following postal address or e-mail address: Applications Jennic Ltd Furnival Street Sheffield S1 4QT United Kingdom [email protected]
JN-UG-3028 v1.8
Jennic 2008
Jennic
Jennic 2008
JN-UG-3028 v1.8
Jennic
1 Overview
For developing applications in an IDE (Integrated Development Environment), Jennic recommends the use of Code::Blocks. This is a full-featured, open source IDE which is available free-of-charge. When developing applications for the Jennic wireless microcontrollers, you should use the specially adapted version of Code::Blocks available from Jennic. This version of Code::Blocks is available as part of the Jennic Software Developers Kit (SDK) Toolchain (JN-SW-4031), but may be selected as an individual option. Installation instructions are provided in the Jennic SDK Installation Guide (JN-UG-3035). The Jennic SDK Toolchain installer and the Installation Guide are available on the: Jennic evaluation kit CDs Support area of the Jennic web site (www.jennic.com/support) This manual describes how to: Create a Code::Blocks project for your application Edit your application code, as required, using the Code::Blocks editor Build your application, to produce a binary file Download your binary file to the device that is to run the application Use Code::Blocks in debugging your application code
Note: Before creating and building your own projects, you are recommended to follow the instructions in Chapter 2 to practise using Code::Blocks with the example applications available on the Jennic web site.
JN-UG-3028 v1.8
Jennic 2008
Jennic
Jennic 2008
JN-UG-3028 v1.8
Jennic
Note: You are advised to practise using Code::Blocks with the examples before you use the IDE with your own applications.
Important: In order to build the software provided with an Application Note, the applications folder must be placed directly under: C:\Jennic\cygwin\jennic\SDK\Application The above directory is automatically created when you install the latest Jennic Software Developers Kit (SDK). You can obtain the latest versions of the SDK libraries and SDK toolchain from the Support area of the Jennic web site (www.jennic.com/support). The relevant part codes are JN-SW-4030 for the SDK libraries and JN-SW-4031 for the SDK toolchain.
JN-UG-3028 v1.8
Jennic 2008
Jennic
2.2 Opening and Building an Example Project
Once you have downloaded an example application from the Jennic web site: Step 1 Unzip the example application into the directory C:\Jennic\cygwin\jennic\SDK\Application The application folder created should be located directly under \SDK\Application. The top level of the applications folder contains a .cbp file for each possible target device type (JN5121 or JN5139) - this is the Code::Blocks project file for the application. Step 2 Step 3 Run Code::Blocks. Open the appropriate .cbp project file (for the target device type) by following the menu path File>Open and browsing for the file. The .c source file and any other files specified in the project can now be accessed via the Projects tab of the left pane in the Code::Blocks window (to view the source code, double-click on the .c file). The compiler and paths to use are also defined. Step 4 Check which compiler is set, as follows: a) b) c) Step 5 Step 6 Follow the menu path Project>Build options to display the Project build options screen. Click on the project name at the top of the tree displayed in the left pane of the screen. Check the Selected compiler field this should show the JN51xx Compiler. If not, select it from the drop-down list.
Make any required edits to the code, using Code::Blocks as the editor. Build the example by following the menu path Build>build. A .bin file is generated and output to a sub-directory that is created by the build process and called JN5121_Build or JN5139_Build, depending on the target device.
Note: To download the .bin file to the target device, refer to Chapter 4.
10
Jennic 2008
JN-UG-3028 v1.8
Jennic
Note: The Jennic installation of Code::Blocks puts a file called default.conf on the C drive of your computer, in the directory Documents and Settings\<user>\Application Data\ codeblocks. This file is used to pre-configure the JN51xx Compiler with the appropriate program files and paths.
Note: Jennic have simplified the project creation process by providing a wizard which can be selected when project creation is first entered. As part of the project creation process, Code::Blocks creates a project file, with extension .cbp. This is put into the project directory, along with the C source file(s). The project file contains essential project information, such as all required directory paths and the compiler to use for building the application. Once created, a project can be displayed and manipulated in the Projects tab in the Management pane on the left of the Code::Blocks window. The rest of this chapter describes: How to create a Code::Blocks project (see Section 3.2) How to work on a project in Code::Blocks (see Section 3.3) How to build a project (see Section 3.4)
JN-UG-3028 v1.8
Jennic 2008
11
Jennic
3.2 Creating a Project
To create your own project: Step 1 Step 2 In Code::Blocks, follow the menu path File>New>Project. This displays the New from template screen.
In this screen, select the Jennic icon and then click Go. This starts the Jennic project wizard.
Step 3
In the first screen of the wizard, simply click Next (and, if desired, tick the checkbox Skip this page next time).
12
Jennic 2008
JN-UG-3028 v1.8
Jennic
In the Project title field, enter a name for your project (this is used to create the project filename see Substep c below). In the field Folder to create project in, navigate to the appropriate directory as follows: If you are using the latest Jennic SDK version, the project area is normally C:\Jennic\cygwin\jennic\SDK\ If you are using an earlier Jennic SDK version, the project area may be C:\Jennic\cygwin\jennic\developer\
Step 4
c) d)
The remaining two fields (Project filename and Resulting filename) are filled in automatically by the wizard leave them unchanged! Click Next.
JN-UG-3028 v1.8
Jennic 2008
13
Jennic
Step 5 Step 6 In the next screen, select the JN51xx Compiler and click Next.
Now select the environment in which you will work on the application: If you are using the latest Jennic SDK version, you will normally work in the SDK directory: C:\Jennic\cygwin\jennic\SDK\ If you are using an earlier Jennic SDK version (from a JN5121 evaluation kit), you may work in the developer directory: C:\Jennic\cygwin\jennic\developer\ Then click Next.
14
Jennic 2008
JN-UG-3028 v1.8
Jennic
Step 7
In the next screen, choose the application type. The following are always presented: IEEE 802.15.4 application ZigBee End Device ZigBee Co-ordinator ZigBee Router If you have installed the Jenie software patch (JN-SW-4029), the following will also be presented: Jenie End Device Jenie Co-ordinator Jenie Router Jenie-ZigBee End Device Jenie-ZigBee Co-ordinator Jenie-ZigBee Router The Jenie options are used for Jenie running on JenNet, and the Jenie-ZigBee options are used for Jenie running on ZigBee. Then click Next.
Step 8
Now select the type of board to which the application will be downloaded, from the following: DK1 board (from JN5121-EK000 or JN5121-EK010 evaluation kit) DK2 board (from JN513x-EK000 or JN513x-EK010 evaluation kit) NTS (Network Test System) board High-Power Development Kit board Then click Next.
JN-UG-3028 v1.8
Jennic 2008
15
Jennic
Step 9
In the next screen, select the type of Jennic wireless microcontroller on which you will run the application, from the following (your chip type is marked on the chip or module): JN5121 JN513x (select this option for the JN5139) JN513xR1 (select this option for the early version of the JN5139) Finally, click Finish. Your project has been created!
Note: A Code::Blocks project file (with extension .cbp) has been created in the directory C:\Jennic\cygwin\jennic\SDK\<project name> or C:\Jennic\cygwin\jennic\developer\<project name>
16
Jennic 2008
JN-UG-3028 v1.8
Jennic
!
Step 5
Caution: You must rename the .c source file before saving it. Once the file has been saved, the rename option is removed.
To display the code in the main pane, double-click on the .c source file in the Projects tab. You can now edit the code in the main pane. When you have finished editing the .c source file, ensure that you save your changes (for example, by following the menu path File>Save) and then close the file (for example, by following the menu path File>Close file). You are recommended to save your changes regularly while editing. Once you have finished working on the project, save the project changes (for example, by following the menu path File>Save project) and close the project (for example, by following the menu path File>Close project).
Step 6
Step 7
JN-UG-3028 v1.8
Jennic 2008
17
Jennic
3.4 Building Your Project
This section describes how to prepare for and perform an application build. It also provides advice on dealing with compilation errors.
Step 3
Click on the Compiler sub-tab and ensure that the paths to all the required header files are listed. If you need to add a directory path, use the Add button to specify the new path.
18
Jennic 2008
JN-UG-3028 v1.8
Jennic
Step 4
Click on the Linker sub-tab and ensure that the path to the linker command file is set as follows: If you are working in the SDK directory, the appropriate path depends on the target device type: For the JN5139: C:\Jennic\cygwin\jennic\SDK\Chip\JN513x\Build For the JN5139R1 (early version of JN5139): C:\Jennic\cygwin\jennic\SDK\Chip\JN513xR1\Build For the JN5121: C:\Jennic\cygwin\jennic\SDK\Chip\JN5121\Build If you are working in the developer directory, the appropriate path is: C:\Jennic\cygwin\jennic\developer\Build.
Step 5
Click on the Linker tab (top-level) to obtain the view shown below.
Step 6
Ensure that the paths to all the necessary link libraries are present in the Link libraries field. If you need to add a directory path, use the Add button to specify the new path. Click OK to register any changes and to exit the Project build options screen.
Step 7
JN-UG-3028 v1.8
Jennic 2008
19
Jennic
3.4.2 Performing a Build
!
Step 1
Caution: Before attempting to build your application, make sure you have specified all the necessary paths for the linker and compiler, as described above in Section 3.4.1.
To build a finished project: If the required project is not already open then open the project by following the menu path File>Open and browsing for the relevant .cbp project file. This file should be located in the directory C:\Jennic\cygwin\jennic\SDK\<project name> or C:\Jennic\cygwin\jennic\developer\<project name> Step 2 Step 3 Click on the Projects tab in the Management pane (on the left of the Code::Blocks window), then browse to and click on the project to be built. Select the required build type, Debug or Release, by following the menu path Build>Select target. If you are building for debug purposes, select Debug If you are building for a final release, select Release Alternatively, you can make this choice using the Build target drop-down list in the Code::Blocks toolbar. Step 4 Build the project (for example, by following the menu path Build>build). The resulting binary file is output to a sub-folder of the project folder, as follows: If you are working in the SDK directory path, the output sub-folder is created during the build process and called JN5121_Build or JN5139_Build, depending on the target device. If you are working in the developer directory path, the output sub-folder is Build. In either case, depending on the build type (Debug or Release), the binary file is put in a further sub-folder called Debug or Release.
Note: During the build, log messages are displayed in the Build log and Build messages tabs of the Messages pane at the bottom of the Code::Blocks window.
20
Jennic 2008
JN-UG-3028 v1.8
Jennic
JN-UG-3028 v1.8
Jennic 2008
21
Jennic
22
Jennic 2008
JN-UG-3028 v1.8
Jennic
4.1 Pre-requisites
Ensure that you have the following: A target device containing a Jennic wireless microcontroller. A serial cable and dongle allowing connection between your PC and the target device. The .bin file to be downloaded following a build, this file is placed in the Build\Release or Build\Debug directory for the project, as appropriate.
JN-UG-3028 v1.8
Jennic 2008
23
Jennic
4.2.1 Using the Integrated Flash Programmer
The version of Code::Blocks provided by Jennic includes the possibility of an integrated Flash programmer that allows you to download your binary file to the target device from within Code::Blocks. To use this facility, you must have opted to install it during the installation process. To download your .bin file to a device: Step 1 Step 2 Connect a USB port of your PC to the target device (if prompted to install the device driver for the USB-to-serial cable, refer to Appendix B). In Code::Blocks, follow one of the following menu paths, depending on whether you wish to initiate the download from a GUI (Graphical User Interface) or from the command line:
Note: You will need to set the PC communications port that has been assigned to the connection to the target device to identify this port, refer to Appendix C. If you are going to work from the command line and need to use a PC comms port other than port 1 (the default), refer to Appendix D for details of how to set a port. Tools>Flash GUI The following JN51xx Flash Programmer GUI window is displayed:
24
Jennic 2008
JN-UG-3028 v1.8
Jennic
Tools>Download to Flash You must select the command line option according to the target device and the build type (Debug or Release). The following command window is displayed:
Step 3
Reset the device and put it into programming mode. To do this on boards/modules from kits JN5139-EK000, JN5139-EK010 and JN5139-EK020: a) b) c) Press and hold down the Programming button on the board/module. Press and then release the Reset button on the board/module. Release the Programming button.
Important: For boards from kits JN5121-EK000 and JN5121EK010, reset the board by switching it OFF and then ON again (alternatively, on Controller boards, you can use the Reset button). These boards are automatically put into programming mode when the Flash programmer starts and asserts the RTS line, which is connected to the SPi-bus MISO line. Step 4 To start the download, perform either of the following actions, as appropriate: Browse for the binary file in the GUI window and then click the Program button. Make sure you are in the command window and then press the Enter (or Return) key on your keyboard. Step 5 Once the download has finished, disconnect the device from the PC and powercycle the device.
JN-UG-3028 v1.8
Jennic 2008
25
Jennic
4.2.2 Using a Separate Flash Programmer
If you wish to use a separate installation of the JN51xx Flash Programmer, refer to the procedure for downloading binary code in the Jennic JN51xx Flash Programmer Application User Guide (JN-UG-3007).
26
Jennic 2008
JN-UG-3028 v1.8
Jennic
Caution: When debugging code using the integrated debugger, you are recommended to disable any compiler optimiser settings, otherwise the debugger may not operate correctly. For more information, refer to the tip on page 35.
JN-UG-3028 v1.8
Jennic 2008
27
Jennic
5.1.1 Configuring the Integrated Debugger
The procedure below describes how to configure the integrated debugger. Step 1 Step 2 Step 3 Step 4 Connect a USB port of your PC to the target device (if you are prompted to install the device driver for the USB-to-serial cable, refer to Appendix B) Start Code::Blocks (if not already started). Follow the menu path Settings>Compiler and debugger. This displays the Compiler and debugger settings screen. Select the Debugger settings icon from the left panel and fill in the dialogue box as follows: a) Update the following lines in the Debugger initialisation commands field:
set remotebaud 9600 target remote /dev/ttyS2
Note that this assumes you will use a baud rate of 9600 bps. However, you can use a different baud rate, if you wish see Section 5.1.3. It also assumes you will use serial communications port COM3 for debugging. If you need to use a different serial port, change x in /dev/ttySx accordingly (note that COM1 corresponds to ttyS0, COM2 to ttyS1 and so on). You can identify the serial port that has been allocated to the connection with the target device as described in Appendix C. b) If necessary, also update the source code paths in the Debugger initialisation commands field. For example, if the source files are stored in the folder Source_v1, modify the dir lines to:
dir ..\Source_v1 dir ..\..\Source_v1
c) d)
Ensure that the checkbox Do not run the debugee (program to be debugged) is selected. In the area Choose disassembly flavor (GDB only), from the drop-down list select Custom (specify instruction set) and in the right field enter or32. This screen should then look like the screenshot below.
28
Jennic 2008
JN-UG-3028 v1.8
Jennic
Step 5 Step 6
Select the Global compiler settings icon from the left panel and then in the Selected compiler field, ensure that the JN51xx compiler is selected. Select the Programs tab and then the Program Files sub-tab, and set the Debugger field to ba-elf-gdb.exe. This screen should then look as shown in the screenshot below.
JN-UG-3028 v1.8
Jennic 2008
29
Jennic
Step 7 Step 8
Select the Compiler tab and then the Compiler Flags sub-tab, and ensure that the checkbox Produce debugging symbols [-g] is ticked. Click on OK to register all changes and leave the Compiler and debugger settings screen.
30
Jennic 2008
JN-UG-3028 v1.8
Jennic
b)
Add the following as the first few lines of the function AppColdStart() or, in the case of a Jenie application, the function vJenie_CbInit():
#ifdef GDB /* Debug hooks: include regardless of whether debugging */ HAL_GDB_INIT(); HAL_BREAKPOINT(); #endif
Step 3
In Code::Blocks, ensure that optimisation is OFF in Project>Build options and that the defines in your project build options include "GDB". If your application is based on an example provided by Jennic or generated using the New Project wizard, this should have already been done. Build the application for a Debug target, as described in Section 3.4. Download the resulting debug binary file to the device which is to run the application, using the Jennic Flash programmer as described in Section 4.2. Once the download has completed, close the Flash programmer in order to release the serial port for the debugger to use (otherwise, GDB will not be able to access the serial port). Open the Watch window by following the menu path Debug>Debugging Windows>Watches. Set the desired breakpoints by right-clicking on the required line and selecting Toggle breakpoint from the menu. A red dot then appears next to the line number. Do this for as many breakpoints as you need. Reset the target device. This puts the target device under the control of GDB and enables Code::Blocks to control the device. Start the debugger by following the menu path Debug>Start or clicking on the Debug/Continue icon. There will be a short pause before the debugger is ready for use. A yellow arrow appears on the source display to show the current debug position in the code - this should be the default GDB breakpoint, HAL_BREAKPOINT.
Step 7 Step 8
Step 9 Step 10
JN-UG-3028 v1.8
Jennic 2008
31
Jennic
Step 11 Start debugging by performing the following actions, as appropriate:
Use Run to cursor, Single step (and other options), as appropriate. To watch any local variables, click on the '+' to open the tree in the Watch window. To end the debugger session, follow the menu path Debug>Stop Debugger. Once the debugger session has been stopped, to run the debugger again go back to Step 9 and continue from there. Practical advice on using the integrated debugger is provided in the next section.
Note that changing the baud rate in your code, as described above, modifies the baud rate of the UART on the JN51xx device. You must also change the PC baud rate in Code::Blocks, as described in Section 5.1.1. In addition to E_AHI_UART_RATE_38400 (for 38400 bps), other enumerations are available for different baud rates. These are defined in the header file AppHardwareApi.h and listed in Table 1 below.
32
Jennic 2008
JN-UG-3028 v1.8
Jennic
Baud Rate (bps) 4800 9600 19200 38400 76800 115200 Enumeration E_AHI_UART_RATE_4800 E_AHI_UART_RATE_9600 E_AHI_UART_RATE_19200 E_AHI_UART_RATE_38400 E_AHI_UART_RATE_76800 E_AHI_UART_RATE_115200 Value 0 1 2 3 4 5
Caution: The baud rate of 9600 will work for all JN51xx devices and developer platforms. As the baud rate is increased, the debug system may fail due to platform variations. In this case, you are recommended to use a lower baud rate, or the default 9600 bps.
Preventing Watchdog timer operation during debug All watchdog hardware timers will continue to run while the debugger is held at a breakpoint and could timeout, forcing a reset. This gives the impression that the debugger is not running correctly the cursor will jump back to HAL_BREAKPOINT, giving the appearance that no debug progress is being made. To avoid this situation, watchdog operation must be prevented during debug this is achieved with a conditional compile around the watchdog timer instruction, implemented using a GDB define, as shown in the following example:
#ifndef GDB /* Initialise and start the watchdog */ InitWatchDogTimer(); #endif
Preventing the use of UART0 during debug The integrated debugger uses UART0. Therefore, you must not use UART0 for other purposes during debug. This can be achieved by including any actions that involve UART0 in a GDB define, as in the following example:
#ifndef GDB /* Comms activity on UART0 */ PrintToComm0("test"); #endif
JN-UG-3028 v1.8
Jennic 2008
33
Jennic
Setting correct compiler options for migrated projects
If a Code::Blocks project has been migrated from an earlier version of Code::Blocks then you must ensure that the correct compiler options have been set for the latest compiler, otherwise you may get unexpected debugger behaviour such as not recognising line numbers or not stepping through the code correctly. If your compiler settings are incorrect, you will obtain messages in the Debugger window similar to those shown below.
For an explanation of how to update the project so that all the compiler and linker settings are correct, refer to the Application Note Migrating Projects to Upgraded SDK (JN-AN-1053). Bringing device out of reset so that debugger can start The serial cable connection can occasionally hold the device in reset, so the debugger does not start. To resolve this issue: 1. Disconnect the serial cable from the device. 2. Reset the device. 3. Reconnect the serial cable to the device. 4. In Code::Blocks, start the debugger by following the menu path Debug>Start or clicking on the appropriate debugger icon. Using the Debug button (rather than the Run button) The Run button and the Build and run button attempt to execute the binary on the PC rather than on the JN51xx target device. To execute the binary on the JN51xx device, use the Debug button or the menu option Debug>Start (see Section 5.1.2). If you attempt to run debug code on the PC, you will obtain the following error message:
34
Jennic 2008
JN-UG-3028 v1.8
Jennic
Disabling optimisation for debug When debugging code using the integrated debugger, you are recommended to disable any compiler optimiser settings. When the compiler optimiser is invoked, it uses a variety of techniques to optimise for size or speed (as specified by the user). Optimisation techniques vary depending on the compiler being used, but can involve unwinding loops, saving variables in registers, delaying variable initialisation, and in-lining small or rarely used functions. All these tasks take the code generation away from the 'ideal case' and, as a result, make it difficult for the debugger to map the progress of the processor back onto the user source code. This can give the appearance that the code is misbehaving. Depending on the degree of optimisation used, the yellow run cursor can appear to move randomly around the lines in the source code window, variables can appear to have the wrong values and stack traces can appear corrupt.
JN-UG-3028 v1.8
Jennic 2008
35
Jennic
5.2.1 Preparing the Application
You must first prepare your application source code, as described in the procedure below. Step 1 Step 2 Step 3 Step 4 Step 5 Step 6 Step 7 Load the project to be debugged into Code::Blocks. Check that the build target is Release by following the path Build>Select target. Add the library vPrintf files using Project>Add Files. Select SDK\Chip\Common\Source\Printf.c. Click the checkboxes for both the Release and Debug builds. Add the library vPrintf files using Project>Add Files. Select SDK\Chip\Common\Include\Printf.h. Click the checkboxes for both the Release and Debug builds. Add the following code to the source file under test. Include the Printf.h header file:
#include "..\..\..\Chip\Common\Include\Printf.h"
Note: \n\r is used to provide CR LF in the terminal emulator. Step 8 Step 9 Step 10 Step 11 Build the project for Release, as described in Section 3.4. Connect the Flash programmer, via the serial cable, to UART0 on the target device. Using the Flash programmer, download the application binary to the target device. Close the Flash programmer (otherwise it will hold the serial port open).
Note: You must connect/disconnect after each session in order to use the Flash programmer. Alternatively you can use Brays free Terminal v1.9 - this utility detects if another program is using the port and will automatically disconnect if you tick the Auto Dis/Connect box (www.hw-server.com/software/termv19b.html).
36
Jennic 2008
JN-UG-3028 v1.8
Jennic
Note: If no modem has been configured on the PC, you may get screens requesting the location. Ignore these screens. Step 2 Access the New Connection screen by following the menu path File>New Connection. Type a name for the connection, then click OK.
JN-UG-3028 v1.8
Jennic 2008
37
Jennic
Step 3
In the Connect To screen, choose the serial communications port that the board is connected to and then click OK.
The next screen, COM Properties, is then displayed. Step 4 In the COM Properties screen, set the port properties to 19200 bits per second, 8 data bits, no parity, 1 stop bit and no flow control, then click OK.
The terminal connects to the communications port and the HyperTerminal screen is displayed.
38
Jennic 2008
JN-UG-3028 v1.8
Jennic
JN-UG-3028 v1.8
Jennic 2008
39
Jennic
40
Jennic 2008
JN-UG-3028 v1.8
Jennic
Appendices
A The Integrated Debugger Explained
This appendix explains the operation of the integrated GDB debugger. What is GDB? GDB (GNU project debugger) is a general-purpose debugger that can be used to debug applications written in C, C++, Pascal and Fortran, amongst other languages. The debugger is available (free-of-charge) as part of the well-known GNU toolkit and is used through a text-based interface here, this interface is provided by Code::Blocks. One of the main features of the GDB debugger is its facility for remote debugging that is, it allows you to debug code running on one platform from another platform (running GDB). For example, an application running on a microcontroller device can be debugged from a PC running GDB. In this case, the two platforms are connected via a serial port, a network link or some other method. This capability is utilised when debugging code running on a Jennic JN51xx wireless microcontroller, allowing you to step through code, set breakpoints and view memory contents, as well as generally interact with the microcontroller. The main disadvantage of the GDB debugger is that it is not easily adapted to embedded real-time environments, since GNU components were initially designed for developing desktop applications in Unix-type environments. How does GDB operate? For remote debug (as used for the JN51xx device), GDB interacts with the target application via a debug stub, which is a small, intermediate application compiled into the target system. Communication between GDB and the debug stub is implemented using the GDB Remote Serial Protocol this is an ASCII messagebased command set which supports tasks that include reading/writing from/to memory, querying registers and running the application under test. Jennic's debug stub is activated using the macro HAL_GDB_INIT. The debugger deals with setting and processing a breakpoint in the following way: 1. When a breakpoint is set, GDB employs memory read/write commands to non-destructively replace a source instruction with a TRAP instruction. 2. When the instruction is reached during execution, control is transferred from the processor to the debug stub. 3. The debug stub notifies GDB that a breakpoint has been encountered. The user can now interact with the hardware, as required. 4. GDB sends a command corresponding to the required action to the debug stub. 5. Once the breakpoint has been dealt with, the debug stub returns control to the processor.
JN-UG-3028 v1.8 Jennic 2008 41
Jennic
What happens during a breakpoint on the JN51xx?
When a breakpoint is reached, the debug stub is invoked on the JN51xx target. The stub then services any requests and commands received from the GDB host. GDB stalls any application code that was running on the device processor before the breakpoint was encountered.
Note: During a breakpoint, only the JN51xx CPU is stalled. The JN51xx integrated peripherals still run normally, with timers running and expiring, network packets arriving and the integrated peripherals free to generate interrupts. What happens after a breakpoint on the JN51xx? When you instruct GDB (via the Code::Blocks IDE) to step out of the breakpoint, the CPU interrupt handler processes all other queued interrupts generated during the period of the breakpoint. Therefore, any timer interrupts, network packets and analogue peripheral interrupts that have occurred during this period are processed. Control is then returned to the processor, resuming application execution.
Note: Application data and peripheral hardware status may have changed during the breakpoint period. The processing of queued interrupts may alter buffer contents and update program variables. Understanding this is key to explaining any unexpected behaviour in the application while it is being debugged. Where can I get more information on GDB? The following are useful web links to further information on GDB: For a more detailed description of using GDB in an embedded environment: http://www.embedded.com/1999/9909/9909feat2.htm For an excellent guide to GDB: http://www.dirac.org/linux/GDB/ For detailed manuals on GDB: http://docs.freebsd.org/info/GDB/GDB.pdf http://wwwcdf.pd.infn.it/localdoc/GDBint.pdf
42
Jennic 2008
JN-UG-3028 v1.8
Jennic
Note: Alternatively, you can obtain the relevant driver for your operating system from the FTDI web page www.ftdichip.com/FTDrivers.htm. Go to the VCP drivers, download the required driver to your desktop and double-click on its icon to install.
JN-UG-3028 v1.8
Jennic 2008
43
Jennic
C Identifying PC Communications Port Used
When connecting your PC to a board, you need to find out which serial communications port your PC has allocated to the connection, as described below. 1. In the Windows Start menu, follow the menu path: Start>Control Panel>System This displays the System Properties screen. 2. In the System Properties screen: a) Select the Hardware tab. b) Click the Device Manager button This displays the Device Manager screen. 3. In the Device Manager screen: a) Look for the Ports folder in the list of devices and unfold it. b) Identify the port which is connected to the board (it will be labelled USB Serial Port) and make a note of it (e.g. COM1).
44
Jennic 2008
JN-UG-3028 v1.8
Jennic
Note: For the GUI version of the Flash programmer, you can set the PC communications port from within the GUI itself. Step 1 Step 2 In Code::Blocks, follow the menu path Tools>Configure tools. This displays the User-defined tools dialogue box, containing a list of tools. Select the tool you wish to use (e.g. Download to Flash for JN513x Release) and then click Edit. The Edit tool screen is displayed.
The fields of this screen are pre-filled with the relevant information, as shown above.
JN-UG-3028 v1.8
Jennic 2008
45
Jennic
The fields are briefly as follows:
Name: The name of the tool (e.g. Download to Flash for JN513x Release) to appear in the Tools menu in Code::Blocks. Executable: The path to the executable for the download tool. Parameters: Specifies the name of the binary file to be downloaded and the PC communications port to use. When working on a project, {PROJECT_NAME} is automatically substituted with the Code::Blocks project name. Working directory: Specifies the location of the binary file to be downloaded. {PROJECT_DIR} is automatically substituted with the Code::Blocks project directory. Step 3 In the Parameters field, ensure that the PC communications port setting is as required (in f ${PROJECT_NAME}.bin c1, the 1 is the comms port setting). Change the port number, if needed. Then click OK.
46
Jennic 2008
JN-UG-3028 v1.8
Jennic
Step 3
In the first screen of the wizard, simply click Next (and, if desired, tick the checkbox Skip this page next time).
JN-UG-3028 v1.8
Jennic 2008
47
Jennic
Step 4 In the next screen, enter your project information as detailed below.
a) b)
In the Project title field, enter a name for your project (this is used to create the library filename see Substep c below). In the field Folder to create project in, navigate to the development directory in which the library project folder should be created. The required path is normally C:\Jennic\cygwin\jennic\SDK\Application. The remaining two fields (Project filename and Resulting filename) are filled in automatically by the wizard leave them unchanged! Click Next.
c) d)
48
Jennic 2008
JN-UG-3028 v1.8
Jennic
Step 5
In the next screen ensure that the Compiler field shows JN51xx Compiler and then click Finish.
Your library project has been created! Step 6 To include a specific source file in the library, follow the menu path Project >Add files and add the file into the project.
JN-UG-3028 v1.8
Jennic 2008
49
Jennic
50
Jennic 2008
JN-UG-3028 v1.8
Jennic
Date 29-Nov-2006 07-Feb-2007 23-Feb-2007 Description First release Updated to cover both JN5121 and JN513x series devices Corrected paths for new SDK folder structure. Removed basic integrated Flash programmer. Installation chapter removed and download chapter updated for JN513x chip series Updated for R1 of JN5139 device. Added chapter on integrated debugger. Added debugger chapter and appendices Added Jenie to project templates Updated for new SDK installers (JN-SW-4030 and JN-SW-4031). Added procedures to Appendix for connecting a PC to a network node. Added procedure for building custom libraries in Code::Blocks and made other minor modifications
Revision History
Version 1.0 1.1 1.2
1.3
25-Apr-2007
1.4
24-May-2007
1.8
04-Dec-2008
JN-UG-3028 v1.8
Jennic 2008
51
Jennic
Important Notice
Jennic reserves the right to make corrections, modifications, enhancements, improvements and other changes to its products and services at any time, and to discontinue any product or service without notice. Customers should obtain the latest relevant information before placing orders, and should verify that such information is current and complete. All products are sold subject to Jennics terms and conditions of sale, supplied at the time of order acknowledgment. Information relating to device applications, and the like, is intended as suggestion only and may be superseded by updates. It is the customers responsibility to ensure that their application meets their own specifications. Jennic makes no representation and gives no warranty relating to advice, support or customer product design. Jennic assumes no responsibility or liability for the use of any of its products, conveys no license or title under any patent, copyright or mask work rights to these products, and makes no representations or warranties that these products are free from patent, copyright or mask work infringement, unless otherwise specified. Jennic products are not intended for use in life support systems/appliances or any systems where product malfunction can reasonably be expected to result in personal injury, death, severe property damage or environmental damage. Jennic customers using or selling Jennic products for use in such applications do so at their own risk and agree to fully indemnify Jennic for any damages resulting from such use. All trademarks are the property of their respective owners.
Corporate Headquarters Furnival Street Sheffield S1 4QT United Kingdom Tel +44 (0)114 281 2655 Fax +44 (0)114 281 2951 E-mail [email protected] United States Sales Office 1060 First Avenue, Suite 400 King of Prussia PA 19406 USA Tel +1 619 223 2215 Fax +1 619 223 2081 E-mail [email protected]
Japan Sales Office Osakaya building 4F 1-11-8 Higashigotanda Shinagawa-ku, Tokyo 141-0022, Japan Tel +81 3 5449 7501 Fax +81 3 5449 0741 E-mail [email protected] Korean Sales Office 601, Bethel B/D, #324-1 Yangjae-dong Seocho-gu Seoul 137-897 Korea Tel +82 2 552 5325 Fax +82 2 577 9130 E-mail [email protected]
Taiwan Sales Office 19F-1, 182, Sec.2 Tun Hwa S. Road Taipei 106 Taiwan Tel +886 2 2735 7357 Fax +886 2 2739 5687 E-mail [email protected]
52
Jennic 2008
JN-UG-3028 v1.8