cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F7 bootloader usart comm

hbarta2
Associate III
Posted on January 31, 2017 at 15:56

Hi All,

I'm working with a board with two STM32F7 processors and trying to connector to the built in bootloader on one from the other via USART. The TX/RX lines are connected to the target on USART3 and on the master on USART4. I'm using the following code to configure the  USART4 on the master (8E1, no handshaking.)

/* UART4 init function */

static void MX_UART4_Init(void)

{

  huart4.Instance = UART4;

  huart4.Init.BaudRate = 19200;

  huart4.Init.WordLength = UART_WORDLENGTH_8B;

  huart4.Init.StopBits = UART_STOPBITS_1;

  huart4.Init.Parity = UART_PARITY_EVEN;

  huart4.Init.Mode = UART_MODE_TX_RX;

  huart4.Init.HwFlowCtl = UART_HWCONTROL_NONE;

  huart4.Init.OverSampling = UART_OVERSAMPLING_16;

  huart4.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;

  huart4.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;

  if (HAL_UART_Init(&huart4) != HAL_OK)

  {

    Error_Handler();

  }

}

The code to establish communication between boards is:

// First set the BOOTA pin high and then drive the RST pin

SET_PROC_A_BOOT;

SET_PROC_A_RESET;

vTaskDelay(pdMS_TO_TICKS(10)); // hold for 10 ms

CLR_PROC_A_RESET;

vTaskDelay(1); // hold for shortest FreeRTOS delay

CLR_PROC_A_BOOT;

// Proc A should be in built in bootloader mode.

// establish contact by sending 0x7F until the device responds.

uartBuf[0] = 0x7F;

do {

  loopCount++;

  if(loopCount >= BUFFER_LEN)

    Error_Handler();

  st = HAL_UART_Transmit(&PROC_A_UART, uartBuf, 1, 1);

  if(st == HAL_TIMEOUT)

    continue;

  if(st != HAL_OK)

    Error_Handler();

  vTaskDelay(pdMS_TO_TICKS(1)); // delay 1 ms

  st = HAL_UART_Receive(&PROC_A_UART, uartBuf+loopCount, 1, 1);

  if(!(st == HAL_OK || st == HAL_TIMEOUT))

    Error_Handler();

  vTaskDelay(pdMS_TO_TICKS(1)); // delay 1 ms

  if(uartBuf[loopCount] != 0)

    __NOP();

// } while(uartBuf[loopCount] != 0x79);

  } while(uartBuf[loopCount] != 0x7F);

// Get command

uartBuf[0] = 0x00;

uartBuf[1] = 0xFF; // checksum

st = HAL_UART_Transmit(&PROC_A_UART, uartBuf, 2, 1);

if(st != HAL_OK)

   Error_Handler();

Depending on baud rates I seem to be able to read something back from time to time but I have yet to see an ACK (0x79). With the present setup I do see 0x73 on the 17th read and 0xF7 on the 18th read. If I exit the loop when a 0xF7 is received and try to send the Get command, I get a HAL timeout.

I have add some delay between send and receive to allow the target time to configure the UART once the baud rate is determined and also time to send out the reply. Two questions I have include:

  1. What should I try differently to get proper baud rate detection? 
  2. How can I get a HAL_TIMEOUT return status when a UART is configured with no handshaking?

Apologies if the code is not correctly formatted above. I can't seem to get the 'Source Code' button to work as expected and I can't find a way to preview the post.

Thanks! 

1 ACCEPTED SOLUTION

Accepted Solutions
Posted on January 31, 2017 at 16:44

The source code button is like 'show codes', you want the Syntax Highlight which is off via the '...' and More buttons

UART_WORDLENGTH_8B  this needs to be 9B to account for the bit you are using for parity

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..

View solution in original post

2 REPLIES 2
Posted on January 31, 2017 at 16:44

The source code button is like 'show codes', you want the Syntax Highlight which is off via the '...' and More buttons

UART_WORDLENGTH_8B  this needs to be 9B to account for the bit you are using for parity

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
hbarta2
Associate III
Posted on January 31, 2017 at 17:04

That's it - Thanks! (And Thanks!)