martes, 11 de diciembre de 2012

Español : Aprendiendo a usar el entorno de desarollo NXP LPCXpresso LPC812 Ingles: Learning how to use NXP LPXXpresso LPC812 development board

 

Español

Antes que nada los artículos que pondré de ahora en adelante serán tanto en inglés como en español, espero y funcione por lo pronto no estoy seguro si poner las dos versiones en el mismo post o hacerlo de manera individual; hoy serán ambos idiomas en el mismo post.

Pues como les dije hace unos días me aventuraré en el uso de los µC ARM-CORTEX-MX para eso cuento con varias tarjetas de diferentes fabricantes (más información la pueden encontrar en el post anterior). Empezaré con el de NXP.

Antes que nada comienzo con esta placa y esta serie ya que NXP lo que trata de hacer de µC LPC8XX es desplazar los µC de 8-bits ya que los de esta seria tienen µC de 8 pines en empaquetado DIP y hasta 20 pines en empaquetado TSSOP, con 4 hasta 16 KB de memoria flash y 1 hasta 4KB de memoria RAM, el único lado “MALO” para los hobistas, es que sólo trabajan con voltajes de 1.8V a 3.6V.

LPC800_block_diagram_thumb4

Imagen 1- diagrama a bloques del LPC8XX

Otras de las cosas interesantes que tiene este microcontrolador es algo que NXP llama “SWITCH MATRIX”(matríz de switches), esto te da la opción de configurar casi todos los pines del µC (voltaje y tierra no se pueden configurar) con cualquier función que incluya el µC ya sea de las UART´s, GPIO´s, I2C, SPI, etc… en cualquier pin que quieras lo único que debes de hacer es usar la herramienta que llaman SWITCH MATRIX TOOL y ésta nos genera un código que se debe de incluir al principio del µC (o al menos es lo que creo hasta el momento).

switchmatrixtool_thumb3

Imagen 2 – Switch Matrix Tool

Y por último y no menos importante es que NXP decidió poner drivers de bajo nivel para el I2C y el UART en una memoria ROM entonces sólo requieren llamadas a API´s que vienen dentro de una memoria ROM del µC.

Por el momento los chips como tales no los venden todavía (solo las tarjetas de demostración).

Les comento un poco sobre esta placa, aunque pueden encontrar más información aquí.

En primera: el empaque en lo personal no me gustó pero bueno por los 24 USD que costó pues está bien. Viene en una bolsa de cartón con el plástico este de bolitas que se truenan y cuyo nombre no recuerdo (venia abierta por que la aduana la abrió).

2012121121.30.02_thumb7

Imagen 3 Bolsa donde viene la LPC812

Dentro de ésta viene la placa dentro de una bolsa antiestática y un plástico con agujeros para los componentes que están más altos como son el potenciómetro el conector USB los dos cristales, el del debug y el del µC y el JTAG. Incluido viene una tarjeta pequeña con un código de cupones que funciona en embedded artists que les da un descuento, aunque no creo que sea muy útil en México (salvo que vayas a comprar un software que sea descargable) pero pedir algo desde allá sale caro.

2012121121.27.57_thumb9

Imagen 4 lo que viene dentro del paquete.

2012121121.28.33_thumb8

Imagen 5 - PCB

Espero y se alcance a ver (la única cámara que tengo es la de mi celular), pero en el centro de la PCB se ven unas hileras de pines machos con espaciamiento de 100 mil. Entre estas dos hay soldadura, que hay que remover y poner pines normales para así poder usar el JTAG que tiene en otro dispositivo y para usar el JTAG en el µC interno debes de puentear esto con jumpers.

conectorJTAG_thumb1

Imagen 7 - Conector JTAG para dispositivos externos

Ahora sí, antes de comenzar debes de descargar el IDE LPCXpresso basado en eclipse desde aquí . Este IDE es gratuito y es de Code Red, aun así hay que registrarse y después activar el IDE aquí (les menciono para que no les pase como a mí) bajen la versión LPCXpresso v5.0.12 o más nueva por que las versiones anteriores aún no soportan los LPX8XX y de esta manera no tendrán que bajarlo dos veces

lpcxpresso_thumb2

Imagen 8 LPCXpresso IDE

Como lo ven pues el IDE está basado en eclipse entonces es bastante familiar para los que ya han usado eclipse como su IDE. En lo personal yo no lo conozco entonces me iré familiarizando con él poco a poco.

Antes de comenzar no está de más bajar la hoja de datos del LPC812 y de la serie LPC8XX, también el diagrama esquemático de la tarjeta y los Sample codes

Después de esto lo que tenemos que hacer es importar los sample codes al LCPXpresso, para esto hay que abrir el IDE, después seleccionar file y después import.

import_thumb2

Imagen 9 Ventana de Import

Después de esto en la sección de General seleccionamos existing projects into workspace y damos en Next como se muestra en la imagen.

Cuando hacemos esto nos cambia de ventana y sale una ventana como esta.

selecciondearchivpp_thumb2

Imagen 10 Selección de archivo

Aquí marcamos la opción que dice Select root directory y le damos en browse, que está a la izquierda. Auí nos aparece una ventana y tenemos que seleccionar la carpeta del archivo que se descomprimió y descargamos con los códigos muestra.

Para finalizar le damos click en Finish, después deben de ver el IDE de esta manera. Aquí yo ya lo activé, deben de hacerlo ustedes también solo sigan los paso que les pide para activarlo.

image_thumb

Imagen 11 – LPCXpresso IDE

Después de esto tenemos ya todos los proyectos de muestra importados y listos para ser compilados. Por el momento sólo usaremos el que se llama Blinky.

Antes de eso debemos de tener conectada la tarjeta de desarrollo con sus controladores a la PC y en windows nos debe de aparecer de la siguiente manera.

drivers_thumb2

Imagen 12 – Drivers correctamente instalados

Si esto aparece así quiere decir que ya están instalados los controladores para la tarjeta de desarrollo y que podemos proceder.

El IDE (Integrated Developmente Enviorment) como antes lo mencioné está basado en ECLIPSE y cuenta con 4 zonas que describiré a continuación.

explicacionIDE_thumb2

Imagen 13 – Descripción del LPCXpresso IDE

    1. Explorador de Proyectos: aquí tienes todos los códigos fuente que están en tu lugar de trabajo actual.
    2. Inicio Rápido: Links usados como: nuevo proyecto, importar de proyectos, etc …
    3. Editor: Te permite modificar y guardar tu código fuente actual.
    4. Consola: despliega información de: compilación, depuración, errores, etc …

Sabiendo esto le damos click al explorador de proyectos y abrimos la carpeta que dice blinky. Dentro de eso nos aparecen varias carpetas entre esas una que dice src la abrimos y salen 3 archivos:

  • cr_starup_lpc8xx.c
  • crp.c
  • main.c

Le damos dos click a la que dice main.c

exploradordeproyectos_thumb5

Imagen 14 – click en main.c

Aquí les dejo el código fuente

   1: /****************************************************************************
   2:  *   $Id:: blinky.c 3634 2012-10-31 00:09:55Z usb00423                      $
   3:  *   Project: NXP LPC8xx Blinky example
   4:  *
   5:  *   Description:
   6:  *     This file contains LED blink code example which include timer,
   7:  *     GPIO initialization, and clock monitoring.
   8:  *
   9:  ****************************************************************************
  10:  * Software that is described herein is for illustrative purposes only
  11:  * which provides customers with programming information regarding the
  12:  * products. This software is supplied "AS IS" without any warranties.
  13:  * NXP Semiconductors assumes no responsibility or liability for the
  14:  * use of the software, conveys no license or title under any patent,
  15:  * copyright, or mask work right to the product. NXP Semiconductors
  16:  * reserves the right to make changes in the software without
  17:  * notification. NXP Semiconductors also make no representation or
  18:  * warranty that such application will be suitable for the specified
  19:  * use without further testing or modification.
  20: 
  21:  * Permission to use, copy, modify, and distribute this software and its
  22:  * documentation is hereby granted, under NXP Semiconductors'
  23:  * relevant copyright in the software, without fee, provided that it
  24:  * is used in conjunction with NXP Semiconductors microcontrollers. This
  25:  * copyright, permission, and disclaimer notice must appear in all copies of
  26:  * this code.
  27: 
  28: ****************************************************************************/
  29: #ifdef __USE_CMSIS
  30: #include "LPC8xx.h"
  31: #endif
  32: #include "lpc8xx_clkconfig.h"
  33: #include "lpc8xx_gpio.h"
  34: #include "lpc8xx_mrt.h"
  35: extern uint32_t mrt_counter;
  36: /* Main Program */
  37: int main (void) {
  38:   uint32_t regVal;
  39:   SystemCoreClockUpdate();
  40:   /* Config CLKOUT, mostly used for debugging. */
  41:   regVal = LPC_SWM->PINASSIGN8 & ~( 0xFF << 16 );
  42:   LPC_SWM->PINASSIGN8 = regVal | ( 12 << 16 );    /* P0.12 is CLKOUT, ASSIGN(23:16). */
  43:   CLKOUT_Setup( CLKOUTCLK_SRC_MAIN_CLK );
  44:     #if 0
  45:     regVal = LPC_SWM->PINASSIGN0 & ~( (0xFF << 0) | (0xFF << 8) );
  46:     LPC_SWM->PINASSIGN0 = regVal | ( (2 << 0) | (3 << 8) );    /* P0.2 is UART0 TX, ASSIGN(7:0); P0.3 is UART0 RX. ASSIGN(15:8). */
  47: #endif
  48:   /* Enable AHB clock to the GPIO domain. */
  49:   LPC_SYSCON->SYSAHBCLKCTRL |= (1<<6);
  50:   /* Set port p0.7 to output */
  51:   GPIOSetDir( 0, 7, 1 );
  52:     /* Set port p0.16 to output */
  53:   GPIOSetDir( 0, 16, 1 );
  54:  /* Set port p0.17 to output */
  55:   GPIOSetDir( 0, 17, 1 );
  56:     init_mrt(0x8000);
  57:   while (1)                                /* Loop forever */
  58:   {
  59:         /* I/O configuration and LED setting pending. */
  60:         if ( (mrt_counter > 0) && (mrt_counter <= 200) )
  61:         {
  62:             GPIOSetBitValue( 0, 7, 0 );
  63:         }
  64:         if ( (mrt_counter > 200) && (mrt_counter <= 400) )
  65:         {
  66:             GPIOSetBitValue( 0, 7, 1 );
  67:         }
  68:         if ( (mrt_counter > 400) && (mrt_counter <= 600) )
  69:         {
  70:             GPIOSetBitValue( 0, 16, 0 );
  71:         }
  72:         if ( (mrt_counter > 600) && (mrt_counter <= 800) )
  73:         {
  74:             GPIOSetBitValue( 0, 16, 1 );
  75:         }
  76:         if ( (mrt_counter > 800) && (mrt_counter <= 1000) )
  77:         {
  78:             GPIOSetBitValue( 0, 17, 0 );
  79:         }
  80:         if ( (mrt_counter > 1000) && (mrt_counter <= 1200) )
  81:         {
  82:             GPIOSetBitValue( 0, 17, 1 );
  83:         }
  84:         else if ( mrt_counter > 1200 )
  85:         {
  86:             mrt_counter = 0;
  87:         }
  88:   }
  89: }

Ahorita no me concentraré mucho en esto debido a que me interesa más que aprendamos a cómo depurar el microcontrolador pero aquí está el código .


Teniendo esto hay que compilar el proyecto. Para esto hay que darle en la barra de herramientas donde dice Project y después le damos en Build Project. Para saber que esta operación fue exitosa, en la consola debe de decir BUILD Finished (took Xs.xxxms)


Ya habiendo compilado esto en el explorador de proyectos queremos recalcar el que dice Blinky y luego en la barra de inicio rápido le damos click en Debugg blinky y si no encontramos problemas ahora estamos depurando el programa (y así comenzamos la depuración).

En mi siguiente post les explicaré en qué nos beneficia depurar el programa y cómo se hace.

Espero y les haya gustado.

Cualquier comentario, pregunta o sugerencia no duden en enviarme un correo a mecatronicamexicana@gmail.com o deja un comentario aquí.

English


Before anything I always be putting thee blog post in 2 different languages, English and Spanish, I hope this works by this time I am not really sure I´ll put the Spanish and English version in the same post or in different post, this time both are going to be in the same.

As I comment you some days before I´ll will star using µC ARM-CORTEX-MX, as you know I have been purchasing several development boards of different manufacturers for more information you can find it in the last post but just to be aware this post it´s only in Spanish as this last post says I will start with the NXP board

I start with this development board because NXP seems to try to replace 8-bit µC with this µC series LPC8XX because this series has µC starting from 8 pin in a DIP package to 20 pin in a TSSOP package and has up to 16 KB of flash memory and up to 4 KB of RAM memory, the only down side is for the hobbyists because this µC only work with voltage from 1.8V to 3.6V.


LPC800_block_diagram_thumb5


Image 1 – LPC8XX Block diagram


One of the interesting things this µC has is something NXP calls “SWITCH MATRIX”, this gives you the choice of configure almost every pin of the µC (just VCC and VDD can´t be configured) with any function that the µC has this can be the UART, GPIO, I2C, SPI, etc….. in any pin you want the only thing you have to use is this tool that they call SWITCH MATRIX TOOL, this generates a code that need to be included in the start of the µC or at least this is what I think.

switchmatrixtool_thumb

Image 2 – Switch Matrix Tool

At last but not less important is that NXP decided to put low level drivers for I2C and UART in a ROM memory so you only need to make some API call´s for the functions that are in the ROM

For the moment the chip isn´t in sale just the development boards

I will tell you some of the characteristics of this development board but you can find more information here.

At first the package in my personal opinion I didn´t like it but It´s ok for the 24 USD that it cost this comes in a bag made of carton with the plastic that has little bubbles.

2012121121.30.02_thumb


Image 3 – Bag where the LPC812 board comes.


Inside this bag it comes the development board inside and antistatic bag with a plastic that has holes for the taller component like the potentiometer, the USB connector and both of the crystals one for JTAG and the other for the µC. Included in the package comes a little card with a coupon code for discount in embedded artists

2012121121.27.57_thumb

Image 4 – What´s inside the package


2012121121.28.33_thumb


Image 5 – development board


I hope this seems fine because the only camera I have is the camera off my cellphone, but in the center of the development board you can see some holes for pins with a 100 mil spacement, here you can find some points with weld we have to remove this weld and put a male pin header if we need to use the JTAG to program the development board target we need to put some jumpers in this if not we only need to remove them to program an external target.

conectorJTAGe_thumb1

Image 6 –Jtag connector for external devices


Now before we star we need to download the IDE that´s based in eclipse form here this IDE it´s free of charge it´s from Code Red, but we need to register and after that activate it. I comment you need to download LPCXpresso v5.0.12 or a newer one the old ones don’t have support for this µC series

lpcxpresso_thumb

Image 8 – LPCXpresso IDE


As you can see the IDE is based in Eclipse so it´s very familiar for the persons that use Eclipse as there IDE, I don´t know it I will get used to it little by little

Before we begin we need to have dome information of the LPC812 development board and the LPC8XX µC series, also the schematic diagram of the board and the sample codes.


After all of this we need to import the simple codes to the LPCXpresso IDE to do this we need to open the IDE after this select File and then import

import_thumb

Image 9 – Import window


After this in the General section we select existing projects into workspace and click in next this is as shown in the image

When we do this our Windows changes and put us one of this

selecciondearchivpp_thumb

Image 10 – Selecting the file


Here we mark the option that says select root directory and we click in browse that´s on the left, it pop up a windows and we need to select the folder that we download and unzipped the sample codes.

To finish this we need to click in Finish after all of this you can see the IDE like this way. I have activated my IDE you must also do it you just only need to follow the steps to activate it it´s completely free.

lpcxpresso_thumb3

Image 11 – LPCxpresso IDE


After all of this we have all the projects imported and ready to be compiled by the moment we will only use the one that´s named Blinky

Before this we need to have connected the development board and the drivers to the PC in windows they need to be something like this.

driverse_thumb2

Image 12 – LPC812 Drivers


If this appears like this it mean that the drivers of the development board are installed correctly and we can proceed

The IDE as before is based in Eclipse and I has 4 different areas I´ll describe this different areas.

explicacionIDE_thumb

Image 13 – LPCXpresso IDE




  1. Project explorer: here we have all the project you have in your work space.


  2. Quick Start: useful links like new project, import projects, etc…..


  3. Editor: lets us edit or change the code.


  4. Console: Give´s you information of compilation time and debugging time

Knowing all this we click in the Project explorer and open the folder that says blinky inside this there are several folders one of those is srs we open it and they are 3 files inside it that are



  • cr_starup_lpc8xx.c


  • crp.c


  • main.c

We click on main.c

exploradordeproyectose_thumb2

Image 14 – Main.c


Here is the source code



   1: /****************************************************************************
   2:  *   $Id:: blinky.c 3634 2012-10-31 00:09:55Z usb00423                      $
   3:  *   Project: NXP LPC8xx Blinky example
   4:  *
   5:  *   Description:
   6:  *     This file contains LED blink code example which include timer,
   7:  *     GPIO initialization, and clock monitoring.
   8:  *
   9:  ****************************************************************************
  10:  * Software that is described herein is for illustrative purposes only
  11:  * which provides customers with programming information regarding the
  12:  * products. This software is supplied "AS IS" without any warranties.
  13:  * NXP Semiconductors assumes no responsibility or liability for the
  14:  * use of the software, conveys no license or title under any patent,
  15:  * copyright, or mask work right to the product. NXP Semiconductors
  16:  * reserves the right to make changes in the software without
  17:  * notification. NXP Semiconductors also make no representation or
  18:  * warranty that such application will be suitable for the specified
  19:  * use without further testing or modification.
  20: 
  21:  * Permission to use, copy, modify, and distribute this software and its
  22:  * documentation is hereby granted, under NXP Semiconductors'
  23:  * relevant copyright in the software, without fee, provided that it
  24:  * is used in conjunction with NXP Semiconductors microcontrollers. This
  25:  * copyright, permission, and disclaimer notice must appear in all copies of
  26:  * this code.
  27: 
  28: ****************************************************************************/
  29: #ifdef __USE_CMSIS
  30: #include "LPC8xx.h"
  31: #endif
  32: #include "lpc8xx_clkconfig.h"
  33: #include "lpc8xx_gpio.h"
  34: #include "lpc8xx_mrt.h"
  35: extern uint32_t mrt_counter;
  36: /* Main Program */
  37: int main (void) {
  38:   uint32_t regVal;
  39:   SystemCoreClockUpdate();
  40:   /* Config CLKOUT, mostly used for debugging. */
  41:   regVal = LPC_SWM->PINASSIGN8 & ~( 0xFF << 16 );
  42:   LPC_SWM->PINASSIGN8 = regVal | ( 12 << 16 );    /* P0.12 is CLKOUT, ASSIGN(23:16). */
  43:   CLKOUT_Setup( CLKOUTCLK_SRC_MAIN_CLK );
  44:     #if 0
  45:     regVal = LPC_SWM->PINASSIGN0 & ~( (0xFF << 0) | (0xFF << 8) );
  46:     LPC_SWM->PINASSIGN0 = regVal | ( (2 << 0) | (3 << 8) );    /* P0.2 is UART0 TX, ASSIGN(7:0); P0.3 is UART0 RX. ASSIGN(15:8). */
  47: #endif
  48:   /* Enable AHB clock to the GPIO domain. */
  49:   LPC_SYSCON->SYSAHBCLKCTRL |= (1<<6);
  50:   /* Set port p0.7 to output */
  51:   GPIOSetDir( 0, 7, 1 );
  52:     /* Set port p0.16 to output */
  53:   GPIOSetDir( 0, 16, 1 );
  54:  /* Set port p0.17 to output */
  55:   GPIOSetDir( 0, 17, 1 );
  56:     init_mrt(0x8000);
  57:   while (1)                                /* Loop forever */
  58:   {
  59:         /* I/O configuration and LED setting pending. */
  60:         if ( (mrt_counter > 0) && (mrt_counter <= 200) )
  61:         {
  62:             GPIOSetBitValue( 0, 7, 0 );
  63:         }
  64:         if ( (mrt_counter > 200) && (mrt_counter <= 400) )
  65:         {
  66:             GPIOSetBitValue( 0, 7, 1 );
  67:         }
  68:         if ( (mrt_counter > 400) && (mrt_counter <= 600) )
  69:         {
  70:             GPIOSetBitValue( 0, 16, 0 );
  71:         }
  72:         if ( (mrt_counter > 600) && (mrt_counter <= 800) )
  73:         {
  74:             GPIOSetBitValue( 0, 16, 1 );
  75:         }
  76:         if ( (mrt_counter > 800) && (mrt_counter <= 1000) )
  77:         {
  78:             GPIOSetBitValue( 0, 17, 0 );
  79:         }
  80:         if ( (mrt_counter > 1000) && (mrt_counter <= 1200) )
  81:         {
  82:             GPIOSetBitValue( 0, 17, 1 );
  83:         }
  84:         else if ( mrt_counter > 1200 )
  85:         {
  86:             mrt_counter = 0;
  87:         }
  88:   }
  89: }

Here is the source code I won´t put a lot of focus on the source code since I am more interested in learning how to debug the µC

Having this we need to compile the project to do this we need to click in project this is in the toolbar after that we click in build project. To now that this operation was succesfull the console must show BUILD finished (took Xs.xxms)

Having this in the project explorer we highlight the project we want to debug in this case Blinky and then in the quick start we click where it says Debugg blinky if we didn’t have problems we are known debugging the program but that would be all for this post. Debugging the program would be in the next post .

Hope you like it and if you know any comment question suggestion you can email me to mecatronicamexicana@gmail.com or leave a comment here.

No hay comentarios: