Challenge: CCL port to the RPi Pico (RP2040)

Tim McNerney <[email protected]> Sun, 28 Jul 2024 10:54:15 -0400
Newsgroups gmane.lisp.openmcl.devel
Message-ID <[email protected]>
--Apple-Mail-DF01E5E3-85C1-4858-8D04-47B666DA7108
Content-Type: text/plain;
	charset=utf-8
Content-Transfer-Encoding: quoted-printable

=EF=BB=BFThe popular Raspberry Pi Pico chip (RP2040) is a remarkable micropr=
ocessor with memory resources not dissimilar from the Mac 512k, CCL=E2=80=99=
s debut target. Here are some quick facts.=20
Dual ARM Cortex-M0+ @ 133MHz

264kB on-chip SRAM in six independent banks

Support for up to 16MB of off-chip Flash memory via dedicated QSPI bus

Some might argue it=E2=80=99s not comparable to a Mac 512. I claim it is: co=
nsider that the RAM would only used for the heap, stack(s), and housekeeping=
? It is the off-chip flash support that makes all the difference. That=E2=80=
=99s where you can store static code and data segments that make up the bulk=
 of a CCL image.=20

My big questions:

1) Could this chip run CCL?

2) Would it be worth the effort?

I think yes on both fronts. A lot of embedded code is truly modest, so a sma=
ll heap is useful enough. This is the arena where microPython shines=E2=80=94=
itself sporting a garbage collector.=20

3) Does anyone want to try?

CCL already has 32-bit ARM support. There is no OS interfacing work to do he=
re (only work to make up for the lack of OS).=20

This could be a fun little project that would a great way to become familiar=
 with CCL internals without a lot of distractions from OS and GUI issues. Fi=
rst get it working from a serial port console (over Bluetooth maybe?) and fo=
cus on embedded applications. Slash and burn the rest, at least for starters=
.=20

--Tim

> On Jul 28, 2024, at 01:32, R. Matthew Emerson <[email protected]> wrote:
> =EF=BB=BF
>=20
>> On Jul 27, 2024, at 8:23=E2=80=AFPM, Gr=C3=A9gory Vanuxem <g.vanuxem@gmai=
l.com> wrote:
>>=20
>> In FriCAS  built on top of Clozure CL I obtain this output in a terminal (=
WSL2)
>>=20
>> (gamma(x) =C3=83=C3=82=C2=A2=C3=83=C3=82=C3=83=C3=82 reals && Re(x) > 0) |=
| (x =C3=83=C3=82=C2=A2=C3=83=C3=82=C3=83=C3=82 integers &&
>> gamma(x) =C3=83=C3=82=C2=A2=C3=83=C3=82=C3=83=C3=82 reals)
>>=20
>> instead of (SBCL)
>>=20
>> (gamma(x) =E2=88=88 reals && Re(x) > 0) || (x =E2=88=89 integers && gamma=
(x) =E2=88=88 reals)
>>=20
>> if I (print ...) a string with, for example, =E2=88=88, in a pure Clozure=
 CL
>> (recently git cloned) this is correctly printed, no problem.
>>=20
>> So I wonder if I have to modify the output stream character encoding
>> or the output routine.
>=20
> Check that the external format of the FriCAS output stream is what you exp=
ect. In other words, if you pass an explicit :external-format argument to cl=
:open, make sure it matches what your terminal requires.
>=20
> Doing (describe *terminal-io*) might show something interesting. Here=E2=80=
=99s what it shows for me:
>=20
> ? (describe *terminal-io*)     =20
> #<ECHOING-TWO-WAY-STREAM input #<BASIC-CHARACTER-INPUT-STREAM UTF-8 (TTY/0=
) #x1824C7D6>, output #<BASIC-CHARACTER-OUTPUT-STREAM UTF-8 (TTY/1) #x1824C2=
A6> #x1825FBE6>
> Class: #<STANDARD-CLASS ECHOING-TWO-WAY-STREAM>
> Wrapper: #<CLASS-WRAPPER ECHOING-TWO-WAY-STREAM #x18039A16>
> Instance slots
> SHARED-RESOURCE: NIL
> OPEN-P: T
> INPUT-STREAM: #<BASIC-CHARACTER-INPUT-STREAM UTF-8 (TTY/0) #x1824C7D6>
> OUTPUT-STREAM: #<BASIC-CHARACTER-OUTPUT-STREAM UTF-8 (TTY/1) #x1824C2A6>
>=20
> The default external format has been #<EXTERNAL-FORMAT :UTF-8/:UNIX #x1824=
9C6E> for quite a long time now.
>=20
> https://ccl.clozure.com/docs/ccl.html#characters-and-external-formats
>=20
>=20
>>=20
>> And more importantly, how can I achieve that?
>>=20
>> - Greg
>>=20
>> PS:
>> (1) -> )lisp CCL:*DEFAULT-EXTERNAL-FORMAT*
>> Value =3D :UNIX

--Apple-Mail-DF01E5E3-85C1-4858-8D04-47B666DA7108
Content-Type: text/html;
	charset=utf-8
Content-Transfer-Encoding: quoted-printable

<html><head><meta http-equiv=3D"content-type" content=3D"text/html; charset=3D=
utf-8"></head><body dir=3D"auto"><div dir=3D"ltr">=EF=BB=BFThe popular Raspb=
erry Pi Pico chip (RP2040) is a remarkable microprocessor with <i>memory res=
ources</i> not dissimilar from the Mac 512k, CCL=E2=80=99s debut target. Her=
e are some quick facts.&nbsp;<div dir=3D"ltr"><div><ul style=3D"-webkit-text=
-size-adjust: auto; box-sizing: border-box; font-family: Roboto, sans-serif;=
"><li style=3D"box-sizing: border-box;"><p style=3D"box-sizing: border-box; m=
argin: 0px 0px 15px; padding: 0px; font-size: 0.95em; line-height: 1.5em;">D=
ual ARM Cortex-M0+ @ 133MHz</p></li><li style=3D"box-sizing: border-box;"><p=
 style=3D"box-sizing: border-box; margin: 0px 0px 15px; padding: 0px; font-s=
ize: 0.95em; line-height: 1.5em;">264kB on-chip SRAM in six independent bank=
s</p></li><li style=3D"box-sizing: border-box;"><p style=3D"box-sizing: bord=
er-box; margin: 0px 0px 15px; padding: 0px; font-size: 0.95em; line-height: 1=
.5em;">Support for up to 16MB of off-chip Flash memory via dedicated QSPI bu=
s</p></li></ul><div>Some might argue it=E2=80=99s not comparable to a Mac 51=
2. I claim it is: consider that the RAM would <i>only</i> used for the heap,=
 stack(s), and housekeeping? It is the off-chip flash support that makes all=
 the difference. That=E2=80=99s where you can store static code and data seg=
ments that make up the bulk of a CCL image.&nbsp;</div><div><br></div><div>M=
y big questions:</div><div><br></div><div>1) Could this chip run CCL?</div><=
div><br></div><div>2) Would it be worth the effort?</div><div><br></div><div=
>I think <b>yes</b> on both fronts. A lot of embedded code is truly modest, s=
o a small heap is useful enough. This is the arena where microPython shines=E2=
=80=94itself sporting a garbage collector.&nbsp;</div><div><br></div><div>3)=
 Does anyone want to try?</div><div><br></div><div>CCL already has 32-bit AR=
M support. There is no OS interfacing work to do here (only work to make up f=
or the <i>lack</i> of OS).&nbsp;</div><div><br></div><div>This could be a fu=
n little project that would a great way to become familiar with CCL internal=
s without a lot of distractions from OS and GUI issues. First get it working=
 from a serial port console (over Bluetooth maybe?) and focus on embedded ap=
plications. Slash and burn the rest, at least for starters.&nbsp;</div><div>=
<br id=3D"lineBreakAtBeginningOfSignature"><div dir=3D"ltr">--Tim</div><div d=
ir=3D"ltr"><br><blockquote type=3D"cite">On Jul 28, 2024, at 01:32, R. Matth=
ew Emerson &lt;[email protected]&gt; wrote:<br><br></blockquote></div><blockqu=
ote type=3D"cite"><div dir=3D"ltr">=EF=BB=BF<span></span><br><span></span><b=
r><blockquote type=3D"cite"><span>On Jul 27, 2024, at 8:23=E2=80=AFPM, Gr=C3=
=A9gory Vanuxem &lt;[email protected]&gt; wrote:</span><br></blockquote><b=
lockquote type=3D"cite"><span></span><br></blockquote><blockquote type=3D"ci=
te"><span>In FriCAS &nbsp;built on top of Clozure CL I obtain this output in=
 a terminal (WSL2)</span><br></blockquote><blockquote type=3D"cite"><span></=
span><br></blockquote><blockquote type=3D"cite"><span>(gamma(x) =C3=83=C3=82=
=C2=A2=C3=83=C3=82=C3=83=C3=82 reals &amp;&amp; Re(x) &gt; 0) || (x =C3=83=C3=
=82=C2=A2=C3=83=C3=82=C3=83=C3=82 integers &amp;&amp;</span><br></blockquote=
><blockquote type=3D"cite"><span>gamma(x) =C3=83=C3=82=C2=A2=C3=83=C3=82=C3=83=
=C3=82 reals)</span><br></blockquote><blockquote type=3D"cite"><span></span>=
<br></blockquote><blockquote type=3D"cite"><span>instead of (SBCL)</span><br=
></blockquote><blockquote type=3D"cite"><span></span><br></blockquote><block=
quote type=3D"cite"><span>(gamma(x) =E2=88=88 reals &amp;&amp; Re(x) &gt; 0)=
 || (x =E2=88=89 integers &amp;&amp; gamma(x) =E2=88=88 reals)</span><br></b=
lockquote><blockquote type=3D"cite"><span></span><br></blockquote><blockquot=
e type=3D"cite"><span>if I (print ...) a string with, for example, =E2=88=88=
, in a pure Clozure CL</span><br></blockquote><blockquote type=3D"cite"><spa=
n>(recently git cloned) this is correctly printed, no problem.</span><br></b=
lockquote><blockquote type=3D"cite"><span></span><br></blockquote><blockquot=
e type=3D"cite"><span>So I wonder if I have to modify the output stream char=
acter encoding</span><br></blockquote><blockquote type=3D"cite"><span>or the=
 output routine.</span><br></blockquote><span></span><br><span>Check that th=
e external format of the FriCAS output stream is what you expect. In other w=
ords, if you pass an explicit :external-format argument to cl:open, make sur=
e it matches what your terminal requires.</span><br><span></span><br><span>D=
oing (describe *terminal-io*) might show something interesting. Here=E2=80=99=
s what it shows for me:</span><br><span></span><br><span>? (describe *termin=
al-io*) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><br><span>#&lt;ECHOING-TWO-WAY-=
STREAM input #&lt;BASIC-CHARACTER-INPUT-STREAM UTF-8 (TTY/0) #x1824C7D6&gt;,=
 output #&lt;BASIC-CHARACTER-OUTPUT-STREAM UTF-8 (TTY/1) #x1824C2A6&gt; #x18=
25FBE6&gt;</span><br><span>Class: #&lt;STANDARD-CLASS ECHOING-TWO-WAY-STREAM=
&gt;</span><br><span>Wrapper: #&lt;CLASS-WRAPPER ECHOING-TWO-WAY-STREAM #x18=
039A16&gt;</span><br><span>Instance slots</span><br><span>SHARED-RESOURCE: N=
IL</span><br><span>OPEN-P: T</span><br><span>INPUT-STREAM: #&lt;BASIC-CHARAC=
TER-INPUT-STREAM UTF-8 (TTY/0) #x1824C7D6&gt;</span><br><span>OUTPUT-STREAM:=
 #&lt;BASIC-CHARACTER-OUTPUT-STREAM UTF-8 (TTY/1) #x1824C2A6&gt;</span><br><=
span></span><br><span>The default external format has been #&lt;EXTERNAL-FOR=
MAT :UTF-8/:UNIX #x18249C6E&gt; for quite a long time now. </span><br><span>=
</span><br><span>https://ccl.clozure.com/docs/ccl.html#characters-and-extern=
al-formats</span><br><span></span><br><span></span><br><blockquote type=3D"c=
ite"><span></span><br></blockquote><blockquote type=3D"cite"><span>And more i=
mportantly, how can I achieve that?</span><br></blockquote><blockquote type=3D=
"cite"><span></span><br></blockquote><blockquote type=3D"cite"><span>- Greg<=
/span><br></blockquote><blockquote type=3D"cite"><span></span><br></blockquo=
te><blockquote type=3D"cite"><span>PS:</span><br></blockquote><blockquote ty=
pe=3D"cite"><span>(1) -&gt; )lisp CCL:*DEFAULT-EXTERNAL-FORMAT*</span><br></=
blockquote><blockquote type=3D"cite"><span>Value =3D :UNIX</span><br></block=
quote><span></span><br><span></span><br></div></blockquote></div></div></div=
></div></body></html>=

--Apple-Mail-DF01E5E3-85C1-4858-8D04-47B666DA7108--