andysworkshop / stm32plus

The C++ library for the STM32 F0, F100, F103, F107 and F4 microcontrollers

Home Page:http://www.andybrown.me.uk

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

USART receive example on Nucleo-F042K6 not working as expected

dbaba opened this issue · comments

commented

Hello, I'm now trying to run usart_receive_sync example on Nucleo-F042K6 (with USB cable connecting to my laptop/MBP) but had no luck so far. As long I understood, the example is just an echo-back application. So with the app, when I send some string/data, it will be returned. However, nothing was returned.

Here is detail:

Unlike the original usart_receive_sync .cpp code, Nucleo-F042K6 uses UART2 with PA_2 and PA_3 for USB serial. So I modified the code at line 50 like this:

      Usart2<> usart(57600); // was Usart1 

After flashing the built binary, I entered some data from my laptop via terminal connecting to the USB port but nothing returned.

As long as I traced with gdb with OpenOCD, I found the loop at Usart::receive(), and USART_GetFlagStatus(_peripheralAddress,USART_FLAG_RXNE)==SET(Usart.h) was kept returning false even though I sent data.

Is there any limitation on running the example app with Nucleo-F042K6 or am I missing something?
Any suggestions are appreciated.

commented

It's my fault!
I assumed a wrong pin number regarding USB Serial RX, which is PA_15 rather than PA_3.

Providing a dedicated pin package struct to Usart2_Custom made the app work properly!

       struct Usart2NucleoF042K6PinPackage {
         enum {
           Port_TX=GPIOA_BASE,
           Port_RX=GPIOA_BASE,
           Port_RTS=GPIOA_BASE,
           Port_CTS=GPIOA_BASE,
           Port_CK=GPIOA_BASE,

           Pin_TX=GPIO_Pin_2, // not PA_14
           Pin_RX=GPIO_Pin_15,
           Pin_RTS=GPIO_Pin_1,
           Pin_CTS=GPIO_Pin_0,
           Pin_CK=GPIO_Pin_4
         };
       };

      Usart2_Custom<Usart2NucleoF042K6PinPackage> usart(115200);