Skip to main content
LMI2
Senior III
October 31, 2018
Question

How to enable USART6 in STM32F746 Discovery

  • October 31, 2018
  • 2 replies
  • 934 views

I have a heavily modified example running in my 746 Discovey board. I want to have UART6 running on pins PC6 and PC7. Mainly because those pins are easy to reach. Both pins are at 3.3V now. That is the problem.

It would be nice to know for example in what files are PC6 and PC7 defined as UART pins. But that is not so important.

I call  MX_USART6_UART_Init(); but something seems be missing. Clock perhaps.

This is SystemClock_Config. What else?

static void SystemClock_Config(void)
{
 RCC_ClkInitTypeDef RCC_ClkInitStruct;
 RCC_OscInitTypeDef RCC_OscInitStruct;
 RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
 HAL_StatusTypeDef ret = HAL_OK;
 
 /* Enable HSE Oscillator and activate PLL with HSE as source */
 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
 RCC_OscInitStruct.HSEState = RCC_HSE_ON;
	 RCC_OscInitStruct.LSIState = RCC_LSI_ON;
 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
	
 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
 RCC_OscInitStruct.PLL.PLLM = 25;
 RCC_OscInitStruct.PLL.PLLN = 400;
 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
 RCC_OscInitStruct.PLL.PLLQ = 8;
 
 ret = HAL_RCC_OscConfig(&RCC_OscInitStruct);
 if(ret != HAL_OK)
 {
 while(1) { ; }
 }
 
 /* Activate the OverDrive to reach the 200 MHz Frequency */ 
 ret = HAL_PWREx_EnableOverDrive();
 if(ret != HAL_OK)
 {
 while(1) { ; }
 }
 
 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */
 RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; 
 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; 
 
 ret = HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_6);
 if(ret != HAL_OK)
 {
 while(1) { ; }
 } 
 }

    This topic has been closed for replies.

    2 replies

    Tesla DeLorean
    Guru
    October 31, 2018

    Doesn't the HAL/CubeMX model put this stuff in the MSP file?

    It is this obfuscation that annoys me a lot. Main code looks simple, but you can't find anything.

    Try Grep/Find-in-Files for "USART6" should pin it down pretty quickly...

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    LMI2
    LMI2Author
    Senior III
    October 31, 2018

    I think I got it working. It is getting late, so I'll fix crossed TX and RX tomorrow.

    I found several Usart6 instances. But I could not understand them. Obscure is a good word for those. I couldn't find MSP file. I remember seeing them in other projects.

    ST documentation is useless or I could not find a suitable pdf. I found a 1900 + pages pdf but it had no code or usefull info. I had to search internet a bit. STM32F746 is not a common chip but with the settings below, there is now life in the USART TX pin.

     HAL_Init();
     __USART6_CLK_ENABLE();
     __GPIOC_CLK_ENABLE();
     
     GPIO_InitTypeDef GPIO_InitStructure;
     
     GPIO_InitStructure.Pin = GPIO_PIN_5;
     GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
     GPIO_InitStructure.Alternate = GPIO_AF8_USART6;
     GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
     GPIO_InitStructure.Pull = GPIO_NOPULL;
     HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
     
     GPIO_InitStructure.Pin = GPIO_PIN_6;
    		GPIO_InitStructure.Mode =GPIO_MODE_AF_PP;
     GPIO_InitStructure.Alternate = GPIO_AF8_USART6;
     HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);