drozd
drozd on Hacker News
The linker script specifies that .data section starts where 192k RAM region starts - in other words, addresses of all variables, etc, are in the RAM memory range.
But the firmware image (that resides on flash), which has .text and .data concatenated, has that .data section in Flash region, obviously. So we have .data section residing in Flash region, but all its addresses in the RAM memory range. That's why it is necessary to copy it over manually.
Hope this is clear... Let me know if not!
Posted by
drozd on Monday December 12, 2022 @09:43AM
from the github.com dept.
Posted by
drozd on Thursday December 06, 2018 @08:49AM
from the youtube.com dept.
Fast prototyping is the answer. If you or some others are skilled in C/C++, you don't need JS.
For others, having a simple way to prototype fast on the target hardware is a big benefit.
mJS allows you to use C/C++ SDK functions directly without writing a glue code - basically, you can prototype things quite fast with the libraries/drivers that do not have any scripting support yet.
That's right, cause Linux cannot run on the large class of microcontrollers - particularly, those with less than 4M of RAM. Mongoose OS is targeting that category.
Sure, try to run those on e.g. TI CC3200 microcontroller.
Ah, thanks, wrong about flash footprint.
Neil has done a great job adopting Duktape on ESP32.
Hi Gordon! Nice to meet you :) I am the author of the article, and I am quite fond of Espruino, it's a great project. Wasn't aware that Espruino has FFI API!
Yes. Closures add quite a bit of complexity and footprint.
Anticipated use case was a short script that orchestrates the device logic, calling existing SDK functions.
Nice!
I wasn't aware of lua ffi api, thank you!
Nope.
It's similar though, cause some of the concepts, and the code, were reused.
mJS does not need an embedding API, really. The intent is that FFI is used.
Embedded environment in this context means hardware low on resources, e.g. microcontrollers. Your perception of that word is "embedded into the C/C++ program". These are two different things. I agree that Lua (like some other languages) were designed to be embedded into C/C++ apps.
Duktape is nice, and I've mentioned it in the article. However it's quite fat, and can't be used on some boards like ESP8266. It's flash footprint is Megabytes, whereas mJS flash footprint is ~25k.
I recall that very much the same opinions were expressed about the JS and backend programming, until node.js appeared. Now the reality is different.
To be honest, we do not think that JS is a good language for embedded. Like any other existing popular scripting language. Perhaps scripted Go would be a better choice.
The point is that in many, many cases scripting brings a lot of benefits to the embedded environment. It all depends on a specific tasks - for some tasks, scripting will never be appropriate.
There is no yacc code in either V7 or mJS.
V7 uses hand-written recursive-descent parser. Initially, it was using ordinary C functions, and that created a problem on systems with low stack size. E.g. each '(' starts statement parsing from the top, so 1 + (2 + (3 + (4 + 5))) consumed stack, and sometimes resulted in stack overflow in e.g. interrupt handlers or network callbacks.
Therefore we have rewritten recursive descent using C coroutines, and that is extremely sophisticated piece of work. See https://raw.githubusercontent.com/cesanta/v7/master/v7.c , search for #line 1 "v7/src/parser.c"
mJS on the other hand uses lemon parser generator - the one from sqlite project. It generates a LALR parser which is quite efficient in terms of memory.
The ability to script without the need of rebuilding/reflashing the whole firmware is often fairly useful.
The most value is not in JS per se, but in the ability to script.
Currently, mJS FFI is limited to functions only. And, to simple enough functions.
On how to access memory from mJS: write an accessor function!
// C
void setmem(uint8_t *ptr, int index, int value) {
ptr[index] = value;
}
// mJS
let setmem = ffi('void setmem(void *, int, int)');
let malloc = ffi('void *malloc(int)');
let mem = malloc(10);
setmem(mem, 3, 5);
Posted by
drozd on Thursday July 14, 2016 @01:44PM
from the github.com dept.
Posted by
drozd on Friday June 10, 2016 @07:09AM
from the github.com dept.
Posted by
drozd on Thursday March 10, 2016 @05:08AM
from the blog.cesanta.com dept.