STM32F103VCT6 - TCP connects but won't send (Cellular)

Hiya. I’m having a weird issue I don’t understand.

I’m reverse-engineering an automotive GPS tracker device based on an STM32F103VCT6 that I accidentally bricked (long story).

I’ve managed to activate all the peripherals however it is using HSI and LSI as for some reason it isn’t keen on activating the xtal oscillators (both are present)

I’ve managed to interface with the 3G module, get it connected to PPP etc. My problem lays with the Socket network layer.

Neither UDP nor TCP sockets will connect and send data.

  • DNS lookup succeeds
  • Socket reports connect success
  • Packet capture on the ‘remote’ end (my own webserver) shows the TCP handshake occurring
  • Attempt to send any data fails (not received by server, as in example below) or times out (HTTPRequest class)

Any hints? I’m stumped. Main function is below.

int main()
 //----------------------------------ORIGINAL CODE--------------------------------//

    Thread tNorm(osPriorityNormal);
    DO_AuxPwr = 1;
    Modem_ONOFF = 0;


    tNorm.start(callback(&npQueue, &EventQueue::dispatch_forever));
    npQueue.call_every(500ms, blinkLed);

    Modem_ONOFF = 1;

//-------------------------------CELLULAR EXAMPLE--------------------------------//


    printf("Establishing connection\n");

    iface = CellularContext::get_default_instance();

    // sim pin, apn, credentials and possible plmn are taken automatically from json when using NetworkInterface::set_default_parameters()

    nsapi_error_t retcode = NSAPI_ERROR_NO_CONNECTION;

    /* Attempt to connect to a cellular network */
    if (do_connect() == NSAPI_ERROR_OK) {

        printf("\n----- Setting up TCP connection -----\n");

        TCPSocket* socket = new TCPSocket();

        SocketAddress address;
        printf("Looking up hostname\n");
        nsapi_error_t dns_result = iface->gethostbyname("<<HOSTNAME>>",&address);        
        if(dns_result != 0){
            printf("DNS Failed...\n");
        } else {
            printf("Got IP: %s\n", address.get_ip_address());
        nsapi_error_t open_result = socket->open(iface);
        if (open_result != 0) {
            printf("Opening TCPSocket failed... %d\n", open_result);
            return 1;
        nsapi_error_t connect_result = socket->connect(address);
        if (connect_result != 0) {
            printf("Connecting over TCPSocket failed... %d\n", connect_result);
            return 1;
        } else {
        socket->send("GET / HTTP/1.0\n\n", 19);

    if (iface->disconnect() != NSAPI_ERROR_OK) {
        print_function("\n\n Disconnect failed.\n\n");

    if (retcode == NSAPI_ERROR_OK) {
        print_function("\n\nSuccess. Exiting \n\n");
    } else {
        print_function("\n\nFailure. Exiting \n\n");


    return 0;



I do not have any experiences with Cellular just with Ethernet, but you could try Mbed official example with their Echo server (I hope the server is still UP) - Cellular - API references and tutorials | Mbed OS 6 Documentation
With this way you will verified the hardware and code for connection + send/recv.

BR, Jan

Thanks, this prettymuch is the cellular example, however using a session to a server I control, instead of one I do not. The cellular example did not work, in the exact same way.

And we can close this one… Apparently I specifically needed to add a data plan… to a data SIM. Weird that they let a couple packets through then kill it.