Skip to main content
Visitor II
December 19, 2024
Question

Hints for detecting USART-input on tty - STM32F411CE* - weact* - Linux

  • December 19, 2024
  • 6 replies
  • 1181 views

Given:

 

 

void USART2_Init (void)
{
	RCC->APB1ENR |= (1<<17);
	RCC->AHB1ENR |= (1<<0);
	GPIOA-> AFR[0] = (7<<8);
	GPIOA->MODER |= (1<<5);
	
	USART2->BRR = 0x0683; // 9600 at 16MHz
	USART2->CR1 |= (1<<3);
	USART2->CR1 |= (1<<13);

}

void USART2_Write(int ch)
{
	while(!(USART2-> SR & (1<<7)));
	USART2->DR = (ch & 0xFF);	
	
}

 

 

 

No input data on /dev/tty* -

Are there hints/commands for generating input/later output data on tty* ?

 

Greetings

TIMBO

 

    This topic has been closed for replies.

    6 replies

    Graduate II
    December 19, 2024

    The number of people who are interested in debugging vague issues with uncommented register level code is very low.

    Read the manuals, use a debugger, understand and explain the issue more carefully. Perhaps put a scope on the signals to confirm which end the problem is, your STM32 code, or your LINUX code/board.

    void USART2_Init (void)
    {
    	RCC->AHB1ENR |= (1<<0); // GPIOAEN (do several cycles prior to usage)
    	RCC->APB1ENR |= (1<<17); // USART2EN
    
    	GPIOA->AFR[0] = (7<<8); // PA2:AF7
    	GPIOA->MODER |= (2<<4); // PA2:AF MODE
    	
    	USART2->BRR = 0x0683; // 9600 at 16MHz (16,000,000 / 9,600) OVER16
    	USART2->CR1 |= (1<<3); // TE - Transmit Enable
    	USART2->CR1 |= (1<<13); // UE - UART Enable
    }
    
    void USART2_Write(int ch)
    {
    	while(!(USART2-> SR & (1<<7)));
    	USART2->DR = (ch & 0xFF);		
    }

    Doesn't look unreasonable, but not highly invested.

    What are you sending? When are you sending it? What are you observing on the wire?

    Remember this is an adult technical venue, please try to present your problem with clarity and indication of what troubleshooting you've done, with observations.

    timbo2023Author
    Visitor II
    December 19, 2024

    In addition a question, how can I record the signal under my console in Linux?

    No virtual driver - it could be set later.

     

    It actually must possible to record data with the

    cat /dev/tty  command ... something like this?!?

     

    I just make my experiments with minicom.

    I also tried /dev/bus/usb/**

     

    Any hints for this purpose?

    Graduate II
    December 19, 2024

    I'd imagine it could use cat and that you could open() and read() the /dev/tty directly in some C app you build, but this isn't a Linux forum, and no one here knows what board or distro of Linux you're actually working with or attaching this WeAct F411 board too, and to what end.

    Do you work with/around people of a technical mind with whom you can discuss this stuff with?

    Graduate II
    December 21, 2024

    You have to use usb to ttl converter and find it is connected to which /dev/ttyUSB. As an initial test connect tx and rx. In minicom chek if you get back your characters. It's lot easier in windows . 

    timbo2023Author
    Visitor II
    December 23, 2024

    Bought from waveshare - I will try it again. Any hints for it?

    But the function of the usb-c is not my ...

     

    Have a nice day.

    TIMBO

    Graduate II
    December 23, 2024

    https://stm32-base.org/boards/STM32F411CEU6-WeAct-Black-Pill-V2.0.html

    The board isn't going to inherently present as a USB CDC/VCP type device unless you've put some Arduino like loader on it, or compiled a USB CDC Device Example.

    Inserted with BOOT0 HIGH it might present as a "STM32 BOOT" type device which is a DFU Device, and can be downloaded to via STM32 Cube Programmer.

    For beginners I might suggest starting with a NUCLEO board as these include a built in debugger with a VCP and MSC device, allowing mapping of a UART on the Target and the drag-n-drop of a compiled binary directly.

    Perhaps go find some specific example for the WeAct board that you can download with an ST-LINK 

    timbo2023Author
    Visitor II
    December 27, 2024

    Thanks to "TECHN" - After a small hobby invest to "waveshare", I am able to receive and transmit data. I just checked it.

    I power the weact-board with 5 V, if there is an interest.

     

    But back to the program-code, could you explain me in a shortest way the function and the use of the AFR(Low and High-)-register?@ "TESLA"

    In my case is TX - B6 and RX - B7.

     

    Which configuration I should change in look to the short code above from you?

    timbo2023Author
    Visitor II
    December 27, 2024
    void USART2_Init (void)
    {
    	RCC->APB1ENR |= (1<<17);
    	RCC->AHB1ENR |= (1<<1);
    	
    	GPIOB-> AFR[0] |= (7<<12);
    	GPIOB-> AFR[0] |= (7<<8);
    	
    	GPIOB->MODER |= (1<<15); // PB7 as a Rx
    	GPIOB->MODER |= (1<<13); // PB6 a a Tx
    	
    	USART2->BRR = 0x0683; // 9600 at 16MHz
    	USART2->CR1 |= (1<<2); // Rx Enable
    	USART2->CR1 |= (1<<3); // Tx Enable
    	USART2->CR1 |= (1<<13); // USART Enable
    
    }

     

     

     

    Just an example for my intention to read and write over PB6 and PB7 -

    I am unsure regarding the alternate functions and the control register.

     

     

    timbo2023Author
    Visitor II
    March 21, 2025

    -----------------------------------------------------------------------

    Now the decision went to an USART1:

    Could you check Alternate Function for PA9?

    void USART1_Init (void)
    {
    	RCC->APB2ENR |= (1<<4);
    	RCC->AHB1ENR |= (1<<0);
    	// GPIOA-> AFR[0] = (7<<8); // ? Angleichen an PA9
    	GPIOA->AFR[0]	|=	(1U<<8);
    	GPIOA->AFR[0]	|=	(1U<<9);
    	GPIOA->AFR[0]	|=	(1U<<10);
    	GPIOA->AFR[0]	&= 	~(1U<<11);
    	
    	GPIOA->MODER |= (1<<19);
    	
    	USART1->BRR = 0x0683; // 9600 at 16MHz
    	USART1->CR1 |= (1<<3);
    	USART1->CR1 |= (1<<13);
    
    }
    
    void USART1_Write(int ch)
    {
    	while(!(USART1-> SR & (1<<7)));
    	USART1->DR = (ch & 0xFF);
    	
    }