Skip to content

BasicPlus v6.0 — orden en los micros

Choose a tag to compare

@legio-e legio-e released this 12 Sep 18:08
· 1243 commits to main since this release

Español · English below ↓

BasicPlus v6.0 — «orden en los micros»

En la versión 6 nos hemos enfocado en el código de los microcontroladores. Más que añadir
prestaciones, hemos analizado el código que había y hemos puesto orden: lo que hacía lo
mismo en cada micro es ahora común. Medido sobre lo que enlaza cada firmware, algo más del
90 % del código es común
a todos los micros; un 7-8 % es de cada familia (la capa HAL del
fabricante y la capa HAL de BasicPlus que la envuelve); y menos del 1 % es propio de cada
placa
, concentrado en el arranque. Eso ahorra código, mejora el mantenimiento y hace que
añadir un micro de una familia que ya tenemos sea relativamente sencillo — aunque hay un
trabajo de probar y ajustar en la placa que apenas se refleja en el código.

Y lo de siempre, que no cambia: el mismo bytecode corre byte-idéntico en el PC y en el
micro
, y todo está verificado en placa — esta vez en las nueve.

Lo nuevo

  • Dos micros más de la familia ESP32: el C3 y el C6. Con el C6 llega la primera
    pantalla por SPI
    (Waveshare ESP32-C6-LCD-1.3, ST7789 240×240). Son ya cuatro pantallas
    —la DK2, las dos P4 y el C6— con la misma GUI. El parque de V6 son siete imágenes y
    nueve placas
    .
  • La GUI corre en su propio hilo. Gui.start() arranca la interfaz y vuelve, stop()
    y join() la paran y la esperan; Gui.run() sigue siendo el «arranca y espera» de
    siempre. Un handler ya no congela el programa, y un programa puede seguir calculando con
    la pantalla viva.
  • Un modelo de componentes coherente. Cada contenedor conoce a sus hijos
    (Container), delete() borra en cascada, y una ventana se puede guardar y volver a
    cargar como JSON
    (toJson() produce el mismo .win que carga load).
  • Captura de pantalla del micro desde el PC. Gui.shot(path) escribe la pantalla tal
    como LVGL la dibujó, comprimida; se baja por el cable y shot2png.py la pasa a PNG. Es
    el testigo con el que se prueban las placas con pantalla.
  • El IDE atiende el cable mientras el programa corre: el firmware lleva dos hilos de
    sistema en las cinco familias, y Stop, reset y HELLO responden siempre. La salida va por
    líneas (hasta 5× más rápida en la placa) y el UART tiene un anillo de recepción.
  • El firmware repone /lib solo en cada arranque, y el IDE sólo sube lo que falta o
    cambió (compara por CRC). Ya no hay stdlib rancia en la placa sin que nadie lo diga.
  • La memoria de la VM la reparte un único planificador en las cinco familias, con el
    tamaño de las pilas (stack=N) y el cuanto del planificador (quantum=N) en el entorno
    de la placa, y un guardián que dice quién se quedó memoria al acabar un RUN.
  • Un sistema semiautomático de pruebas: un agente conduce las placas por el cable,
    ejecuta los programas y compara con el PC (tanda.py). Es lo que ha probado esta versión.
  • El micro simulado del IDE lleva LVGL y SQLite dentro: los programas con base de datos
    se prueban en el PC sin placa.
  • Y bugs corregidos por todo el sistema: el GC de la VM Java descarrilaba con cadenas
    vacías; guardar en un word[] pisaba el elemento siguiente; print e imprimía basura;
    SQLite estaba rota en placa (el puente nativo del pack era de otra ABI); y más — el detalle
    en las notas de versión.

⚠️ Al actualizar desde V5

Reflashea el firmware y borra /app de la placa (lo que sobreviva ahí de otra versión
tapa a lo nuevo). /lib ya no hace falta borrarlo: el firmware lo repone solo. Si tienes
grabado el pack de SQLite, grábalo de nuevo (packs/SQLite.pack): el de V5 no vale.

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

  • import Core en todo módulo que use List, los envoltorios, Comparable,
    Exception, RuntimeError o un catch. Los imports no son transitivos.
  • parent: Container en los constructores de la GUI; Keyboard.setTextarea(ta) en
    vez de attach; Tabview.addTab() devuelve TabPage.

Lo que cambia sin que el compilador avise: print e imprime el mensaje de la excepción;
el screen mide lo que mide el panel de la placa (un .win guardado lleva ese tamaño);
los handlers de la GUI se despachan dentro de run(); un programa que muere lanzando
sale con 1; Wdt en el STM32 y Adc sin driver lanzan en vez de fingir; y
OwnerList libera sus elementos.

Lo que no rompe: Pico.* sigue compilando (alias de Machine); los .mod de V5 se siguen
ejecutando; Gui.run() sigue bloqueando.

Descarga

Un solo fichero: BasicPlus-6.0-win.zip (Windows; requiere JDK 8+). Dentro va todo —
IDE, compilador, librería estándar, ejemplos, documentación, el micro simulado (con LVGL y
SQLite) y las siete 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/:

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 — nueva
bpvm_esp32c6_merged.bin ESP32-C6 y Waveshare ESP32-C6-LCD-1.3 — nueva
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)
2279292d65afef3ae6df240e00fad8b66cf7e50f5f17f53b814cf4c6fdc88434  BasicPlus-6.0-win.zip

Documentación

Limitaciones conocidas

  • Las bases de datos siguen pidiendo placa con la VM-C de línea de comandos; el micro
    simulado del IDE sí las lleva.
  • El S3 no tiene AOT (Xtensa); el C3 y el C6 interpretan sus native hasta que haya
    un destino RISC-V sin FPU — un blob del P4 se ignora con mensaje.
  • listDir e input() sólo funcionan en la VM Java.
  • Una native larga no se puede parar hasta que vuelve (el Stop se atiende entre
    instrucciones del intérprete).
  • En el P4, un pack grabado gana a /lib y a /app: un pack de librería que lleve
    módulos de la stdlib tapa a los del firmware (los packs de v6.0 llevan los mismos, byte a
    byte). Se refina en V7.
  • La lista completa, en PENDIENTES.md.

English

BasicPlus v6.0 — «order in the micros»

Version 6 is about the microcontroller code. Rather than adding features, we went through
what was there and put it in order: whatever did the same job on every micro is now shared.
Measured on what each firmware actually links, a bit over 90 % of the code is common to
all micros; 7-8 % belongs to each family (the vendor HAL and the BasicPlus HAL layer on top);
and under 1 % is board-specific, concentrated in the boot. That saves code, helps
maintenance and makes adding a micro from a family we already support comparatively easy —
though there is testing and tuning on the board that barely shows in the code.

And the one thing that never changes: the same bytecode runs byte-identical on the PC and
on the micro
, verified on hardware — this time on all nine boards.

What's new

  • Two more ESP32 micros: the C3 and the C6. The C6 brings the first SPI display
    (Waveshare ESP32-C6-LCD-1.3, ST7789 240×240). Four screens now — the DK2, the two P4s and
    the C6 — all running the same GUI. V6 ships seven images for nine boards.
  • The GUI runs in its own thread. Gui.start() starts the interface and returns,
    stop() and join() stop and wait for it; Gui.run() is still "start and wait". A
    handler no longer freezes the program, and a program can keep computing with the screen
    alive.
  • A coherent component model. Every container knows its children (Container),
    delete() cascades, and a window can be saved and reloaded as JSON (toJson() writes
    the same .win that load reads).
  • Screen capture of the micro from the PC. Gui.shot(path) writes the screen as LVGL
    drew it, compressed; it comes down the wire and shot2png.py turns it into a PNG. It is
    the witness the boards with a screen are tested with.
  • The IDE keeps talking to the board while a program runs: the firmware runs two OS
    threads on all five families, and Stop, reset and HELLO always answer. Output goes by lines
    (up to 5× faster on the board) and the UART has a receive ring.
  • The firmware restores /lib by itself on every boot, and the IDE only uploads what is
    missing or changed (by CRC). No more stale stdlib on the board with nobody saying so.
  • One memory planner for the VM on all five families, with stack size (stack=N) and
    scheduler quantum (quantum=N) in the board's environment, and a guard that says who kept
    memory when a RUN ends.
  • A semi-automatic test system: an agent drives the boards over the wire, runs the
    programs and compares against the PC (tanda.py). It is what tested this version.
  • The IDE's simulated micro carries LVGL and SQLite: database programs run on the PC
    without a board.
  • And bugs fixed all over: the Java VM's GC derailed on empty strings; storing into a
    word[] clobbered the next element; print e printed garbage; SQLite was broken on boards
    (the pack's native bridge had another ABI); and more — details in the
    release notes (Spanish).

⚠️ Upgrading from V5

Reflash the firmware and delete /app on the board (anything left there from another
version shadows the new one). /lib no longer needs deleting: the firmware restores it.
If you had the SQLite pack burned, burn it again (packs/SQLite.pack): the V5 one does
not work.

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

  • import Core in every module that uses List, the wrappers, Comparable,
    Exception, RuntimeError or a catch. Imports are not transitive.
  • parent: Container in GUI constructors; Keyboard.setTextarea(ta) instead of
    attach; Tabview.addTab() returns TabPage.

What changes without a compiler warning: print e prints the exception message; the
screen is the size of the board's panel
(a saved .win carries that size); GUI handlers
are dispatched inside run(); a program that dies throwing exits with 1; Wdt on STM32
and Adc without a driver throw instead of pretending; OwnerList frees its elements.

What does not break: Pico.* still compiles (alias of Machine); V5 .mod files still run;
Gui.run() still blocks.

Download

One file: BasicPlus-6.0-win.zip (Windows; needs JDK 8+). Everything is inside — IDE,
compiler, standard library, samples, documentation, the simulated micro (with LVGL and
SQLite) and the seven 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/:

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 — new
bpvm_esp32c6_merged.bin ESP32-C6 and Waveshare ESP32-C6-LCD-1.3 — new
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)
2279292d65afef3ae6df240e00fad8b66cf7e50f5f17f53b814cf4c6fdc88434  BasicPlus-6.0-win.zip

Documentation

Known limitations

  • Databases still need a board with the command-line C VM; the IDE's simulated micro
    has them.
  • The S3 has no AOT (Xtensa); the C3 and C6 interpret their native functions until
    there is a soft-float RISC-V target — a P4 blob is ignored with a message.
  • listDir and input() only work on the Java VM.
  • A long native cannot be stopped until it returns (Stop is honoured between
    interpreter instructions).
  • On the P4, a burned pack wins over /lib and /app: a library pack carrying stdlib
    modules shadows the firmware's (the v6.0 packs carry the same ones, byte for byte).
    Refined in V7.
  • The full list is in PENDIENTES.md (Spanish).