cancel
Showing results for 
Search instead for 
Did you mean: 

SO8N STM32G031C6 USART not working.

fancyrat
Associate III

I'm trying to setup an USART for a very small MCU of the STM32G0 family, the MCU it's theoretically being programmed, but the USART is not responding, I configured the MCU just like I did in other projects (of bigger MCUs), I'm not able to find what I'm doing wrong in this case.

This is what I can see from the USART (theoretically in this image I'm sending "0xFF" all the time, but it does the same whatever I put in the buffer).

0693W00000YAa9tQAD.pngCodewise I'm enabling the USART DMA with LL_USART_EnableDMAReq_TX(USART1), then configuring with LL_DMA_ConfigAddresses.

Some checks with LL_DMA_IsEnabledChannel, and finally sending stuff with both LL_DMA_SetDataLength & LL_DMA_EnableChannel once the buffer has something on it.

Also tried to clear TC1 flag & disable channel every communication, checking it with LL_DMA_IsActiveFlag_TC1.

The USART is configured as Half-duplex (as it need to be) & baudrate, word length, etc...are correct: 0693W00000YAaAhQAL.png

18 REPLIES 18
KnarfB
Principal III

And if you don't use DMA but simply write to TXD?

Is is a pin issue or a DMA prog issue?

hth

KnarfB

Hi,

I've always worked with DMA so I'm not confident in the code I've just wrote, but it seems that the same is happening.

I write this very quickly anyway, so I'll keep investigating in this direction. This is the code I've just written that doesn't use DMA.

void comms_init(void)
{
    // USART clock
    RCC->APBENR2 |= RCC_APBENR2_USART1EN;
 
    // USART baud rate
    USART1->BRR = (uint16_t)(SystemCoreClock / 115200);
 
    // USART data  (8 data bits, no parity, 1 stop bit)
    USART1->CR1 = USART_CR1_TE | USART_CR1_RE | USART_CR1_UE;
 
    // USART peripheral
    USART1->CR1 |= USART_CR1_UE;
}
 
void USART_SendData(uint8_t data)
{
    // Wait for empty transmit data register 
    while (!(USART1->ISR & USART_ISR_TXFE))
        ;
 
    // Write data to the TDR
    USART1->TDR = data;
 
    // Wait for the transmission
    while (!(USART1->ISR & USART_ISR_TC))
        ;
}
 
void comms_task(void)
{
 
    while (1)
    {
        USART_SendData('H');
        USART_SendData('e');
        USART_SendData('l');
        USART_SendData('l');
        USART_SendData('o');
        USART_SendData('\r');
        USART_SendData('\n');
    }
}

fancyrat
Associate III

EDIT: If I remove the watchdog the "spikes" that go to 0 disapear.

KnarfB
Principal III

Your later code works* if you replace the flag with:

while (!(USART1->ISR & USART_ISR_TXE_TXFNF))

*) have added more init code for the pins, namely the auto-generated MX_USART1_UART_Init() for my STM32G031 Disco..Note that USART1_TX pin is same as BOOT0 and SWCLK, which might be confusing...

hth

KnarfB

Viktor POHORELY
ST Employee

Did you tried just simple GPIO toggling, to see if the issue comes from pin or IP ?

There are several pins in paralel on those small packages, thus in case you have other one configured as output it may not work correctly.

fancyrat
Associate III

Thank you all,

I built the project from scratch and I manage to sent data both with the DMA & HAL, now the problem I'm having is that the data I'm receiving it's not exactly correct, I'm receiving incorrect characters, I'll try to check if with an oscilloscope, but at a simple glance, everything looks good.

Also I would try again with my old code, as @KnarfB​ confirms that it worked with a very small change.

Edit: Well I just tried with USART_SendData code and I'm still receiving weird stuff.

fancyrat
Associate III

Just as a reference, this is what I've got now, it should be saying "HOLA" using the UART with an DMA, I'm receiving other stuff mostly random symbols, I can't seem to find the relation to it:

0693W00000YAhL3QAL.png0693W00000YAgtoQAD.png

fancyrat
Associate III

Now I've tried to write "*\n* just to have some other signal to compare like the one in this link: https://hackaday.com/2016/06/22/what-could-go-wrong-asynchronous-serial-edition/

It seems that in my case the message keeps repeating multiple times. But the bits are correct:

0693W00000YAhNYQA1.png0693W00000YAhNEQA1.png

Viktor POHORELY
ST Employee

Do you have baud rate set correctly?