Witam, jadę z kursem STM32 ale napotkałem na pewien problem. Chodzi o funkcję printf.
Jeśli piszę stały ciąg znaków wszystko jest OK, ale jeśli chcę wstawić zmienną to procek się zawiesza i na terminalu już nie pojawia się linia ze zmienną. Tak jakby formatowanie tekstu nie działało. Poniżej testowy program:
#include "stm32f4xx.h"
#include <stdio.h>
void send_char(char c)
{
while (USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
USART_SendData(USART2, c);
}
int __io_putchar(int c)
{
if (c=='\n')
send_char('\r');
send_char(c);
return c;
}
int main(void)
{
int a=123;
GPIO_InitTypeDef gpio;
USART_InitTypeDef uart;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA |RCC_AHB1Periph_GPIOB |RCC_AHB1Periph_GPIOC| RCC_AHB1Periph_GPIOD, ENABLE);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_USART2);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_USART2);
gpio.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3; // Konfiguracja RS232
gpio.GPIO_Mode = GPIO_Mode_AF;
gpio.GPIO_OType = GPIO_OType_PP;
gpio.GPIO_PuPd = GPIO_PuPd_UP;
gpio.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &gpio);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
USART_StructInit(&uart);
uart.USART_BaudRate = 115200;
USART_Init(USART2, &uart);
USART_Cmd(USART2, ENABLE);
printf("Hello World!\n");
printf("Zmienna a = %d \n", a); //TU JEST PROBLEM !!!
while(1){
printf("Napis 2!\n");
}
}
Program zawiesza się po wypisaniu na terminal "Hello World!". Napisu "Napis 2!" już w ogóle nie wyświetla. Jeżeli usunę linię:
printf("Zmienna a = %d \n", a);
to program wchodzi do pętli while(1). Nie wiem dlaczego nie mogę formatować tekstu.
Korzystam z płytki STM32F4 - discovery z konwerterem USB<-->RS232. Program z kursu przerobiony pod tą płytkę. Środowisko System Workbench for STM32.
Ktoś pomoże?