Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 10 months ago.
RPC for RawSerial hangs after sometime
I have added RPC support on FRDM K64 target so that i can communicate from PC using python.
I have K64 communicating with BT chip over UART (for this I have to use RawSerial as Serial had problems where it hangs due to mutex calls from C library). This is on UART0.
From python script I am trying to call putc and getc. It works for some time but later my mbed target gets hanged in serial_getc() function and never comes out of this.
Note: the hang is not seen when I disable my debug serial terminal which is on UART3. It is only when the debug terminal is on the mbed hangs in serial_getc().
Code snippet on mbed:
mbed k64 code
Serial pc(PTC17,PTC16); #include "mbed.h" main() { EthernetInterface eth; if(eth.init()) { pc.printf("Error while initializing the ethernet interface.\n"); return -1; } if(eth.connect()) { pc.printf("Error while starting the ethernet interface.\n"); return -1; } pc.printf("IP Address is %s\n", eth.getIPAddress()); RPC::add_rpc_class<RpcRawSerial>(); // Note: I added RPCRawSerial support in RPCclasses.h RpcRawSerial bt(PTB17,PTB16,"btuart"); TCPSocketServer server; server.bind(ECHO_SERVER_PORT); server.listen(); while (true) { pc.printf("\nWait for new connection...\n"); TCPSocketConnection client; server.accept(client); pc.printf("Connection from: %s\n", client.get_address()); char buffer[256]; while (true) { int n = client.receive(buffer, sizeof(buffer)); if (n <= 0) break; buffer[n] = '\0'; pc.printf("Received message from Client :'%s'\n",buffer); RPC::call(buffer, outbuf); pc.printf("Result got =%s\n", outbuf); client.send_all(outbuf, n); if (n <= 0) break; } client.close(); } return 0; }
I tried even using the RPCSerial instead of my own RPCRawSerial, but the result is the same. Hangs in serial_getc.
Only after completely disabling the debug UART it works fine.
Any clue on Why there is a hang when debug is enabled ?
mbed k64 code
My RPC raw Serial class is as below class RpcRawSerial : public RPC { public: RpcRawSerial(PinName a0, PinName a1, const char *name=NULL) : RPC(name), o(a0, a1) {} void baud(int a0) {o.baud(a0);} int readable(void) {return o.readable();} int writeable(void) {return o.writeable();} int putc(int a0) {return o.putc(a0);} int getc(void) {return o.getc();} int puts(const char * a0) {return o.puts(a0);} virtual const struct rpc_method *get_rpc_methods() { static const rpc_method rpc_methods[] = { {"baud", rpc_method_caller<RpcRawSerial, int, &RpcRawSerial::baud>}, {"readable", rpc_method_caller<int, RpcRawSerial, &RpcRawSerial::readable>}, {"writeable", rpc_method_caller<int, RpcRawSerial, &RpcRawSerial::writeable>}, {"putc", rpc_method_caller<int, RpcRawSerial, int, &RpcRawSerial::putc>}, {"getc", rpc_method_caller<int, RpcRawSerial, &RpcRawSerial::getc>}, {"puts", rpc_method_caller<int, RpcRawSerial, const char *, &RpcRawSerial::puts>}, RPC_METHOD_SUPER(RPC) }; return rpc_methods; } static struct rpc_class *get_rpc_class() { static const rpc_function funcs[] = { {"new", rpc_function_caller<const char*, PinName, PinName, const char*, &RPC::construct<RpcRawSerial, PinName, PinName, const char*> >}, RPC_METHOD_END }; static rpc_class c = {"RawSerial", funcs, NULL}; return &c; } private: RawSerial o; //Instead of Serial, i made it RawSerial };
-yk
Any input on why a hang (serial_getc) when I use the standard RPC serial along with the serial debug port. It does not hang when I do not use my serial debug port. I want both enabled as part of my project.? Any approach I should take to debug this problem ? - YK
posted by yogesh kulkarni 27 Oct 2015