erpc icon indicating copy to clipboard operation
erpc copied to clipboard

Linux - FreeRTOS communication using callbacks

Open anakorenko opened this issue 2 years ago • 14 comments

Hello, I'm trying to implement the next erpc client-server communication. My erpc server is running under Cortex-M4 microprocessor under FreeRTOS and CMSIS_UART as communication interface. My client is running under Linux. Client-server communication is working fine, but I got some difficulties in setting server callback back to client. In all discussions I've found all server to client callbacks are working when both client and server using the same architecture: e.g server and client are both under Linux and using pthreads, or server and client are using FreeRTOS threads. Is it possible to implement server callbacks to client when they are running on different archs?

anakorenko avatar Sep 12 '22 12:09 anakorenko

Hi eRPC user. Thank you for your interest and welcome. We hope you will enjoy this framework well.

github-actions[bot] avatar Sep 12 '22 12:09 github-actions[bot]

Hi @anakorenko , different architecture shouldn't be an issue. But currently it is supported in C only. The way how it works is that erpc is sending index to an array of functions which is created on both sides by erpc.

Hadatko avatar Sep 12 '22 13:09 Hadatko

Thank you, @Hadatko, for quick replay. If architecture isn`t an issue how to configure threading in erpc_config.h? Can I setup client for pthread and server for freertos multithreading?

anakorenko avatar Sep 12 '22 13:09 anakorenko

Hi @anakorenko , as you will have two applications, each application will have its own erpc_config.h file where you can specify different enviroment settings.

Hadatko avatar Sep 13 '22 05:09 Hadatko

Thank you, your answer helped me. But i have another questions do i need to use arbitrator in this case?

anakorenko avatar Sep 13 '22 13:09 anakorenko

You are welcome. Arbitrator need be used if you have client and server on each side. So you want do client requests from both sides and servers will respond on both sides.

Hadatko avatar Sep 13 '22 13:09 Hadatko

Greate, thanks, now i`m trying to make my callbacks work using examples from test directory, but somehow receiving strange error when trying to compile server-side of the application:

/usr/local/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld: _build/nrf52840_xxaa/erpc_demo_server.cpp.o: in function `linuxTonordic_service::myFun_shim(erpc::Codec*, erpc::MessageBufferFactory*, unsigned long)':
/home/artem/Documents/Packetcraft/ProjFreeRtos/pca10056/blank/armgcc/../../../erpc_demo_server.cpp:76: undefined reference to `erpc_malloc'
/usr/local/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld: /home/artem/Documents/Packetcraft/ProjFreeRtos/pca10056/blank/armgcc/../../../erpc_demo_server.cpp:111: undefined reference to `erpc_free'
/usr/local/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld: /home/artem/Documents/Packetcraft/ProjFreeRtos/pca10056/blank/armgcc/../../../erpc_demo_server.cpp:111: undefined reference to `erpc_free'
/usr/local/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld: /home/artem/Documents/Packetcraft/ProjFreeRtos/pca10056/blank/armgcc/../../../erpc_demo_server.cpp:111: undefined reference to `erpc_free'

This errors occurs only if i use out in my function arguments myFun(in callback1_t pCallback1_in, out callback1_t pCallback1_out) -> void

And second question. I need to execute some code on a client side using parameter from server side. For example i have this function on my client: void testfun(bool onOff){ if(onOff) printf("true\n"); else printf("false\n"); } i want to pass it to my server using callbacks

myFun(callback, &pCallback1_out);

on server side set argument as true and execute it back on client. Is this gonna work? Many thanks)

anakorenko avatar Sep 13 '22 16:09 anakorenko

You need choose erpc_port_*.cpp file from https://github.com/EmbeddedRPC/erpc/tree/develop/erpc_c/port

Hadatko avatar Sep 13 '22 16:09 Hadatko

Yep, now it works, and what about second question?

anakorenko avatar Sep 13 '22 17:09 anakorenko

Sorry i missed your question. No, you need also pass onOff as out parameter for function (same call or new call) e.g: myFun(callback, &pCallback1_out, &onOff); of myFun2(out onOFF)

Hadatko avatar Sep 13 '22 17:09 Hadatko

Hello again, can i use arbitrator on linux-rtos communication setup? I have seen couple of examples and in every FreeRTOS is used to run client and server tasks simultaneously. But in my case i can`t use FreeRTOS on the second end of setup. Also i saw issue #101, and option where callback is executed on a client is exactly what i want to create. Thanks

anakorenko avatar Sep 16 '22 13:09 anakorenko

Hi, I am also doing a similar thing. The difference is that the communication middleware is USB_CDC. I focus on the server-side application now. And FreeRTOS runs on STM32. According to the Porting Guide, I choose the erpc_port_freertos.* and change the erpc_config.h. Here is the episode from my CMakeList.txt:

file(GLOB_RECURSE SOURCES "startup/*.*" "Middlewares/*.*" "Drivers/*.*" "USB_DEVICE/*.*" "Core/*.*" 
"Communication/*.*"
"autogen/*.*" 
"erpc/erpc_c/config/*.*"
"erpc/erpc_c/setup/erpc_setup_usb_cdc.*"
"erpc/erpc_c/setup/erpc_server_setup.*"
"erpc/erpc_c/setup/erpc_client_setup.*"
"erpc/erpc_c/transport/erpc_usb_cdc_transport.*"
"erpc/erpc_c/transport/erpc_serial_transport.*"
"erpc/erpc_c/port/erpc_serial.*"
"erpc/erpc_c/port/erpc_port_freertos.cpp"
"erpc/erpc_c/port/erpc_setup_extensions_freertos.cpp"
"erpc/erpc_c/port/erpc_threading_freertos.cpp"
)

I received a compiling error:

In file included from /home/birdman/FOC/erpc/erpc_c/setup/erpc_setup_usb_cdc.cpp:12:
/home/birdman/FOC/erpc/erpc_c/transports/erpc_usb_cdc_transport.hpp:21:10: fatal error: fsl_component_serial_manager.h: No such file or directory
   21 | #include "fsl_component_serial_manager.h"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/FOC.elf.dir/build.make:843: CMakeFiles/FOC.elf.dir/erpc/erpc_c/setup/erpc_setup_usb_cdc.cpp.obj] Error 1
make[2]: *** Waiting for unfinished jobs....
In file included from /home/birdman/FOC/erpc/erpc_c/port/erpc_serial.h:50,
                 from /home/birdman/FOC/erpc/erpc_c/port/erpc_serial.cpp:39:
/usr/include/newlib/termios.h:4:10: fatal error: sys/termios.h: No such file or directory
    4 | #include <sys/termios.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/FOC.elf.dir/build.make:778: CMakeFiles/FOC.elf.dir/erpc/erpc_c/port/erpc_serial.cpp.obj] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/FOC.elf.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

What am I missing? Does modification of erpc_erpc_usb_cdc_transport.* required? I am new to this. Can anyone help? Thank you.

Second222None avatar Dec 01 '22 01:12 Second222None

@anakorenko Arbirator should be possible for different OS.

Hadatko avatar Dec 04 '22 19:12 Hadatko

@Second222None based on your output you are missing Linux or NXP SDK dependencies. It means there is no port for STM32 and you should do it on your own if you want it. If you provide PR in that case we will appretiate it.

Hadatko avatar Dec 04 '22 19:12 Hadatko