Skip to content

BasicPlus v7.0

Choose a tag to compare

@legio-e legio-e released this 13 Oct 15:27
· 511 commits to main since this release

Español · English below ↓

BasicPlus v7.0

En esta versión nos hemos centrado en tres puntos:

  • Los packs. En las versiones anteriores se desarrolló la zona de packs: una zona fija de la flash donde se
    graban los packs, que no necesitan cargarse en RAM, y así se ahorra memoria. Se pensó primero para los módulos y
    luego se extendió al código nativo; el primer gran logro fue poder cargar SQLite. En esta versión 7 lo hemos
    extendido a LVGL, el motor de la interfaz gráfica. Todo esto representa un cambio de paradigma: hay una imagen por
    micro, y es el usuario el que decide si incorpora SQLite y el entorno gráfico, sin necesidad de crear imágenes ni
    compilar código C.
  • Terminar lo pendiente. La versión 6 era para arreglar un montón de cosas que se habían quedado a medias, y
    bugs. Esta versión 7 es más de lo mismo: se ha resuelto una ingente cantidad de cosas pendientes. Entre ellas, las
    funciones nativas: había casos que no se podían convertir a native, y ahora prácticamente se han reducido a cero.
  • El segundo núcleo. Lo hemos habilitado para aumentar el rendimiento de los programas BasicPlus que usan varios
    hilos. En todos los micros de dos núcleos ha mejorado el rendimiento, aunque no por igual: con dos hilos trabajando
    a la vez, en la ESP32-P4 se consigue el 200 % del rendimiento de un núcleo (en las cadenas, el 133 %), y en el
    RP2350, entre el 113 % (Metro) y el 168 % (Pico 2); allí, en cambio, las cadenas van más lentas que con uno.
    Todavía no sabemos la razón de la diferencia.

En resumen, esta versión, que podía haber sido una versión de transición, se ha convertido en una gran versión. Hay
que destacar el enorme trabajo de Claude Code, tanto en la revisión del código como en las pruebas y en el código
nuevo.

Lo que no cambia es el invariante de siempre: el mismo bytecode, la misma salida byte a byte en las dos VMs, y todo
verificado en placa — esta vez en las diez.

Lo nuevo

  • La pantalla, en un pack. LVGL sale de las imágenes y se graba en la zona de packs, como SQLite: una sola
    imagen por micro, lleve la placa pantalla o no, y más memoria libre (la imagen de la P4, 644 KB de flash y 368 KB
    de RAM estática menos). Gui.pack lleva tres motores —Cortex-M33, RISC-V con FPU y sin ella— y a la placa va sólo
    el suyo; GuiMini.pack es el de las pantallas pequeñas. Se graban desde el IDE (botón Placa → el panel de
    packs), que avisa antes si el motor no cabe.
  • La biblioteca estándar, en un pack (Stdlib.pack): se ejecuta desde la flash sin copiarse a la RAM, que es lo
    que necesitan las placas sin PSRAM. Los packs de librería ya no llevan su propia copia de la stdlib.
  • Un panel SPI nuevo, sin código C: DriverSpi es un driver genérico de paneles MIPI-DCS por SPI; la placa se
    describe en su Entorno, y el controlador, en un fichero de texto.
  • Una placa nueva, la ESP32-C5 (Waveshare ESP32-C5-Touch-LCD-2.8): RISC-V, 8 MB de PSRAM, 32 MB de flash y
    pantalla táctil de 240×320. Son ocho imágenes y diez placas, en tres arquitecturas.
  • Dos núcleos en la Pico 2, la Metro, la S3 y la P4: la VM ejecuta dos hilos del programa a la vez. Se vuelve a
    uno desde el Entorno, sin regrabar (vm.runs=1, vm.cores=1).
  • El destructor ~Clase() y try var. Al acabar un programa —bien, con un error o con el Stop del IDE— se
    destruyen sus objetos, y cada clase que toma algo del hardware lo suelta: un PWM se para y las salidas vuelven a su
    estado de reset.
  • Compatibilidad entre versiones, como Java: el .mod pasa al formato MOD9, que enlaza por nombre al cargar. Un
    programa corre con una versión más nueva de una librería, y lo incompatible se rechaza nombrando el símbolo.
  • Casi todo se puede convertir a native: lleva try/catch dentro, tuplas, las funciones intrínsecas de la
    stdlib y los métodos de otro módulo. Una native es un hilo más: si bloquea, los demás siguen, y el Stop la para. La
    C3, la C5 y la C6 compilan las suyas.
  • El lenguaje y la biblioteca: arrays fijos tipo[N] sin heap; switch sobre cadenas, enums y long;
    try … finally sin catch; import Core ya no hace falta; IO.File e IO.TextFile con cursor; los módulos
    Time (sin el tope de 2038) y Heap; Map con claves y valores tipados; los buses compartidos (Spi.Device,
    transacciones). Y las cadenas, mucho más rápidas en placa: 192 concatenaciones en la Metro, de 2 122 a 44 ms.
  • El IDE lista y baja ficheros de la placa mientras el programa corre; sube por trozos y reintenta si falla el
    cable; marca en rojo lo que la placa no cargaría; y sube cada librería sólo si la placa no tiene su versión.
  • Probado en placa: la ronda de V7, 50 pruebas por placa, verde en las diez con las imágenes que se publican; la
    red de paridad dual-VM, de 59 a 149 casos; 102 pruebas de C de la VM.
  • Y bugs de V6 corregidos: una lista enlazada de unos cientos de nodos colgaba la placa (el marcado del GC era
    recursivo); un hilo que recursaba de más pisaba la pila del vecino; un switch sobre una cadena no casaba nunca;
    continue en un for no avanzaba; y más — el detalle, en las
    notas de versión.

⚠️ Al actualizar desde V6

Graba la imagen de V7 y vuelve a grabar los packs. Los packs de V6 no cargan —su código nativo es de otra ABI—:
en el panel de Packs, Formatear zona…, y graba los de V7. En las placas con pantalla (la C5, la C6, las P4 y
la DK2), sin los packs de la GUI no se pinta nada: graba los suyos, pon el bloque de RAM en el Entorno (packRam=)
y, en la C5 y la C6, las líneas de su pantalla. Todo, en
INSTALAR_FIRMWARE.md, «Los packs de la placa».

Recompila los .mod. Un .mod de V6 que use clases de la biblioteca no enlaza, y lo dice. El IDE recompila en
cada Run; lo que hay que mirar es lo que quedó en /app, sobre todo el programa del autorun.

Lo que rompe fuentes de V6 — el compilador lo dice en cada caso:

  • Math.signF(x) es Math.sign(x).
  • Los arrays fijos tipo[N] no compilan a nivel de módulo (usa tipo[]), y uno local no se pasa, ni se asigna, ni
    se devuelve.
  • Leer una variable local sin valor; un switch sobre un real o un objeto; un finally que sale con return,
    break o continue; step 0; Color(1); concatenar a una cadena un array, una tupla o null.
  • La visibilidad se aplica: un constructor sin public es protegido, y un campo private no se lee desde una
    subclase.

Lo que cambia sin que el compilador avise: con dos núcleos, dos hilos corren a la vez de verdad —lo compartido, con
un Mutex; vm.runs=1 deja la placa como en V6—; al acabar un programa todo vuelve al reset; una excepción sin
atrapar en un hilo que no es el main acaba ese hilo; un desbordamiento de pila es un RuntimeError;
from "<ruta>" ya no se usa al ejecutar; fileExists de una carpeta da false; y tras un fallo fatal la placa no
relanza el autorun.

Lo que no rompe: import Core escrito sigue compilando; un .mod de V6 que no use clases de la biblioteca se sigue
ejecutando; Pico.* sigue siendo alias de Machine; y SQLite=<MB> sigue valiendo.

Descarga

Un solo fichero: BasicPlus-7.0-win.zip (Windows; requiere JDK 8+). Dentro va todo — IDE, compilador,
librería estándar, los cinco packs, ejemplos, documentación, el micro simulado (con LVGL y SQLite) y las ocho
imágenes de firmware. Se descomprime y funciona; no hay instalador.

Las imágenes están en firmware/, con su SHA256SUMS.txt al lado y las plantillas de board.json del RP2350 en
firmware/boards/; los packs, en packs/:

Imagen Placas
bpvm_pico.uf2 Raspberry Pi Pico 2 y Adafruit Metro RP2350 (BOOTSEL + copiar)
bpvm_esp32_merged.bin ESP32-S3 (esptool write-flash 0x0 …)
bpvm_esp32c3_merged.bin ESP32-C3
bpvm_esp32c5_merged.bin Waveshare ESP32-C5-Touch-LCD-2.8 — nueva
bpvm_esp32c6_merged.bin ESP32-C6 y Waveshare ESP32-C6-LCD-1.3
bpvm_esp32p4_merged.bin ESP32-P4-Function-EV y Waveshare ESP32-P4 (display=st7701 en el ENV)
bpvm_stm32_nucleo.bin STM32 Nucleo-U575ZI-Q (ST-LINK / CubeProgrammer)
bpvm_stm32_dk2.bin STM32U5G9J-DK2, con pantalla (ST-LINK / CubeProgrammer)
8f843444f3bb5a0b9327d137a95cdabaddc5cafd38fbb43b8db6c91f45d0b93b  BasicPlus-7.0-win.zip

Documentación

Limitaciones conocidas

  • La imagen de dos núcleos de la RP2350 es más lenta de lo que debería: en la Metro, un programa de un hilo va
    un 35 % más lento que con la imagen de un núcleo, y las cadenas no escalan con dos hilos. Se investiga en V8.
  • Un error en la placa no dice su línea (la VM Java del PC da la traza entera). V8.
  • No hay red, ni Bluetooth, ni bajo consumo en placa. Son V8.
  • El depurador va con un solo run en las placas de dos núcleos, no para dentro de una native en la placa y no
    despliega objetos.
  • Un fallo fatal de la VM tumba la placa: la RP2350 con dos núcleos y las ESP32 se reinician sin lanzar el
    autorun; las STM32 se quedan paradas.
  • La S3 no tiene AOT (Xtensa), y un .mod lleva el nativo de una sola familia.
  • Las STM32: su Wdt lanza (el IWDG no se puede parar) y no tienen ni Neopixel ni SD. La C3 tiene menos
    VM que en V6: su bloque ya no llega a 128 KB.
  • input() sólo funciona en la VM Java.
  • La lista completa, en PENDIENTES.md.

BasicPlus v7.0 (English)

In this version we focused on three things:

  • Packs. Earlier versions built the pack zone: a fixed area of flash where packs are burned; they don't need to
    be loaded into RAM, so memory is saved. It was first meant for modules and then extended to native code; the first
    big achievement was loading SQLite. In version 7 we have extended it to LVGL, the graphical interface engine. All of
    this is a paradigm shift: there is one image per micro, and it is the user who decides whether to add SQLite and the
    graphical environment, without building images or compiling C code.
  • Finishing what was pending. Version 6 was about fixing a lot of things that had been left half done, and bugs.
    Version 7 is more of the same: a huge number of pending items have been resolved. Among them, native functions:
    there were cases that could not be turned into native, and now they are practically down to zero.
  • The second core. We enabled it to speed up BasicPlus programs that use several threads. Performance improved
    on every dual-core micro, though not equally: with two threads working at once, the ESP32-P4 reaches 200 % of one
    core's performance (133 % with strings), and the RP2350 between 113 % (Metro) and 168 % (Pico 2); there, however,
    strings run slower than with one core. We don't know the reason for the difference yet.

In short, this version, which could have been a transition release, has become a big one. Special mention goes to
the enormous work of Claude Code, in code review as well as in testing and new code.

What doesn't change is the usual invariant: the same bytecode, the same byte-for-byte output on both VMs, and
everything verified on hardware — this time on all ten boards.

What's new

  • The screen, in a pack. LVGL leaves the images and is burned into the pack zone, like SQLite: one image per
    micro, whether the board has a screen or not, and more free memory (the P4 image is 644 KB of flash and 368 KB of
    static RAM smaller). Gui.pack carries three engines —Cortex-M33, RISC-V with and without FPU— and only the board's
    own goes to the board; GuiMini.pack is the one for small screens. They are burned from the IDE (Placa button →
    the packs panel), which warns beforehand if the engine doesn't fit.
  • The standard library, in a pack (Stdlib.pack): it runs from flash without being copied to RAM, which is what
    boards without PSRAM need. Library packs no longer carry their own copy of the stdlib.
  • A new SPI panel, without C code: DriverSpi is a generic driver for MIPI-DCS panels over SPI; the board is
    described in its environment (ENV), and the controller in a text file.
  • A new board, the ESP32-C5 (Waveshare ESP32-C5-Touch-LCD-2.8): RISC-V, 8 MB of PSRAM, 32 MB of flash and a
    240×320 touch screen. That makes eight images for ten boards, across three architectures.
  • Two cores on the Pico 2, the Metro, the S3 and the P4: the VM runs two of the program's threads at once. Going
    back to one is an ENV setting, no reflashing (vm.runs=1, vm.cores=1).
  • The ~Class() destructor and try var. When a program ends —normally, with an error or with the IDE's Stop—
    its objects are destroyed, and every class that takes something from the hardware gives it back: a PWM stops and
    the outputs return to their reset state.
  • Compatibility across versions, Java-style: the .mod moves to the MOD9 format, which links by name at load
    time. A program runs with a newer version of a library, and anything incompatible is rejected naming the symbol.
  • Almost everything can be made native: try/catch inside, tuples, the stdlib's intrinsic functions and
    methods from another module. A native is just another thread: if it blocks, the others carry on, and Stop halts it.
    The C3, the C5 and the C6 compile theirs.
  • The language and the library: fixed arrays type[N] with no heap; switch on strings, enums and long;
    try … finally without catch; import Core is no longer needed; IO.File and IO.TextFile with a cursor; the
    Time (no 2038 limit) and Heap modules; Map with typed keys and values; shared buses (Spi.Device,
    transactions). And strings, much faster on the board: 192 concatenations on the Metro, from 2,122 to 44 ms.
  • The IDE lists and downloads the board's files while the program runs; uploads in chunks and retries if the
    wire fails; marks in red what the board would not load; and uploads each library only if the board lacks its
    version.
  • Tested on hardware: the V7 round, 50 tests per board, green on all ten with the images being released; the
    dual-VM parity net, from 59 to 149 cases; 102 C tests of the VM.
  • And V6 bugs fixed: a linked list of a few hundred nodes hung the board (the GC mark was recursive); a thread that
    recursed too deep trampled its neighbour's stack; a switch on a string never matched; continue in a for did
    not advance; and more — details in the
    release notes (Spanish).

⚠️ Upgrading from V6

Flash the V7 image and burn the packs again. V6 packs don't load —their native code has another ABI—: in the
Packs panel, Formatear zona… (format zone), then burn the V7 ones. On the boards with a screen (the C5, the
C6, the P4s and the DK2), nothing is drawn without the GUI packs: burn theirs, set the RAM block in the ENV
(packRam=) and, on the C5 and the C6, their panel lines. All of it in
INSTALAR_FIRMWARE.md, «The board's packs».

Recompile your .mod files. A V6 .mod that uses library classes does not link, and says so. The IDE
recompiles on every Run; what to check is what was left in /app, above all the autorun program.

What breaks V6 sources — the compiler says so in each case:

  • Math.signF(x) is Math.sign(x).
  • Fixed arrays type[N] don't compile at module level (use type[]), and a local one is not passed, assigned or
    returned.
  • Reading a local variable with no value; a switch on a real or an object; a finally that leaves with return,
    break or continue; step 0; Color(1); concatenating an array, a tuple or null to a string.
  • Visibility is enforced: a constructor without public is protected, and a private field cannot be read from a
    subclass.

What changes without a compiler warning: with two cores, two threads really run at once —protect shared data with a
Mutex; vm.runs=1 leaves the board as in V6—; when a program ends everything returns to reset; an uncaught
exception in a thread other than main ends that thread; a stack overflow is a RuntimeError; from "<path>" is no
longer used at run time; fileExists on a folder is false; and after a fatal fault the board does not relaunch the
autorun.

What does not break: a written import Core still compiles; a V6 .mod that uses no library classes still runs;
Pico.* is still an alias of Machine; and SQLite=<MB> is still valid.

Download

One file: BasicPlus-7.0-win.zip (Windows; needs JDK 8+). Everything is inside — IDE, compiler, standard
library, the five packs, samples, documentation, the simulated micro (with LVGL and SQLite) and the eight
firmware images. Unzip and run; there is no installer.

The images live in firmware/, next to their SHA256SUMS.txt, with the RP2350 board.json templates in
firmware/boards/; the packs, in packs/:

Image Boards
bpvm_pico.uf2 Raspberry Pi Pico 2 and Adafruit Metro RP2350 (BOOTSEL + copy)
bpvm_esp32_merged.bin ESP32-S3 (esptool write-flash 0x0 …)
bpvm_esp32c3_merged.bin ESP32-C3
bpvm_esp32c5_merged.bin Waveshare ESP32-C5-Touch-LCD-2.8 — new
bpvm_esp32c6_merged.bin ESP32-C6 and Waveshare ESP32-C6-LCD-1.3
bpvm_esp32p4_merged.bin ESP32-P4-Function-EV and Waveshare ESP32-P4 (display=st7701 in the ENV)
bpvm_stm32_nucleo.bin STM32 Nucleo-U575ZI-Q (ST-LINK / CubeProgrammer)
bpvm_stm32_dk2.bin STM32U5G9J-DK2, with screen (ST-LINK / CubeProgrammer)
8f843444f3bb5a0b9327d137a95cdabaddc5cafd38fbb43b8db6c91f45d0b93b  BasicPlus-7.0-win.zip

Documentation

Known limitations

  • The RP2350 dual-core image is slower than it should be: on the Metro, a single-threaded program runs 35 %
    slower than with the single-core image, and strings don't scale with two threads. Being investigated for V8.
  • An error on the board does not give its line (the Java VM on the PC gives the full trace). V8.
  • No networking, Bluetooth or low power on the board. They are V8.
  • The debugger runs with a single run on dual-core boards, does not stop inside a native on the board and does
    not expand objects.
  • A fatal VM fault takes the board down: the dual-core RP2350 and the ESP32s reboot without launching the
    autorun; the STM32s stay halted.
  • The S3 has no AOT (Xtensa), and a .mod carries the native code of a single family.
  • The STM32s: their Wdt throws (the IWDG cannot be stopped) and they have neither Neopixel nor SD. The C3
    has less VM than in V6: its block no longer reaches 128 KB.
  • input() only works on the Java VM.
  • The full list is in PENDIENTES.md (Spanish).