This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

STM32, printf wiindow and USART2 to printf

Hello,

I got PCB where a Bluetooth modul is SMD mounted at USART2 and a STM32F103ZE T6 (High Density). I'm using Keil + cmsis + stlib3.5.0

I'm trying to get the BT Modul working.
For that I need to see what the USART2 is echoing from my BT-Module and I have to write some AT-Commands to the USART2 from a debug window in keil (is that possible?)

Can anyone help me?

I started to do my retarget.c, it looks like this but i dont know if its correct or not:

#include <stdio.h>
#include <rt_misc.h>

#pragma import(__use_no_semihosting_swi)

extern int  SendChar (int ch);                    /* In Serial.c                        */

struct __FILE { int handle; /* Add whatever you need here */ };
FILE __stdout;

int fputc (int ch, FILE *f) { return (SendChar(ch)); }

int ferror (FILE *f)
{
/* Your implementation of ferror */
    return EOF;
}


void _ttywrch (int ch) { SendChar(ch); }

void _sys_exit (int return_code) { for (;;); }

and my stmdbg.ini for the ULINK2:

FUNC void DebugSetup (void) {

  _WDWORD(0xE0042004, 0x00000027);  // DBGMCU_CR
  _WDWORD(0x40044064, 0x00000003);  // Enable SWO on P0.9
}


DebugSetup();                       // Debugger Setup

and my serial.c

/******************************************************************************/
/* SERIAL.C: Low Level Serial Routines                                        */
/******************************************************************************/
/* This file is part of the uVision/ARM development tools.                    */
/* Copyright (c) 2005-2007 Keil Software. All rights reserved.                */
/* This software may only be used under the terms of a valid, current,        */
/* end user licence from KEIL for a compatible version of KEIL software       */
/* development tools. Nothing else gives you the right to use this software.  */
/******************************************************************************/

#define ITM_Port8(n)    (*((volatile unsigned char *)(0xE0000000+4*n)))
#define ITM_Port16(n)   (*((volatile unsigned short*)(0xE0000000+4*n)))
#define ITM_Port32(n)   (*((volatile unsigned long *)(0xE0000000+4*n)))

#define DEMCR           (*((volatile unsigned long *)(0xE000EDFC)))
#define TRCENA          0x01000000

#include <stm32f10x_lib.h>                        /* STM32F10x Library Definitions      */


/* Implementation of putchar (also used by printf function to output data)    */
int SendChar (int ch)                             /* Write character to Serial Port     */
{

#ifdef DBG_ITM
    if (DEMCR & TRCENA)
    {
        while (ITM_Port32(0) == 0);
        ITM_Port8(0) = ch;
    }
#else
    USART_SendData(USART2, (unsigned char) ch);
    while (!(USART2->SR & USART_FLAG_TXE));
#endif
    return (ch);
}


int GetKey (void)                                 /* Read character from Serial Port    */
{

    while (!(USART2->SR & USART_FLAG_RXNE));
    return (USART_ReceiveData(USART2));
}

///////////////////////////////////////////////////////////////////////////////////
If anyone has something finshed please share or give some good adivce :)

with regards
Sven

0