microbit: Removal of explicit Serial instance for debugging.

Debugging now runs via the standrad MicroBit::serial interface.
This commit is contained in:
Joe Finney 2015-11-01 23:42:53 +00:00
parent 99ac37e454
commit 13456c60c1
5 changed files with 23 additions and 33 deletions

View file

@ -62,10 +62,6 @@
#define MICROBIT_PIN_SDA P0_30
#define MICROBIT_PIN_SCL P0_0
#if CONFIG_ENABLED(MICROBIT_DBG)
extern Serial pc;
#endif
/**
* Class definition for a MicroBit device.
*
@ -90,9 +86,7 @@ class MicroBit
MicroBitI2C i2c;
// Serial Interface
#if CONFIG_DISABLED(MICROBIT_DBG)
MicroBitSerial serial;
#endif
// Array of components which are iterated during a system tick
MicroBitComponent* systemTickComponents[MICROBIT_SYSTEM_COMPONENTS];

View file

@ -58,9 +58,7 @@ void bleDisconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t r
MicroBit::MicroBit() :
flags(0x00),
i2c(MICROBIT_PIN_SDA, MICROBIT_PIN_SCL),
#if CONFIG_DISABLED(MICROBIT_DBG)
serial(USBTX, USBRX),
#endif
MessageBus(),
display(MICROBIT_ID_DISPLAY, MICROBIT_DISPLAY_WIDTH, MICROBIT_DISPLAY_HEIGHT),
buttonA(MICROBIT_ID_BUTTON_A,MICROBIT_PIN_BUTTON_A, MICROBIT_BUTTON_SIMPLE_EVENTS),
@ -92,6 +90,9 @@ MicroBit::MicroBit() :
*/
void MicroBit::init()
{
// Set the default baud rate for the serial port.`
uBit.serial.baud(115200);
//add the display to the systemComponent array
addSystemComponent(&uBit.display);

View file

@ -62,13 +62,13 @@ void microbit_heap_print(HeapDefinition &heap)
if (heap.heap_start == NULL)
{
pc.printf("--- HEAP NOT INITIALISED ---\n");
uBit.serial.printf("--- HEAP NOT INITIALISED ---\n");
return;
}
pc.printf("heap_start : %p\n", heap.heap_start);
pc.printf("heap_end : %p\n", heap.heap_end);
pc.printf("heap_size : %d\n", (int)heap.heap_end - (int)heap.heap_start);
uBit.serial.printf("heap_start : %p\n", heap.heap_start);
uBit.serial.printf("heap_end : %p\n", heap.heap_end);
uBit.serial.printf("heap_size : %d\n", (int)heap.heap_end - (int)heap.heap_start);
// Disable IRQ temporarily to ensure no race conditions!
__disable_irq();
@ -77,10 +77,10 @@ void microbit_heap_print(HeapDefinition &heap)
while (block < heap.heap_end)
{
blockSize = *block & ~MICROBIT_HEAP_BLOCK_FREE;
pc.printf("[%C:%d] ", *block & MICROBIT_HEAP_BLOCK_FREE ? 'F' : 'U', blockSize*4);
uBit.serialpc.printf("[%C:%d] ", *block & MICROBIT_HEAP_BLOCK_FREE ? 'F' : 'U', blockSize*4);
if (cols++ == 20)
{
pc.printf("\n");
uBit.serial.printf("\n");
cols = 0;
}
@ -95,10 +95,10 @@ void microbit_heap_print(HeapDefinition &heap)
// Enable Interrupts
__enable_irq();
pc.printf("\n");
uBit.serial.printf("\n");
pc.printf("mb_total_free : %d\n", totalFreeBlock*4);
pc.printf("mb_total_used : %d\n", totalUsedBlock*4);
uBit.serial.printf("mb_total_free : %d\n", totalFreeBlock*4);
uBit.serial.printf("mb_total_used : %d\n", totalUsedBlock*4);
}
@ -108,7 +108,7 @@ void microbit_heap_print()
{
for (int i=0; i < MICROBIT_HEAP_COUNT; i++)
{
pc.printf("\nHEAP %d: \n", i);
uBit.serial.printf("\nHEAP %d: \n", i);
microbit_heap_print(heap[i]);
}
}
@ -329,7 +329,7 @@ void *microbit_malloc(size_t size)
if (p != NULL)
{
#if CONFIG_ENABLED(MICROBIT_DBG) && CONFIG_ENABLED(MICROBIT_HEAP_DBG)
pc.printf("microbit_malloc: ALLOCATED: %d [%p]\n", size, p);
pc.uBit.serial("microbit_malloc: ALLOCATED: %d [%p]\n", size, p);
#endif
return p;
}
@ -345,7 +345,7 @@ void *microbit_malloc(size_t size)
#if CONFIG_ENABLED(MICROBIT_DBG) && CONFIG_ENABLED(MICROBIT_HEAP_DBG)
// Keep everything trasparent if we've not been initialised yet
if (microbit_active_heaps())
pc.printf("microbit_malloc: NATIVE ALLOCATED: %d [%p]\n", size, p);
pc.uBit.serial("microbit_malloc: NATIVE ALLOCATED: %d [%p]\n", size, p);
#endif
return p;
}
@ -354,7 +354,7 @@ void *microbit_malloc(size_t size)
#if CONFIG_ENABLED(MICROBIT_DBG) && CONFIG_ENABLED(MICROBIT_HEAP_DBG)
// Keep everything trasparent if we've not been initialised yet
if (microbit_active_heaps())
pc.printf("microbit_malloc: OUT OF MEMORY\n");
pc.uBit.serial("microbit_malloc: OUT OF MEMORY\n");
#endif
#if CONFIG_ENABLED(MICROBIT_PANIC_HEAP_FULL)
@ -375,7 +375,7 @@ void microbit_free(void *mem)
#if CONFIG_ENABLED(MICROBIT_DBG) && CONFIG_ENABLED(MICROBIT_HEAP_DBG)
if (microbit_active_heaps())
pc.printf("microbit_free: %p\n", mem);
pc.uBit.serial("microbit_free: %p\n", mem);
#endif
// Sanity check.
if (memory == NULL)

View file

@ -1,9 +1,5 @@
#include "MicroBit.h"
#if CONFIG_ENABLED(MICROBIT_DBG)
Serial pc(USBTX, USBRX);
#endif
MicroBit uBit;
InterruptIn resetButton(MICROBIT_PIN_BUTTON_RESET);
@ -16,17 +12,16 @@ int main()
resetButton.fall(microbit_reset);
#if CONFIG_ENABLED(MICROBIT_DBG)
pc.baud(115200);
// For diagnostics. Gives time to open the console window. :-)
uBit.serial.baud(115200);
for (int i=3; i>0; i--)
{
pc.printf("=== SUPERMAIN: Starting in %d ===\n", i);
uBit.serial.printf("=== SUPERMAIN: Starting in %d ===\n", i);
wait(1.0);
}
pc.printf("micro:bit runtime DAL version %s\n", MICROBIT_DAL_VERSION);
uBit.serial.printf("micro:bit runtime DAL version %s\n", MICROBIT_DAL_VERSION);
#endif

View file

@ -117,7 +117,7 @@ void MicroBitDFUService::onDataWritten(const GattWriteCallbackParams *params)
uBit.display.clear();
#if CONFIG_ENABLED(MICROBIT_DBG)
pc.printf(" ACTIVATING BOOTLOADER.\n");
uBit.serial.printf(" ACTIVATING BOOTLOADER.\n");
#endif
bootloader_start();
}
@ -126,7 +126,7 @@ void MicroBitDFUService::onDataWritten(const GattWriteCallbackParams *params)
case MICROBIT_DFU_OPCODE_START_PAIR:
#if CONFIG_ENABLED(MICROBIT_DBG)
pc.printf(" PAIRING REQUESTED.\n");
uBit.serial.printf(" PAIRING REQUESTED.\n");
#endif
flashCodeRequested = true;
break;
@ -143,7 +143,7 @@ void MicroBitDFUService::onDataWritten(const GattWriteCallbackParams *params)
if (lockCode == NRF_FICR->DEVICEID[0])
{
#if CONFIG_ENABLED(MICROBIT_DBG)
pc.printf("MicroBitDFU: FLASHCODE AUTHENTICATED\n");
uBit.serial.printf("MicroBitDFU: FLASHCODE AUTHENTICATED\n");
#endif
authenticated = true;
}else{