All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH atusb/fw v2 0/2] atusb/fw: Firmware patch to support HULUSB v2
@ 2017-09-11 11:58 Josef Filzmaier
  2017-09-11 11:58 ` [PATCH atusb/fw v2 1/2] atusb/fw: Introduce DEBUG flag Josef Filzmaier
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Josef Filzmaier @ 2017-09-11 11:58 UTC (permalink / raw)
  To: linux-wpan; +Cc: Josef Filzmaier

This patch (in combination with the linux kernel patch)
introduces support for the Busware HUL stick. There are two 
commits, one that enables UART debugging (for convenience purposes)
and another that modularizes the firmware to better support
multiple hardware targets. As the Busware HUL stick uses the
at86rf212 transceiver there have been a few modifications to
support this transceiver. Otherwise this board is very similar to the
already existing atusb and rzusb boards, meaning most of the code
can be shared. (e.g. it also uses the at90usb1287 microcontroller).

Josef Filzmaier (2):
  atusb/fw: Introduce DEBUG flag
  atusb/fw: Introduction of a new board named HULUSB

 atusb/fw/Makefile              |  16 +++-
 atusb/fw/atusb.c               |  11 +++
 atusb/fw/board.c               |  68 ++++++++++------
 atusb/fw/board.h               |   9 +++
 atusb/fw/board_atusb.c         |  40 +++++++++
 atusb/fw/board_hulusb.c        | 179 +++++++++++++++++++++++++++++++++++++++++
 atusb/fw/board_hulusb.h        |  66 +++++++++++++++
 atusb/fw/board_rzusb.c         |  40 +++++++++
 atusb/fw/ep0.c                 |  15 +++-
 atusb/fw/include/atusb/atusb.h |   8 ++
 atusb/fw/include/atusb/ep0.h   |   5 --
 atusb/fw/mac.c                 |  32 --------
 atusb/fw/uart.c                |  64 +++++++++++++++
 atusb/fw/uart.h                |  25 ++++++
 14 files changed, 513 insertions(+), 65 deletions(-)
 create mode 100644 atusb/fw/board_hulusb.c
 create mode 100644 atusb/fw/board_hulusb.h
 create mode 100644 atusb/fw/uart.c
 create mode 100644 atusb/fw/uart.h

-- 
2.14.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH atusb/fw v2 1/2] atusb/fw: Introduce DEBUG flag
  2017-09-11 11:58 [PATCH atusb/fw v2 0/2] atusb/fw: Firmware patch to support HULUSB v2 Josef Filzmaier
@ 2017-09-11 11:58 ` Josef Filzmaier
  2017-09-11 11:58 ` [PATCH atusb/fw v2 2/2] atusb/fw: Introduction of a new board named HULUSB Josef Filzmaier
  2017-09-13 16:08 ` [PATCH atusb/fw v2 0/2] atusb/fw: Firmware patch to support HULUSB v2 Stefan Schmidt
  2 siblings, 0 replies; 4+ messages in thread
From: Josef Filzmaier @ 2017-09-11 11:58 UTC (permalink / raw)
  To: linux-wpan; +Cc: Josef Filzmaier

This flag can be used to enable debugging over uart. Currently only
available for boards with the at90usb1287 chip.

Signed-off-by: Josef Filzmaier <j.filzmaier@gmx.at>
---
 atusb/fw/Makefile | 10 ++++++++-
 atusb/fw/atusb.c  | 11 ++++++++++
 atusb/fw/ep0.c    |  7 ++++++
 atusb/fw/uart.c   | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 atusb/fw/uart.h   | 25 ++++++++++++++++++++++
 5 files changed, 116 insertions(+), 1 deletion(-)
 create mode 100644 atusb/fw/uart.c
 create mode 100644 atusb/fw/uart.h

diff --git a/atusb/fw/Makefile b/atusb/fw/Makefile
index c1c68d7..4cc749c 100644
--- a/atusb/fw/Makefile
+++ b/atusb/fw/Makefile
@@ -1,5 +1,5 @@
 #
-# Makefile - Makefile of the ATUSB firmware 
+# Makefile - Makefile of the ATUSB firmware
 #
 # Written 2010-2011, 2013 by Werner Almesberger
 # Copyright 2010-2011, 2013 by Werner Almesberger
@@ -13,11 +13,16 @@
 SHELL = /bin/bash
 
 NAME = atusb
+DEBUG = false
 
 CFLAGS = -g -mmcu=$(CHIP) -DBOOT_ADDR=$(BOOT_ADDR) \
 	 -Wall -Wextra -Wshadow -Werror -Wno-unused-parameter \
 	 -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes
 
+ifeq ($(DEBUG),true)
+CFLAGS += -DDEBUG
+endif
+
 ifeq ($(NAME),rzusb)
 CHIP=at90usb1287
 CFLAGS += -DRZUSB -DAT86RF230
@@ -46,6 +51,9 @@ OBJS = atusb.o board.o board_app.o sernum.o spi.o descr.o ep0.o \
 BOOT_OBJS = boot.o board.o sernum.o spi.o flash.o dfu.o \
             dfu_common.o usb.o boot-atu2.o
 
+ifeq ($(DEBUG),true)
+OBJS +=  uart.o
+endif
 
 ifeq ($(NAME),rzusb)
 OBJS += board_rzusb.o
diff --git a/atusb/fw/atusb.c b/atusb/fw/atusb.c
index 1f65d53..28faf40 100644
--- a/atusb/fw/atusb.c
+++ b/atusb/fw/atusb.c
@@ -24,6 +24,10 @@
 #include "spi.h"
 #include "atusb/ep0.h"
 
+#ifdef DEBUG
+#include "uart.h"
+#endif
+
 
 int main(void)
 {
@@ -35,6 +39,13 @@ int main(void)
 
 	/* now we should be at 8 MHz */
 
+#ifdef DEBUG
+	uart_init();
+	static FILE atben_stdout = FDEV_SETUP_STREAM(uart_write_char, NULL,
+						     _FDEV_SETUP_WRITE);
+	stdout = &atben_stdout;
+#endif
+
 	usb_init();
 	ep0_init();
 #ifdef ATUSB
diff --git a/atusb/fw/ep0.c b/atusb/fw/ep0.c
index 2b92f6d..674f9de 100644
--- a/atusb/fw/ep0.c
+++ b/atusb/fw/ep0.c
@@ -45,8 +45,15 @@
 #define	HW_TYPE		HW_TYPE_RZUSB
 #endif
 
+#ifdef DEBUG
+#include "uart.h"
+#include <stdio.h>
+#define debug(FORMAT,args...) printf(FORMAT,##args)
+#define error(FORMAT,args...) printf(FORMAT,##args)
+#else
 #define debug(...)
 #define error(...)
+#endif
 
 
 static const uint8_t id[] = { EP0ATUSB_MAJOR, EP0ATUSB_MINOR, HW_TYPE };
diff --git a/atusb/fw/uart.c b/atusb/fw/uart.c
new file mode 100644
index 0000000..44bec27
--- /dev/null
+++ b/atusb/fw/uart.c
@@ -0,0 +1,64 @@
+/*
+ * fw/uart.h - Functions needed for debugging over uart
+ *
+ * Code adapted from http://www.roboternetz.de/wissen/index.php/UART_mit_avr-gcc
+ * and http://www.mikrocontroller.net/articles/AVR-GCC-Tutorial
+ *
+ * Published under the Creative Commons Share-Alike licence
+ * https://creativecommons.org/licenses/by-sa/2.0/de/
+ *
+ * S. Salewski 2007
+ *
+ * Adapted by
+ * Josef Filzmaier 2017
+ */
+
+#include <avr/io.h>
+#include "uart.h"
+
+#define USART_BAUD 38400UL
+#define F_CPU 8000000UL
+
+#define Wait_USART_Ready() while (!(UCSR1A & (1<<UDRE1)))
+#define UART_UBRR (F_CPU/(16L*USART_BAUD)-1)
+
+// initialize USART, 8N1 mode
+void
+uart_init(void)
+{
+/* TODO: Find a working configuration for uart for the atmega32u2 */
+#if CHIP == at90usb1287
+	CLKPR = (1 << CLKPCE);
+	CLKPR = 0; // clock prescaler == 0, so we have 16 MHz mpu frequency
+	UBRR1 = UART_UBRR;
+	UCSR1C = (1 << UCSZ10) | (1 << UCSZ11);
+	UCSR1B = (1 << TXEN1);
+	do
+	{
+		UDR1;
+	}
+	while (UCSR1A & (1 << RXC1));
+#endif
+
+}
+
+int uart_write_char(char c, FILE* stream)
+{
+	if (c == '\n'){
+		uart_new_line();
+	}
+	else {
+		Wait_USART_Ready();
+		UDR1 = c;
+	}
+	return 0;
+}
+
+void
+uart_new_line(void)
+{
+	Wait_USART_Ready();
+	UDR1 = '\r';
+	Wait_USART_Ready();
+	UDR1 = '\n';
+}
diff --git a/atusb/fw/uart.h b/atusb/fw/uart.h
new file mode 100644
index 0000000..4810f9c
--- /dev/null
+++ b/atusb/fw/uart.h
@@ -0,0 +1,25 @@
+/*
+ * fw/uart.h - Functions needed for debugging over uart
+ *
+ * Code adapted from http://www.roboternetz.de/wissen/index.php/UART_mit_avr-gcc
+ * and http://www.mikrocontroller.net/articles/AVR-GCC-Tutorial
+ *
+ * Published under the Creative Commons Share-Alike licence
+ * https://creativecommons.org/licenses/by-sa/2.0/de/
+ *
+ * S. Salewski 2007
+ *
+ * Adapted by
+ * Josef Filzmaier 2017
+ */
+
+#ifndef UART_H_
+#define	UART_H_
+
+#include <stdio.h>
+
+void uart_init(void);
+int uart_write_char(char c, FILE* stream);
+void uart_new_line(void);
+
+#endif /* UART_H_ */
-- 
2.14.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH atusb/fw v2 2/2] atusb/fw: Introduction of a new board named HULUSB
  2017-09-11 11:58 [PATCH atusb/fw v2 0/2] atusb/fw: Firmware patch to support HULUSB v2 Josef Filzmaier
  2017-09-11 11:58 ` [PATCH atusb/fw v2 1/2] atusb/fw: Introduce DEBUG flag Josef Filzmaier
@ 2017-09-11 11:58 ` Josef Filzmaier
  2017-09-13 16:08 ` [PATCH atusb/fw v2 0/2] atusb/fw: Firmware patch to support HULUSB v2 Stefan Schmidt
  2 siblings, 0 replies; 4+ messages in thread
From: Josef Filzmaier @ 2017-09-11 11:58 UTC (permalink / raw)
  To: linux-wpan; +Cc: Josef Filzmaier

The Busware HUL v1.1 dongle is a product very similar
to the rzusb dongle but with the at86rf212 instead of
the at86rf230 transceiver.

Some code refactoring has been made in order to better
support multiple hardware targets. This includes:

The reset_rf functions are now in the board specific files.
The led functions are now in the board specific files.
The register read/write functions are moved from mac.c to the generic
board.c file as they are used by functions like reset_rf that are
not within the mac.c file. Also the subreg_read and subreg_write
functions were introduced for convenience.
The function to change state is now also in board.c.

The hardware types are moved into the atusb.h file (which is always
synchrornized with the linux atusb driver) because they are now used
by the driver to identify and configure the hardware.

Within the makefile a new target name is specified called: hulusb

Signed-off-by: Josef Filzmaier <j.filzmaier@gmx.at>
---
 atusb/fw/Makefile              |   6 ++
 atusb/fw/board.c               |  68 ++++++++++------
 atusb/fw/board.h               |   9 +++
 atusb/fw/board_app.c           |   2 +-
 atusb/fw/board_atusb.c         |  40 +++++++++
 atusb/fw/board_hulusb.c        | 179 +++++++++++++++++++++++++++++++++++++++++
 atusb/fw/board_hulusb.h        |  66 +++++++++++++++
 atusb/fw/board_rzusb.c         |  40 +++++++++
 atusb/fw/ep0.c                 |   8 +-
 atusb/fw/include/atusb/atusb.h |   8 ++
 atusb/fw/include/atusb/ep0.h   |   5 --
 atusb/fw/mac.c                 |  40 ++-------
 12 files changed, 406 insertions(+), 65 deletions(-)
 create mode 100644 atusb/fw/board_hulusb.c
 create mode 100644 atusb/fw/board_hulusb.h

diff --git a/atusb/fw/Makefile b/atusb/fw/Makefile
index 4cc749c..c79cb26 100644
--- a/atusb/fw/Makefile
+++ b/atusb/fw/Makefile
@@ -26,6 +26,9 @@ endif
 ifeq ($(NAME),rzusb)
 CHIP=at90usb1287
 CFLAGS += -DRZUSB -DAT86RF230
+else ifeq ($(NAME),hulusb)
+CHIP=at90usb1287
+CFLAGS += -DHULUSB -DAT86RF212
 else
 CHIP=atmega32u2
 CFLAGS += -DATUSB -DAT86RF231
@@ -58,6 +61,9 @@ endif
 ifeq ($(NAME),rzusb)
 OBJS += board_rzusb.o
 BOOT_OBJS += board_rzusb.o
+else ifeq ($(NAME),hulusb)
+OBJS += board_hulusb.o
+BOOT_OBJS += board_hulusb.o
 else
 OBJS += board_atusb.o
 BOOT_OBJS += board_atusb.o
diff --git a/atusb/fw/board.c b/atusb/fw/board.c
index 8567589..c3b8d26 100644
--- a/atusb/fw/board.c
+++ b/atusb/fw/board.c
@@ -29,45 +29,63 @@
 
 uint8_t board_sernum[42] = { 42, USB_DT_STRING };
 
-void reset_rf(void)
+/* ----- Register access --------------------------------------------------- */
+
+void change_state(uint8_t new)
 {
-	/* set up all the outputs; default port value is 0 */
+	while ((reg_read(REG_TRX_STATUS) & TRX_STATUS_MASK) ==
+		TRX_STATUS_TRANSITION);
+	reg_write(REG_TRX_STATE, new);
+}
 
-	DDRB = 0;
-	DDRC = 0;
-	DDRD = 0;
-	PORTB = 0;
-	PORTC = 0;
-	PORTD = 0;
 
-	OUT(LED);
-	OUT(nRST_RF);   /* this also resets the transceiver */
-	OUT(SLP_TR);
+uint8_t reg_read(uint8_t reg)
+{
+	uint8_t value;
 
-	spi_init();
+	spi_begin();
+	spi_send(AT86RF230_REG_READ | reg);
+	value = spi_recv();
+	spi_end();
 
-	/* AT86RF231 data sheet, 12.4.13, reset pulse width: 625 ns (min) */
+	return value;
+}
 
-	CLR(nRST_RF);
-	_delay_us(2);
-	SET(nRST_RF);
 
-	/* 12.4.14: SPI access latency after reset: 625 ns (min) */
+uint8_t subreg_read(uint8_t address, uint8_t mask, uint8_t position)
+{
+	/* Read current register value and mask out subregister. */
+	uint8_t register_value = reg_read(address);
+	register_value &= mask;
+	register_value >>= position; /* Align subregister value. */
 
-	_delay_us(2);
+	return register_value;
+}
 
-	/* we must restore TRX_CTRL_0 after each reset (9.6.4) */
 
-	set_clkm();
+void reg_write(uint8_t reg, uint8_t value)
+{
+	spi_begin();
+	spi_send(AT86RF230_REG_WRITE | reg);
+	spi_send(value);
+	spi_end();
 }
 
 
-void led(bool on)
+void subreg_write(uint8_t address, uint8_t mask, uint8_t position, uint8_t value)
 {
-	if (on)
-		SET(LED);
-	else
-		CLR(LED);
+	/* Read current register value and mask area outside the subregister. */
+	uint8_t register_value = reg_read(address);
+	register_value &= ~mask;
+
+	/* Start preparing the new subregister value. shift in place and mask. */
+	value <<= position;
+	value &= mask;
+
+	value |= register_value; /* Set the new subregister value. */
+
+	/* Write the modified register value. */
+	reg_write(address, value);
 }
 
 
diff --git a/atusb/fw/board.h b/atusb/fw/board.h
index 78a9065..dbcd410 100644
--- a/atusb/fw/board.h
+++ b/atusb/fw/board.h
@@ -24,6 +24,9 @@
 #ifdef RZUSB
 #include "board_rzusb.h"
 #endif
+#ifdef HULUSB
+#include "board_hulusb.h"
+#endif
 
 #define	SET_2(p, b)	PORT##p |= 1 << (b)
 #define	CLR_2(p, b)	PORT##p &= ~(1 << (b))
@@ -83,4 +86,10 @@ void get_sernum(void);
 
 void board_app_init(void);
 
+uint8_t reg_read(uint8_t reg);
+uint8_t subreg_read(uint8_t address, uint8_t mask, uint8_t position);
+void reg_write(uint8_t reg, uint8_t value);
+void subreg_write(uint8_t address, uint8_t mask, uint8_t position, uint8_t value);
+void change_state(uint8_t new);
+
 #endif /* !BOARD_H */
diff --git a/atusb/fw/board_app.c b/atusb/fw/board_app.c
index 815f4da..1fa9bf4 100644
--- a/atusb/fw/board_app.c
+++ b/atusb/fw/board_app.c
@@ -154,7 +154,7 @@ static void done(void *user)
 
 uint8_t irq_serial;
 
-#ifdef ATUSB
+#if defined(ATUSB) || defined(HULUSB)
 ISR(INT0_vect)
 #endif
 #ifdef RZUSB
diff --git a/atusb/fw/board_atusb.c b/atusb/fw/board_atusb.c
index 518fe78..a02fb7f 100644
--- a/atusb/fw/board_atusb.c
+++ b/atusb/fw/board_atusb.c
@@ -29,6 +29,46 @@
 
 static bool spi_initialized = 0;
 
+void reset_rf(void)
+{
+	/* set up all the outputs; default port value is 0 */
+
+	DDRB = 0;
+	DDRC = 0;
+	DDRD = 0;
+	PORTB = 0;
+	PORTC = 0;
+	PORTD = 0;
+
+	OUT(LED);
+	OUT(nRST_RF);   /* this also resets the transceiver */
+	OUT(SLP_TR);
+
+	spi_init();
+
+	/* AT86RF231 data sheet, 12.4.13, reset pulse width: 625 ns (min) */
+
+	CLR(nRST_RF);
+	_delay_us(2);
+	SET(nRST_RF);
+
+	/* 12.4.14: SPI access latency after reset: 625 ns (min) */
+
+	_delay_us(2);
+
+	/* we must restore TRX_CTRL_0 after each reset (9.6.4) */
+
+	set_clkm();
+}
+
+void led(bool on)
+{
+	if (on)
+		SET(LED);
+	else
+		CLR(LED);
+}
+
 void set_clkm(void)
 {
 	/* switch CLKM to 8 MHz */
diff --git a/atusb/fw/board_hulusb.c b/atusb/fw/board_hulusb.c
new file mode 100644
index 0000000..084714e
--- /dev/null
+++ b/atusb/fw/board_hulusb.c
@@ -0,0 +1,179 @@
+/*
+ * fw/board_hulusb.c - Busware HUL Board-specific functions (for boot loader and application)
+ *
+ * Written 2017 by Filzmaier Josef
+ * Based on fw/board_rzusb written and Copyright 2016 Stefan Schmidt
+ *
+ * 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 2 of the License, or
+ * (at your option) any later version.
+ */
+
+
+#include <stdbool.h>
+#include <stdint.h>
+
+#include <avr/io.h>
+#include <avr/interrupt.h>
+#include <avr/boot.h>
+
+#define F_CPU   8000000UL
+#include <util/delay.h>
+
+#include "usb.h"
+#include "at86rf230.h"
+#include "board.h"
+#include "spi.h"
+#include "usb/usb.h"
+
+static bool spi_initialized = 0;
+
+void reset_rf(void)
+{
+	/* set up all the outputs; default port value is 0 */
+
+	DDRB = 0;
+	DDRC = 0;
+	DDRD = 0;
+	PORTB = 0;
+	PORTC = 0;
+	PORTD = 0;
+
+	OUT(LED_RED);
+	OUT(LED_GREEN);
+	SET(LED_RED); /* Leds are active low on HULUSB board */
+	CLR(LED_GREEN); /* Green Led indicates the dongle is running */
+	OUT(nRST_RF);   /* this also resets the transceiver */
+	OUT(SLP_TR);
+
+	spi_init();
+
+	/* AT86RF212 data sheet, Appendix B, p166 Power-On Reset procedure */
+	/*-----------------------------------------------------------------*/
+	CLR(SLP_TR);
+	SET(nRST_RF);
+	SET(nSS);
+	_delay_us(400);
+
+	CLR(nRST_RF);
+	_delay_us(2);
+	SET(nRST_RF);
+
+	/* 5.1.4.5: Wait t10: 625 ns (min) */
+
+	_delay_us(2);
+
+	reg_write(REG_TRX_CTRL_0, 0x19);
+
+	change_state(TRX_CMD_FORCE_TRX_OFF);
+	/*-----------------------------------------------------------------*/
+
+	/* we must restore TRX_CTRL_0 after each reset (7.7.4) */
+
+	set_clkm();
+}
+
+void led_red(bool on) {
+	if (on)
+		CLR(LED_RED);
+	else
+		SET(LED_RED);
+}
+
+void led_green(bool on) {
+	if (on)
+		CLR(LED_GREEN);
+	else
+		SET(LED_GREEN);
+}
+
+void led(bool on)
+{
+	led_red(on);
+}
+
+void set_clkm(void)
+{
+	/* CLKM is not connected on BUSWARE HUL and therefore it is running in
+	 * async mode. */
+	reg_write(REG_TRX_CTRL_0, 0x00);
+
+	/* TX_AUTO_CRC_ON, default disabled */
+	subreg_write(SR_TX_AUTO_CRC_ON, 1);
+}
+
+void board_init(void)
+{
+	/* Disable the watchdog timer */
+
+	MCUSR = 0;		/* Remove override */
+	WDTCSR |= 1 << WDCE;	/* Enable change */
+	WDTCSR = 1 << WDCE;	/* Disable watchdog while still enabling
+	change */
+
+	CLKPR = 1 << CLKPCE;
+	/* We start with a 16 MHz/8 clock. Put the prescaler to 2. */
+	CLKPR = 1 << CLKPS0;
+
+	get_sernum();
+}
+
+void spi_begin(void)
+{
+	if (!spi_initialized)
+		spi_init();
+	CLR(nSS);
+}
+
+void spi_off(void)
+{
+	spi_initialized = 0;
+	SPCR &= ~(1 << SPE);
+}
+
+void spi_init(void)
+{
+	SET(nSS);
+	OUT(SCLK);
+	OUT(MOSI);
+	OUT(nSS);
+	IN(MISO);
+
+	SPCR = (1 << SPE) | (1 << MSTR);
+	SPSR = (1 << SPI2X);
+
+	spi_initialized = 1;
+}
+
+void usb_init(void)
+{
+	USBCON |= 1 << FRZCLK;		/* freeze the clock */
+
+	/* enable the PLL and wait for it to lock */
+	/* TODO sheet page 50 For Atmel AT90USB128x only. Do not use with Atmel AT90USB64x. */
+	/*  FOR 8 XTAL Mhz only!!! */
+	PLLCSR = ((1 << PLLP1) | (1 << PLLP0));
+	PLLCSR |= 1 << PLLE;
+	while (!(PLLCSR & (1 << PLOCK)));
+
+	UHWCON |= (1 << UVREGE);
+
+	USBCON &= ~((1 << USBE) | (1 << OTGPADE));		/* reset the controller */
+	USBCON |= ((1 << USBE) | (1 << OTGPADE));
+
+	USBCON &= ~(1 << FRZCLK);	/* thaw the clock */
+
+	UDCON &= ~(1 << DETACH);	/* attach the pull-up */
+	UDIEN = 1 << EORSTE;		/* enable device interrupts  */
+	//	UDCON |= 1 << RSTCPU;		/* reset CPU on bus reset */
+
+	ep_init();
+}
+
+void board_app_init(void)
+{
+	/* enable INT0, trigger on rising edge */
+	EICRA = 1 << ISC01 | 1 << ISC00;
+	EIMSK = 1 << INT0;
+}
diff --git a/atusb/fw/board_hulusb.h b/atusb/fw/board_hulusb.h
new file mode 100644
index 0000000..a1dadf0
--- /dev/null
+++ b/atusb/fw/board_hulusb.h
@@ -0,0 +1,66 @@
+/*
+ * fw/board_hulusb.h - Busware HUL Board-specific functions (for boot loader and application)
+ *
+ * Written 2017 by Filzmaier Josef
+ * Based on fw/board_rzusb written and Copyright 2016 Stefan Schmidt
+ *
+ * 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 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#ifndef BOARD_HULUSB_H
+#define	BOARD_HULUSB_H
+
+#include <stdbool.h>
+#include <stdint.h>
+
+#define LED_RED_PORT		A
+#define LED_GREEN_PORT		A
+#define LED_RED_BIT		3
+#define LED_GREEN_BIT 		4
+#define LED_PORT		LED_RED_PORT
+#define LED_BIT		  	LED_RED_BIT
+
+#define nRST_RF_PORT		B
+#define nRST_RF_BIT	  	5
+#define SLP_TR_PORT		B
+#define SLP_TR_BIT	  	4
+
+#define SCLK_PORT		B
+#define SCLK_BIT	  	1
+#define MOSI_PORT		B
+#define MOSI_BIT	  	2
+
+#define MISO_PORT		B
+#define MISO_BIT	  	3
+#define nSS_PORT		B
+#define nSS_BIT		  	0
+#define IRQ_RF_PORT		D
+#define IRQ_RF_BIT	  	4
+
+#define SR_TX_AUTO_CRC_ON	0x04, 0x20, 5
+#define SR_CHANNEL		0x08, 0x1f, 0
+
+#define RG_CC_CTRL_1		(0x14)
+
+#define SPI_WAIT_DONE()	while ((SPSR & (1 << SPIF)) == 0)
+#define SPI_DATA	SPDR
+
+void set_clkm(void);
+void board_init(void);
+
+void led_red(bool on);
+void led_green(bool on);
+
+void spi_begin(void);
+void spi_off(void);
+void spi_init(void);
+
+#ifdef DEBUG
+void printStatus(void);
+#define PRINT_STATUS() printStatus()
+#endif
+
+#endif /* !BOARD_HULUSB_H */
diff --git a/atusb/fw/board_rzusb.c b/atusb/fw/board_rzusb.c
index 83333f8..e83d6fa 100644
--- a/atusb/fw/board_rzusb.c
+++ b/atusb/fw/board_rzusb.c
@@ -29,6 +29,46 @@
 
 static bool spi_initialized = 0;
 
+void reset_rf(void)
+{
+	/* set up all the outputs; default port value is 0 */
+
+	DDRB = 0;
+	DDRC = 0;
+	DDRD = 0;
+	PORTB = 0;
+	PORTC = 0;
+	PORTD = 0;
+
+	OUT(LED);
+	OUT(nRST_RF);   /* this also resets the transceiver */
+	OUT(SLP_TR);
+
+	spi_init();
+
+	/* AT86RF231 data sheet, 12.4.13, reset pulse width: 625 ns (min) */
+
+	CLR(nRST_RF);
+	_delay_us(2);
+	SET(nRST_RF);
+
+	/* 12.4.14: SPI access latency after reset: 625 ns (min) */
+
+	_delay_us(2);
+
+	/* we must restore TRX_CTRL_0 after each reset (9.6.4) */
+
+	set_clkm();
+}
+
+void led(bool on)
+{
+	if (on)
+		SET(LED);
+	else
+		CLR(LED);
+}
+
 void set_clkm(void)
 {
 	/* switch CLKM to 8 MHz */
diff --git a/atusb/fw/ep0.c b/atusb/fw/ep0.c
index 674f9de..fa43f3b 100644
--- a/atusb/fw/ep0.c
+++ b/atusb/fw/ep0.c
@@ -38,11 +38,15 @@
 #include "mac.h"
 
 #ifdef ATUSB
-#define	HW_TYPE		HW_TYPE_110131
+#define	HW_TYPE		ATUSB_HW_TYPE_110131
 #endif
 
 #ifdef RZUSB
-#define	HW_TYPE		HW_TYPE_RZUSB
+#define	HW_TYPE		ATUSB_HW_TYPE_RZUSB
+#endif
+
+#ifdef HULUSB
+#define HW_TYPE		ATUSB_HW_TYPE_HULUSB
 #endif
 
 #ifdef DEBUG
diff --git a/atusb/fw/include/atusb/atusb.h b/atusb/fw/include/atusb/atusb.h
index b22bbaa..555d14b 100644
--- a/atusb/fw/include/atusb/atusb.h
+++ b/atusb/fw/include/atusb/atusb.h
@@ -50,6 +50,14 @@ enum atusb_requests {
 	ATUSB_EUI64_READ,
 };
 
+enum {
+	ATUSB_HW_TYPE_100813,	/* 2010-08-13 */
+	ATUSB_HW_TYPE_101216,	/* 2010-12-16 */
+	ATUSB_HW_TYPE_110131,	/* 2011-01-31, ATmega32U2-based */
+	ATUSB_HW_TYPE_RZUSB,	/* Atmel Raven USB dongle with at86rf230 */
+	ATUSB_HW_TYPE_HULUSB,	/* Busware HUL USB dongle with at86rf212 */
+};
+
 /*
  * Direction	bRequest		wValue		wIndex	wLength
  *
diff --git a/atusb/fw/include/atusb/ep0.h b/atusb/fw/include/atusb/ep0.h
index dd76d8d..7777345 100644
--- a/atusb/fw/include/atusb/ep0.h
+++ b/atusb/fw/include/atusb/ep0.h
@@ -32,11 +32,6 @@
 #define EP0ATUSB_MAJOR	0	/* EP0 protocol, major revision */
 #define EP0ATUSB_MINOR	3	/* EP0 protocol, minor revision */
 
-#define	HW_TYPE_100813	0	/* 2010-08-13 */
-#define	HW_TYPE_101216	1	/* 2010-12-16 */
-#define	HW_TYPE_110131	2	/* 2011-01-31, ATmega32U2-based */
-#define	HW_TYPE_RZUSB	3	/* Atmel Raven USB dongle with at86rf230 */
-
 
 /*
  * bmRequestType:
diff --git a/atusb/fw/mac.c b/atusb/fw/mac.c
index 265d542..835002c 100644
--- a/atusb/fw/mac.c
+++ b/atusb/fw/mac.c
@@ -47,31 +47,6 @@ static inline void next_buf(uint8_t *index)
 }
 
 
-/* ----- Register access --------------------------------------------------- */
-
-
-static uint8_t reg_read(uint8_t reg)
-{
-	uint8_t value;
-
-	spi_begin();
-	spi_send(AT86RF230_REG_READ | reg);
-	value = spi_recv();
-	spi_end();
-
-	return value;
-}
-
-
-static void reg_write(uint8_t reg, uint8_t value)
-{
-	spi_begin();
-	spi_send(AT86RF230_REG_WRITE | reg);
-	spi_send(value);
-	spi_end();
-}
-
-
 /* ----- Interrupt handling ------------------------------------------------ */
 
 
@@ -101,13 +76,6 @@ static void tx_ack_done(void *user)
 	usb_next();
 }
 
-static void change_state(uint8_t new)
-{
-	while ((reg_read(REG_TRX_STATUS) & TRX_STATUS_MASK) ==
-	    TRX_STATUS_TRANSITION);
-	reg_write(REG_TRX_STATE, new);
-}
-
 static void rx_done(void *user)
 {
 	led(0);
@@ -223,6 +191,14 @@ static void do_tx(void *user)
 	 */
 	reg_write(REG_TRX_STATE, TRX_CMD_PLL_ON);
 #endif
+#ifdef AT86RF212
+	/*
+	* We use TRX_CMD_FORCE_PLL_ON instead of TRX_CMD_PLL_ON because a new
+	* reception may have begun while we were still working on the previous
+	* one.
+	*/
+	reg_write(REG_TRX_STATE, TRX_CMD_FORCE_PLL_ON);
+#endif
 
 	handle_irq();
 
-- 
2.14.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH atusb/fw v2 0/2] atusb/fw: Firmware patch to support HULUSB v2
  2017-09-11 11:58 [PATCH atusb/fw v2 0/2] atusb/fw: Firmware patch to support HULUSB v2 Josef Filzmaier
  2017-09-11 11:58 ` [PATCH atusb/fw v2 1/2] atusb/fw: Introduce DEBUG flag Josef Filzmaier
  2017-09-11 11:58 ` [PATCH atusb/fw v2 2/2] atusb/fw: Introduction of a new board named HULUSB Josef Filzmaier
@ 2017-09-13 16:08 ` Stefan Schmidt
  2 siblings, 0 replies; 4+ messages in thread
From: Stefan Schmidt @ 2017-09-13 16:08 UTC (permalink / raw)
  To: linux-wpan

Hello.

On 09/11/2017 01:58 PM, Josef Filzmaier wrote:
> This patch (in combination with the linux kernel patch)
> introduces support for the Busware HUL stick. There are two
> commits, one that enables UART debugging (for convenience purposes)
> and another that modularizes the firmware to better support
> multiple hardware targets. As the Busware HUL stick uses the
> at86rf212 transceiver there have been a few modifications to
> support this transceiver. Otherwise this board is very similar to the
> already existing atusb and rzusb boards, meaning most of the code
> can be shared. (e.g. it also uses the at90usb1287 microcontroller).
> 
> Josef Filzmaier (2):
>    atusb/fw: Introduce DEBUG flag
>    atusb/fw: Introduction of a new board named HULUSB

Both patches have been applied to the atusb firmware repo.
I also added a tiny section in the README how to get the firmware on the 
device.

Thanks a lot for your efforts on this!

I will have a look at the kernel driver tomorrow as I run out of time today.

regards
Stefan Schmidt

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-09-13 16:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-11 11:58 [PATCH atusb/fw v2 0/2] atusb/fw: Firmware patch to support HULUSB v2 Josef Filzmaier
2017-09-11 11:58 ` [PATCH atusb/fw v2 1/2] atusb/fw: Introduce DEBUG flag Josef Filzmaier
2017-09-11 11:58 ` [PATCH atusb/fw v2 2/2] atusb/fw: Introduction of a new board named HULUSB Josef Filzmaier
2017-09-13 16:08 ` [PATCH atusb/fw v2 0/2] atusb/fw: Firmware patch to support HULUSB v2 Stefan Schmidt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.