2024-09-14 12:37 PM - last edited on 2024-09-20 09:18 AM by SofLit
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
/*------------------------------------------------*/
Solved! Go to Solution.
2024-09-25 08:09 AM
Hi,
I have solved the problem. It occurred because of an overrun error.
Thanks
2024-09-15 11:14 PM
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.
2024-09-17 08:28 AM
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.
2024-09-17 08:46 AM
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.
2024-09-17 09:35 AM
Hi @PatrickF ,
Using STM32CubeIDE, the code generated by the tool works fine. However, when I implement my own code, it works correctly up to the pin configuration (MODER register and GPIO_AFR), but the BRR and control registers remain at 0x00. I have confirmed this by debugging the code. I have compared my implementation with the code generated by STM32CubeIDE, but I still cannot identify the issue. help me to understand what might be missing or where I might be going wrong?
Regards
2024-09-17 11:33 PM
Hi,
Maybe obvious, but did you enable the USART3 bus clock in RCC, as you do with GPIOB ? This is required to access. USART3 registers.
This is bit 15 of RCC_MC_APB1ENSETR
Regards
2024-09-20 09:14 AM
HI,
Thanks for the help. By config. RCC_MC_APB1ENSETR now its working perfectly.
I want to read the USART Interrupt and Status Register[alternate] (USART_ISR) to check the Transmission Complete (TC) bit, which is located at bit 6. What should I write in place of [alternate]?
like for USART_ISR - (!(USART3->ISR & (1<<6)))
then for [alternate] (USART_ISR) - ??
Regards.
2024-09-24 08:39 AM
Hi @B_D_R
you should read carefully the reference manual.
There is two description of UART_ISR, one with "FIFO mode enabled", one with "FIFO mode disabled" (this is the [alternate] keyword to distinguish them in the spec). Both are located at same address offset, bitfields differs depending on FIFOEN bit in USART_CR1.
Regards.
2024-09-24 10:38 AM
hi @PatrickF
Thank you for your help! The problem has been resolved. I was trying to receive data using polling, but I was only getting data the first time. After that, I didn't receive any more data, even though the data is being transmitted continuously every second.
code:
mainfunction -
while (1)
{
UART3getChar();
HAL_Delay(500);
}
receiving function -
void UART3getChar (void)
{
uint8_t temp, r[20];
for(i=0; i<14; i++)
{
while(!((USART3->ISR)&(1<<5)));
r[i] = (uint8_t) USART3->RDR;
}
}
2024-09-25 08:09 AM
Hi,
I have solved the problem. It occurred because of an overrun error.
Thanks