currently I'm working on a UART communication between two platforms. One is equipped with an STM32F103VET6. I have to use UART3 for the communication. What it does (should do) is receive an byte array from the master, change a byte and reply the byte array to the master. For debugging I'm only echoing the bytes received.
I can successfully read the whole message until the carriage return character. But when I try to transmit the buffer, the sdWrite only puts the two first bytes on the phy. This happens every time. I've already removed the receiver and fill the tx_buf with dummy data.
When I remove the resetting of the in- and output queue it works like it should, but I have to be sure that the buffers are completely empty.
My code looks (simplified) like this:
Code: Select all
static SerialConfig uart3_cfg = {
        .sc_speed = 115200,
        /* 8 bits UART */
        .sc_cr1 = USART_CR1_WAKE,
        .sc_cr2 = 0,
        .sc_cr3 = 0,
};
static void /*@null@*/* listen(void /*@unused@*/*a)
{
    int bus_addr = max_get_bus_addr();
    uint8_t rx_buf[32] = { 0 };
    uint8_t tx_buf[32] = { 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19 };
    init(bus_addr);
    while (1)
    {
#if 0
    /* Original code, not working. Outputs only two first bytes. All ten bytes are read correctly. */
        chIQResetI(&SD3.iqueue);
        chOQResetI(&SD3.oqueue);
        memset(rx_buf, 0, sizeof(rx_buf));
        memset(tx_buf, 0, sizeof(tx_buf));
        size_t length = sdGetLine(&SD3, rx_buf, sizeof(rx_buf));
        sdWrite(&SD3, rx_buf, length);
#elif 0
    /* Working code. Outputs all 10 bytes */
        chThdSleepMilliseconds(1000);
        sdWrite(&SD3, tx_buf, 10);
#else
    /* Dummy read code, not working. Outputs only two first bytes */
        chIQResetI(&SD3.iqueue);
        chOQResetI(&SD3.oqueue);
        memset(rx_buf, 0, sizeof(rx_buf));
        memset(tx_buf, 0, sizeof(tx_buf));
        /* Simulate data read from UART*/
        uint8_t tx_switch[10] = { 0x01, 0x08, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, '\r' };
        size_t length = sizeof(tx_switch);
        chThdSleepMilliseconds(1000);
        memcpy(rx_buf, tx_switch, length);
        sdWrite(&SD3, rx_buf, length);
#endif
    }
    exit();
    return NULL;
}
static size_t sdGetLine(SerialDriver *sdp, uint8_t *buf, size_t max)
{
    size_t n;
    uint8_t c;
    n = 0;
    do
    {
        c = sdGet(sdp);
        *buf = c;
        buf++;
        n++;
        max--;
    } while ((c != '\r') && (max > 0));
    *buf = 0;
    return n;
}
static void init(int bus_addr)
{
    uart3_cfg.sc_cr2 |= (bus_addr & 0x0F);
    sdStart(&SD3, &uart3_cfg);
}
static void exit(void)
{
    sdStop(&SD3);
}
Â
Hope that someone can point me into the right direction to fix this problem. I'm working this 2.3.4 branch: ftp://opensource.axon.tv/mirror/ChibiOS_2.3.4.zip
When you want more info, please let me know
Thanks in advance!
Matis