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

Bug report: ser_phy_hci_slip_cdc crashes if last byte of packet is SLIP_END or SLIP_ESC.

What happens: if I send a serialization packet whose last byte is SLIP_END (0xC0) or SLIP_ESC (0xDB), the program crashes in an assert in ser_hal_transport.c:141.

Why: The event SER_PHY_EVT_TX_PKT_SENT is triggered two times, because ser_phy_hci_slip_cdc:tx_buf_put() is called two times with m_tx_phase == PHASE_ACK_END or m_tx_phase == PHASE_PACKET_END if the last byte needs to be escaped. This will cause two flushes and two events.

The bug might also be present in ser_phy_hci_slip.c because the code looks similar, but I haven't checked.

My fix: add is_escape argument to tx_buf_put, don't trigger events if it's true.

It works for me, but it feels a bit hacky, there's probably a better way by reworking the state machine. 

142c142
< static bool tx_buf_put(uint8_t data_byte)
---
> static bool tx_buf_put(uint8_t data_byte, bool is_escape)
150c150
<     if (m_tx_phase == PHASE_ACK_END)
---
>     if (m_tx_phase == PHASE_ACK_END && !is_escape)
156c156
<     else if (m_tx_phase == PHASE_PACKET_END)
---
>     else if (m_tx_phase == PHASE_PACKET_END && !is_escape)
205c205
<             can_continue = tx_buf_put(tx_escaped_data);
---
>             can_continue = tx_buf_put(tx_escaped_data, true);
211c211
<             can_continue = tx_buf_put(APP_SLIP_END);
---
>             can_continue = tx_buf_put(APP_SLIP_END, false);
220c220
<             can_continue = tx_buf_put(APP_SLIP_END);
---
>             can_continue = tx_buf_put(APP_SLIP_END, false);
263c263
<             can_continue = tx_buf_put(data);
---
>             can_continue = tx_buf_put(data, false);

sga

Related