Skip to content

Commit

Permalink
Adding Serial USB functionality for debugging purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
davison-sm committed Apr 5, 2017
1 parent f02bbf2 commit d450413
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 62 deletions.
6 changes: 5 additions & 1 deletion jewelbots_friendship_v112/cores/Jewelbot_v1/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <math.h>

// Arduino specific code - C++
Expand All @@ -14,15 +16,17 @@
#include "Buzzer.h"
#include "Animation.h"
#include "Timer.h"
#include "JWB_Serial.h"


#ifdef __cplusplus
extern "C"{
#endif // __cplusplus

#include "arm_math.h"
#include "utils.h"
#include "fsm.h"
#include "led_sequence.h"
#include "nrf_log.h"

/* sketch */
extern void setup( void ) ;
Expand Down
52 changes: 52 additions & 0 deletions jewelbots_friendship_v112/cores/Jewelbot_v1/JWB_Serial.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include <math.h>
#include "Arduino.h"
#include "JWB_Serial.h"
#ifdef __cplusplus
extern "C"{
#endif // __cplusplus
#include "app_uart.h"
#include "nrf.h"
#include "nrf_log.h"
#include "nrf_error.h"
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus

__INLINE void jwb_uart_write(const char * msg)
{
while( *msg )
{
NRF_UART0->TXD = *msg++;
while( NRF_UART0->EVENTS_TXDRDY != 1 );
NRF_UART0->EVENTS_TXDRDY = 0;
}
}

void jwb_uart_write_many(int num_args, ...)
{
const char* msg;
va_list p_args;
va_start(p_args, num_args);

for (int i = 0; i < num_args; i++)
{
msg = va_arg(p_args, const char*);
jwb_uart_write(msg);
}
va_end(p_args);
}

void jwb_uart_printf(const char * format_msg, ...)
{
static char buffer[256];
va_list p_args;
va_start(p_args, format_msg);
vsprintf(buffer, format_msg, p_args);
va_end(p_args);
jwb_uart_write(buffer);
}
21 changes: 21 additions & 0 deletions jewelbots_friendship_v112/cores/Jewelbot_v1/JWB_Serial.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef __JWB_SERIAL_H__
#define __JWB_SERIAL_H__

#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include "Arduino.h"

void jwb_uart_write(const char * str);
void jwb_uart_write_many(int num_args, ...);
void jwb_uart_printf(const char * format_msg, ...);

#define JWB_SERIAL(...) jwb_uart_write_many(NUM_VA_ARGS(__VA_ARGS__), ##__VA_ARGS__)
#define JWB_SERIAL_PRINTF(...) jwb_uart_printf(__VA_ARGS__)




#endif
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,10 @@ void jwb_charging(jewelbot_t *me, jwb_event const *e) {
disable_led();
set_jwb_event_signal(JEWELBOT_ON_SIG);
} else {
set_arduino_coding_false();
led_indicate_charging_state(pmic_is_charging());
if (!get_run_loop_charging()) {
set_arduino_coding_false();
led_indicate_charging_state(pmic_is_charging());
}
}
break; // wait
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

bool arduino_coding = false;
bool arduino_button = false;
bool run_loop_charging = false;

void set_arduino_coding(void) { arduino_coding = true; }
void set_arduino_coding_false(void) { arduino_coding = false; }
Expand All @@ -18,6 +19,9 @@ bool get_arduino_coding(void) { return arduino_coding; }
void set_arduino_button(void) { arduino_button = true; }
bool get_arduino_button(void) { return arduino_button; }

void set_run_loop_charging(void) {run_loop_charging = true; }
bool get_run_loop_charging(void) { return run_loop_charging; }

void ble_address_to_string_convert(ble_gap_addr_t address,
uint8_t *string_buffer) {
const int address_length = 6;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ bool get_arduino_coding(void);
void set_arduino_button(void);
bool get_arduino_button(void);

void set_run_loop_charging(void);
bool get_run_loop_charging(void);


#endif

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ uint32_t log_uart_read_input(char * c)
#include "app_uart.h"
#include <stdio.h>
#include <string.h>
#include "bsp.h"
#include "jewelbot_gpio.h"

uint32_t log_raw_uart_init()
{
Expand All @@ -291,7 +291,7 @@ uint32_t log_raw_uart_init()

// Set a default baud rate of UART0_CONFIG_BAUDRATE
NRF_UART0->PSELTXD = TX_PIN_NUMBER;
NRF_UART0->BAUDRATE = UART0_CONFIG_BAUDRATE;
NRF_UART0->BAUDRATE = UART_BAUDRATE_BAUDRATE_Baud38400;

NRF_UART0->PSELRTS = 0xFFFFFFFF;
NRF_UART0->PSELCTS = 0xFFFFFFFF;
Expand All @@ -309,6 +309,7 @@ uint32_t log_raw_uart_init()
return NRF_SUCCESS;
}


void log_raw_uart_printf(const char * format_msg, ...)
{
static char buffer[256];
Expand Down Expand Up @@ -422,4 +423,3 @@ const char* log_hex(uint32_t value)

return (const char*)hex_string;
}

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#endif

#ifndef NRF_LOG_USES_RAW_UART
#define NRF_LOG_USES_RAW_UART 0
#define NRF_LOG_USES_RAW_UART 1
#endif

#ifndef NRF_LOG_USES_COLORS
Expand Down Expand Up @@ -408,6 +408,7 @@ uint32_t log_raw_uart_init(void);
*/
void log_raw_uart_printf(const char * format_msg, ...);


/**@brief Function for logging a single character to raw UART.
*
* This function is available only when NRF_LOG_USES_RAW_UART is defined as 1.
Expand Down
2 changes: 0 additions & 2 deletions jewelbots_friendship_v112/platform.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ compiler.S.flags=-mcpu=cortex-m0 -mthumb
# Compile c files options
compiler.c.cmd=arm-none-eabi-gcc
compiler.c.flags=-c -g -Os -w -std=gnu99 -fno-common -fmessage-length=0 -Wall -fno-exceptions -ffunction-sections -fdata-sections -fomit-frame-pointer -nostdlib --param max-inline-insns-single=500 -DSOFTDEVICE_PRESENT -DNRF51 -DS130 -DBLE_STACK_SUPPORT_REQD -DREAL_JEWELBOT -DTOOLCHAIN_GCC_ARM -DTOOLCHAIN_GCC -D__CORTEX_M0 -DARM_MATH_CM0

# Compile cpp files options
compiler.cpp.cmd=arm-none-eabi-g++
compiler.cpp.flags=-c -g -Os -w -std=gnu++98 -fno-common -fmessage-length=0 -Wall -fno-exceptions -ffunction-sections -fdata-sections -fomit-frame-pointer -nostdlib --param max-inline-insns-single=500 -fno-rtti -DSOFTDEVICE_PRESENT -DNRF51 -DS130 -DBLE_STACK_SUPPORT_REQD -DREAL_JEWELBOT -DTOOLCHAIN_GCC_ARM -DTOOLCHAIN_GCC -D__CORTEX_M0 -DARM_MATH_CM0

# Create archives options
compiler.ar.cmd=arm-none-eabi-ar
compiler.ar.flags=rcs
Expand Down

0 comments on commit d450413

Please sign in to comment.