ULP RISC-V calling assembly from C not working
Posted: Mon May 03, 2021 10:10 pm
According to the manual, the ULP-RISC-V co-processor on the esp32-s2 can be programmed with both C and assembly. I'm having trouble getting a trivial example using both C and assembly to work.
My code (on GitHub) builds and runs, but doesn't return the correct result from a function implemented in assembly.
This is the code running on the ULP-RISC-V:
My main application prints out both ulp_result_s and ulp_result_c. Instead of 3, both are 0.
If I comment out the call to the external assembly function add()
the C-only part works and ulp_result_c is correct (3).
The add function is implemented as add.S:
I don't think it can get any simpler, but I am by no means an expert in assembly.
Everything builds and flashes to the chip fine. Any help getting this to work is appreciated!
My code (on GitHub) builds and runs, but doesn't return the correct result from a function implemented in assembly.
This is the code running on the ULP-RISC-V:
Code: Select all
#include "ulp_riscv/ulp_riscv.h"
#include "ulp_riscv/ulp_riscv_utils.h"
extern int add(int x, int y);
volatile int result_s;
volatile int result_c;
int main(void)
{
result_s = add(1, 2);
result_c = 1 + 2;
}
If I comment out the call to the external assembly function add()
Code: Select all
//result_s = add(1, 2);
result_c = 1 + 2;
The add function is implemented as add.S:
Code: Select all
.section .text
.global add
.type add, @function
add:
add a0, a0, a1
ret
Everything builds and flashes to the chip fine. Any help getting this to work is appreciated!