cancel
Showing results for 
Search instead for 
Did you mean: 

Why does the debugger not respond after UE bit is set for UART4?

JCorl.1
Senior

Hello everyone!

My setup uses a STM32407VG. I have been using for some time now and have gotten used to how to read the datasheet and use some of features. Today I am trying to get UART4 transmitting some data.

Here is how I went about getting it all setup:

  1. UART4 TX can be used on PC10. Therefore we must enable the AHB1 to turn on GPIOC.
  2. The UART4 module itself is one APB1 so that must be enabled as well.
  3. Via MODER, OTYPE, OSPEEDR PUPDR, I also make sure its push pull, disabled pullups and output speed is medium. Pretty sure I don’t need to do this but I did it anyway!
  4. Via AFR[1], I set the MODER register for GPIOC to be as alternate function mode.
  5. My system clock is running at 168MHz (verified from previous projects), and my APB1 PCLK1 is 42MHz. Via the BRR, I set the baudrate and used this formula: BRR = [pclk + (baud/2)] / baud. I set CR1 to 0x04 to set the TE bit and other parameters.
  6. Here is where I get some problems, I set the UE bit in CR1.

I did step through the debugger (via STLINK) and it appears I am setting all of the correct bits. But when I land on that UE bit, I get the error (in the console) Target is not responding, retrying… until it times out. Below is a code snippet.

/* UART Functions */
 
void UART4_Config()
 
{
 
	// Enable GPIO C
 
	RCC->AHB1ENR |= RCC_AHB1ENR_GPIOCEN;
 
 
	// Enable the UART (PC10=TX PC11=RX)
 
	RCC->APB1ENR |= DKO_UART4_ENABLE;
 
 
	// UART4 TX PIN
 
	GPIOC->MODER &= ~(GPIO_MODER_MODE10); // Clear pin mode field
 
	GPIOC->MODER |= GPIO_MODER_MODER10_1; // Set pin mode field as alternate
 
	GPIOC->OTYPER &= ~(GPIO_OTYPER_OT10); // Clear output type field (push-pull by default)
 
	GPIOC->OSPEEDR &= ~(GPIO_OTYPER_OT10); // Clear output speed field (low by default)
 
	GPIOC->OSPEEDR |= GPIO_OSPEEDR_OSPEED10_0; // Set to medium speed
 
	GPIOC->PUPDR &= ~(GPIO_PUPDR_PUPD10); // Clear pullup/ pulldown mode field (none as default)
 
	GPIOC->AFR[1] &= ~(1U << 8); // Set alternate function to be AF8, bit 8
 
	GPIOC->AFR[1] &= ~(1U << 9); // Set alternate function to be AF8, bit 9
 
	GPIOC->AFR[1] &= ~(1U << 10); // Set alternate function to be AF8, bit 10
 
	GPIOC->AFR[1] |= (1U << 11); // Set alternate function to be AF8, bit 11
 
 
	// UART4 SPECIFIC CONFIG
 
	UART4->BRR = 2188; // Set baudrate to be 19200; formula is BRR = [pclk + (baud/2)] / baud
 
	UART4->CR1 = (1U << 3); // Set the TE bit (transmitter enable bit)
 
	UART4->CR1 |= (1U << 13); // Set the UE bit (uart enable bit)
 
}

I never used a UART other than on things like BASIC STAMP, PICAXE, and ARDUINO. It is a little more setup with bare metal STM32F407 but it looked pretty doable. Any hints would be greatly appreciated! Thanks for your time!

10 REPLIES 10
JCorl.1
Senior

As an update, I got the RX portion working as well. Though I do have another question about UART in general but I will create a new thread for this.