MaJerle / lwpkt

Lightweight packet protocol structure for multi-device communication focused on RS-485
https://majerle.eu/projects/lwpkt-lightweight-packet-protocol-manager
MIT License
115 stars 24 forks source link

STM32 based LwPKT Example #3

Closed suyog44 closed 1 year ago

suyog44 commented 3 years ago

Hi Majrele,

I am planning to construct Multi Device Communication over UART (RS485) protocol. I found LwPKT interesting project to use it. But i am unable to figure out the usage with STM32 UART Interrupt based function. Could you able to give some hints regarding it.

/ Start DMA / if(HAL_UART_Receive_DMA(&huart2, (uint8_t*)pkt_tx_rb_data, 64) != HAL_OK) {
Error_Handler(); }

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) { res = lwpkt_write(&pkt,

    #if LWPKT_CFG_USE_ADDR
                        0x11,                       /* End address to whom to send */
    #endif /* LWPKT_CFG_USE_ADDR */

    #if LWPKT_CFG_USE_CMD
                        0x85,                       /* Command type */
    #endif /* LWPKT_CFG_USE_CMD */
                        data, strlen(data));        /* Length of data and actual data */

}

MaJerle commented 3 years ago

LwPKT uses 2 ringbufers for TX and RX operations. Every received character over UART at STM32 should be written to RX ringbuffer of LwPKT instance, and data that should be sent out from STM32 are available in the TX ringbuff.

Now receiving data and how to handle each character is application specific. From what I can see, you have setup 64-bytes received over DMA. Do you guarantee that you will always receive 64-bytes in one shot? If you don't your application may wait forever to get data. I see 2 possible solutions (pick one):

Second option (my opinion) is preferred.