Recent Changes - Search:

edit SideBar

DuktapeEclipseARMCortexM3

Based heavily on Duktape For ARM-Cortex M3 (accessible only to densoeal members) by Rene Vivanco

Overview

This section details the specific for using DUKtape on Cortex-M3 processor for DUKtape development. In this case we select LPC1768.

Linker File

The Linker file is responsible to accommodate the produced executable in the target processor. It shall match the memory map specifications of the target device. For the case of our specific device (LPC1768), select the mem.ld file and modify as shown below.

Target Peripheral Memory Access

During device configuration and debugging, it is very useful to be able to see the peripheral memory behavior. In Eclipse it is possible to attach a device specific peripheral view. To enable it, follow the steps below

  • Right-click on the project name and select Properties.
  • A new window will appear, expand C/C++ Build and select Settings. This step would take some time.
  • Select Device Tab and choose LPC1768
  • When the device is flashed, the peripherals would be available in the memory window.

Timer Setup

To implement timeval we need a way to keep track of seconds and for microseconds since the system starts. One way to do this is using one of the built-in timers provided in the LPC1768 as follows.

  • The peripheral frequency on the LPC1768 is 25Mhz and the timers have the capability to define a prescaler, so we can set it up to have a tick of 1us and then and ISR that update a variable called seconds.
  • The system can read the Prescaler counter at any time which will provide the miro-second value accurately and seconds as global variable.
  • The function gettimeofday is implemented as follows:
int _gettimeofday(struct timeval *tv, void *tz)
{
        // Read uS from Register
        tv->tv_usec = *T1TC;

        // Read Seconds from global variable
        tv->tv_sec = secs;

        return(0);
}
  • The ISR only needs to update the global variable secs every second.
void __attribute__ ((section(".after_vectors"),weak))
TMR1_IRQHandler (void)
{
        // Clear ISR flag
        T1IR->MR0INT             = 1;

        // Increment seconds
        secs++;
}

Accessor Configuration

DukTape Configuration

  • Config file setup (duktape.We made the next modifications in the configuration file (duk_config.h):
#define __arm__
#define DUK_OPT_NO_JSON_STRINGIFY_FASTPATH
#define DUK_OPT_NO_REFERENCE_COUNTING
#define DUK_OPT_REFCOUNT16
#define DUK_OPT_STRHASH16
#define DUK_OPT_STRLEN16
#define DUK_OPT_BUGLEN16
#define DUK_OPT_OBJSIZES16

// Modify FILE definition as
typedef void duk_file;       // <<== This is just to compile since will not be a file system
  • The main file is as follows:
#include "drv_hw.h"
#include "duktape.h"
void main()
{
    duk_context *ctx = NULL;

    drv_boardInit();
    ctx =  duk_create_heap_default();
    duk_destroy_heap(ctx);
}
  • To compile, we select the option of duktape separate sources, which seems to be cleaner. The results are:
155,686 bytes of readonly code memory    (Flash)
 19,174 bytes of readonly data memory    (Flash-constants)
  4,368 bytes of R/w data memory         (RAM)

Notes

  • Duktape uses a considerable amount of constants which increases the amount of flash utilized.
  • RAM is in a good low number.
  • It might be possible to run duktape in this small devices if an additional storage can be used (such as a sD card or serial SPI flash).

Current Issues

  • The memory numbers that we obtained are lower than duktape website, however dynamic memory allocation of 71 threads blows the memory of the LPC1768.

See Also

Edit - History - Print - Recent Changes - Search
Page last modified on December 30, 2016, at 08:08 AM