Lua on Atmel's AVR Microcontrollers

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

Lua on Atmel's AVR Microcontrollers

Ethernut
Hi,

we developed a tiny Open Source RTOS with TCP stack
for the ATmega128 uC and I recently investigated the
possibility to use Lua scripts for configuring the
hardware dependent parts of the system.

This "configurator" runs on the PC and uses wxWidgets
for the GUI to support most common platforms. Not yet
finished, but Lua was indeed the right choice. I'm now
making up my mind, wether Lua would make a good
scripting language for the target itself.

Has anybody tried to run Lua on an AVR uC or any
similar 8-bit system? Is there any port already
available? Any Open Source would be great as long
as it fits to the BSD- or Lua-style licence.

I'm sorry, if this had been answered recently, but
I tried hard to find a reference.

Many thanks,

Harald Kipp


Reply | Threaded
Open this post in threaded view
|

Re: Lua on Atmel's AVR Microcontrollers

Erik Hougaard
I have looked into putting Lua into a lot of different microcontrollers but most controllers fails on the memory part. You need ltos of memory (for a microcontroller) and you need full a malloc implementation. take a look at the uClinux - My guess is, if a microcontroller can run uClinux it would run Lua also..

But the ATmega128 has only 4 Kb RAM so there is ny chance of Lua running on it....

/Erik

Harald Kipp wrote:

Hi,

we developed a tiny Open Source RTOS with TCP stack
for the ATmega128 uC and I recently investigated the
possibility to use Lua scripts for configuring the
hardware dependent parts of the system.

This "configurator" runs on the PC and uses wxWidgets
for the GUI to support most common platforms. Not yet
finished, but Lua was indeed the right choice. I'm now
making up my mind, wether Lua would make a good
scripting language for the target itself.

Has anybody tried to run Lua on an AVR uC or any
similar 8-bit system? Is there any port already
available? Any Open Source would be great as long
as it fits to the BSD- or Lua-style licence.

I'm sorry, if this had been answered recently, but
I tried hard to find a reference.

Many thanks,

Harald Kipp




Reply | Threaded
Open this post in threaded view
|

Re: Lua on Atmel's AVR Microcontrollers

Ethernut
Erik,

running TCP over Ethernet also requires more than 4kB
RAM, so we added 32kB. When TCP is up and running, there
are around 20kB left. Luckily our RTOS supports malloc.

Additionally we implemented bank switching. The latest
hardware got 512kB RAM, 32kB fixed plus 30 banks 16KB ea.
Unfortunately no compiler for the AVR supports banked
memory. The application (or any special driver) must
handle bank switching.

If there are somehow central points, where Lua accesses
large memory areas, one could implement this.

Any opinions?

Thanks,
Harald

P.S. I know uCLinux, but do not have any experience with.

At 11:53 04.06.2004 +0200, you wrote:
I have looked into putting Lua into a lot of different microcontrollers but most controllers fails on the memory part. You need ltos of memory (for a microcontroller) and you need full a malloc implementation. take a look at the uClinux - My guess is, if a microcontroller can run uClinux it would run Lua also..

But the ATmega128 has only 4 Kb RAM so there is ny chance of Lua running on it....

/Erik


Reply | Threaded
Open this post in threaded view
|

Re: Lua on Atmel's AVR Microcontrollers

Erik Hougaard
The way Lua does memory makes it hard to use a microcontroller... I think 20KB is still to little depending on the how good your ROTS is...

Try to build a sample Lua application, simulating what you would like to run in the microcontroller.. Then create a debug interface so you can monitor lua memory usage Just done all call to lmem.c to a file that you can import into Excel for something afterward...

You might be able to store scripts in your 16KB banks and the use the 20KB for the rest....

See http://lua-users.org/lists/lua-l/2004-05/msg00060.html for inspiration and http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/

/Erik

Harald Kipp wrote:

Erik,

running TCP over Ethernet also requires more than 4kB
RAM, so we added 32kB. When TCP is up and running, there
are around 20kB left. Luckily our RTOS supports malloc.

Additionally we implemented bank switching. The latest
hardware got 512kB RAM, 32kB fixed plus 30 banks 16KB ea.
Unfortunately no compiler for the AVR supports banked
memory. The application (or any special driver) must
handle bank switching.

If there are somehow central points, where Lua accesses
large memory areas, one could implement this.

Any opinions?

Thanks,
Harald

P.S. I know uCLinux, but do not have any experience with.

At 11:53 04.06.2004 +0200, you wrote:

I have looked into putting Lua into a lot of different microcontrollers but most controllers fails on the memory part. You need ltos of memory (for a microcontroller) and you need full a malloc implementation. take a look at the uClinux - My guess is, if a microcontroller can run uClinux it would run Lua also..

But the ATmega128 has only 4 Kb RAM so there is ny chance of Lua running on it....

/Erik





Reply | Threaded
Open this post in threaded view
|

Re: Lua on Atmel's AVR Microcontrollers

Luiz Henrique de Figueiredo
In reply to this post by Ethernut
>If there are somehow central points, where Lua accesses
>large memory areas, one could implement this.

I'm not sure what you mean, but Lua 5.1 does not rely on malloc. Instead, the
host is required to provide a memory allocator when creating a Lua state. So,
you can implement whatever allocation policy when need or want. But Lua will
still ask for memory as it needs, that is, not in blocks.
--lhf

Reply | Threaded
Open this post in threaded view
|

Re: Lua on Atmel's AVR Microcontrollers

Asko Kauppi-3
In reply to this post by Ethernut

Nice to see people using AVR & Lua together.  I like them both. :)

I did a proof-of-concept compilation with avr-gcc a while back, and the code fits. Memory consumption is most likely to be the problem?

-ak

ps. There was a (I think Canadian?) project, fitting these together. I couldn't find it on the net now.. :(


4.6.2004 kello 12:47, Harald Kipp kirjoitti:

 Hi,

we developed a tiny Open Source RTOS with TCP stack
for the ATmega128 uC and I recently investigated the
possibility to use Lua scripts for configuring the
hardware dependent parts of the system.

This "configurator" runs on the PC and uses wxWidgets
for the GUI to support most common platforms. Not yet
finished, but Lua was indeed the right choice. I'm now
making up my mind, wether Lua would make a good
scripting language for the target itself.

Has anybody tried to run Lua on an AVR uC or any
similar 8-bit system? Is there any port already
available? Any Open Source would be great as long
as it fits to the BSD- or Lua-style licence.

I'm sorry, if this had been answered recently, but
I tried hard to find a reference.

Many thanks,

Harald Kipp



Reply | Threaded
Open this post in threaded view
|

Re: Lua on Atmel's AVR Microcontrollers

Ethernut
In reply to this post by Luiz Henrique de Figueiredo
Luiz,

I hadn't a chance to look into 5.1, but 5.0 uses realloc()
in lmem.c.

In case of simple, MMU-less memory banking, allocation
is no big deal, but accessing items is. As only a few
banks (only one in our case) are visible at a time, banks
have to be switched before accessing the data in the bank.

Regards,

Harald

At 07:34 04.06.2004 -0300, you wrote:
>If there are somehow central points, where Lua accesses
>large memory areas, one could implement this.

I'm not sure what you mean, but Lua 5.1 does not rely on malloc. Instead, the
host is required to provide a memory allocator when creating a Lua state. So,
you can implement whatever allocation policy when need or want. But Lua will
still ask for memory as it needs, that is, not in blocks.
--lhf


Reply | Threaded
Open this post in threaded view
|

Re: Lua on Atmel's AVR Microcontrollers

Erik Hougaard
Thats why I'm suggesting that you uses your bank for storing the source+byte code and use your 20kb for the rest.

/E

Harald Kipp wrote:

Luiz,

I hadn't a chance to look into 5.1, but 5.0 uses realloc()
in lmem.c.

In case of simple, MMU-less memory banking, allocation
is no big deal, but accessing items is. As only a few
banks (only one in our case) are visible at a time, banks
have to be switched before accessing the data in the bank.

Regards,

Harald

At 07:34 04.06.2004 -0300, you wrote:

>If there are somehow central points, where Lua accesses
>large memory areas, one could implement this.

I'm not sure what you mean, but Lua 5.1 does not rely on malloc. Instead, the host is required to provide a memory allocator when creating a Lua state. So, you can implement whatever allocation policy when need or want. But Lua will
still ask for memory as it needs, that is, not in blocks.
--lhf





Reply | Threaded
Open this post in threaded view
|

Re: Lua on Atmel's AVR Microcontrollers

Ethernut
Erik,

At 13:30 04.06.2004 +0200, you wrote:
Thats why I'm suggesting that you uses your bank for storing the source+byte code and use your 20kb for the rest.

Code must be kept in non-volatile memory. Moving
it to RAM may make sense for decreasing access
times. IMHO, reading byte code will not be the
speed bottleneck.

Harald


Reply | Threaded
Open this post in threaded view
|

Re: Lua on Atmel's AVR Microcontrollers

Erik Hougaard
Then I'm not sure I understand what you want to do......

My original idea, was to create a LuaChip (you heard it first here :-) that could receive Lua code on the fly and execute it and have a sort of RPC between Chips - all Chips sitting on either I2C, CAM, or Ethernet..

Can you write to the flash from a running program on a Mega128 ???

/Erik

Harald Kipp wrote:

Erik,

At 13:30 04.06.2004 +0200, you wrote:

Thats why I'm suggesting that you uses your bank for storing the source+byte code and use your 20kb for the rest.


Code must be kept in non-volatile memory. Moving
it to RAM may make sense for decreasing access
times. IMHO, reading byte code will not be the
speed bottleneck.

Harald




Reply | Threaded
Open this post in threaded view
|

Re: Lua on Atmel's AVR Microcontrollers

Ethernut


Can you write to the flash from a running program on a Mega128 ???

Yes, that's possible. We are using this in our TFTP/DHCP based
bootloader.

If would be nice to have the script running after
power down - power up cycles without the need to
reload it from a PC.

Harald


Reply | Threaded
Open this post in threaded view
|

LuaChip

Asko Kauppi-3
In reply to this post by Erik Hougaard

**whisteling to myself**... :DD

I'm _very_ delighted to see this idea. And yes, the LuaChip name is a brilliant one. :)

Would you consider an ARM based, all-included chip for this? That is, how low is the price target and you'll be forced to have external RAM anyways (with AVR).

http://www.atmel.com/dyn/products/param_table.asp? family_id=605&OrderBy=part_no&Direction=ASC
	AT91FR4042:	512k Flash, 256k RAM, no I2C/TWI or SPI :( but two USARTs

You can write to flash from any current AVR. It's page based, not quite trivial but it works. :)

-ak


ps. With CAM you surely mean CAN..? ;)


4.6.2004 kello 14:53, Erik Hougaard kirjoitti:

 Then I'm not sure I understand what you want to do......

My original idea, was to create a LuaChip (you heard it first here :-) that could receive Lua code on the fly and execute it and have a sort of RPC between Chips - all Chips sitting on either I2C, CAM, or Ethernet..

Can you write to the flash from a running program on a Mega128 ???

/Erik

Harald Kipp wrote:

Erik,

At 13:30 04.06.2004 +0200, you wrote:

Thats why I'm suggesting that you uses your bank for storing the source+byte code and use your 20kb for the rest.


Code must be kept in non-volatile memory. Moving
it to RAM may make sense for decreasing access
times. IMHO, reading byte code will not be the
speed bottleneck.

Harald





Reply | Threaded
Open this post in threaded view
|

Re: Lua on Atmel's AVR Microcontrollers

Ethernut
In reply to this post by Asko Kauppi-3
Asko,

At 13:40 04.06.2004 +0300, you wrote:

Nice to see people using AVR & Lua together.  I like them both. :)

Quite obvious, both are committed to simplicity. :-)


ps. There was a (I think Canadian?) project, fitting these together. I couldn't find it on the net now.. :(

Even after extensive googling I couldn't find anything.
In case you or anybody else got a reference, please let
me know.

Thanks,

Harald


Reply | Threaded
Open this post in threaded view
|

Re: LuaChip

Erik Hougaard
In reply to this post by Asko Kauppi-3
Asko Kauppi wrote:

I'm _very_ delighted to see this idea. And yes, the LuaChip name is a brilliant one. :)

Yeah !

Would you consider an ARM based, all-included chip for this? That is, how low is the price target and you'll be forced to have external RAM anyways (with AVR).

Have have considered a lot of different microcontrollers...

Ubicom IP3032
Atmel AT91FR40162*
*Motorola Coldfire 5282
Infineon TC1130 (No flash)

But right now I havent really found the chip that would be perfect.. I want the package to be as small as possible, so it can be embedded everywhere.

The perfect chip has the following features:

32 bit flat address
100+ MIPS
Low Power
Very small support schematics
512 Kb Flash
1024 Kb Ram
Ethernet controller builtin - external trans. ok!
USB Controller
and ofcause all the usual microcontroller stuff like uarts, timers, pwm, ADC etc...
**
All suggestions are welcome!

ps. With CAM you surely mean CAN..? ;)

Yes... Ofcause ... Controller Area Metwork :-)

/Erik