Skip to content
This repository has been archived by the owner on May 19, 2024. It is now read-only.

Commit

Permalink
Complete but lightly tested version
Browse files Browse the repository at this point in the history
  • Loading branch information
mubes committed Apr 16, 2017
1 parent f28e68c commit e0ef6d5
Show file tree
Hide file tree
Showing 11 changed files with 1,567 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ofiles
.DS_Store
*.bin
*.hex
*.o
*.d
.*.swp
*~
*.pyc
tags
.gdbinit
*.s#*
*.b#*

62 changes: 62 additions & 0 deletions Docs/BlackMagicProbe-Interface
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
Using the Black Magic Debug Probe
=================================

When connecting to a Black Magic Debug probe the command line for
ACSOPT will be something like;

>./acsopt -b swo/

...which will create the fifos in a subdirectory swo of the current
directory. The directory must exist already.

By default on BMP the SWO baudrate is 2.25MBps but that can be changed
as an optional parameter to the monitor traceswo command at the gdb
console, like this;

monitor traceswo 115200

....would set the swo output at the low speed of 115kbps.

Until a monitor traceswo command has been issued the BMP will not send
any data to ACSOPT. Once it's been issued then ACSOPT will
automatically grab packets and publish them to its fifos.

BMP SWO capture speed is constrained by both the capabilities of the
STM32F103 USART and the ability to get the packets back out over the
USB link. The UART baudrate is set by b=(72x10^6)/(16*d)...so for d=1
that means a maximum speed of 4.5Mbps. For continious streaming that
turns out to be _too_ fast for the USB link, so the next available
option is the 2.25Mbps that we use. ....you can safely use the 4.5Mbps
setting if your debug data is bursty, or if you're using a different
CPU to the STM32F103 as your BMP host, but you potentially run the
risk of losing packets if you have long runs of sending which the usb
cannot flush in time (there's a 12K buffer, so the it is a pretty long
run before it becomes a problem).

Note that the baudrate equation means there are only certain speeds
available. The highest half dozen are;

1 4.50 Mbps
2 2.25 Mbps
3 1.50 Mbps
4 1.125 Mbps
5 0.900 Mbps
6 0.750 Mbps

...the USART will cope with some timing slip, but it's advisible to
stay as close to these values as you can. As the speed comes down the
spread between each valid value so mis-timing is less of an issue. The
'monitor traceswo <x>' command will automatically find the closest
divisor to the value you set for the speed, so be aware the error
could be significant.

You can also use ACSOPT with a RZ mode SWO port (e.g. on a genuine
BMP). In that case then you will need the trace output speed to be
quite a lot lower...in the order of 200kHz or so, by means of changing
the divisor to something like 359. That's because the STM32F103
doesn't have a dedicated RZ decoder so it all has to be done in
software. The advantage of RZ is that the probe can adapt to the speed
of the target, so you don't have to set the speed on the probe in the
monitor traceswo command, and it will be tolerant of different speeds.

Using BMP the SWO data appears on USB Interface 5, Endpoint 5.
21 changes: 21 additions & 0 deletions Docs/TTLSerial-Interface
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Using a TTL Serial Interface
============================

The NRZ data that comes out of the SWO is just UART formatted, but in
a frame. ACSOPT has been extended to accomodate TTL Serial Dongles
that can pick this up. Success has been had with CP2102 dongles at up
to 921600 baud.

To use this mode just connect SWO to the RX pin of your dongle, and
start swolisten with parmeters representing the speed and port. An
example;

>./acsopt -p /dev/cu.SLAB_USBtoUART -b swo/ -s 921600

Any individual dongle will only support certain baudrates (Generally
multiples of 115200) so you may have to experiment to find the best
supported ones. For the CP2102 dongle 1.3824Mbps wasn't supported and
1.8432Mbps returned corrupted data.

Please email [email protected] with information about dongles you find
work well and at what speed.
95 changes: 95 additions & 0 deletions Inc/itmDecoder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* ITM Decoder Module
* ==================
*
* Copyright (C) 2017 Dave Marples <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _ITM_DECODER_
#define _ITM_DECODER_

#include <stdint.h>

#ifndef BOOL
#define BOOL int
#define FALSE (0)
#define TRUE (!FALSE)
#endif

#define ITM_MAX_PACKET_DATA (4)
#define ITM_MAX_PACKET (ITM_MAX_PACKET_DATA+1)

enum ITMPumpEvent {ITM_EV_NONE,
ITM_EV_UNSYNCED,
ITM_EV_SYNCED,
ITM_EV_TS_PACKET_RXED,
ITM_EV_SW_PACKET_RXED,
ITM_EV_HW_PACKET_RXED,
ITM_EV_OVERFLOW,
ITM_EV_ERROR
};

enum _protoState {ITM_UNSYNCED, ITM_IDLE, ITM_TS, ITM_SW, ITM_HW};
#define PROTO_NAME_LIST "UNSYNCED", "IDLE", "TS", "SW", "HW"

/* Type of the packet received over the link */
struct ITMPacket

{
uint8_t srcAddr;
int len;
union
{
uint8_t d[ITM_MAX_PACKET_DATA];
uint8_t u8;
uint16_t u16;
uint32_t u32;
int8_t s8;
int16_t s16;
int32_t s32;
};
};

struct ITMDecoder

{
int targetCount; /* Number of bytes to be collected */
int currentCount; /* Number of bytes that have been collected */
union
{
uint8_t rxPacket[ITM_MAX_PACKET_DATA]; /* Packet in reception */
uint8_t d[ITM_MAX_PACKET_DATA];
uint8_t u8;
uint16_t u16;
uint32_t u32;
int8_t s8;
int16_t s16;
int32_t s32;
};

uint32_t syncStat; /* Sync monitor status */
int srcAddr; /* Source address for this packet */

enum _protoState p; /* Current state of the receiver */
};

// ====================================================================================================
void ITMDecoderInit(struct ITMDecoder *i, BOOL isLiveSet);
void ITMDecoderForceSync(struct ITMDecoder *i, BOOL isSynced);
BOOL ITMGetPacket(struct ITMDecoder *i, struct ITMPacket *p);
enum ITMPumpEvent ITMPump(struct ITMDecoder *i, uint8_t c);
// ====================================================================================================
#endif
63 changes: 63 additions & 0 deletions Inc/tpiuDecoder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* TPIU Decoder Module
* ===================
*
* Copyright (C) 2017 Dave Marples <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _TPIU_DECODER_
#define _TPIU_DECODER_

#include <stdint.h>

#ifndef BOOL
#define BOOL int
#define FALSE (0)
#define TRUE (!FALSE)
#endif

enum TPIUPumpEvent {TPIU_EV_NONE, TPIU_EV_UNSYNCED, TPIU_EV_SYNCED, TPIU_EV_RXING, TPIU_EV_RXEDPACKET, TPIU_EV_ERROR};
enum TPIUPumpState {TPIU_UNSYNCED, TPIU_SYNCED, TPIU_RXING, TPIU_ERROR };

#define TPIU_PACKET_LEN (16)

struct TPIUDecoder {
enum TPIUPumpState state;
uint8_t byteCount;
uint8_t currentStream;
uint32_t syncMonitor;
int32_t delayedStreamChange;
struct timeval lastPacket;
BOOL isLive;
uint8_t rxedPacket[TPIU_PACKET_LEN];
};

struct TPIUPacket {
uint8_t len;
struct
{
int8_t s;
int8_t d;
} packet[TPIU_PACKET_LEN];
};

// ====================================================================================================
void TPIUDecoderInit(struct TPIUDecoder *t, BOOL isLiveSet);
void TPIUDecoderForceSync(struct TPIUDecoder *t, uint8_t offset);
BOOL TPIUGetPacket(struct TPIUDecoder *t, struct TPIUPacket *p);
enum TPIUPumpEvent TPIUPump(struct TPIUDecoder *t, uint8_t d);
// ====================================================================================================
#endif
130 changes: 130 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#VERBOSE=1
DEBUG=1

##########################################################################
# User configuration and firmware specific object files
##########################################################################

# Overall system defines for compilation
ifdef DEBUG
GCC_DEFINE= -DDEBUG
OPT_LEVEL =
else
GCC_DEFINE=
OPT_LEVEL = -O2
endif

GCC_DEFINE+= -std=gnu99

CFILES =
SFILES =
OLOC = ofiles
INCLUDE_PATHS = -I/usr/local/include/libusb-1.0
LDLIBS = -L/usr/local/lib -lusb-1.0
DEBUG_OPTS = -g3 -gdwarf-2 -ggdb

##########################################################################
# Generic multi-project files
##########################################################################

##########################################################################
# Project-specific files
##########################################################################

# Main Files
# ==========
App_DIR=Src
App_Inc_DIR=Inc
INCLUDE_PATHS += -IInc -I$(OLOC)
INCLUDE_PATHS += $(patsubst %,-I%,$(shell find $(App_Inc_DIR) -name "*.h" -exec dirname {} \; | uniq ))
CFILES += $(shell find $(App_DIR) -name "*.c" -print)

##########################################################################
# GNU GCC compiler prefix and location
##########################################################################

CROSS_COMPILE =
ASTYLE = astyle
AS = $(CROSS_COMPILE)gcc
CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)gcc
GDB = $(CROSS_COMPILE)gdb
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
GET_GIT_HASH = Tools/git_hash_to_c/git_hash_to_c.sh
MAKE = make
OUTFILE = orbuculum

##########################################################################
# Quietening
##########################################################################

ifdef VERBOSE
cmd = $1
Q :=
else
cmd = @$(if $(value 2),echo "$2";)$1
Q := @
endif

HOST=-lc -lusb


##########################################################################
# Compiler settings, parameters and flags
##########################################################################
# filename for embedded git revision
GIT_HASH_FILENAME=git_version_info.h

CFLAGS = $(ARCH_FLAGS) $(STARTUP_DEFS) $(OPT_LEVEL) $(DEBUG_OPTS) \
-ffunction-sections -fdata-sections -Wall $(INCLUDE_PATHS) $(GCC_DEFINE)
ASFLAGS = -c $(DEBUG_OPTS) $(INCLUDE_PATHS) $(ARCH_FLAGS) $(GCC_DEFINE) \
-x assembler-with-cpp
LDFLAGS = $(CFLAGS)

OCFLAGS = --strip-unneeded

OBJS = $(patsubst %.c,%.o,$(CFILES)) $(patsubst %.s,%.o,$(SFILES))
POBJS = $(patsubst %,$(OLOC)/%,$(OBJS))
PDEPS =$(POBJS:.o=.d)

all : build

get_version:
$(Q)$(GET_GIT_HASH) > $(OLOC)/$(GIT_HASH_FILENAME)

$(OLOC)/%.o : %.c
$(Q)mkdir -p $(basename $@)
$(call cmd, \$(CC) -c $(CFLAGS) -MMD -o $@ $< ,\
Compiling $<)

build: get_version $(POBJS) $(SYS_OBJS)
$(Q)$(LD) $(LDFLAGS) -o $(OLOC)/$(OUTFILE) $(MAP) $(POBJS) $(LDLIBS)

tags:
-@etags $(CFILES) 2> /dev/null

clean:
-$(call cmd, \rm -f $(POBJS) $(LD_TEMP) $(OUTFILE) $(OUTFILE).map $(EXPORT) ,\
Cleaning )
$(Q)-rm -rf SourceDoc/*
$(Q)-rm -rf *~ core
$(Q)-rm -rf $(OLOC)/*
$(Q)-rm -rf config/*~
$(Q)-rm -rf TAGS

$(generated_dir)/git_head_revision.c:
mkdir -p $(dir $@)
../Tools/git_hash_to_c.sh > $@

doc:
doxygen $(DOXCONFIG)

print-%:
@echo $* is $($*)

pretty:
#The exclude is needed to prevent prettifying the cyclic link..no detrimental impact
$(Q)-$(ASTYLE) --options=config/astyle.conf "*.h" "*.c"

-include $(PDEPS)
Loading

0 comments on commit e0ef6d5

Please sign in to comment.