Skip to main content
Visitor II
September 14, 2024
Solved

Configure USART3 at STM32MP157D-DK1

  • September 14, 2024
  • 1 reply
  • 2281 views

Hello Friends,

I am trying to configure USART3 as UART full duplex on the STM32MP157 evaluation board. The pin configuration for USART seems to be working correctly, but I’m having trouble with the USART3 Control Register1 & BRR . Can anyone help me identify what might be wrong with the code?

Code:

/*---------------------PIN CONFIGURATION-----------------*/
RCC->MC_AHB4ENSETR |= (1<<1); //ENABLE GPIOB PERIP. CLOCK ENABLE

/*------------CHANGE MODER TO ALTERNATE FUNCTION MODE (10)--------------*/
//PB 10 -- TX_USART3
//PB 12 -- RX_USART3
GPIOB->MODER |= (1<<21); //pb10
GPIOB->MODER &= ~(1<<20);
GPIOB->MODER |= (1<<25); //pb12
GPIOB->MODER &= ~(1<<24);

/*-----------SET GPIO ALTERNATE FUNCTION REGISTER-----------------------*/
//AF7-----USART AVAILAVBLE AT AF7 IN DIAGRAM (AF7 = 0111 =7 , AF8=1000=8 - GPIO ALTERNATE REGISTER)

//ARF - [0] (LOW_REGISTER), [1] (HIGH_REGISTER)
GPIOB->AFR[0] = 0x00; //ARF LOW = 0 HAS 1 TO 7, ARF[1] 10, 12PIN

GPIOB->AFR[1] |= (7<<8); //PB10 - START 11 10 9 8 ----- 0111

GPIOB->AFR[1] |= (8<<16); //PB12 - START 19 18 17 16 ----- 1000

/*---------------------------------------------------------*/

/*-----------------UART CONFIGURATION----------------------*/

/*-----------------UART CONTTROL REGISTER 1----------------*/

//SET UE,M,TE,RE
USART3->CR1 = 0x00; //CLAER ALL

// USART3->CR1 &= ~(1<<0); //FOR 8BIT DATA M0,M1 = 00

// USART3->CR1 &= ~(1<<0);



USART3->CR1 |= (1<<2); //RE

USART3->CR1 |= (1<<3); //TE

/*----------------SET BAUD RATE------------------------*/

USART3->BRR = (38<<4); //SET BAUDRATE TO 115200

/*-----------------------------------------------------*/

USART3->CR1 |= (1<<0); //UE

/*------------------------------------------------*/
    This topic has been closed for replies.
    Best answer by B_D_R

    Hi,

    I have solved the problem. It occurred because of an overrun error.

    Thanks

    1 reply

    Technical Moderator
    September 16, 2024

    Hi @B_D_R 

    If you are using Cortex-M4 in engineering boot, did you enabled the USART kernel clocks in RCC ?

    Is Linux running on Cortex-A7 side ? did you assigne USART for M4 side ?

    For Cortex-M4 SW, I encourage you to start from the one generated with CubeMx.

    Regards.

    B_D_RAuthor
    Visitor II
    September 17, 2024

    Hi @PatrickF ,

    I was trying it on a Cortex M4 in engineering mode. I have also enabled the USART kernel clock in the RCC. Is it necessary to assign USART for the M4 in engineering mode? If so, how do I do it?

    Regards.

    Technical Moderator
    September 17, 2024

    Hi @B_D_R 

    obviously as there is no Linux running on engineering mode, there is no assignment to do, M4 has almost full access to every resources.

    Are you able to debug your code ? It should probably help you to find where issue is and focus to a solution.

    Are you able to generate a basic code with CubeMx with USART3 ? Although it will be using HAL, it could allows you to compare if you missed something.

    Btw, looking at your code, although using all manual direct register bit-banding and ultra low level  peripheral management is very good for your knowledge, it is hardly readable and much more prone to error than using existing libraries you could find in CubeMP1.

    Maybe look at your peripheral 'C' struct definitions as registers must always be access at 32-bits address boundaries.

    Regards.