Olimex Support Forum

ARM => ST => Topic started by: lim on October 29, 2020, 02:54:29 am

Title: Olimex STM32-E407 and ARM-USB-OCD-H
Post by: lim on October 29, 2020, 02:54:29 am
I tried to setup the debugging environment using the printf through a UART3 provided by ARM-USB-OCD-H. I presume UART-3 as it is being stated in section 6.11 (BOOT pads) in the user manual.

Somehow, I am puzzled how or what setting the UART3 in the Olimex STM32 board should be, and what coding are needed in my program.

Appreciate your comment, please?
Title: Re: Olimex STM32-E407 and ARM-USB-OCD-H
Post by: LubOlimex on October 29, 2020, 08:54:54 am
I don't know what printf has to do with debugging.

ARM-USB-OCD-H has two interfaces - one is the JTAG interfaces suitable for programming and debugging targets like STM32-E407; the other is RS232-USB convertor interface that can NOT be used for debugging and programming, it is an extra for people that need RS232 interface but their PC doesn't have RS232 (like most modern personal computers). The RS232-USB interface can't not be used for JTAG debugging. It has nothing to do with debugging, it is a side extra.
Title: Re: Olimex STM32-E407 and ARM-USB-OCD-H
Post by: lim on October 29, 2020, 12:37:47 pm
My bad, the wording "debugging" has caused confusion. I use the printf(), extra information for judging the right or wrong my my coding or logic. Can you please share how to set that up, please?
Title: Re: Olimex STM32-E407 and ARM-USB-OCD-H
Post by: lim on October 30, 2020, 11:29:09 am
I have segment of the code here. But not getting anything from the DB9 COM Port.

Tx(ARM-USB-OCD-H)<->Tx(Pin4) on Olimex STM32-E407
Rx(ARM-USB-OCD-H)<->Tx(Pin3) on Olimex STM32-E407
GRD(ARM-USB-OCD-H)<->GRD(Pin2)on Olimex STM32-E407

-----------------
#ifdef __GNUC__
  /* With GCC, small printf (option LD Linker->Libraries->Small printf
     set to 'Yes') calls __io_putchar() */
  #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
  #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */

-----------------
UART3 setting
static void MX_USART3_UART_Init(void)
{

  /* USER CODE BEGIN USART3_Init 0 */

  /* USER CODE END USART3_Init 0 */

  /* USER CODE BEGIN USART3_Init 1 */

  /* USER CODE END USART3_Init 1 */
  huart3.Instance = USART3;
  huart3.Init.BaudRate = 115200;
  huart3.Init.WordLength = UART_WORDLENGTH_8B;
  huart3.Init.StopBits = UART_STOPBITS_1;
  huart3.Init.Parity = UART_PARITY_NONE;
  huart3.Init.Mode = UART_MODE_TX_RX;
  huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart3.Init.OverSampling = UART_OVERSAMPLING_16;
  if (HAL_UART_Init(&huart3) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN USART3_Init 2 */
  /* Output a message on Hyperterminal using printf function */
    printf("\n\r UART3 Printf Example: retarget the C library printf function to the UART\n\r");
  /* USER CODE END USART3_Init 2 */

}


/**
  * @brief  Retargets the C library printf function to the USART.
  * @param  None
  * @retval None
  */
PUTCHAR_PROTOTYPE
{
  /* Place your implementation of fputc here */
  /* e.g. write a character to the EVAL_COM1 and Loop until the end of transmission */
  HAL_UART_Transmit(&huart3, (uint8_t *)&ch, 1, 0xFFFF);

  return ch;
}

Any comments?
Title: Re: Olimex STM32-E407 and ARM-USB-OCD-H
Post by: LubOlimex on October 30, 2020, 11:33:38 am
The hardware connections you established are dangerous. The voltage levels are not compatible. The ARM-USB-OCD-H has RS232 levels. You need level shifter at STM32-E407. Refer to STM32-P407's design and schematic that has two RS232 ports:

https://www.olimex.com/Products/ARM/ST/STM32-P407/
Title: Re: Olimex STM32-E407 and ARM-USB-OCD-H
Post by: lim on October 30, 2020, 12:51:41 pm
Have purchased the level shifters. Any comments on the code, please?
Title: Re: Olimex STM32-E407 and ARM-USB-OCD-H
Post by: LubOlimex on October 30, 2020, 01:33:28 pm
Tx(Pin4) on Olimex STM32-E407
Tx(Pin3) on Olimex STM32-E407

When you wrote that, did you mean Pin #3 and Pin #4 from the UEXT? These are PC6/USART6_TX and PC7/USART6_RX. In your code you seem to use USART3, while it should be USART6...

Refer to the schematic to identify pins and refer to the chip's datasheet to connect the pin with the available interface:

https://github.com/OLIMEX/STM32F4/blob/master/HARDWARE/STM32-E407/STM32-E407_Rev_F.pdf

https://www.st.com/resource/en/datasheet/dm00037051.pdf

This is not something trivial unfortunately, and we don't have the practice to debug customer code.
Title: Re: Olimex STM32-E407 and ARM-USB-OCD-H
Post by: lim on October 30, 2020, 03:17:14 pm
hi, Sorry it was not my intention for you to debug the code, but have a glance if it makes sense for using USART3. The pins are from HN1X4-Boot connector, where connects to USART3. Anyway, appreciate your comments so far. Cheers!
Title: Re: Olimex STM32-E407 and ARM-USB-OCD-H
Post by: lim on October 30, 2020, 03:29:48 pm
Correction, the correct pins are #1=TX, #2=RX #3=GRD, #4=3.3V. Hope this clarifies the confusion.
Title: Re: Olimex STM32-E407 and ARM-USB-OCD-H
Post by: LubOlimex on October 30, 2020, 04:24:47 pm
Do you really need to connect the power?

Maybe test another USART. Also it might be good idea to test with another USB-serial cable instead of the serial of ARM-USB-OCD-H(something like https://www.olimex.com/Products/Components/Cables/USB-Serial-Cable/USB-SERIAL-F/ or similar 3.3V). These tests would limit the possibilities.

I've also found these related USART attempts with E407 from the past:

https://www.hexnut.net/2015/07/rx-tx-of-usart-is-easy-right.html

https://www.olimex.com/forum/index.php?topic=1356.0

https://www.olimex.com/forum/index.php?topic=45.0
Title: Re: Olimex STM32-E407 and ARM-USB-OCD-H
Post by: lim on October 31, 2020, 05:05:20 am
I have tested it by shorting the RX and TX of the ARM-USB-OCD-H, and sending a text messages to the /dev/ttyUSB0, the Minicom was showing up the text messages. Hence, the ARM-USB-OCD-H  is well. However, checked with Scope, and I did't get any signals from the Olimex board be it Uart3 or Uart6. I was wondering if what is wrong with the code.

Tried by replaced with the USB-serial cable. Passed loopback test, but it behaved the same when running the code/
Title: Re: Olimex STM32-E407 and ARM-USB-OCD-H
Post by: lim on November 01, 2020, 12:57:17 pm
I have got it resolved. Followed the instruction here, https://shawnhymel.com/1873/how-to-use-printf-on-stm32/.