I build the ULP toolchain with the mentioned fix from the pull request:
Code: Select all
./configure --prefix=$HOME/esp/esp32ulp-elf-binutils --target=esp32ulp-elf
make
make install
And wrote a demo with stack and subroutine macros:
See
https://gist.github.com/tomtor/fa7d6d2c ... 07330be3a1 for full code with multiple subroutine calls.
Code: Select all
/*
* Demo of Stack and subroutine macros for ESP32 ULP
*
* R3 is the SP
*/
.macro push rx
st \rx,r3,0
sub r3,r3,1
.endm
.macro pop rx
add r3,r3,1
ld \rx,r3,0
.endm
// Prepare subroutine jump, uses scratch register sr
.macro psr sr=r1 pos=.
.set _next2,(\pos+16)
move \sr,_next2
push \sr
.endm
// Return from subroutine
.macro ret s=r0
pop \s
jump \s
.endm
/* Define variables, which go into .bss section (zero-initialized data) */
.bss
.global stack
stack:
.skip 400
.global stackEnd
stackEnd:
.long 0
/* Code goes into .text section */
.text
.global entry
entry:
move r3,stackEnd