简体   繁体   English

STM32F4微控制器串口线调试不工作

[英]STM32F4 microcontroller serial wire debug not working

I am using the STM32F4 discovery board - http://www.st.com/st-web-ui/static/active/en/resource/technical/document/data_brief/DM00037955.pdf我正在使用 STM32F4 发现板 - http://www.st.com/st-web-ui/static/active/en/resource/technical/document/data_brief/DM00037955.pdf

And I am trying to debug via "printf"-like statements using the Serial Wire Viewer in the ST Micro STLink software: http://www.st.com/st-web-ui/static/active/en/resource/technical/document/user_manual/CD00262073.pdf我正在尝试使用 ST Micro STLink 软件中的串行线查看器通过类似“printf”的语句进行调试:http: //www.st.com/st-web-ui/static/active/en/resource/technical /document/user_manual/CD00262073.pdf

However I cannot see any results in my SWO Viewer despite setting the system clock to 168000000 Hz and stimulus port to 'All'.但是,尽管将系统时钟设置为 168000000 Hz 并将激励端口设置为“全部”,但我在 SWO 查看器中看不到任何结果。 The (relevant) software I have running on the chip is below.我在芯片上运行的(相关)软件如下。 This demo is set up to change the LED lights based on pressing the user button.此演示设置为根据按下用户按钮更改 LED 灯。

static uint8_t lastButtonStatus = RESET;

int main() {
    init();

    do {
        loop();
    } while (1);
}

void init() {
    initLeds();
    initButton();
}

void loop() {
    static uint32_t counter = 0;

    uint8_t currentButtonStatus = GPIO_ReadInputDataBit(GPIOA, USER_BUTTON);

    if (lastButtonStatus != currentButtonStatus
            && currentButtonStatus != RESET) {
        ++counter;
        GPIO_ResetBits(GPIOD, LEDS);
        GPIO_SetBits(GPIOD, LED[counter % 4]);
        // Test SWD output
        SWV_puts("hello from stm32f4\n");
        SWV_printfloat(1.98254, 2);
    }
    lastButtonStatus = currentButtonStatus;
}

Here are the SWV_ printing functions:以下是SWV_打印功能:

void SWV_puts(const char *s )
{
    while (*s) ITM_SendChar(*s++);

}

/**
  * @brief   This function sends numbers to the serial wire viewer.
  * @param  number: number to be displayed on SWV
  * @retval None
  */
void SWV_printnum(long number)
{
 unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars.
 unsigned int i = 0;

 //if number is 0
 if (number == 0)
 {
  ITM_SendChar('0'); //if number is zero
     return;
 }
 //account for negative numbers
 if (number < 0)
 {
  ITM_SendChar('-');
  number = number * -1;
 }
 while(number > 0)
 {
  buf[i++] = number % 10; //display in base 10
  number = number / 10;
  //NOTE: the effect of i++ means that the i variable will be at number of digits + 1
 }
 for(; i > 0; i--)
 {
  ITM_SendChar((char)('0' + buf[i-1]));
 }
}

/**
  * @brief  This function sends numbers to the serial wire viewer.
  * @param  number: number to be displayed on SWV
  * @param  digits: number of digits after decimal point
  * @retval None
  */
void SWV_printfloat(double number, int digits)
{
 int i = 0;
 //handle negative numbers
 if(number < 0.0)
 {
  ITM_SendChar('-');
  number = -number;
 }
 //round correctly so that uart_printfloat(1.999, 2) shows as "2.00"
 double rounding = 0.5;
 for(i = 0; i < digits; ++i) rounding = rounding / 10.0;
 number = number + rounding;

 //extract the integer part of the number and print it
 unsigned long int_part = (unsigned long) number;
 double remainder = (double)(number - (double)int_part);
 SWV_printnum(int_part); //print the integer part
 if(digits > 0) ITM_SendChar('.'); //print decimal pint
 int toprint;
 while(digits-- > 0)
 {
  remainder = remainder * 10.0;
  toprint = (int)remainder;
  SWV_printnum(toprint);
  remainder = remainder - toprint;
 }

}

I can confirm that the code compiles with no errors or warnings.我可以确认代码编译时没有错误或警告。

I have tried your code (nothing else) on my STMF4-discovery and it works fine.我在我的 STMF4-discovery 上尝试了你的代码(没有别的),它工作正常。 I think you have to update any thing to last version:我认为您必须将任何内容更新到最新版本:

STM32 ST/LINK utility v3.4.0
STLinkUSBDriver.dll v4.3.3.0
ST-LINK_CLI.exe v2.0.0
STM32F4 discovery board ST-LINK Firmware version : V2J21S0
STLink dongle 1.1.0.0 (10/12/2013)

good luck祝你好运

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM