I am using the STM32F4 discovery board - 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
However I cannot see any results in my SWO Viewer despite setting the system clock to 168000000 Hz and stimulus port to 'All'. 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.
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:
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. 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.