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

Can't send more than 20 bytes? UART example will restart?

Hi,

I'm using two nrf52 dev kits and the ble_app_uart & ble_app_uart_c examples to test a BLE link that would ideally be able to hit a 1Mbps throughput. I am, however, very much not there yet! I'm still trying to familiarize myself with BLE and all the knobs I can turn.

So far I know that I can increase the MTU size up to 247 bytes and reduce the connection intervals to their minimum setting 7.5 ms to increase throughput. This is great! Buuut when playing with these examples I'm only able to send 20 bytes at a time. If I try to send more than 20 bytes from the central, it seems to restart based off the messages below:

If I try to send say 25 bytes from the peripheral, only the first 20 bytes get sent.

I saw in other posts that I'd need to give the stack some more memory but I am new to this and don't exactly know where the stack size is set. So any advice would be greatly appreciated.  

Thanks,

Ryan

  • Okay, so the answer already existed on the forums but it required some hyperlink following which I'd like to help future users avoid, so I'll post my debug and solution here!

    Ultimately, if you want to increase your BLE throughput you need to increase the NRF_SDH_BLE_GATT_MAX_MTU_SIZE & NRF_SDH_BLE_GAP_DATA_LENGTH  in your sdk_config.h AND also adjust your memory map to provide more room for your buffers. Updating the sdk_config is easy but if you're like me and messing with memory allocation is scary, nordic actually made it very easy with the use of some very helpful error statements that tell you exactly what to set your RAM start and size to.

    The first step was to actually look at the error statements from the ble functions (make sure you have enabled the RTT or UART logging backends in the sdk_config.h). Build and debug your solution - don't forget to hit play. Your terminal should fill up with some stuff and then you'll get an error most likeley. My first error was along the lines of:

     The requested TX/RX packet length is too long by 224/224 octets.

    This was due to how my NRF_SDH_BLE_GAP_DATA_LENGTH was much shorter than the NRF_SDH_BLE_GATT_MAX_MTU_SIZE (because I had been changing various defines during my initial unsuccessful debugging). When I set them both to 251 bytes, I got an error related to my memory allocation! It looked basically like this (not exact numbers).

    nrf_sdh_ble: RAM start should be adjusted from  0x20002934 to 0x20002. 
    nrf_sdh_ble: RAM size should be adjusted to 0xD698.

    This was great because this exactly the issue forseen by other blog posts (link, link, and link) and fixed in this tutorial! Just one last issue, I took the error message a little too literally and didn't pay attention to where I put the RAM start. At first, I actually set it to 0x20002. Keep in mind that 0x20002 is not the same as 0x20002000. so make sure you put in the right amount of zeros in the address otherwise you'll get some weird/mean errors!

Related