mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-23 19:20:51 +00:00
Added debug functions to STM32 BSP.
This commit is contained in:
parent
8268d6d381
commit
412f9ba97f
333
Ports/uCOS/stm32/src/T32_Term.c
Normal file
333
Ports/uCOS/stm32/src/T32_Term.c
Normal file
@ -0,0 +1,333 @@
|
||||
|
||||
/*------------------------------*/
|
||||
/* TRACE32 Terminal Function */
|
||||
/*------------------------------*/
|
||||
/*
|
||||
this terminal Function are for SingeE Access
|
||||
on Devices with Dualport Access only.
|
||||
|
||||
use on the Trace32 Driver the command
|
||||
Terminal Setup:
|
||||
|
||||
TERM.Reset
|
||||
TERM.METHODE.SingleE
|
||||
TERM.MODE Ascii| String | RAW | HEX | VT100
|
||||
|
||||
After this, start your Window Definition.
|
||||
This can containe ONE terminal.view command with the SAME
|
||||
configuration addresses.
|
||||
|
||||
TERM e:TermOutAddress1 e:TermInAddress1
|
||||
TERM e:TermOutAddress2 e:TermInAddress2
|
||||
.....
|
||||
|
||||
|
||||
If you use the Enable functionality, then you can
|
||||
enable (or disable) the T32-Terimanl Driver on the fly
|
||||
by the command
|
||||
|
||||
Data.Set e:TermOutAddress+2 %Byte -1 ; for enable
|
||||
or
|
||||
Data.Set e:TermOutAddress+2 %Byte 0 ; for disable
|
||||
|
||||
note
|
||||
if the "t32_term_pen_port" is located in the zero-section, then the
|
||||
terminal is automatically disabled by default.
|
||||
|
||||
|
||||
In the example, T32OutAddress means the Out-Byte of the Applycation view
|
||||
and the T32InAddress means the In-Byte of the Applycation view
|
||||
|
||||
|
||||
*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* History */
|
||||
/*--------- */
|
||||
/*--Date-+-change---------------------------------------------------+aut+Vers+*/
|
||||
/* 110508: is created for cortex (e.g. target with e: access) :akj:1.00:*/
|
||||
/*-------+----------------------------------------------------------+---+----+*/
|
||||
/* : : : :*/
|
||||
/*-------+----------------------------------------------------------+---+----+*/
|
||||
/* : : : :*/
|
||||
/*-------+----------------------------------------------------------+---+----+*/
|
||||
/* : : : :*/
|
||||
/*-------+----------------------------------------------------------+---+----+*/
|
||||
/* : : : :*/
|
||||
/*-------+----------------------------------------------------------+---+----+*/
|
||||
/* : : : :*/
|
||||
/*-------+----------------------------------------------------------+---+----+*/
|
||||
/* : : : :*/
|
||||
/*-------+----------------------------------------------------------+---+----+*/
|
||||
/* : : : :*/
|
||||
/*-------+----------------------------------------------------------+---+----+*/
|
||||
|
||||
|
||||
#include "T32_Term.h"
|
||||
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Put a character to T32-Terminal */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/*
|
||||
Abstract
|
||||
this funktion puts a character to the 3 (or 2) byte port
|
||||
the port is a 3 cell memory part.
|
||||
|
||||
struct(3 bytes, [0] unsigned char put (unsigned 8 bits),
|
||||
[1] unsigned char get (unsigned 8 bits),
|
||||
[2] unsigned char enable (unsigned 8 bits))
|
||||
|
||||
the last byte is optional and controller by the
|
||||
- T32_term_enable_byte in the T32_Term.h file.
|
||||
if this is >0, the the byte is used.
|
||||
|
||||
The enable byte must be set to >0, otherwise, the terminal
|
||||
functions are disabled in the applycation.
|
||||
--------------------------------------------------------------------------
|
||||
The Put Funtion first checks the Enable Byte. If it is 0x0,
|
||||
the the function is returned.
|
||||
|
||||
If the Terminal is enabled, the Put Function checks the put Byte
|
||||
if no Terminal is opened in the Trace32, then the last Character
|
||||
is not readed and the Put Function will polling up to n parts.
|
||||
n = t32_term_polling_nr defined in the T32_Term.h file.
|
||||
|
||||
--------------------------------------------------------------------------
|
||||
|
||||
Parameter
|
||||
-1-
|
||||
struct t32_term_typedef *Address
|
||||
|
||||
pointer to the Port-Structure. It is defined in the
|
||||
T32_Term.h file. The selectable Port-Channel is for
|
||||
Multi-Terminal mode.
|
||||
Normaly use -> t32_termport <- for this paramter always.
|
||||
|
||||
-2-
|
||||
unsigned char
|
||||
|
||||
8 Bit Value for transmit to the Terminal.
|
||||
Don't send a 0x00 value, it will not transmit.
|
||||
|
||||
|
||||
the terminal can interprete a subset of VT100 syntax.
|
||||
|
||||
return
|
||||
none
|
||||
|
||||
--------------------------------------------------------------------------
|
||||
|
||||
Example:
|
||||
|
||||
include "T32_Term.h"
|
||||
|
||||
T32_Term_Put(t32_termport,Character);
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
void T32_Term_Put(t32_term_typedef *port, char uc_value)
|
||||
{
|
||||
unsigned int polling_loop_ctr;
|
||||
|
||||
|
||||
#if t32_term_enable_byte > 0
|
||||
if (port->enable == 0)
|
||||
return;
|
||||
#endif
|
||||
|
||||
polling_loop_ctr = t32_term_polling_nr;
|
||||
while ((port->put!=0) && (polling_loop_ctr !=0)) {
|
||||
polling_loop_ctr--;
|
||||
}
|
||||
|
||||
if (port->put !=0)
|
||||
return;
|
||||
|
||||
port->put = (unsigned char)uc_value;
|
||||
|
||||
return;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Get a character from T32-Terminal */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/*
|
||||
Abstract
|
||||
this funktion read's a character from the 3 (or 2) byte port
|
||||
the port is a 3 cell memory part.
|
||||
|
||||
struct(3 bytes, [0] unsigned char put (unsigned 8 bits),
|
||||
[1] unsigned char get (unsigned 8 bits),
|
||||
[2] unsigned char enable (unsigned 8 bits))
|
||||
|
||||
the last byte is optional and controller by the
|
||||
- T32_term_enable_byte in the T32_Term.h file.
|
||||
if this is >0, the the byte is used.
|
||||
|
||||
The enable byte must be set to > 0, otherwise, the terminal
|
||||
functions are disabled in the applycation.
|
||||
--------------------------------------------------------------------------
|
||||
The Get Funtion first checks the Enable Byte. If it is 0x0,
|
||||
the the function is returned with 0x00.
|
||||
|
||||
If the Terminal is enabled, the Get Function reads the Value from
|
||||
get Byte and then writes a 0x00 to the get byte for signaling to
|
||||
Trace32, that the charcater is taked.
|
||||
|
||||
--------------------------------------------------------------------------
|
||||
|
||||
Parameter
|
||||
-1-
|
||||
struct t32_term_typedef *Address
|
||||
|
||||
pointer to the Port-Structure. It is defined in the
|
||||
T32_Term.h file. The selectable Port-Channel is for
|
||||
Multi-Terminal mode.
|
||||
Normaly use -> t32_termport <- for this paramter always.
|
||||
|
||||
|
||||
return unsigned char
|
||||
|
||||
- 0x00 for no character is present
|
||||
> 0x00 as Terminal Value.
|
||||
|
||||
--------------------------------------------------------------------------
|
||||
|
||||
Example:
|
||||
|
||||
include "T32_Term.h"
|
||||
|
||||
unsigned char uc_terminal_char;
|
||||
|
||||
uc_terminal_char = T32_Term_Get(t32_termport);
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
unsigned char T32_Term_Get(t32_term_typedef *port)
|
||||
{
|
||||
unsigned char uc_val;
|
||||
|
||||
#if t32_term_enable_byte > 0
|
||||
if (port->enable == 0)
|
||||
return (unsigned char)0x0;
|
||||
#endif
|
||||
|
||||
uc_val = (unsigned char)port->get; /* read port */
|
||||
if (uc_val > 0)
|
||||
port->get = 0; /* write handshake */
|
||||
|
||||
return uc_val;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* RX-Status T32-Terminal */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/*
|
||||
Abstract see Put and Get Function
|
||||
--------------------------------------------------------------------------
|
||||
|
||||
Parameter
|
||||
-1-
|
||||
struct t32_term_typedef *Address
|
||||
|
||||
pointer to the Port-Structure. It is defined in the
|
||||
T32_Term.h file. At this time, only one Terminal can
|
||||
be used in the Trace32. The selectable Port-Channel is for
|
||||
future.
|
||||
Normaly use -> t32_termport <- for this paramter always.
|
||||
|
||||
|
||||
return unsigned char
|
||||
|
||||
- 0x00 for no character is present
|
||||
0xFF a Character is ready for get it
|
||||
|
||||
--------------------------------------------------------------------------
|
||||
|
||||
Example:
|
||||
|
||||
include "T32_Term.h"
|
||||
|
||||
unsigned char uc_terminal_status;
|
||||
|
||||
uc_terminal_status = T32_Term_RXStatus(t32_termport);
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
unsigned char T32_Term_RXStatus(t32_term_typedef *port)
|
||||
{
|
||||
unsigned char uc_val;
|
||||
|
||||
#if t32_term_enable_byte > 0
|
||||
if (port->enable == 0)
|
||||
return (unsigned char)0x0;
|
||||
#endif
|
||||
|
||||
uc_val = port->get; /* read port */
|
||||
if (uc_val > 0)
|
||||
return (unsigned char)0x0;
|
||||
else
|
||||
return (unsigned char)0xff;
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* TX-Status T32-Terminal */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/*
|
||||
Abstract see Put and Get Function
|
||||
--------------------------------------------------------------------------
|
||||
|
||||
Parameter
|
||||
-1-
|
||||
struct t32_term_typedef *Address
|
||||
|
||||
pointer to the Port-Structure. It is defined in the
|
||||
T32_Term.h file. At this time, only one Terminal can
|
||||
be used in the Trace32. The selectable Port-Channel is for
|
||||
future.
|
||||
Normaly use -> t32_termport <- for this paramter always.
|
||||
|
||||
|
||||
return unsigned char
|
||||
|
||||
- 0x00 TX Buffer is empty
|
||||
0xFF TX Buffer is not ready for transmit
|
||||
|
||||
--------------------------------------------------------------------------
|
||||
|
||||
Example:
|
||||
|
||||
include "T32_Term.h"
|
||||
|
||||
unsigned char uc_terminal_status;
|
||||
|
||||
uc_terminal_status = T32_Term_TXStatus(t32_termport);
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
unsigned char T32_Term_TXStatus(t32_term_typedef *port)
|
||||
{
|
||||
unsigned char uc_val;
|
||||
|
||||
#if t32_term_enable_byte > 0
|
||||
if (port->enable == 0)
|
||||
return (unsigned char)0x0;
|
||||
#endif
|
||||
|
||||
uc_val = port->put;
|
||||
if (uc_val > 0)
|
||||
return (unsigned char)0xff;
|
||||
else
|
||||
return (unsigned char)0x00;
|
||||
}
|
||||
|
||||
/* eof */
|
||||
|
72
Ports/uCOS/stm32/src/T32_Term.h
Normal file
72
Ports/uCOS/stm32/src/T32_Term.h
Normal file
@ -0,0 +1,72 @@
|
||||
/*------------------------------*/
|
||||
/* TRACE32 Terminal Header File */
|
||||
/*------------------------------*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* History */
|
||||
/*--------- */
|
||||
/*--Date-+-change---------------------------------------------------+aut+Vers+*/
|
||||
/* 110508: is created for cortex (e.g. target with e: access) :akj:1.00:*/
|
||||
/*-------+----------------------------------------------------------+---+----+*/
|
||||
/* : : : :*/
|
||||
/*-------+----------------------------------------------------------+---+----+*/
|
||||
/* : : : :*/
|
||||
/*-------+----------------------------------------------------------+---+----+*/
|
||||
/* : : : :*/
|
||||
/*-------+----------------------------------------------------------+---+----+*/
|
||||
/* : : : :*/
|
||||
/*-------+----------------------------------------------------------+---+----+*/
|
||||
/* : : : :*/
|
||||
/*-------+----------------------------------------------------------+---+----+*/
|
||||
/* : : : :*/
|
||||
/*-------+----------------------------------------------------------+---+----+*/
|
||||
/* : : : :*/
|
||||
/*-------+----------------------------------------------------------+---+----+*/
|
||||
|
||||
|
||||
|
||||
#ifndef __t32_term_def_h
|
||||
#define __t32_term_def_h
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define t32_term_enable_byte 1 /* 1 = terminal Enable-Byte is used; 0= not used */
|
||||
#define t32_term_polling_nr 100 /* n pollings for transmit a byte is used (min is 1) */
|
||||
#define t32_termportaddress 0x2000fff0 /* Put = 0x20083ff0, get = 0x20083ff1, enable = 0x20083ff2 */
|
||||
#define t32_termportaddress2 0x2000fff3 /* Put = 0x20083ff3, get = 0x20083ff4, enable = 0x20083ff5 */
|
||||
|
||||
|
||||
/*----------------*/
|
||||
/* Define Struct */
|
||||
/*----------------*/
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
volatile unsigned char put;
|
||||
volatile unsigned char get;
|
||||
#if t32_term_enable_byte > 0
|
||||
volatile unsigned char enable;
|
||||
#endif
|
||||
} t32_term_typedef;
|
||||
|
||||
#define t32_termport (( t32_term_typedef *) t32_termportaddress)
|
||||
#define t32_termport_2 (( t32_term_typedef *) t32_termportaddress2)
|
||||
|
||||
|
||||
|
||||
/*----------------*/
|
||||
/* Define Function*/
|
||||
/*----------------*/
|
||||
|
||||
extern void T32_Term_Put(t32_term_typedef * port,
|
||||
char uc_value ); /* send a character from application to the host */
|
||||
unsigned char T32_Term_Get(t32_term_typedef *port ); /* get a character from host to application */
|
||||
extern unsigned char T32_Term_TXStatus(t32_term_typedef *port ); /* check terminal status */
|
||||
extern unsigned char T32_Term_RXStatus(t32_term_typedef *port ); /* check terminal status */
|
||||
|
||||
#endif
|
||||
|
||||
/* eof */
|
||||
|
375
Ports/uCOS/stm32/src/bsp_debug.c
Normal file
375
Ports/uCOS/stm32/src/bsp_debug.c
Normal file
@ -0,0 +1,375 @@
|
||||
/*=============================================================================
|
||||
* (C) Copyright Albis Technologies Ltd 2011
|
||||
*==============================================================================
|
||||
* STM32 Example Code
|
||||
*==============================================================================
|
||||
* File name: bsp_debug.c
|
||||
*
|
||||
* Notes: STM32 evaluation board UM0780 debug utilities BSP.
|
||||
*============================================================================*/
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "bsp.h"
|
||||
#include "bsp_debug.h"
|
||||
#include "T32_Term.h"
|
||||
|
||||
#include "stm32f10x_gpio.h"
|
||||
#include "stm32f10x_usart.h"
|
||||
|
||||
#define DEBUG_T32_TERM_IN_USE 0
|
||||
|
||||
#define DEBUG_UART_IN_USE 0
|
||||
#define UART_2_REMAP 1
|
||||
|
||||
#define DEBUG_UART_1 1
|
||||
#define DEBUG_UART_2 2
|
||||
#define DEBUG_UART_3 3
|
||||
|
||||
/*=============================================================================
|
||||
=============================================================================*/
|
||||
static void writeByteSerialPort(const char b)
|
||||
{
|
||||
#if(DEBUG_UART_IN_USE == DEBUG_UART_1)
|
||||
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) != SET);
|
||||
USART_SendData(USART1, b);
|
||||
#endif
|
||||
|
||||
#if(DEBUG_UART_IN_USE == DEBUG_UART_2)
|
||||
while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) != SET);
|
||||
USART_SendData(USART2, b);
|
||||
#endif
|
||||
|
||||
#if(DEBUG_UART_IN_USE == DEBUG_UART_3)
|
||||
while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) != SET);
|
||||
USART_SendData(USART3, b);
|
||||
#endif
|
||||
|
||||
#if(DEBUG_T32_TERM_IN_USE > 0)
|
||||
while(T32_Term_TXStatus(t32_termport) != 0);
|
||||
T32_Term_Put(t32_termport, b);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*=============================================================================
|
||||
=============================================================================*/
|
||||
static void writeStringSerialPort(const char *s)
|
||||
{
|
||||
int total = 0;
|
||||
|
||||
while(s[total])
|
||||
{
|
||||
writeByteSerialPort(s[total++]);
|
||||
}
|
||||
}
|
||||
|
||||
/*=============================================================================
|
||||
=============================================================================*/
|
||||
static void dbgOutNumHex(unsigned long n, long depth)
|
||||
{
|
||||
if(depth)
|
||||
{
|
||||
depth--;
|
||||
}
|
||||
|
||||
if((n & ~0xf) || depth)
|
||||
{
|
||||
dbgOutNumHex(n >> 4, depth);
|
||||
n &= 0xf;
|
||||
}
|
||||
|
||||
if(n < 10)
|
||||
{
|
||||
writeByteSerialPort((unsigned char)(n + '0'));
|
||||
}
|
||||
else
|
||||
{
|
||||
writeByteSerialPort((unsigned char)(n - 10 + 'A'));
|
||||
}
|
||||
}
|
||||
|
||||
/*=============================================================================
|
||||
=============================================================================*/
|
||||
static void dbgOutNumDecimal(unsigned long n)
|
||||
{
|
||||
if(n >= 10)
|
||||
{
|
||||
dbgOutNumDecimal(n / 10);
|
||||
n %= 10;
|
||||
}
|
||||
writeByteSerialPort((unsigned char)(n + '0'));
|
||||
}
|
||||
|
||||
/*=============================================================================
|
||||
=============================================================================*/
|
||||
void initSerialDebug(void)
|
||||
{
|
||||
#if(DEBUG_UART_IN_USE > 0)
|
||||
GPIO_InitTypeDef gpio_init;
|
||||
USART_InitTypeDef usart_init;
|
||||
USART_ClockInitTypeDef usart_clk_init;
|
||||
|
||||
/* ----------------- INIT USART STRUCT ---------------- */
|
||||
usart_init.USART_BaudRate = 115200 / 2;
|
||||
usart_init.USART_WordLength = USART_WordLength_8b;
|
||||
usart_init.USART_StopBits = USART_StopBits_1;
|
||||
usart_init.USART_Parity = USART_Parity_No;
|
||||
usart_init.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
||||
usart_init.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
|
||||
|
||||
usart_clk_init.USART_Clock = USART_Clock_Disable;
|
||||
usart_clk_init.USART_CPOL = USART_CPOL_Low;
|
||||
usart_clk_init.USART_CPHA = USART_CPHA_2Edge;
|
||||
usart_clk_init.USART_LastBit = USART_LastBit_Disable;
|
||||
|
||||
#if(DEBUG_UART_IN_USE == DEBUG_UART_1)
|
||||
BSP_PeriphEn(BSP_PERIPH_ID_USART1);
|
||||
|
||||
/* ----------------- SETUP USART1 GPIO ---------------- */
|
||||
#if(UART_1_REMAP > 0)
|
||||
BSP_PeriphEn(BSP_PERIPH_ID_IOPB);
|
||||
BSP_PeriphEn(BSP_PERIPH_ID_IOPD);
|
||||
BSP_PeriphEn(BSP_PERIPH_ID_AFIO);
|
||||
GPIO_PinRemapConfig(GPIO_Remap_USART1, ENABLE);
|
||||
|
||||
/* Configure GPIOB.6 as push-pull. */
|
||||
gpio_init.GPIO_Pin = GPIO_Pin_6;
|
||||
gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
gpio_init.GPIO_Mode = GPIO_Mode_AF_PP;
|
||||
GPIO_Init(GPIOB, &gpio_init);
|
||||
|
||||
/* Configure GPIOB.7 as input floating. */
|
||||
gpio_init.GPIO_Pin = GPIO_Pin_7;
|
||||
gpio_init.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
||||
GPIO_Init(GPIOB, &gpio_init);
|
||||
#else
|
||||
BSP_PeriphEn(BSP_PERIPH_ID_IOPA);
|
||||
|
||||
/* Configure GPIOA.9 as push-pull. */
|
||||
gpio_init.GPIO_Pin = GPIO_Pin_9;
|
||||
gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
gpio_init.GPIO_Mode = GPIO_Mode_AF_PP;
|
||||
GPIO_Init(GPIOA, &gpio_init);
|
||||
|
||||
/* Configure GPIOA.10 as input floating. */
|
||||
gpio_init.GPIO_Pin = GPIO_Pin_10;
|
||||
gpio_init.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
||||
GPIO_Init(GPIOA, &gpio_init);
|
||||
#endif /* UART_1_REMAP */
|
||||
|
||||
/* ------------------ SETUP USART1 -------------------- */
|
||||
USART_Init(USART1, &usart_init);
|
||||
USART_ClockInit(USART1, &usart_clk_init);
|
||||
USART_Cmd(USART1, ENABLE);
|
||||
|
||||
#ifdef UART_IRQ
|
||||
BSP_IntVectSet(BSP_INT_ID_USART1, debug_uart_isr);
|
||||
BSP_IntEn(BSP_INT_ID_USART1);
|
||||
#endif /* UART_IRQ */
|
||||
#endif /* DEBUG_UART_1 */
|
||||
|
||||
#if(DEBUG_UART_IN_USE == DEBUG_UART_2)
|
||||
BSP_PeriphEn(BSP_PERIPH_ID_USART2);
|
||||
|
||||
/* ----------------- SETUP USART2 GPIO ---------------- */
|
||||
#if(UART_2_REMAP > 0)
|
||||
BSP_PeriphEn(BSP_PERIPH_ID_IOPD);
|
||||
BSP_PeriphEn(BSP_PERIPH_ID_AFIO);
|
||||
GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
|
||||
|
||||
/* Configure GPIOD.5 as push-pull. */
|
||||
gpio_init.GPIO_Pin = GPIO_Pin_5;
|
||||
gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
gpio_init.GPIO_Mode = GPIO_Mode_AF_PP;
|
||||
GPIO_Init(GPIOD, &gpio_init);
|
||||
|
||||
/* Configure GPIOD.6 as input floating. */
|
||||
gpio_init.GPIO_Pin = GPIO_Pin_6;
|
||||
gpio_init.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
||||
GPIO_Init(GPIOD, &gpio_init);
|
||||
#else
|
||||
BSP_PeriphEn(BSP_PERIPH_ID_IOPA);
|
||||
|
||||
/* Configure GPIOA.2 as push-pull. */
|
||||
gpio_init.GPIO_Pin = GPIO_Pin_2;
|
||||
gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
gpio_init.GPIO_Mode = GPIO_Mode_AF_PP;
|
||||
GPIO_Init(GPIOA, &gpio_init);
|
||||
|
||||
/* Configure GPIOA.3 as input floating. */
|
||||
gpio_init.GPIO_Pin = GPIO_Pin_3;
|
||||
gpio_init.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
||||
GPIO_Init(GPIOA, &gpio_init);
|
||||
#endif /* UART_2_REMAP */
|
||||
|
||||
/* ------------------ SETUP USART2 -------------------- */
|
||||
USART_Init(USART2, &usart_init);
|
||||
USART_ClockInit(USART2, &usart_clk_init);
|
||||
USART_Cmd(USART2, ENABLE);
|
||||
|
||||
#ifdef UART_IRQ
|
||||
BSP_IntVectSet(BSP_INT_ID_USART2, debug_uart_isr);
|
||||
BSP_IntEn(BSP_INT_ID_USART2);
|
||||
#endif /* UART_IRQ */
|
||||
#endif /* DEBUG_UART_2 */
|
||||
|
||||
#if(DEBUG_UART_IN_USE == DEBUG_UART_3)
|
||||
BSP_PeriphEn(BSP_PERIPH_ID_USART3);
|
||||
|
||||
/* ----------------- SETUP USART3 GPIO ---------------- */
|
||||
#if(UART_3_REMAP_PARTIAL > 0)
|
||||
BSP_PeriphEn(BSP_PERIPH_ID_IOPC);
|
||||
BSP_PeriphEn(BSP_PERIPH_ID_AFIO);
|
||||
GPIO_PinRemapConfig(GPIO_PartialRemap_USART3, ENABLE);
|
||||
|
||||
/* Configure GPIOC.10 as push-pull. */
|
||||
gpio_init.GPIO_Pin = GPIO_Pin_10;
|
||||
gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
gpio_init.GPIO_Mode = GPIO_Mode_AF_PP;
|
||||
GPIO_Init(GPIOC, &gpio_init);
|
||||
|
||||
/* Configure GPIOC.11 as input floating. */
|
||||
gpio_init.GPIO_Pin = GPIO_Pin_11;
|
||||
gpio_init.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
||||
GPIO_Init(GPIOC, &gpio_init);
|
||||
|
||||
#elif(UART_3_REMAP_FULL > 0)
|
||||
BSP_PeriphEn(BSP_PERIPH_ID_IOPD);
|
||||
BSP_PeriphEn(BSP_PERIPH_ID_AFIO);
|
||||
GPIO_PinRemapConfig(GPIO_FullRemap_USART3, ENABLE);
|
||||
|
||||
/* Configure GPIOD.8 as push-pull. */
|
||||
gpio_init.GPIO_Pin = GPIO_Pin_8;
|
||||
gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
gpio_init.GPIO_Mode = GPIO_Mode_AF_PP;
|
||||
GPIO_Init(GPIOD, &gpio_init);
|
||||
|
||||
/* Configure GPIOD.9 as input floating. */
|
||||
gpio_init.GPIO_Pin = GPIO_Pin_9;
|
||||
gpio_init.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
||||
GPIO_Init(GPIOD, &gpio_init);
|
||||
|
||||
#else
|
||||
BSP_PeriphEn(BSP_PERIPH_ID_IOPB);
|
||||
|
||||
/* Configure GPIOB.10 as push-pull. */
|
||||
gpio_init.GPIO_Pin = GPIO_Pin_10;
|
||||
gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
gpio_init.GPIO_Mode = GPIO_Mode_AF_PP;
|
||||
GPIO_Init(GPIOB, &gpio_init);
|
||||
|
||||
/* Configure GPIOB.11 as input floating. */
|
||||
gpio_init.GPIO_Pin = GPIO_Pin_11;
|
||||
gpio_init.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
||||
GPIO_Init(GPIOB, &gpio_init);
|
||||
#endif /* UART_3_REMAP_FULL */
|
||||
|
||||
/* ------------------ SETUP USART3 -------------------- */
|
||||
USART_Init(USART3, &usart_init);
|
||||
USART_ClockInit(USART3, &usart_clk_init);
|
||||
USART_Cmd(USART3, ENABLE);
|
||||
|
||||
#ifdef UART_IRQ
|
||||
BSP_IntVectSet(BSP_INT_ID_USART3, debug_uart_isr);
|
||||
BSP_IntEn(BSP_INT_ID_USART3);
|
||||
#endif /* UART_IRQ */
|
||||
#endif /* DEBUG_UART_3 */
|
||||
#endif /* DEBUG_UART_IN_USE */
|
||||
}
|
||||
|
||||
/*=============================================================================
|
||||
=============================================================================*/
|
||||
void printos(const char *sz, ...)
|
||||
{
|
||||
unsigned char c;
|
||||
va_list vl;
|
||||
|
||||
va_start(vl, sz);
|
||||
|
||||
while (*sz)
|
||||
{
|
||||
c = *sz++;
|
||||
switch (c)
|
||||
{
|
||||
case '%':
|
||||
c = *sz++;
|
||||
switch (c) {
|
||||
case 'x':
|
||||
dbgOutNumHex(va_arg(vl, unsigned long), 0);
|
||||
break;
|
||||
case 'B':
|
||||
dbgOutNumHex(va_arg(vl, unsigned long), 2);
|
||||
break;
|
||||
case 'H':
|
||||
dbgOutNumHex(va_arg(vl, unsigned long), 4);
|
||||
break;
|
||||
case 'X':
|
||||
dbgOutNumHex(va_arg(vl, unsigned long), 8);
|
||||
break;
|
||||
case 'd':
|
||||
{
|
||||
long l;
|
||||
|
||||
l = va_arg(vl, long);
|
||||
if (l < 0) {
|
||||
writeByteSerialPort('-');
|
||||
l = - l;
|
||||
}
|
||||
dbgOutNumDecimal((unsigned long)l);
|
||||
}
|
||||
break;
|
||||
case 'u':
|
||||
dbgOutNumDecimal(va_arg(vl, unsigned long));
|
||||
break;
|
||||
case 's':
|
||||
writeStringSerialPort(va_arg(vl, char *));
|
||||
break;
|
||||
case '%':
|
||||
writeByteSerialPort('%');
|
||||
break;
|
||||
case 'c':
|
||||
c = (unsigned char)va_arg(vl, unsigned int);
|
||||
writeByteSerialPort(c);
|
||||
break;
|
||||
|
||||
default:
|
||||
writeByteSerialPort(' ');
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case '\r':
|
||||
if (*sz == '\n')
|
||||
sz ++;
|
||||
c = '\n';
|
||||
/* fall through */
|
||||
case '\n':
|
||||
writeByteSerialPort('\r');
|
||||
/* fall through */
|
||||
default:
|
||||
writeByteSerialPort(c);
|
||||
}
|
||||
}
|
||||
|
||||
va_end(vl);
|
||||
}
|
||||
|
||||
/*=============================================================================
|
||||
=============================================================================*/
|
||||
void restartSystem(void)
|
||||
{
|
||||
BSP_LED_On(3);
|
||||
|
||||
/* TODO */
|
||||
for(;;);
|
||||
}
|
||||
|
||||
/*=============================================================================
|
||||
=============================================================================*/
|
||||
void fatalErrorHandler(const int reset,
|
||||
const char *fileName,
|
||||
unsigned short lineNumber)
|
||||
{
|
||||
printos("\r\nFATAL SW ERROR IN %s at %d!\r\n", fileName, lineNumber);
|
||||
|
||||
restartSystem();
|
||||
}
|
39
Ports/uCOS/stm32/src/bsp_debug.h
Normal file
39
Ports/uCOS/stm32/src/bsp_debug.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*=============================================================================
|
||||
* (C) Copyright Albis Technologies Ltd 2011
|
||||
*==============================================================================
|
||||
* STM32 Example Code
|
||||
*==============================================================================
|
||||
* File name: bsp_debug.h
|
||||
*
|
||||
* Notes: STM32 evaluation board UM0780 debug utilities BSP.
|
||||
*============================================================================*/
|
||||
|
||||
#ifndef BSP_DEBUG_H
|
||||
#define BSP_DEBUG_H
|
||||
|
||||
void fatalErrorHandler(const int reset,
|
||||
const char *fileName,
|
||||
unsigned short lineNumber);
|
||||
|
||||
// Whether or not source code file names are revealed.
|
||||
#define REVEAL_SOURCE_FILE_NAMES 1
|
||||
|
||||
#if (REVEAL_SOURCE_FILE_NAMES == 1)
|
||||
#define DEFINE_THIS_FILE static char const _this_file_name_[] = __FILE__;
|
||||
#else
|
||||
#define DEFINE_THIS_FILE static char const _this_file_name_[] = "***";
|
||||
#endif // REVEAL_SOURCE_FILE_NAMES
|
||||
|
||||
#define SYS_ERROR(reset) fatalErrorHandler(reset, \
|
||||
_this_file_name_, \
|
||||
__LINE__)
|
||||
|
||||
#define SYS_ASSERT(cond) if(!(cond)) { SYS_ERROR(1); }
|
||||
|
||||
void initSerialDebug(void);
|
||||
|
||||
void printos(const char *sz, ...);
|
||||
|
||||
void restartSystem(void);
|
||||
|
||||
#endif // BSP_DEBUG_H
|
Loading…
x
Reference in New Issue
Block a user