MDK-ARM Keil, MDK-ARM Datasheet

KIT REALVIEW MCU DEVELOPMENT

MDK-ARM

Manufacturer Part Number
MDK-ARM
Description
KIT REALVIEW MCU DEVELOPMENT
Manufacturer
Keil
Type
Compiler and IDEr
Datasheets

Specifications of MDK-ARM

For Use With/related Products
ARM MCUs
Lead Free Status / RoHS Status
Lead free / RoHS Compliant
www.keil.com

Related parts for MDK-ARM

MDK-ARM Summary of contents

Page 1

... www.keil.com ...

Page 2

... Copyright © 1997-2009 ARM Ltd and ARM Germany GmbH. All rights reserved. Keil, the Keil Software Logo, µVision, MDK-ARM, RL-ARM, ULINK, and Device Database are trademarks or registered trademarks of ARM Ltd, and ARM Inc. ® ...

Page 3

... Keil Microcontroller Development Kit (MDK-ARM the Real-Time Library (RL-ARM). If you are new to the MDK-ARM, there is a separate Getting Started guide, which will introduce you to the key features. The online documentation for the MDK-ARM, including the Getting Started guide, is located at www ...

Page 4

... Chapter Overview “Chapter 1. Introduction”, provides a product overview, remarks referring to the installation requirements, and shows how to get support from the Keil technical support team. “Chapter 2. Developing with an RTOS”, describes the advantages of the RTX, explains the RTX kernel, and addresses RTOS features, such as tasks, semaphores, mutexes, time management, and priority schemes. “ ...

Page 5

Getting Started: Building Applications with RL-ARM Document Conventions Examples Description 1 README.TXT Bold capital text is used to highlight the names of executable programs, data files, source files, environment variables, and commands that you can enter at the command prompt. ...

Page 6

Content Preface ................................................................................................................... 3 Document Conventions ........................................................................................ 5 Content .................................................................................................................. 6 Chapter 1. Introduction .................................................................................... 10 RL-ARM Overview ......................................................................................... 10 RTX RTOS ...................................................................................................... 11 Flash File System ............................................................................................. 11 TCP/IP ............................................................................................................. 12 USB .................................................................................................................. 12 CAN ................................................................................................................. 13 Installation ...

Page 7

Getting Started: Building Applications with RL-ARM Rendezvous ...................................................................................................... 35 Barrier Turnstile ............................................................................................... 36 Semaphore Caveats .......................................................................................... 38 Mutex ............................................................................................................... 38 Mutex Caveats ................................................................................................. 39 Mailbox ............................................................................................................ 39 Task Lock and Unlock ..................................................................................... 43 Configuration ................................................................................................... 43 Task Definitions ............................................................................................... 44 ...

Page 8

Debug Support ................................................................................................. 74 Using RL-TCPnet with RTX ........................................................................... 74 RL-TCPnet Applications ................................................................................. 76 Trivial File Transfer ......................................................................................... 76 Adding the TFTP Service ................................................................................ 76 HTTP Server .................................................................................................... 77 Web Server Content ......................................................................................... 78 Adding Web Pages........................................................................................... 78 Adding ...

Page 9

Getting Started: Building Applications with RL-ARM Interface Descriptor ....................................................................................... 120 Endpoint Descriptor ....................................................................................... 121 RL-USB ......................................................................................................... 122 RL-USB Driver Overview ............................................................................. 122 First USB Project ........................................................................................... 124 Configuration ................................................................................................. 124 Event Handlers ............................................................................................... 125 USB Descriptors ............................................................................................ 126 Class Support ...

Page 10

... This allows you to learn the software once and then use it multiple times. The RL-ARM middleware integrates into the Keil Microcontroller Development Kit (MDK-ARM). These two development tools allow you to rapidly develop sophisticated software applications across a vast range of ARM processor-based microcontrollers. In this book, we will look at each of the RL-ARM middleware components and see how to use all the key features in typical applications ...

Page 11

... SRAM and Flash memory. This makes it possible to use more advanced software development techniques. Introducing a Real-Time Operating System (RTOS) or real-time executive into your project development is an important step in the right direction. With an RTOS, all the functional blocks of your design are developed as tasks, which are then scheduled by RTX ...

Page 12

... Flash drivers, SPI drivers, and MultiMedia Card interface drivers. This gets the file system up-and-running with minimal fuss and allows you to concentrate on developing your application software. In the past, the use of a full file system in a small, embedded microcontroller has been something of a luxury. ...

Page 13

... Windows operating system and its device drivers. Getting all of these elements working together would be a development project in its own. Like the TCP/IP library, the RL-USB driver is a common software stack designed to work across all supported microcontrollers. Although you can use the RL-USB driver to communicate with a custom Windows device driver, it has been designed to support common USB classes ...

Page 14

... The RL-ARM is a collection of middleware components designed to integrate with the Keil Microcontroller Development Kit (MDK-ARM). To use this book you will need to have both the MDK-ARM and RL-ARM installed on your PC. MDK-ARM may be installed from either CD-ROM, or may be downloaded from the web. Currently, RL-ARM may only be downloaded from the web. ...

Page 15

... Read the section in this manual that pertains to the task you are attempting, 2. Check the update section of the Keil web site to make sure you have the latest software and utility version, 3 ...

Page 16

... Chapter 2. Developing With an RTOS In the course of this chapter we will consider the idea of using RTX, the Keil small footprint RTOS ARM processor-based microcontroller. If you are used to writing procedural-based C code on microcontrollers, you may doubt the need for such an operating system. If you are not familiar with using an RTOS in real-time embedded systems, you should read this chapter before dismissing the idea ...

Page 17

... ARM processor-based microcontroller you are using. Different versions of the file are located in . C:\KEIL\ARM\STARTUP If you are using an ARM7 or ARM9-based microcontroller, you can select the correct version for the microcontroller family you are using and RTX will work “out-of-the-box”. For Cortex-M-based microcontrollers there is one generic configuration file ...

Page 18

... RTX we must modify the SWI vector code to call RTX. A part of RTX runs in the privileged supervisor mode and is called with software interrupts (SWI). We must therefore disable the SWI trap in the startup code. With Cortex-based microcontroller, the interrupt structure is different and does not require you to change the startup code, so you can ignore this step ...

Page 19

Getting Started: Building Applications with RL-ARM RTX Kernel RTX consists of a scheduler that supports round-robin, pre-emptive, and co- operative multitasking of program tasks, as well as time and memory management services. Inter-task communication is supported by additional RTOS objects, ...

Page 20

This code would normally manage the native stack. Since the RTX scheduler handles this function, we can safely remove this code. This saves both code and data memory and increases ...

Page 21

Getting Started: Building Applications with RL-ARM Each task has its own stack for saving its data during a context switch. The Task Control Block is used by the kernel to manage the active tasks. The Task Control Block contains information ...

Page 22

IODIR1 = 0x00FF0000; os_sys_init (task1); } The os_sys_init () function launches RTX, but only starts the first task running. After the operating system has been initialized, control will be passed to this task. When the ...

Page 23

Getting Started: Building Applications with RL-ARM The first task can create further active tasks with the os_tsk_create() function. This launches the task and assigns its task ID number and priority. In the example above we have two running tasks, task2 ...

Page 24

Task Management Once the tasks are running, there are a small number of RTX system calls, which are used to manage the running tasks possible to elevate or lower a task’s priority either from another function or ...

Page 25

Getting Started: Building Applications with RL-ARM Time Delay The most basic of these timing services is a simple timer delay function. This is an easy way of providing timing delays within your application. Although the RTX kernel size is quoted ...

Page 26

Periodic Task Execution We have seen that the scheduler runs tasks with a round-robin or pre-emptive scheduling scheme. With the timing services also possible to run a selected task at specific time intervals. Within a task, we ...

Page 27

Getting Started: Building Applications with RL-ARM void os_tmr_call (U16 info) switch (info) { case 0x01: … break ; } } This function knows which timer has expired by reading the info parameter. We can then run the appropriate code after ...

Page 28

Inter-Task Communication So far we have seen how application code can be written as independent tasks and how we can access the timing services provided by RTX real application, we need to be able to communicate between ...

Page 29

Getting Started: Building Applications with RL-ARM Any task can set the event flags of any other task in a system with the os_evt_set() RTX function call. We use the task ID to select the task. void os_evt_set (unsigned short event_flags, ...

Page 30

... ARM7/9-based microcontrollers do not support nested interrupts without additional software to avoid potential deadlocks and any system based on nested interrupts has an unpredictable stack usage. With an RTX-based application best to implement the interrupt service code as a task and assign it a high priority. The first line of code in the interrupt task should make it wait for an event flag. ...

Page 31

Getting Started: Building Applications with RL-ARM Task Priority Scheme When writing an RTOS-based application you must have a clear idea of how you will prioritize tasks. The FIQ interrupt is the highest priority interrupt on ARM CPUs (a non-maskable interrupt ...

Page 32

Semaphores Like events, semaphores are a method of synchronizing activity between two or more tasks. Put simply, a semaphore is a container that holds a number of tokens task executes, it will reach an RTOS call to ...

Page 33

Getting Started: Building Applications with RL-ARM To use a semaphore in RTX you must first declare a semaphore container: OS_SEM <semaphore>; Then within a task, the semaphore container can be initialized with a number of tokens. void os_sem_init (OS_ID semaphore, ...

Page 34

Using Semaphores Although semaphores have a simple set of OS calls, they have a wide range of synchronizing applications. This makes them perhaps the most challenging RTOS objects to understand. In this section, we will look at the most ...

Page 35

Getting Started: Building Applications with RL-ARM Here, the multiplex semaphore has five tokens. Before a task can continue, it must acquire a token. Once the function finished, the token is sent back. If more than five tasks are calling ProcessBuffer(), ...

Page 36

Barrier Turnstile Although a rendezvous is very useful for synchronizing the execution of code, it only works for two functions. A barrier is a more generalized form of rendezvous, which works to synchronize multiple tasks. A barrier is shared ...

Page 37

Getting Started: Building Applications with RL-ARM The code for the entry turnstile is duplicated in each of the participating tasks: os_sem_init(Mutex, 1); os_sem_init(Entry_Turnstile, 0); os_sem_init(Exit_Turnstile, 1); count = 0; …………… while (1) { …………… os_sem_wait (Mutex, 0xffff); count = count+1; ...

Page 38

Semaphore Caveats Semaphores are an extremely useful feature of any RTOS. However, semaphores can be misused. You must always remember that the number of tokens in a semaphore is not fixed. During the runtime of a program, semaphore tokens ...

Page 39

Getting Started: Building Applications with RL-ARM Mutex Caveats Clearly, you must take care to return the Mutex token when you are finished with the chip resource, or you will have effectively prevented any other task from accessing it. You must ...

Page 40

To configure a mailbox object we must first declare the message pointers. Here we are using 16 mail slots. This is an arbitrary number and varies depending on your requirements, but typical starting point. The message ...

Page 41

Getting Started: Building Applications with RL-ARM Then we send the message. os_mbx_send (MsgBox, mptr, 0xffff); In practice, this locks the mail slot protecting the data, and the message pointer is transferred to the waiting task. Further messages can be sent ...

Page 42

A task sending a message: __task void Send_Task (void) … MESSAGE *mptr; os_mbx_init (MsgBox, sizeof (MsgBox)); tsk1 = os_tsk_self (); tsk2 = os_tsk_create (Receive_Task, 0x1); while (1) { mptr = _alloc_box (mpool); for (i=0; i < i++) ...

Page 43

Getting Started: Building Applications with RL-ARM Task Lock and Unlock In a real application often necessary to ensure that a section of code runs as a contiguous block, so that no interrupts occur while it is executing. In ...

Page 44

Task Definitions In the Task Definitions section, we define the basic resources that will be required by the tasks. For each task, we allocate a default stack space (in the above example this is 200 bytes). We also define ...

Page 45

Getting Started: Building Applications with RL-ARM System Timer Configuration The system timer configuration section defines which on-chip timer will be used to generate a periodic interrupt to provide a time base for the scheduler. On ARM7 and ARM9-based microcontroller, you ...

Page 46

Pre-emptive Scheduling If the round robin option is disabled in the declared with a different priority. When the RTOS is started and the tasks are created, the task with the highest priority will run pre-emptive RTOS, each ...

Page 47

Getting Started: Building Applications with RL-ARM Round Robin Pre-emptive Scheduling As discussed at the beginning of this chapter, the default scheduling option for RTX is round robin pre-emptive. For most applications, this is the most useful option and you should ...

Page 48

However, the low priority task T3 could be pre-empted by a medium priority task T2. Now free to run until it blocks (assuming it does) before allowing T3 to resume completing its operation and allowing T1 to ...

Page 49

Getting Started: Building Applications with RL-ARM Chapter 3. RL-Flash Introduction This chapter discusses configuring and using the RL-Flash embedded file system. To many experienced developers of small embedded systems, the concept of using a file system may be considered something ...

Page 50

... The file system library functions are re-entrant and thread safe. Therefore, with RTX, any task can access the file system. Note that, if the code is build with the MDK-ARM, MicroLIB is not supporting the system, and so you must use the default ARM Compiler libraries. ...

Page 51

Getting Started: Building Applications with RL-ARM The file system buffers data in dynamically allocated memory must reserve heap space in the startup code enable the drive type we File_Config.c want to use and set its parameters. ...

Page 52

File I/O Routines Once the file system has been configured, we can manipulate files. Function Description fopen Creates a new file or opens an existing file. fclose Writes buffered data to a file and then closes the file. fflush ...

Page 53

Getting Started: Building Applications with RL-ARM feof() returns zero until the end of file is reached. Notice possible to read past the end of a file. While reading or writing data, ferror() reports access errors in the file ...

Page 54

Volume Maintenance Routines As you create and update files important to maintain the health of the drive. A number of functions maintain the volume and manipulate the content of the drive. The file system provides five drive ...

Page 55

... You must also add the code to initialize the real-time clock. The file located in C:\KEIL\ARM\RL\FLASHFS\SRC project in C:\KEIL\ARM\RL\FLASH When rebuilding the library, be careful to select either the ARM_LE (ARM7/9 Little-Endian) or Cortex as the target. The you are using a RAM-based file system. Exercise: Drive Functions This project contains several examples, which demonstrate maintaining and working with a drive volume ...

Page 56

... Next, we must add the programming algorithms for the internal Flash memory. These algorithms are defined for supported microcontrollers and are located in C:\KEIL\ARM\RL\FLASHFS\FLASH Each subdirectory contains the necessary support files for a given microcontroller or parallel Flash device. Each of these directories contains ...

Page 57

Getting Started: Building Applications with RL-ARM // Flash sector definitions in Flash_Page.c // #define FLASH_DEVICE DFB (0x008000, 0x000000), DFB (0x008000, 0x008000), #define FL_NSECT 2 // File_Config.c as displayed as in the µVision Configuration Wizard // Traget device Base address Device ...

Page 58

... If RL-Flash does not provide direct support for your microcontroller or the parallel Flash on your board possible to adapt the programming algorithms, used by the Keil ULINK USB-JTAG adapter family, to use them as drivers for the Flash file system. The ULINK family Flash programming algorithms are ...

Page 59

Getting Started: Building Applications with RL-ARM provide some extra code to manage the Flash page size. Typically, this code has to read the current data stored in the Flash page, concatenate this with the new data stored in the file ...

Page 60

... SD/MMC card. If the DMA is limited to certain regions of memory, the “relocate buffer cache” option allows you to force the file buffer cache into a suitable region. Do check that this is correct for your particular microcontroller. Chapter 3. RL-Flash Introduction C:\KEIL\ARM\RL\FLASHFS\DRIVERS to use the memory card. In File_Config.c . ...

Page 61

Getting Started: Building Applications with RL-ARM From this point onwards, the file system API can be used as normal. However are communicating with an external memory card, which may have some timing latencies, it may fail the finit() ...

Page 62

... The protocol file is very similar to the parallel Flash driver files and can be found in C:\KEIL\ARM\RL\FLASHFS\FLASH Here select the directory named after the Flash device you intend to use and copy the contents to your project directory. The files contained in the device directory ...

Page 63

... TCP/IP protocol and then examine each feature of RL-TCPnet. Each of the exercises accompanying this chapter show minimal examples intended to demonstrate one aspect of RL-TCPnet. Full examples can be found in the board examples directory C:\KEIL\ARM\BOARDS\<vendor>\<board name>\RL\TCPNET code size for each of these programs is as follows: Demo Example HTTP Server (without RTX Kernel) ...

Page 64

In a typical microcontroller-based system, this layer corresponds to the Ethernet MAC with PHY chip and the low-level device driver. The TCP/IP stack handles the transport and network routing layers. The network layer handles the transmission of data packets ...

Page 65

Getting Started: Building Applications with RL-ARM Ethernet and IEEE 802.3 Today’s most dominant networking transport layer for local area networks is Ethernet (or rather Ethernet exact). The Ethernet header contains a synchronization preamble, followed by source and ...

Page 66

The IP protocol supports message fragmentation and re- assembly; for a small, embedded node, this can be expensive in terms of RAM used to buffer messages. The IP protocol rides within the Ethernet information frame as shown below. The ...

Page 67

Getting Started: Building Applications with RL-ARM the IP address of the remote station. The broadcast message also contains the local station’s Ethernet address and its IP address. All the other nodes on the network will receive the ARP broadcast message ...

Page 68

Dynamic Host Control Protocol DHCP The DHCP supports automatic allocation of IP addresses and configuration of the subnet mask within a LAN. A DHCP server must be present within the LAN. This can run on any station and listens ...

Page 69

... The TCP port number associates the TCP data with target application software. The standard TCP/IP application protocols have “well-known ports” so that remote clients may easily connect to a standard service. The device providing the service can open a TCP port and listen on this port until a remote client connects ...

Page 70

User Datagram Protocol Like the Transmission Control Protocol, the User Datagram Protocol rides within the data packet of the Internet Protocol. Unlike TCP, UDP provides no acknowledgement and no flow control mechanisms. UDP can be defined as a best ...

Page 71

... Ethernet Media Access Controller (MAC) address. This is the station address for the Ethernet network and it must be unique. During development, you can use a “made up number”, but when you produce a real product, it must contain a unique MAC address. This is discussed in more detail at the end of this chapter. . The Ethernet C:\KEIL\ARM\RL\TCPNET\SRC C:\KEIL\ARM\RL\TCPNET\DRIVERS 71 . ...

Page 72

RL-TCPnet also supports the NetBIOS Frames Protocol. If this is enabled, we can provide our node with a NetBIOS local host name as well address. Finally, we must enable the TCP and UDP protocols. The ICMP ...

Page 73

Getting Started: Building Applications with RL-ARM Once the RL-TCPnet library has been configured, we need to add the following code to our application code. void timer_poll () { if (100mstimeout) { timer_tick (); tick = __TRUE int main ...

Page 74

Debug Support There are two available versions of the RL-TCPnet: a release version and a debug version. The debug version uses the printf() function to output network debug messages, which can be used during development. By default, the printf() ...

Page 75

Getting Started: Building Applications with RL-ARM void init (void) __task init_TcpNet (); os_tsk_create (timer_task, 30); os_tsk_create_user (tcp_task, 0, &tcp_stack, sizeof (tcp_stack)); os_tsk_delete_self (); } Since the TCP task has a greater memory requirement than most user tasks, it must be ...

Page 76

RL-TCPnet Applications RL-TCPnet supports a number of standard internet applications. These include trivial file transfer (TFTP), web server (HTTP), email client (SMTP), telnet, and domain name server (DNS) client. In RL-TCPnet, each of these applications is quick and easy ...

Page 77

... SRAM footprint. Complete the TFTP server by adding a user interface file, C:\KEIL\ARM\RL\TCPNET\SRC link the server to the file system not need to modify this file to make the basic TFTP server work. To add special features to the TFTP server, modify these callback functions ...

Page 78

... Emdedded Web Server</p> <p><img src="Keil_logo.gif"> <embed src="sound.wav" autostart="true" hidden="true"></p> </body> </html> RL-TCPnet allows you to store the HTML pages in two different ways. You can convert the HTML into C arrays, which are then stored as part of the application code in the microcontroller program Flash ...

Page 79

... Each of these files should be added as a text file type. These files have to be processed into a virtual file system in order to get them into the web server. This is done by a special utility provided with the MDK-ARM, called converter for ARM). The directory. The utility is used to FCARM ...

Page 80

... FileTab [FILECNT] = {"index.html", (U8 *) &index_html, 255}, {"sound.wav", (U8 *) &sound_wav, 8903}, {"keil_logo.gif", (U8 *) &keil_logo_gif, 4637}, … make an active web server, you simply add the rebuild the project. This approach embeds the web server content as part of your application ...

Page 81

Getting Started: Building Applications with RL-ARM Adding HTML with RL-Flash The RL-TCPnet web server can be configured to serve web pages stored in a Flash file system implemented with RL- Flash. This makes it possible for users to upload HTML ...

Page 82

... TCP/IP server. In the case of a HTTP server, the data is output as dynamically modified HTML. To enable the CGI interface, we need to add a new C file from the RL-TCPnet library to our project. This file is called source directory C:\KEIL\ARM\RL\TCPNET\SRC access the CGI interface must have the extension . rather cgi ...

Page 83

Getting Started: Building Applications with RL-ARM An HTML file that is intended to output a dynamically changing greeting message to the web browser would look like this: t <HTML><HEAD><TITLE> Hello World Example </TITLE></HEAD> t <H2 ALIGN=CENTER> Output a Greeting as ...

Page 84

This technique is very straightforward and easy to use. You can apply the CGI scripting to any part of the HTML text, in order to generate dynamically any form of HTML display. In the above example, we have only ...

Page 85

Getting Started: Building Applications with RL-ARM <HTML> <HEAD> <TITLE>Post example</TITLE> </HEAD> <BODY> <FORM ACTION="index.cgi" METHOD="POST" NAME="CGI"> <TABLE> <TR> <TD> <INPUT TYPE="TEXT" ID="textbox1" SIZE="16" VALUE=""></TD> <TD ALIGN="right"> <INPUT TYPE="SUBMIT" ID="change" VALUE="change"></TD> </TR> </TABLE> </FORM> </BODY> </HTML> When this page is viewed, ...

Page 86

Now, all we need add code to parse this string and pass any entered data to our C application. Exercise: CGI POST Method This exercise used the CGI POST method to pass input data from ...

Page 87

Getting Started: Building Applications with RL-ARM In this case, the data held in the application_data variable will be converted to an ASCII string. When the HTML page is loaded, the string will appear as the content of the text box. ...

Page 88

Using JavaScript JavaScript like scripting language stored on a web server and downloaded on demand to a client browser. The client interprets and executes the script on its host processor, be this a PC, MAC, or ...

Page 89

Getting Started: Building Applications with RL-ARM When the html page is loaded, the JavaScript library is sent to the browser client. The HTML code is used to create the graph object and define the coordinates. When the graph page is ...

Page 90

Here we want to display temperature values held array controlled by the application code. We add a script command for each line of JavaScript that is used to pass the graph coordinates. The fixed graph values ...

Page 91

Getting Started: Building Applications with RL-ARM that consumes minimal bandwidth. The most commonly used browsers can take this data and update the web page without having to reload the full page. This gives flicker free “real-time” update of dynamic objects ...

Page 92

92 /*------------------------------------- * xml_http.js *------------------------------------*/ function periodicObj (url, period) this.url = url; this.period = (typeof period == "undefined" period; } #-------------------------------------- # buttons.cgi #-------------------------------------- t var formUpdate = new periodicObj ("buttons.cgx", 300); /*---------------------------------------- * xml_http.js *---------------------------------------*/ function ...

Page 93

Getting Started: Building Applications with RL-ARM /*--------------------------------------- * cgi_func() in HTTP_CGI.c *--------------------------------------*/ case 'y': len = sprintf ( (char*) buf, "<checkbox><id><button%c</id> <on>%s</on></checkbox>", env [1], (get_button () & (1<<(env [1]-'0'))) ? "true" : "false" ); break; <!----------------------------------------- # Generated XML #-----------------------------------------> ...

Page 94

... Ajax support. Simple Mail Transfer Client The RL-TCPnet library includes an SMTP client, which allows your application software to send email messages. Each email message can be a fixed text string can be a dynamic message generated by the application software. Adding SMTP Support We can add SMTP support by ...

Page 95

Getting Started: Building Applications with RL-ARM Sending a Fixed Email Message Once the server has been configured, the application starts the SMTP client by calling the smtp_connect() function. This function connects to an SMTP server, sends a single email, disconnects ...

Page 96

... It is possible to send dynamically created email messages. The sender and recipient email addresses and the subject can be held as strings, so that different addresses and subjects can be selected. The application software can also dynamically generate the data sent in the message possible to send long email messages that contain application data. For each call to the smtp_cbfunc() function, we can only send a packet of data with the size of the buffer buf ...

Page 97

Getting Started: Building Applications with RL-ARM Next, expand the case 5 switch statement of the smtp_cbfunc() function, to handle multiple data packets. Add another switch statement as shown in the code below. The local buffer MYBUF(pvar)-->id counts how many data ...

Page 98

It is only possible to send the first 127 ASCII text characters as part of an email message. If you plan to send binary data in an email message, it must be encoded as a text string. The most ...

Page 99

Getting Started: Building Applications with RL-ARM The second function is telnet_process_cmd(). This command line parser is used to read the input from the Telnet client and then calls the required C application functions. When a client connects to the Telnet ...

Page 100

In a simple Telnet server, the amount of data that can be sent to the Telnet client is limited by the size of the reply buffer buf. However possible to force the RL-TCPnet library to make multiple ...

Page 101

... DNS client would be to convert a configuration string entered by a human to a usable IP address, for example post.keil.com. To configure the DNS client we must first enter the IP address of a primary and secondary DNS server in the the Dynamic Host Configuration Protocol (DHCP) client is enabled. This is because the DHCP server will provide these addresses when the DHCP client leases an IP address ...

Page 102

... IP address. Each record is 12 bytes in size. Once the DNS client has been configured, we can resolve a symbolic address by calling the get_host_by_name() function. get_host_by_name ("www.keil.com", dns_cbfunc); This function takes the host symbolic name as a string and also the address of a user-defined call back function. Once invoked, the DNS client will attempt to resolve the address by contacting the DNS server ...

Page 103

Getting Started: Building Applications with RL-ARM User Datagram Protocol (UDP) Communication In this first example, we will connect two boards together through an Ethernet crossover cable. The boards will communicate by sending packets of data as UDP frames. The Sockets ...

Page 104

Once the data has been written into the packet, we can use udp_send() to transmit it. When we call the udp_send() function, we must pass the socket handle, the remote IP address, the remote port, the buffer pointer and ...

Page 105

Getting Started: Building Applications with RL-ARM Transmission Control Protocol (TCP) Communication We will use the same basic PING project in order to establish TCP communication between the two boards. Of course, this time we must enable the TCP protocol in ...

Page 106

The tcp_get_state() function will return the current state of a socket. The possible socket states are shown below: On the first call, tcp_get_state() will report that the socket is closed. In this case, we can open the socket for ...

Page 107

Getting Started: Building Applications with RL-ARM On the server side, we must get a socket and configure server. Then we need to open a port to listen for a client connection. socket_tcp = tcp_get_socket (TCP_TYPE_SERVER, 0, 10, ...

Page 108

Deployment During development you can use the default Media Access Control (MAC) address provided in Net_Config.c final product, each unit you are making must have a unique MAC address possible to purchase a block of 4096 MAC ...

Page 109

... We must encode the values used as control characters, in order to send them in a data packet. For example are using the Xon/Xoff software flow control, the value used to start the serial data stream, To allow the values ...

Page 110

... Once we have finished with the serial connection, it must be closed using the either of the functions below: ppp_close(); Exercise: PPP Connection This exercise demonstrates replacing the Ethernet driver with a serial driver configured for the Point-to-Point protocol. Chapter 4. RL-TCPnet Introduction C:\KEIL\ARM\RL\TCPNET\DRIVERS slip_listen(); slip_is_up(); slip_close(); . ...

Page 111

Getting Started: Building Applications with RL-ARM Chapter 5. RL-USB Introduction Today the Universal Serial Bus (USB) is the standard way to connect external peripherals to a Personal Computer (PC). Consequently, if you are designing an embedded system that has to ...

Page 112

The physical USB network is implemented as a tiered star network. The USB host provides one attachment port for an external USB peripheral. If more than one peripheral is required, connect a hub to the root port and the ...

Page 113

Getting Started: Building Applications with RL-ARM With USB 2.0, peer-to-peer communication is not possible. USB On-The–Go (OTG extension to the USB 2.0 specification, which directly supports peer- to-peer communication. For example, allowing pictures stored on a camera to ...

Page 114

... The Control pipe is reserved for the host to send and request configuration information to and from the device. Generally, the application software does not use it. The unidirectional pipes are defined as either IN pipes, which transfer data from the device to the host, or OUT pipes, which transfer data from the host to the device ...

Page 115

Getting Started: Building Applications with RL-ARM Interrupt Pipe The first of the varieties of user pipe is an interrupt pipe. Since only the host can initiate a data transfer, no network device can asynchronously communicate to the host. Using an ...

Page 116

Bandwidth Allocation The USB protocol is a master slave protocol so all communication is initiated by the host. Therefore the host to determine what pipe packets are contained in each USB frame. Any ending Control ...

Page 117

Getting Started: Building Applications with RL-ARM Device Configuration When a device is first connected to the USB host, its signaling speed is determined. It has Endpoint 0 configured to accept a Control pipe. In addition, every new device that is ...

Page 118

Device Descriptor Device Descriptor At the top of the descriptor tree is the Device Descriptor. This descriptor At the top of the descriptor tree is the Device Descriptor. This descriptor contains the basic information about the device. Included in ...

Page 119

... Configuration Descriptor The Configuration descriptor contains information about the device’s power requirements and the number of interfaces it can support. A device can have multiple configurations. The host can select the configuration that best matches the requirements of the application software it is running. 119 ...

Page 120

Interface Descriptor The Interface descriptor describes a collection of Endpoints. This interface supports a group of pipes that are suitable for a particular task. Each configuration can have multiple interfaces and these interfaces may be dynamically selected by the ...

Page 121

Getting Started: Building Applications with RL-ARM Endpoint Descriptor The Endpoint descriptor transfers configuration details of each supported Endpoint in a given interface, such as the: Transfer type supported, Maximum packet size, Endpoint number, and Polling rate ( ...

Page 122

... The information is transferred to the host during enumeration. The host can then switch between device interfaces depending on what type of software it is running. For example, a data logger obtains the hosts configuration information, but also transfers large amounts of logged data stored card ...

Page 123

Getting Started: Building Applications with RL-ARM The RL-USB stack is made up of the following files: usbcfg templated configuration file that allows you to enable class support for the Human Interface, Mass Storage, and Audio classes. Is ...

Page 124

First USB Project The RL-USB driver may be used standalone or with the RTX RTOS. The RL-USB driver is contained in four source modules and one templated include file. The bulk of the RL-USB driver code is located in ...

Page 125

... USB event handlers. We can enable support for USB bus events. Depending on the USB controller, these may be handled by the USB controller hardware or may need additional software support. Each enabled event has a matching function in functions, such as reset_ event() will be provided, but optional functions, such as start of frame event will be empty stubs, and you will need to provide custom code ...

Page 126

The exception is Endpoint 0. The event handler for Endpoint 0 is located in Endpoint handles the control pipe not necessary to modify this function. The RL-USB driver also provides some additional call-back functions to handle additional ...

Page 127

Getting Started: Building Applications with RL-ARM const U8 USB_ConfigDescriptor[] = … USB_CONFIG_BUS_POWERED USB_CONFIG_POWER_MA(100), … USB_INTERFACE_DESCRIPTOR_TYPE, // bDescriptorType … USB_ENDPOINT_DESCRIPTOR_TYPE, … the configuration descriptor, you must define the device as self-powered, USB_CONFIG_SELF_POWERED, or bus-powered USB_CONFIG_BUS_POWERED. If the device is ...

Page 128

Human Interface Device The Human Interface Device (HID) within Windows is primarily used to support USB mice and keyboards. The HID driver can also be used to interface any other I/O device. For an embedded system, the HID driver ...

Page 129

... To understand how these are used, we will examine the Report descriptor used in the basic HID example, which may be found in the directory. C:\KEIL\ARM\BOARDS In this example, the host sends one byte to the device to control the state of eight LEDs. The device then sends one byte to the host. The first three bits report the state of three general purpose input/output (GPIO) pins configured as inputs ...

Page 130

Here, we define a unique vendor profile. The HID Usage is an index pointing to a subset within the usage page. Once the usage table has been defined, open the collection of input and output items. Remember, everything in ...

Page 131

Getting Started: Building Applications with RL-ARM Once the input and output items have been defined, we can complete the Report descriptor by closing the collection. HID_EndCollection }; By default, the HID OUT packet is sent to Endpoint ...

Page 132

The button data is held in a single byte, InReport. This variable is updated by the GetInReport() function user function placed in must update the InReport variable, which is defined in the example, the InReport consists of ...

Page 133

... Win32 API calls. This can be complicated if you are not used to host programming. However, the source code for a complete HID client application is located in C:\KEIL\ARM\UTILITIES\HID_CLIENT Visual C++. You will also need the Microsoft Driver Development Kit, which can be downloaded from the Microsoft web site. To make life easy, all of the necessary Win32 API calls have been placed in wrapper functions in the module ...

Page 134

Once we have located the driver and opened the connection, two further read and write functions allow us to exchange data with the attached HID device. BOOL HID_Read (BYTE *buf, DWORD sz, DWORD *cnt); BOOL HID_Write (BYTE *buf, DWORD ...

Page 135

Getting Started: Building Applications with RL-ARM // Endpoint, HID Interrupt Out USB_ENDPOINT_DESC_SIZE, USB_ENDPOINT_DESCRIPTOR_TYPE, USB_ENDPOINT_OUT(1), USB_ENDPOINT_TYPE_INTERRUPT, WBVAL(0x0040), 0x20, The Endpoint descriptor is added beneath the existing Endpoint 1 descriptor. We must also make sure that the overall descriptor size reflects the ...

Page 136

Within the client, we can use the existing code and just need to change the size of the IN and OUT reports. BYTE OutReport [64]; BYTE InReport [65]; if (!HID_Write (OutReport, sizeof (OutReport), &cnt)) OnError(); return (!HID_Read ...

Page 137

Getting Started: Building Applications with RL-ARM /*---------------------------------------------------------- / Mass storage class interface descriptor ----------------------------------------------------------*/ USB_INTERFACE_DESCRIPTOR_TYPE, 0x00, 0x00, 0x02, USB_DEVICE_CLASS_STORAGE, MSC_SUBCLASS_SCSI, MSC_PROTOCOL_BULK_ONLY, 0x62, The Mass Storage Class uses pipes, which have been configured to use bulk transfer. Although the bulk transfer ...

Page 138

USB_Init(); while ( (WakeUp) { WakeUp = __FALSE; USB_Connect (__FALSE); sd_main (); } else { if (mmc_init ()) mmc_read_config (&mmcfg); MSC_BlockCount = mmcfg.blocknr; USB_Connect (__TRUE); } while (!WakeUp void sd_main (void) { init_card (); while ...

Page 139

Getting Started: Building Applications with RL-ARM In , the Audio Class usbcfg.h support has been enabled, and Endpoint 3 is used for the streaming audio data the HID class configuration, information is sent in the form set_request and ...

Page 140

... Before releasing your USB device necessary to ensure that it fully meets the USB specification. A suite of USB compliance tests can be downloaded from the USB Implementers’ Forum. This software is called the USB command verifier. It automatically tests your device’s response to the core USB setup commands and the appropriate device class commands ...

Page 141

... CAN peripheral can be used as a glorified UART, without the need for an expensive and complex protocol stack. Since CAN is also used in Industrial Automation, there are a number of software standards defining how the CAN messages are used. This is necessary in order to transfer data between different manufacturers’ ...

Page 142

The two most popular of these application layer standards are CANopen and DeviceNet. The sole purpose of these standards is to provide interoperability between different Original Equipment Manufacturers’ (OEM) equipment. If you are developing your own closed system, then ...

Page 143

... Kbit/s. CAN Message Frames The CAN bus has two message objects, which may be generated by the application software. These are the message frame and the remote request frame. The message frame is used to transfer data around the network. The message frame is shown below. ...

Page 144

CRC field. After the CRC, there is an acknowledge slot. The transmitting node expects the receiving nodes to insert an acknowledgement in this ...

Page 145

Getting Started: Building Applications with RL-ARM As previously mentioned, the CAN message identifier can bits long. There are two standards of CAN protocol, the only difference being the length of the message identifier possible ...

Page 146

CAN arbitrates its messages by a method called “non-destructive bit-wise arbitration”. In the diagram, three messages are pending transmission. Once the bus is idle and the messages are synchronized by the start bit, they will start to write their ...

Page 147

Getting Started: Building Applications with RL-ARM level API and message buffering. The second file, level code for a specific CAN peripheral. Both modules have an include file, , which is used to provide custom settings. Like all the other CAN_cfg.h ...

Page 148

CAN_init() defines the bit rate of a given CAN controller. The CAN driver supports microcontrollers with multiple CAN controllers. Each CAN controller is referred number that starts from one. These numbers map directly onto the physical ...

Page 149

Getting Started: Building Applications with RL-ARM Then we call the CAN send function: CAN_send (1, &msg_send, 0x0F00); This will place the CAN message into the message queue. The message queue is a First-In-First-Out (FIFO) buffer, so the messages are guaranteed ...

Page 150

The node that sends this message will immediately reply to the remote frame with a message frame matching the identifier and its current data. When sending the remote frame you must be careful with the DLC setting. Although the ...

Page 151

Getting Started: Building Applications with RL-ARM Object Buffers The internal architecture of a CAN controller comes in two varieties: Basic CAN and Full CAN. Basic CAN has a single transmit and receive buffer. Full CAN has multiple transmit and receive ...

Page 152

... Meanwhile also used in other industries. It allows microcontrollers and devices to communicate with each other without a host computer. CGI Common Gateway Interface A standard protocol for interfacing application software to an internet service typically a HTTP server. Composite A USB device that supports two or more device classes. ...

Page 153

Getting Started: Building Applications with RL-ARM Datagram A networking message packet that does not provide any form of delivery acknowledgment. DHCP Dynamic Host Control Protocol A TCP\IP networking protocol that allows a station to obtain configuration information. DLC Data Length ...

Page 154

HID Human Interface Device A USB device class that supports peripherals, which provide input and output to humans. Typically, these are mouse and keyboards. HTTP Hyper Text Transfer Protocol A TCP\IP application level protocol for distributed “hypertext”. A collection ...

Page 155

... UDP User Datagram Protocol A primary protocol in the TCP\IP networking suite. UPD provides a simple transmission model without handshaking. UDP provides an ‘unreliable’ service; the application software must provide error checking and handshaking if necessary. RTR Remote Transmission Request Also part of the CAN message frame to differentiate a data frame from a remote frame. The dominant RTR bit (set to 0) indicates a data frame ...

Page 156

SLIP Serial Line Internet Protocol An internet protocol designed to provide a TCP\IP connection over a serial or modem link. SLIP is now obsolete and is replaced by SMTP Simple Mail Transfer Protocol A TCP\IP application layer protocol for ...

Related keywords