YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

Squirrel on a PIC32 microcontroller
FlNo
#1 Posted : Thursday, July 14, 2016 8:08:52 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 7/14/2016(UTC)
Posts: 1

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Hello,

I want to run some very small scripts an a PIC32 microcontroller to extend it's functionality without changing the firmware. I found Squirrel and it looks very good to me. Especially I like the c similarity of the language.
Does anyone have experience in running Squirrel on an embedded system? I would use the XC32 Compiler from Microchip (http://ww1.microchip.com/downloads/en/DeviceDoc/50001686J.pdf). It is based on the gcc. I think it should work, or are there any known issues?

Thanks for all kinds of informations
Florian
fagiano
#2 Posted : Thursday, July 14, 2016 9:15:58 PM(UTC)
Rank: Advanced Member

Groups: Registered, Administrators
Joined: 6/11/2005(UTC)
Posts: 1,056

Thanks: 0 times
Was thanked: 78 time(s) in 60 post(s)
Few companies run Squirrel on MCUs(electricimp.com). Cortex M3 mostly, for what I know. There should not be any problem other than memory constraints. I've been thinking of making an official embedded version, I have a version of 3.0 that has some optimization specific for MCUs(like running bytecode straight from flash).

ALberto
Follow me on Twitter @squirrellang
Quentis
#3 Posted : Wednesday, July 20, 2016 1:19:29 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 7/20/2016(UTC)
Posts: 2

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Hello,

I would like to ask some questions about how squirrel can be used on microcontrollers:

Could you tell me what are the dependencies of squirrel?
-What C++ dialect it was written in? (Cpp11?)
-Does it use external libraries or STL? (STL is rarely available)
-Does it use OS APIs?

Best regards,
Quentis
fagiano
#4 Posted : Wednesday, July 20, 2016 7:06:44 PM(UTC)
Rank: Advanced Member

Groups: Registered, Administrators
Joined: 6/11/2005(UTC)
Posts: 1,056

Thanks: 0 times
Was thanked: 78 time(s) in 60 post(s)
It can be used. It is used by a number of companies already.
-It uses a very portable subset of C++ (no C++11) it compiles with all C++ compilers I tried so far gcc, clang, VC++, keil, digital mars(from the top of my head).
-no STL, no exceptions, no standard allocator(it overrides all the allocations with it's own function see sqmem.cpp by default it's implement with malloc and free)
-only CRT and not much of it(the most complex functions you'll need are sprintf & Co.)

PS: you can also compile without the compiler embedded to save space, you can precompile the scripts offline.

I hope this helps

ciao
Alberto
Follow me on Twitter @squirrellang
absence
#5 Posted : Thursday, July 21, 2016 1:05:35 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 8/23/2014(UTC)
Posts: 109
Man
Location: Northern Germany & Lincolnshire, U.K.

Thanks: 1 times
Was thanked: 10 time(s) in 10 post(s)
the most serious issue usually is indeed the use of VARGS and vsnprintf and co, those quite often are not properly supported by MCU libraries.
Unfortunately, those are also the ones pumping up footprint a lot (which is why they're often not fully supported)

Some additional (but quite standard) libs add up when using sqstdlib (e.g. system, time, file stream handling and a few others), but those are easy to circumvent or omit.

The makefiles are straigtforward, you can compile squirrel simply by adding all source files to a project and there you go.

(BTW: Add Metroworks compiler to the list)

Some other hints:
- After loading a script and running it, when you do not intend to completely run it again but only want to call functions from it - DELETE THE LOADED SCRIPT (After the first run it's never used again, so you can free that memory chunk).
- Compile with NO_GARBAGECOLLECTOR. You really want so save that extra memory and cpu power on a MCU
- Amend sqconfig.h properly to fit your needs, you could also easily replace the printf stuff with own functions here, if necessary
- write your own memory allocation and management. Squirrel tends to use certain block sizes a damn lot. Also,usually "realloc" is THE bottleneck when it comes to performance. Squirrel for example does a lot of reallocs simply doubling the block size (which again are quite often powers of 2). You can optimize hell of a lot here...

Well, and as Alberto already said, you don't want the squirrel compiler if you can run precompiled scripts and never need to compile runtime (note that this impacts sqstdlib, too, see "dofile", for example)

With some effort (somewhere between "does run out of the box" and a few days) you should be able to get a decent system up and running.
Quentis
#6 Posted : Thursday, July 21, 2016 5:58:06 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 7/20/2016(UTC)
Posts: 2

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Thank you very much for your help. :)
May I ask if there is any tools for squirrel made by the community?
e.g. Notepad++ syntax highlight or plugin (vs, eclipse)

Best regards,
Quentis
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Clean Slate theme by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.4 | YAF © 2003-2010, Yet Another Forum.NET
This page was generated in 0.191 seconds.