Closed dryet closed 12 months ago
Hi @dryet,
What kind of a function is func()
? Is it being built for the LP core? To me it seems like the func()
function is part of a component which isn't being built for the LP core but rather for the HP core (main core). Since the binary that is loaded on to the LP core is different, you may have to compile sources/components for the LP core specifically. You may have to update the components/ulp/lp_core/CMakeLists.txt to achieve this.
Hello @sudeep-mohanty, It is the default function of the component to make things easier to recreate. Yes, I think you are right because I added it the way I would add a component normally to a HP core code.
So if I understand it correctly I should add my components that are used by the LP core to the main/lp_core folder?
I am sorry if this question seems stupid but how can I add a component to this components/ulp/lp_core/CMakeLists.txt cmake list from my project? Do I modify the list in main folder?
Thank you for your help.
No problem! My previous suggestion was under the assumption that the component is common to the HP core and LP core and hence the CMakeLists.txt would have been the place to specifically add source files. But I stand corrected and as you pointed out, it would be much easier to have your new component as part of your application to manage it. main/lp_core
looks good to me.
Yes it was common to both but I moved it to the lp_core folder.
So I did the following: Created new component using the IDE. Moved it to the lp_core folder. Included the header file if main.c file. But i still get the reference error. Is it because I have not edited the ulp part of the cmake list?
#
#
set(ulp_app_name lpcore${COMPONENT_NAME}) #
set(ulp_lp_core_sources "lp_core/main.c")
#
set(ulp_exp_dep_srcs "lp_i2c_main.c")
#
ulp_embed_binary(${ulp_app_name} "${ulp_lp_core_sources}" "${ulp_exp_dep_srcs}")
Do I need to make any changes to this to include my component for the LP core binary? For testing purposes lets say my component name is "test" and I have a test.c file in main/lp_core/test/test.c path.
@dryet If your application folder looks like this (notice my_component
) -
├── CMakeLists.txt
├── README.md
├── main
│ ├── CMakeLists.txt
│ ├── bh1750_defs.h
│ ├── lp_core
│ │ ├── main.c
│ │ └── my_component
│ │ ├── include
│ │ │ └── test.h
│ │ └── test.c
│ └── lp_i2c_main.c
Then your main/CMakeLists.txt
would look like this (notice changes to INCLUDE_DIRS
and ulp_lp_core_sources
) -
# Register the component
idf_component_register(SRCS "lp_i2c_main.c"
INCLUDE_DIRS "" "lp_core/my_component/include"
REQUIRES ulp)
#
# ULP support additions to component CMakeLists.txt.
#
# 1. The LP Core app name must be unique (if multiple components use LP Core).
set(ulp_app_name lp_core_${COMPONENT_NAME})
#
# 2. Specify all C files.
# Files should be placed into a separate directory (in this case, lp_core/),
# which should not be added to COMPONENT_SRCS.
set(ulp_lp_core_sources "lp_core/main.c" "lp_core/my_component/test.c")
#
# 3. List all the component source files which include automatically
# generated LP Core export file, ${ulp_app_name}.h:
set(ulp_exp_dep_srcs "lp_i2c_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_lp_core_sources}" "${ulp_exp_dep_srcs}")
And when you need to use this component, your lp_core/main.c
would look like -
#include "test.h"
void main()
{
func();
...
...
}
@sudeep-mohanty Thank you so much this is exactly what I needed any my code works now. Your answer is very clear.
Glad that it works for you now! Closing this issue now. Please feel free to reach out to us if you any issues. Thanks!
Answers checklist.
IDF version.
v5.2-dev-2756-g2bc1f2f574
Operating System used.
Windows
How did you build your project?
Eclipse IDE
If you are using Windows, please specify command line type.
None
What is the expected behavior?
I expect the code to build withou issues. There should be a reference to the func fuction.
What is the actual behavior?
Instead it builds with error conserning the reference to the func function.
Steps to reproduce.
Build or installation Logs.
More Information.
Main.c file:
/*
include
include
include
include "ulp_lp_core_i2c.h"
include "ulp_lp_core_utils.h"
include "../bh1750_defs.h"
include "../../components/sensor/include/sensor.h"
define LP_I2C_TRANS_TIMEOUT_CYCLES 5000
define LP_I2C_TRANS_WAIT_FOREVER -1
define LUX_THRESHOLD_LOW 5
define LUX_THRESHOLD_HIGH 1000
static uint32_t sensor_on = 0; static uint32_t res_update_done = 0; volatile uint32_t lux = 0;
static void bh1750_read() { uint8_t data_rd[2]; esp_err_t ret = lp_core_i2c_master_read_from_device(LP_I2C_NUM_0, BH1750_I2C_ADDR, data_rd, sizeof(data_rd), LP_I2C_TRANS_TIMEOUT_CYCLES); if (ret != ESP_OK) { // Skip this round of calculation and return return; }
}
int main (void) { uint8_t data_wr = 0; esp_err_t ret = ESP_OK;
}