-
Not working.
It must be a reason for that ?_____ _ | |_ ___ ___ _ ||___ ___ | |_ -| . | _| | | | | . | ||| || |_|||_|_|
|_| http://espruino.com 1v50 Copyright 2014 G.Williams
echo(0); X= 0 Y= 0 X= 0 Y= 0 X= 0 Y= 0 X= 0 Y= 0 X= 0 Y= 0
=undefined X= 0 Y= 0function onInit() { SPI1.setup({ sck: A5, miso: A6, mosi: A7 , cs: E3, int1: E0, int2:E1 } ); SPI1.send([0x20,0b01000111], E3); } var avrx=0.0, avry=0.0; function getAcc() { var accx = SPI1.send([0xA9,0], E3)[1]; var accy = SPI1.send([0xAB,0], E3)[1]; if (accx>127) accx-=256; if (accy>127) accy-=256; avrx = 0.1*accx + 0.9*avrx; avry = 0.1*accy + 0.9*avry; console.log("X= "+avrx+" Y= "+avry); } onInit(); var t = setInterval(getAcc, 10); // clearInterval(t);
-
-
-
I don't want to bother you with stupid problems, but…
something really unexpected is happening, at least on my STM32F4DISCOVERY board.I checked on two different boards, the behavior was the same.
Then taking for grant a same board, I went back installing the past versions of Espruino.
When I installed version 1v41 the SPI behaved as expected.
Using later version I always got ZERO as output.
When I checked with the scope , seeing no data activity over theMISO , MOSI lines but correct clocks over the SCK line, I was using version 1v51.( my custom complilation )
The same wrong behavior happens with my backup versions: 1v48, 1v50.
I am going to look deeply at the code.
I noticed this behavior just now, because other functionalities gave no problems, so I proceeded installing new versions.Is there a place in the code were I can easily and immediately check for ?
Of course the Javascript code was the same.
function onInit() {
SPI1.send([0x20,0b01000111], E3);
}var avrx=0.0, avry=0.0;
function getAcc() {
var accx = SPI1.send([0xA9,0], E3)[1];
var accy = SPI1.send([0xAB,0], E3)[1];
if (accx>127) accx-=256;
if (accy>127) accy-=256;
avrx = 0.1*accx + 0.9*avrx;
avry = 0.1*accy + 0.9*avry;
console.log("X= "+avrx+" Y= "+avry);
}
onInit();var t = setInterval(getAcc, 10);
// clearInterval(t);X= 10.342832 Y= -1.9707
X= 10.308549 Y= -1.97363
X= 10.277694 Y= -2.076267
X= 10.249925 Y= -2.06864
X= 10.224932 Y= -2.061776
X= 10.302439 Y= -2.055598
X= 10.272195 Y= -2.050039
X= 10.244975 Y= -2.045035
X= 10.220478 Y= -2.140531
X= 10.29843 Y= -2.026478
X= 10.268587 Y= -2.02383
X= 10.241728 Y= -2.021447
X= 10.317555 Y= -2.019302
X= 10.2858 Y= -2.017372
X= 10.25722 Y= -2.015635
X= 10.331498 Y= -2.014071
X= 10.298348 Y= -2.012664
X= 10.268513 Y= -2.011398
X= 10.241662 Y= -2.010258
X= 10.217495 Y= -2.009232
X= 10.295746 Y= -2.008309 -
May it be that the new upgrade of version 1v51 introduced some bugs: with respect SPI and I2C programming ?
This works fine : Added Number.toFixed test056)
but this seems to haveSPI or I2C communications no longer working at leads on STm32F4Discovery.
Now use jshardware's SPI for SD filesystems - more multi platform.
Looking with a scope non signal is sent over the MOSI line, even clocks ar properly generated over the SCK line.
All serials are working fine. -
Possibly ESPRUINO software internal architecture is better than what can be expected after a first look.
I am now beginning to understand that having a local storage (SD card ) and a "huge SDRAM " amount for variables and adding to that the possibility to add or remove cached modules gives a program the ability to work as in the old fashioned overlapped memory concept.
Not the same as a virtual memory but a really effective technique on embedded system.Assuming those SDRAM memory cost figures:
expr 20 * 5450 = 109000 100KB/192KB SDRAM 92KB free STM32F4x7, x=0,1,2
expr 20 * 8200 = 164000 164KB/256KB SDRAM 92KB free STM32F4x9, x=2,3a lot of possibility arise for the Javascript interpreter, whose memory allocation penalty is bigger for simple variables such a int, float but not for objects or functions.
The STm32F429 can use an external 133mhz SDR SDRAM so memory cost of allocating variables will be minimized at all.Has the capability of adding and removing cache modules been designed for such purposes or is there something more behind the scenes ?
-
To me is now becoming more clear how the Javascript interpreter works looking at how this simple example code has been parsed and put into memory structures.
I am now asking myself which should be the best way to use Espruino.
In example adding a simple toFixed function would require adding a prototype to Number Class, which is too complex with respect using an existing native C sprintf function, even a big piece of C code itself in the real world.
Probably the best use of Espruino could be to act as a scripted shell coprocessor of a traditional CPU, doing more intensive computations ( i.e. another STm32Fx micro controller ).
It seems that there are pro and cons using Espruino.
Is there a place where to find good books about the theory of a Javascript interpreter or handy manuals about how to build one.
Looking inside the Espruino code should give enough explanation, but to a novice this is the hardest way.var Circle = function(radius) { this.radius = radius; }; Circle.prototype.area = function() { return Math.PI * this.radius* this.radius; }; var a = new Circle(3); var b = new Circle(4); var c = new Circle(1); a.area(); // .toFixed(2); b.area(); // .toFixed(2); c.area(); #1[r1,l1] Object { #4[r1,l0] Name: '>timers' #5[r2,l0] Array [ ] #6[r1,l0] Name: '>watches' #7[r2,l0] Array [ ] #9[r1,l0] Name: '>history' #10[r1,l0] Array [ #11[r1,l0] Name: int 0 #8[r1,l0] String echo(0); #24[r1,l0] Name: int 1 #16[r1,l0] String var Circle = function(radius) {\n this.radius = radius;\n}; #41[r1,l0] Name: int 2 #30[r1,l0] String Circle.prototype.area = function() {\n return Math.PI * this.radius* this.radius;\n}; #50[r1,l0] Name: int 3 #43[r1,l0] String var a = new Circle(3); #61[r1,l0] Name: int 4 #54[r1,l0] String var b = new Circle(4); #72[r1,l0] Name: int 5 #65[r1,l0] String var c = new Circle(1); #75[r1,l0] Name: int 6 #77[r1,l0] String a.area(); #82[r1,l0] Name: int 7 #83[r1,l0] String b.area(); #86[r1,l0] Name: int 8 #76[r1,l0] String c.area(); #88[r1,l0] Name: int 9 #89[r1,l0] String echo(1); ] #12[r4,l0] Name: 'Circle' #13[r1,l0] Function { #14[r1,l0] Param Name: 'radius' undefined #23[r1,l0] Name: '>code' #15[r1,l0] String {\n this.radius = radius;\n} #26[r4,l0] Name: 'prototype' #25[r1,l0] Object { #28[r1,l0] Name: 'area' #29[r1,l0] Function { #40[r1,l0] Name: '>code' #36[r1,l0] String {\n return Math.PI * this.radius* this.radius;\n} } } } #42[r1,l0] Name: 'a' #45[r1,l0] Object { #46[r1,l0] Name: '__proto__' #26[r4,l0] ... #52[r1,l0] Name: 'radius' #49[r1,l0] Integer 3 #48[r1,l0] Name: 'constructor' #12[r4,l0] ... } #53[r1,l0] Name: 'b' #56[r1,l0] Object { #57[r1,l0] Name: '__proto__' #26[r4,l0] ... #63[r1,l0] Name: 'radius' #60[r1,l0] Integer 4 #59[r1,l0] Name: 'constructor' #12[r4,l0] ... } #64[r1,l0] Name: 'c' #67[r1,l0] Object { #68[r1,l0] Name: '__proto__' #26[r4,l0] ... #74[r1,l0] Name: 'radius' #71[r1,l0] Integer 1 #70[r1,l0] Name: 'constructor' #12[r4,l0] ... } #81[r1,l0] Name: 'Math' #80[r1,l0] Function { } } process.memory() = {"free" :5394, "usage":56, "total":5450, "history":40, "stackEndAddress" :536983744, "flash_start" :134217728, "flash_binary_end":134404416, "flash_code_start":135135232, "flash_length" : 1048576}
-
-
In order to recompile the espruino code for the STM32F4 board, as Gordon suggests, you need to :
1) change the python definition file.
2) add the define USE_FILESYSTEM=1 in the Makefile
3) modify the spi_diskio.c file and include the management of the SPI peripheral in order to manage the slightly different instructions for the STM32 processors, such alternate function. or OType and PuPd records in the GPIO init port structure.
I succeded in doing the update, but at present time my code has bugs possibly in the C code, do I have to verify using gdb debugger why the code hangs up, as can be seen in the following screenshot. May be that the SPI clock is wrongly set. -
I read the accelerometer on a STM32F4-DISCOVERY board.
I wanted to have 40 samples /s and I got 40 messages displayed on the Terminal screen, after accumulating data on a moving average process.print("X= "+accx+" Y= "+accy+" Z= "+accz+" [16bit]" );
accv_start = setInterval(function () { print(getAcc()); }, 25); // 40 Hz
acc_stop = setInterval(function () { clearInterval(acc_start); print(console.log("ACC STOP"));}, 1000); // stop after a whileAs expected the timer behavior was pretty deterministic , having a minimum timer resolution of 1 ms.
Now my question is :Are you going to improve the timer's resolution , I say in example to 10 us, in a near future ?
Nothing changed at all.