Skip to content

About

Build scripts for compiling ESP32 ULP code into MicroPython friendly format.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MicroPython ULP firmware builder

This is a wrapper for esp-idf which allows you to build ULP code for the ESP32 series, either RISCV or FSM variants.

At this time, this is the only way I was able to do this, as I am not that skilled enough to configure cmake myself to use espressif's ULP compile in a standalone way. If you have a better setup, please submit a pull request

This compiler outputs a python file with a dict that has the following:

	data = {
		'symbols' : {
			'counter': 1342177624
		},
		'binary' : b'o\x00...'
	}
  • data['symbols'] contains the memory addresses of any variables defined in the ULP source code with a name prefixed with var_

  • data['binary'] contains the compiled ULP binary.

Example use in MicroPython

	import my_ulp_code
	import esp32
	from machine import mem32
	import time

	u = esp32.ULP()
	u.load_binary(my_ulp_code.data['binary'])
	u.run()

	for i in range(10):
		tick = mem32[my_ulp_code.data['symbols']['counter']]
		print(tick)
		time.sleep(1)

Example ULP source code:

	#include <stdio.h>
	#include <stdint.h>
	#include <stdbool.h>
	#include "ulp_riscv.h"
	#include "ulp_riscv_utils.h"

	unsigned int var_counter = 0;

	int main (void)
	{      
		var_counter += 1;

		return 0;
	}

This will run the ULP code which in this example would increment a counter variable (var_conter in the source code, and the python code will print the value every second 10 times.

This will increase the filesize, but you can use the raw .bin file if you like, as that is also available in the output folder.

Note: This build chain uses Docker to easily target different IDF versions

Write your code in the ulp_src folder and compile with:

	make all

for default targets. You can provide more source files by modifying ulp_src/sources.cmake

To compile with your local IDF version, ommiting docker:

	make all DOCKER_CMD=""

Alternmatively you can call

	make target esp32

to configure the esp-idf enviroment to build for esp32 or a target of your choosing. ESP32S2 & S3 targets will build RISCV binaries by default but you can change that in ulp-compiler/sdkconfig.default:

Recommended RISCV config for MicroPython builds with ULP_RV class:

	CONFIG_ULP_COPROC_TYPE_RISCV=y
	CONFIG_ULP_COPROC_RESERVE_MEM=4096

Recommended FSM config for MicroPython default builds:

	CONFIG_ULP_COPROC_TYPE_FSM=y
	CONFIG_ULP_COPROC_RESERVE_MEM=2040

About

Build scripts for compiling ESP32 ULP code into MicroPython friendly format.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages