I'm going to outline a way to reproduce what I am up to. First I started with the ulp example in the esp-idf directory. Then I open up pulse_cnt.S, cut the wake_up label from the bottom and paste it into a new file called library1.S. Then I'll edit the entry in CMakeLists.txt and proceed to compile.
pulse_cnt.S (*abbreviated for brevity, cannot be directly compiled)
Code: Select all
#include "soc/rtc_cntl_reg.h"
#include "soc/rtc_io_reg.h"
#include "soc/soc_ulp.h"
/* Define variables, which go into .bss section (zero-initialized data) */
.bss
/* Next input signal edge expected: 0 (negative) or 1 (positive) */
.global next_edge
next_edge:
.long 0
.
.
.
.global edge_detected
edge_detected:
/* Reset debounce_counter to debounce_max_count */
move r3, debounce_max_count
move r2, debounce_counter
ld r3, r3, 0
st r3, r2, 0
/* Flip next_edge */
move r3, next_edge
ld r2, r3, 0
add r2, r2, 1
and r2, r2, 1
st r2, r3, 0
/* Increment edge_count */
move r3, edge_count
ld r2, r3, 0
add r2, r2, 1
st r2, r3, 0
/* Compare edge_count to edge_count_to_wake_up */
move r3, edge_count_to_wake_up
ld r3, r3, 0
sub r3, r3, r2
jump wake_up, eq
/* Not yet. End program */
halt
Code: Select all
#include "soc/rtc_cntl_reg.h"
#include "soc/rtc_io_reg.h"
#include "soc/soc_ulp.h"
.global wake_up
wake_up:
/* Check if the system can be woken up */
READ_RTC_FIELD(RTC_CNTL_LOW_POWER_ST_REG, RTC_CNTL_RDY_FOR_WAKEUP)
and r0, r0, 1
jump wake_up, eq
/* Wake up the SoC, end program */
wake
halt
Code: Select all
idf_component_register(SRCS "ulp_example_main.c"
INCLUDE_DIRS ""
REQUIRES soc nvs_flash ulp)
#
# ULP support additions to component CMakeLists.txt.
#
# 1. The ULP app name must be unique (if multiple components use ULP).
set(ulp_app_name ulp_${COMPONENT_NAME})
#
# 2. Specify all assembly source files.
# Files should be placed into a separate directory (in this case, ulp/),
# which should not be added to COMPONENT_SRCS.
set(ulp_s_sources "ulp/library1.S" "ulp/pulse_cnt.S")
#
# 3. List all the component source files which include automatically
# generated ULP export file, ${ulp_app_name}.h:
set(ulp_exp_dep_srcs "ulp_example_main.c")
#
# 4. Call function to build ULP binary and embed in project using the argument
# values above.
ulp_embed_binary(${ulp_app_name} ${ulp_s_sources} ${ulp_exp_dep_srcs})
ulp_main.h
Code: Select all
// Variable definitions for ESP32ULP
// This file is generated automatically by esp32ulp_mapgen.py utility
#pragma once
extern uint32_t ulp_wake_up;
Code: Select all
Memory Configuration
Name Origin Length Attributes
ram 0x0000000000000000 0x0000000000000400 rw
*default* 0x0000000000000000 0xffffffffffffffff
Linker script and memory map
LOAD CMakeFiles/ulp_main.dir/library1.ulp.S.obj
.text 0x0000000000000000 0x14 load address 0x000000000000000c
*(.text)
.text 0x0000000000000000 0x14 CMakeFiles/ulp_main.dir/library1.ulp.S.obj
0x0000000000000000 wake_up
.data 0x0000000000000014 0x0 load address 0x0000000000000020
0x0000000000000014 . = ALIGN (0x4)
*(.data)
.data 0x0000000000000014 0x0 CMakeFiles/ulp_main.dir/library1.ulp.S.obj
.bss 0x0000000000000014 0x0 load address 0x0000000000000020
0x0000000000000014 . = ALIGN (0x4)
*(.bss)
.bss 0x0000000000000014 0x0 CMakeFiles/ulp_main.dir/library1.ulp.S.obj
.header 0x0000000000000014 0xc load address 0x0000000000000000
0x0000000000000014 0x4 LONG 0x706c75
0x0000000000000018 0x2 SHORT 0xc LOADADDR (.text)
0x000000000000001a 0x2 SHORT 0x14 SIZEOF (.text)
0x000000000000001c 0x2 SHORT 0x0 SIZEOF (.data)
0x000000000000001e 0x2 SHORT 0x0 SIZEOF (.bss)
OUTPUT(ulp_main elf32-esp32ulp)