[ion] Implement Log::print using SWO on the device

Change-Id: I17e024535cc0f0daf74953c7221e2b98959e6c47
This commit is contained in:
Romain Goyet
2017-02-14 10:57:30 +01:00
parent 2005a3d822
commit 724fdb18e7
6 changed files with 52 additions and 0 deletions

View File

@@ -8,6 +8,8 @@ set pagination off
load
# Tell OpenOCD to reset and halt
monitor itm ports on
monitor tpiu config internal swo.log.bin uart off 16000000
monitor reset halt
break init

View File

@@ -7,6 +7,7 @@ objs += $(addprefix ion/src/device/, \
display.o\
keyboard.o\
led.o\
log.o\
power.o\
sd_card.o\
)

15
ion/src/device/log.cpp Normal file
View File

@@ -0,0 +1,15 @@
#include <ion/log.h>
#include "regs/itm.h"
// We're printing using SWO.
// This is achieved by writing to the ITM register, which is sent through the
// Cortex Debug bus
void Ion::Log::print(const char * message) {
char character = 0;
while ((character = *message++) != 0) {
if (ITM.TER()->get(0)) {
ITM.STIM(0)->set(character);
}
}
}

32
ion/src/device/regs/itm.h Normal file
View File

@@ -0,0 +1,32 @@
#ifndef REGS_ITM_H
#define REGS_ITM_H
#include "register.h"
// See ARM Cortex M4 TRM
class ITM {
public:
class STIM : public Register8 {
};
// http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0314h/Chdbicac.html
class TER : Register32 {
public:
bool get(int index) volatile { return (bool)getBitRange(index, index); }
};
constexpr ITM() {};
volatile STIM * STIM(int i) const {
return (class STIM *)(Base() + 4*i);
};
REGS_REGISTER_AT(TER, 0xE00);
private:
constexpr uint32_t Base() const {
return 0xE0000000;
}
};
constexpr ITM ITM;
#endif

View File

@@ -37,6 +37,7 @@ private:
T m_value;
};
typedef Register<uint8_t> Register8;
typedef Register<uint16_t> Register16;
typedef Register<uint32_t> Register32;
typedef Register<uint64_t> Register64;

View File

@@ -8,6 +8,7 @@
#include "flash.h"
#include "fsmc.h"
#include "gpio.h"
#include "itm.h"
#include "pwr.h"
#include "rcc.h"
#include "sdio.h"