Skip to content

[B96B_F446VE] New platform + development of dma_asynch_serial + hwControlFlow #1470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 20 commits into from
Closed

[B96B_F446VE] New platform + development of dma_asynch_serial + hwControlFlow #1470

wants to merge 20 commits into from

Conversation

adustm
Copy link
Member

@adustm adustm commented Dec 11, 2015

B96B F446VE is a new STM32 platform.
Asynch serial has been implemented using mbed interface (using DEVICE_SERIAL_ASYNCH).
A new define was added : DEVICE_SERIAL_ASYNCH_DMA 1 to force the use of DMA transfer for the async serial. define it to 0 if you want to use interrupts only instead of DMA.
Serial asynch can be extended to every STM32F4 family.

Serial HW Control Flow is supported for this platform (using DEVICE_SERIAL_FC define)

Need to change the SerialBase.cpp api, in order to provide the callback
address to the DMA interrupt.
Simple test works with USBTX and USBRX pins. To be further tested
Different handler for dma rx interrupt, compatible with mbed api
@adustm
Copy link
Member Author

adustm commented Dec 17, 2015

DTCT_1 EXAMPLE_1 MBED_10 MBED_11 MBED_12 MBED_16 MBED_2 MBED_23 MBED_24 MBED_25 MBED_26 MBED_34 MBED_37 MBED_38 MBED_A1 MBED_A21 MBED_A9 MBED_BUSOUT RTOS_1 RTOS_2 RTOS_3 RTOS_4 RTOS_5 RTOS_6 RTOS_7 RTOS_8
ARM B96B_F446VE OK OK OK OK OK FAIL OK OK OK OK OK OK FAIL OK OK OK OK OK OK OK OK OK OK OK OK OK
GCC_ARM B96B_F446VE OK OK OK OK OK FAIL OK OK OK OK OK OK FAIL OK OK OK OK OK OK OK OK OK OK OK OK OK
IAR B96B_F446VE OK OK OK OK OK FAIL OK OK OK OK OK OK FAIL OK OK OK OK OK OK OK OK OK OK OK OK OK
uARM B96B_F446VE OK OK OK OK OK FAIL OK OK OK OK OK OK FAIL OK OK OK OK OK OK OK OK OK OK OK OK OK

@adustm
Copy link
Member Author

adustm commented Dec 17, 2015

MBED_16 is failing due to a modification done recently in mbed micromaster (to be investigated and fixed separately)
MBED_37 is failing on the complete F4 family, but it is not considered as blocking.

@adustm
Copy link
Member Author

adustm commented Dec 17, 2015

Please find hereafter the main I used to validate the serial

#include "mbed.h"

#define TEST_HWFLOWCONTROL 1
#define TRANSMITTER_BOARD
/------------ Constant definitions --------------/
#define TOGGLE_RATE (0.5f)
/* Exported macro ------------------------------------------------------------/
#define COUNTOF(BUFFER) (sizeof(BUFFER) / sizeof(
(BUFFER)))
/-------- Check if platform compatible ----------/
//Serial test_connection(USBTX, USBRX); // tested ok. UART4, via ST-LINK and VirtualComPort
//Serial test_connection(PE_8, PE_7); // not tested, solder JP50 and JP51, unsolder JP48 JP49
//Serial test_connection(PC_12, PD_2); // tested ok. UART5: connector Arduino, pins D4 & D14
//Serial test_connection(PD_8, PD_9); // tested ok. UART3: use connector J10, pins 3 & 4
//Serial test_connection(PA_2, PA_3); // tested ok. UART2: use connector Arduino_A1 and J3 pin3
//Serial test_connection(PD_5, PD_6); // tested ok. UART2: use connector Arduino_D1 and Arduino_D0
//Serial test_connection(PA_9, PA_10); // tested ok. UART1: PA_9 is on JP71, PA_10 is on JP72 (JP72 to be unsoldered)

/------------------ Variables -------------------/
//LowPowerTicker blinker;
event_callback_t serialTXEventCb;
event_callback_t serialRXEventCb;
DigitalOut led2(LED2);
DigitalOut led3(LED3);
DigitalOut led4(LED4);
DigitalIn button(PD_13,PullUp);
//uint8_t aTxBuffer[2] = {0xAA, 0xAA};
uint8_t aTxBuffer[] = " *_UART_TwoBoards communication based on DMA* *_UART_TwoBoards communication based on DMA* _UART_TwoBoards communication based on DMA_* ";
/* Size of Transmission buffer /
#define TXBUFFERSIZE (COUNTOF(aTxBuffer) - 1)
/
Size of Reception buffer /
#define RXBUFFERSIZE TXBUFFERSIZE
uint8_t rx_buf[RXBUFFERSIZE];
volatile uint32_t tx_complete = 0;
volatile uint32_t rx_complete = 0;
volatile uint32_t rx_char_received = 0;
/
------------------ Callbacks -------------------
/

/**

  • This is a callback! Do not call frequency-dependent operations here.
    */
    void serialTxCb(int events) {
    /
    handle TX callback */
    if (events & SERIAL_EVENT_TX_COMPLETE) {
    tx_complete = 1;
    led4 = 1;
    }
    }
    void serialRxCb(int events) {
    unsigned char i;

    if(events & SERIAL_EVENT_RX_CHARACTER_MATCH) {
    rx_char_received = 1;
    rx_complete = 1;
    //Received 'S', check for buffer length
    for(i = 0; i < RXBUFFERSIZE; i++) {
    //Found the length!
    if(rx_buf[i] == 'S') break;
    }
    led3 = 1;
    } else if (events & SERIAL_EVENT_RX_COMPLETE) {
    i = RXBUFFERSIZE - 1;
    rx_complete = 1;
    led3 = 1;
    } else {
    rx_buf[0] = 'E';
    rx_buf[1] = 'R';
    rx_buf[2] = 'R';
    rx_buf[3] = '!';
    rx_buf[4] = 0;
    i = 3;
    led2 = 1;
    }
    }

/**

  • @brief Compares two buffers.

  • @param pBuffer1, pBuffer2: buffers to be compared.

  • @param BufferLength: buffer's length

  • @RetVal 0 : pBuffer1 identical to pBuffer2

  •     >0 : pBuffer1 differs from pBuffer2
    

    /
    static uint16_t Buffercmp(uint8_t
    pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength)
    {
    while (BufferLength--)
    {
    if ((*pBuffer1) != *pBuffer2)
    {
    return BufferLength;
    }
    pBuffer1++;
    pBuffer2++;
    }

    return 0;
    }

/-------------------- Main ----------------------/
int main() {
Serial test_connection(PA_9, PA_10);
int set_event = 0;
led2 = 0; led3 = 0; led4= 0;

/* Setup serial connection */
test_connection.baud(9600);

#if TEST_HWFLOWCONTROL
/* Use set_flow_control /
test_connection.set_flow_control((mbed::SerialBase::Flow)3, PA_12, PA_11);
#endif
/
Very Simple Main (tm) */
serialTXEventCb.attach(serialTxCb);
serialRXEventCb.attach(serialRxCb);

#ifdef TRANSMITTER_BOARD
while (button.read()!=RESET){
}
test_connection.write(aTxBuffer, TXBUFFERSIZE, serialTXEventCb, SERIAL_EVENT_TX_COMPLETE);

while (tx_complete==0){
  // wait there for the write completion. To be removed in case the application wants to work on something else
}
tx_complete = 0;

set_event = SERIAL_EVENT_RX_OVERFLOW | SERIAL_EVENT_RX_PARITY_ERROR | SERIAL_EVENT_RX_FRAMING_ERROR | SERIAL_EVENT_RX_OVERRUN_ERROR | SERIAL_EVENT_RX_COMPLETE;
test_connection.read(rx_buf, RXBUFFERSIZE, serialRxCb, set_event, SERIAL_RESERVED_CHAR_MATCH);

#endif
while (rx_complete==0){
// wait there for the write completion. To be removed in case the application wants to work on something else
}
rx_complete = 0;

/*## Compare the sent and received buffers ##############################*/
if(Buffercmp((uint8_t*)aTxBuffer,(uint8_t*)rx_buf,RXBUFFERSIZE))
{
  while (1){}
}

while(1) {
  led3=0; 
  wait(0.2);
  led3=1;
  wait(0.2);
}

}

obj->databits = UART_WORDLENGTH_8B;
obj->stopbits = UART_STOPBITS_1;
obj->parity = UART_PARITY_NONE;
_SERIAL_OBJ(baudrate) = 9600;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not start a macro with underscore followed by an uppercase letter (it's reserved in any scope , see standard C/C++).

This macro is needed now as not all F4 are up to date to enable this feature ? Because this should not be needed if serial object is same for all F4 , it should be the same?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I'll rename the macro and check your other comments below.
You're right, this is needed as long as this feature is not deployed on every F4.
Cheers

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 4, 2016

There're unit test for asynch, please have a look at : https://github.com/mbedmicro/mbed/tree/master/libraries/tests/utest . I would like to see result from serial one.

If you can align the coding style to the one which is already in the file (should follow https://developer.mbed.org/teams/SDK-Development/wiki/mbed-sdk-coding-style)

uint8_t serial_tx_active(serial_t *obj)
{
MBED_ASSERT(obj);
MBED_ASSERT(HAL_UART_STATE_BUSY_TX==0x12);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this assert for? Same is for BUSY_RX == 0x22 ?

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 4, 2016

This would be easier to integrate if we could split this PR to smaller pieces:

  • adding new target to the current code base
  • adding flow control
  • add serial asynch support

Shall we do that? Sorry for taking longer to review this, but it is quite large changeset which came in before holidays :-)

@adustm
Copy link
Member Author

adustm commented Jan 4, 2016

Hello, is it possible to handle several PRs at several gates of development in the same branch ? How is your suggestion of several PRs usually handled ?

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 5, 2016

@adustm You can do cherry pick to get only those commits adding the platform.. I'll give it a shot. It was just a suggestion for this integration to be smoother/faster.

Can you run those unit tests for this platform for serial? I shared above the links : #1470 (comment)

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 6, 2016

The target was added, please send PR with adding other 2 features. I'll close this one.

@0xc0170 0xc0170 closed this Jan 6, 2016
@adustm adustm deleted the dev_F4_asynch_serial branch February 29, 2016 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants