This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Nrf51822 and STM32 uart bootloader problem

Hello

I try to use this bootloader https://github.com/williamhuang03/STM32F4-Custom-Bootloader on STM32F4 which works well through cable but as suddenly I use Nfr51 as transmitter and ESP32 as receiver so it doesn't work problem is that STM32 bootloader sends these commands in hex format #define ACK 0x06U, #define NACK 0x16U which Nrf51 uart rx ignores. Can mini advise where can be the problem ? I use the standard ble_app_uart code that is included with SDK_8.0.0 thank you for your advice.

Parents
  • Just to calrify: You have a STM32F sends UART commands to the nRF51 running the ble_app_uart example, which in turn sends these over BLE to a ESP32?

    I think that the ble_app_uart example expects the '\n' character to be received before sending the string received over UART on BLE. 

    Best regards

    Bjørn 

  • Exactly, I tried to add an '\ n' update to the STM32 boot code, but I get an error while updating. I Have tested this modified code with FTDI usb and the update will succeed.

    static void Send_ACK(UART_HandleTypeDef *handle)
    {
        uint8_t msg[2] = {ACK, '\n'};
        
        HAL_UART_Tx(handle, msg, 2);
    }
    
    /*! \brief Sends an NACKnowledge byte to the host.
     *  
     *  \param  *UartHandle The UART handle
     */
    static void Send_NACK(UART_HandleTypeDef *handle)
    {
        uint8_t msg[2] = {NACK, '\n'};
        
        HAL_UART_Tx(handle, msg, 2);
    }

  • Looking at the ble_app_uart code in SDK v8.0.0 you should be able to alter it to send a byte as soon as it is received over UART instead of waiting for the '\n' character. See comment below

    void uart_event_handle(app_uart_evt_t * p_event)
    {
        static uint8_t data_array[BLE_NUS_MAX_DATA_LEN];
        static uint8_t index = 0;
        uint32_t err_code;
    
        switch (p_event->evt_type)
        {
            case APP_UART_DATA_READY:
                UNUSED_VARIABLE(app_uart_get(&data_array[index]));
                index++;
                
                //Remove if statement and send a single byte each time the APP_UART_DATA_READY event is processed.
                if ((data_array[index - 1] == '\n') || (index >= (BLE_NUS_MAX_DATA_LEN))) 
                {
                    err_code = ble_nus_string_send(&m_nus, data_array, index);
                    if (err_code != NRF_ERROR_INVALID_STATE)
                    {
                        APP_ERROR_CHECK(err_code);
                    }
                    
                    index = 0;
                }
                break;
    
            case APP_UART_COMMUNICATION_ERROR:
                APP_ERROR_HANDLER(p_event->data.error_communication);
                break;
    
            case APP_UART_FIFO_ERROR:
                APP_ERROR_HANDLER(p_event->data.error_code);
                break;
    
            default:
                break;
                }
    }

  • Yes today I just tried it and it worked, I used the character '\ r' in the code ble_app_uart and in the code for STM32 and I had to modify the application for Windows to work it speed uart I set to 57600. This time, but the problem at 16kb bin file uploads too long about 4 minutes.

  • The nRF51 supports higher baudrates and I guess the STM32 does as well, so you can try to increase it to 115200? Are you only using TX/RX lines or are you using Hardware flow control (i.e. CTS/RTS) lines in addition?

    Best regards

    Bjørn

  • I only use Rx Tx pins I tried to increase the bit rate to 115200 but that's not a big difference, I feel the problem is in the code for ESP32.

  • OK, the nRF51 is limited to the 1Mbit Phy of Bluetooth, so the throughput is limited to 149.2 kbps. However, the actual throughput will depend on the features supported by the ESP32 as it is the BLE master.  I am afraid that we cannot provide a lot of support for issues on non-Nordic ICs. 

Reply Children
No Data
Related