ULP: working example of JUMP Rx

tomtor
Posts: 22
Joined: Thu May 11, 2017 6:15 am

ULP: working example of JUMP Rx

Postby tomtor » Thu Oct 05, 2017 6:22 am

I wrote a working DHT22 driver in ULP assembly and I would like to replace some repeated code with subroutines.

However even the most simple test code which inserts a dummy jump in a bigger working program:

Code: Select all

  move r0,loop
  jump r0
  nop
loop:
  nop
causes a restart of the ULP.

I have not found ANY use of jump Rx in the esp-idf examples and I wonder if there is an issue with the ULP assembler or cpu?


tomtor
Posts: 22
Joined: Thu May 11, 2017 6:15 am

Re: ULP: working example of JUMP Rx

Postby tomtor » Thu Oct 05, 2017 8:04 am

Thanks, so it is a toolchain issue.

The public toolchain download (got it a few days ago) predates the fix and the pull has not been merged so I have to build it myself...

Can someone at Espressif deal with this pull request?

User avatar
urbanze
Posts: 301
Joined: Sat Jun 10, 2017 9:55 pm
Location: Brazil

Re: ULP: working example of JUMP Rx

Postby urbanze » Thu Oct 05, 2017 1:01 pm

I using this in my code, it's a simple increment (++) with FOR loop and 1sec delay.

Code: Select all

.bss

.global x
x:   .long 0


.text
.global entry
entry:

		move r1, x
		ld r0, r1, 0

		
		jump loop
   
 
loop:
		
		add r0, r0, 1
		
		
		stage_rst
		jump delay
				

delay:
		stage_inc 1

		wait 65535
		jumps delay, 122, lt
		
		st r0, r1, 0
		jump loop

tomtor
Posts: 22
Joined: Thu May 11, 2017 6:15 am

Stack and Subroutine Macros for ULP

Postby tomtor » Fri Oct 06, 2017 7:04 am

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

tomtor
Posts: 22
Joined: Thu May 11, 2017 6:15 am

Re: Stack and Subroutine Macros for ULP

Postby tomtor » Wed Oct 25, 2017 8:08 am

tomtor wrote: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
I created a downloadable toolchain build with msys2 on a Windows-7 32-bit installation:

https://drive.google.com/open?id=0B3Q0B ... kpNU3ZVZjg

Also tested the as executable on a Windows-10 64 bit installation.

I installed the msys2 compiler with:

Code: Select all

pacman -S --needed base-devel mingw-w64-i686-toolchain
See also:

https://github.com/orlp/dev-on-windows/ ... C--&-MSYS2

Who is online

Users browsing this forum: No registered users and 78 guests