spatialdude / usqlite

μSQLite library module for MicroPython
MIT License
87 stars 18 forks source link

Build failure esp32 #2

Closed palmtreefrb closed 2 years ago

palmtreefrb commented 2 years ago

First, my apologies for the verbose post(complete build output in zip file). As you can see below the build fails for esp32. Any direction will be appreciated. Thanks, Rick

FYI, I can build esp32 successfully without usqlite.

Ubuntu 20.04 Micropython 1.17 ESP-IDF v4.2

Project Structure /Home ..../Micropython ..../Modules ......../usqlite .........micropython.cmake ... ..../sqlite ....sqlite3.c ....sqlite3.h

micropython/ports/esp32$ make submodules git submodule update --init ../../lib/berkeley-db-1.xx micropython/ports/esp32$ make clean idf.py -D MICROPY_BOARD=GENERIC -B build-GENERIC fullclean Executing action: fullclean Done micropython/ports/esp32$ make USER_C_MODULES=/home/fredrick/micropython/modules/usqlite/micropython.cmake

[1283/1284] Linking CXX executable micropython.elf FAILED: micropython.elf

... build_failure.zip ...

collect2: error: ld returned 1 exit status ninja: build stopped: subcommand failed. ninja failed with exit code 1 make: *** [Makefile:34: all] Error 2 $

palmtreefrb commented 2 years ago

Ok, I found the issue. I had to add compiler option -mtext-section-literals to the toolchain-esp32.cmake file in esp-idf. After all this it seems usqlite to too big for my ESP32-WROOM-32D :-(

**bootloader @0x001000 21104 ( 7568 remaining) partitions @0x008000 3072 ( 1024 remaining) application @0x010000 2015200 ( -442336 remaining) ERROR: application overflows allocated space of 1572864 bytes by 442336 bytes make: * [Makefile:35: all] Error 1

spatialdude commented 2 years ago

@palmtreefrb Thanks for your feedback and I'm glad you got it to compile. I had been waiting for my ESP32 device to turn up so I could try the module out on this platform. I should have it in the next week or so.

In the meantime the one of the major keys to reducing the code footprint is to omit or disable SQLite functionality that you do not need. The configuration is defined in usqlite_config.h In this file you will find the default options I selected. This was a first stab at balancing footprint size with functionality. The footprint size can be further reduced with additional #define SQLITE_OMIT_xxx entries. These options are described in the SQLite compile options reference Options To Omit Features section.

I don't yet have a good measure of what the footprint impact is for various SQLite features, this is something I plan to put some effort into and provide some higher level configuration choices.

palmtreefrb commented 2 years ago

That might be tough to eliminate 442336 bytes plus whatever implementation code for running an application. Most ESP32's have 4MB flash but there is a ESP32-WROVER with 8MB flash but it is hard to come by now on a development board. Chip shortages you know. I have found some out of China Aliexpress ESP32-DevKitC-VE ESP32-WROVER-E 8MB FLASH but shipping here to the US will take several weeks.

spatialdude commented 2 years ago

@palmtreefrb the change to micropython.cmake should avoid having to make any changes to toolchain-esp32.cmake in esp-idf.

I've got my TinyPICO up and running and so far the usqlite module is working nicely. (Note I did have to change partitions.csv to accommodate the firmware image's increase in size.

palmtreefrb commented 2 years ago

Very nice, I will give it a try and let you know how it works for me.

palmtreefrb commented 2 years ago

Very good, looks great...

build-GENERIC/micropython.bin or run 'idf.py -p (PORT) flash' bootloader @0x001000 21104 ( 7568 remaining) partitions @0x008000 3072 ( 1024 remaining) application @0x010000 2029360 ( 329936 remaining) total 2094896

import usqlite if not usqlite.mem_status(): usqlite.mem_status(True) True con = usqlite.connect("data.db") con.executemany( "BEGIN TRANSACTION;" "CREATE TABLE IF NOT EXISTS data (name TEXT, year INT);"+ "INSERT INTO data VALUES ('Larry', 1902);"+ "INSERT INTO data VALUES ('Curly', 1903);"+ "INSERT INTO data VALUES ('Moe', 1897);"+ "INSERT INTO data VALUES ('Shemp', 1895);"+ "COMMIT;") <Cursor 'NULL'> with con.execute("SELECT * from data") as cur: for row in cur: print("stooge:", row)

stooge: ('Larry', 1902) stooge: ('Curly', 1903) stooge: ('Moe', 1897) stooge: ('Shemp', 1895) con.close() print("usqlite mem - current:", usqlite.mem_current(), "peak:", usqlite.mem_peak()) usqlite mem - current: 0 peak: 97296

spatialdude commented 2 years ago

Awesome. Thanks for the feedback @palmtreefrb