2011-02-23 09:01 AM
I have just got one of these boards, but as a noob, I am really struggling to get the USART working. I want to display information on the computer. I understand that the ST_LINK cannot do UART over the built in USB cable (ITM Debug). Is this correct?
So.. I have been looking at pins PA9 and PA10, but cannot see anything coming out. I have the following code. Could someone please take a look and see if they can see my problem?? I have spent hours on this! Thanks all! code: &sharpinclude ''stm32F10x.h'' &sharpinclude ''STM32vldiscovery.h'' &sharpinclude ''stm32f10x_usart.h'' &sharpinclude ''stm32f10x_rcc.h'' &sharpinclude <stdio.h> &sharpdefine LSE_FAIL_FLAG 0x80 &sharpdefine LSE_PASS_FLAG 0x100void Delay(uint32_t nTime);
int main(void)
{ initAll(); while(1) { } }void initGPIO (void)
{ /* Enable GPIOx Clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Initialise LEDs LD3&LD4, both off */ STM32vldiscovery_LEDInit(LED3); STM32vldiscovery_LEDInit(LED4); STM32vldiscovery_LEDOff(LED3); STM32vldiscovery_LEDOff(LED4); /* Initialise USER Button */ STM32vldiscovery_PBInit(BUTTON_USER, BUTTON_MODE_EXTI); }void initSysTick (void)
{ /* Setup SysTick Timer for 1 msec interrupts */ if (SysTick_Config(SystemCoreClock / 1000)) { /* Capture error */ while (1); } }void initLSE (void)
{ /* Enable access to the backup register => LSE can be enabled */ PWR_BackupAccessCmd(ENABLE); /* Enable LSE (Low Speed External Oscillation) */ RCC_LSEConfig(RCC_LSE_ON); /* Check the LSE Status */ while(1) { if(LSE_Delay < LSE_FAIL_FLAG) { /* check whether LSE is ready, with 4 seconds timeout */ Delay (500); LSE_Delay += 0x10; if(RCC_GetFlagStatus(RCC_FLAG_LSERDY) != RESET) { /* Set flag: LSE PASS */ LSE_Delay |= LSE_PASS_FLAG; /* Turn Off Led4 */ STM32vldiscovery_LEDOff(LED4); /* Disable LSE */ RCC_LSEConfig(RCC_LSE_OFF); break; } } else /*if(LSE_Delay >= LSE_FAIL_FLAG)*/ /* LSE_FAIL_FLAG = 0x80 */ { if(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) { /* Set flag: LSE FAIL */ LSE_Delay |= LSE_FAIL_FLAG; /* Turn On Led4 */ STM32vldiscovery_LEDOn(LED4); } /* Disable LSE */ RCC_LSEConfig(RCC_LSE_OFF); break; } } } void initUART (void) { GPIO_InitTypeDef GPIO_InitStructureTx; GPIO_InitTypeDef GPIO_InitStructureRx; USART_InitTypeDef USART_InitStructure;RCC_APB1PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE); // Enable clocks
GPIO_InitStructureTx.GPIO_Pin = GPIO_Pin_9; // Configure TX pin
GPIO_InitStructureTx.GPIO_Mode = GPIO_Mode_AF_PP; // Push-Pull GPIO_InitStructureTx.GPIO_Speed = GPIO_Speed_2MHz; // 50MHz GPIO_Init(GPIOA, &GPIO_InitStructureTx); // InitialiseGPIO_InitStructureRx.GPIO_Pin = GPIO_Pin_10; // Configure RX pin
GPIO_InitStructureRx.GPIO_Mode = GPIO_Mode_IN_FLOATING; // Push-Pull GPIO_InitStructureRx.GPIO_Speed = GPIO_Speed_2MHz; // 50MHz GPIO_Init(GPIOA, &GPIO_InitStructureRx); // IniitialiseUSART_InitStructure.USART_BaudRate = 57600; // Set USART1 Baud Rate
USART_InitStructure.USART_WordLength = USART_WordLength_8b; // Set USART1 Word Length USART_InitStructure.USART_StopBits = USART_StopBits_1; // Configure USART1 Stop Bits USART_InitStructure.USART_Parity = USART_Parity_No; // Configure USART1 Parity Bits USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; // Configure USART1 Flow Control USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; // Set USART1 Operation ModeUSART_Init(USART1, &USART_InitStructure); // Configure UART
USART_Cmd(USART1, ENABLE); // Enable UART
//setvbuf(stdout, NULL, _IONBF, 0);
//printf(''USART1 Inisialised\n''); USART_SendData(USART1, 'c'); //while (!(USART1->SR & USART_FLAG_TXE)); //USART1->DR = (0x35);}
void initAll (void)
{ initGPIO(); initSysTick(); initLSE(); initUART(); } There is also a file which provides the delay procedure, using the SysTick. Thanks for any help or guidance! #stm32 #discovery #usart #rs2322011-02-23 04:28 PM
RCC_APB1PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE); // Enable clocks
RCC_APB2PeriphClockCmd(); Perhaps?
2011-02-24 01:14 AM
Hi. Thanks for your reply! That seems to have helped a lot!
Now that I look closer at the arguments being passed, that does seem to make sense!