atusb: fw: add support for rzusbstick
Alexander Aring
maintainerRFC 1/1 atusb: fw: add support for rzusbstick
This patch adds support for the rzusbstick for the atusb firmware. More detailed information about this usb stick:
http://www.atmel.com/tools/rzusbstick.aspx
Original I have the rzraven kit:
http://www.atmel.com/tools/rzraven.aspx
Which comes with a special cable and avr dragon programmer. You need some programmer and wires to the programmers pins. To lookup how to connect the programmer to the rzusbstick pinout, see:
http://www.atmel.com/Images/doc8117.pdf
page 22 (schematics of the rzusbstick).
Difference between atusb and rzusbstick(rzusb) is mainly the at86rf231 vs at86rf230 one. The rzusb contains the at86rf230 which is a little bit hard to deal with it (and has a huge errata inside the datasheet). Nevertheless with small schanges the atusb firmware can run now on the rzusb. The rzusb contains also a bigger mcu, so we can maybe cache more pdus for receive handling.
To compile the rzusb firmware call:
make NAME=rzusb
this will generate the rzusb.bin
then call the programmer (in my case avrdude):
avrdude -P usb -c dragon_jtag -p usb1287 -U flash:w:rzusb.bin
NOTE: currently there is no chance (I suppose) to ensure that the atusb receive the correct firmware, so don't try to flash the atusb with the rzusb firmware! Also the vendor and product id is the same.
This currently a RFC, it's a quick hack and I think we should update more the documentation to support the rzusb.
--- atusb/fw/Makefile | 6 ++++++ atusb/fw/atusb.c | 2 ++ atusb/fw/board.c | 24 +++++++++++++++++++++--- atusb/fw/board.h | 30 +++++++++++++++++++++++++++++- atusb/fw/board_app.c | 18 ++++++++++++++++-- atusb/fw/mac.c | 34 +++++++++++++++++++++++++--------- atusb/fw/spi.c | 29 ++++++++++++++++++++--------- atusb/fw/usb/atu2.c | 15 +++++++++++++++ 8 files changed, 134 insertions(+), 24 deletions(-)
atusb/fw/Makefile +6 -0
@@ -18,7 +18,13 @@ CFLAGS = -g -mmcu=$(CHIP) -DBOOT_ADDR=$(BOOT_ADDR) \ -Wall -Wextra -Wshadow -Werror -Wno-unused-parameter \ -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes +ifeq ($(NAME),rzusb) +CHIP=at90usb1287 +CFLAGS += -DRZUSB +else CHIP=atmega32u2 +CFLAGS += -DATUSB +endif HOST=jlime BOOT_ADDR=0x7000
atusb/fw/atusb.c +2 -0
@@ -37,11 +37,13 @@ int main(void)usb_init ();ep0_init (); +#ifdef ATUSB timer_init ();/* move interrupt vectors to 0 */ MCUCR =1 <<IVCE ;MCUCR =0 ; +#endif sei ();
atusb/fw/board.c +21 -3
@@ -41,11 +41,24 @@ static void set_clkm(void)* clock. The clock switching procedure is described in the ATmega32U2 * data sheet in secton 8.2.2. */ - +#ifdef ATUSB spi_begin ();spi_send (AT86RF230_REG_WRITE |REG_TRX_CTRL_0 );spi_send (CLKM_CTRL_8MHz);spi_end (); +#endif +#ifdef RZUSB +spi_begin (); +spi_send (AT86RF230_REG_WRITE |REG_TRX_CTRL_0 ); +spi_send (0x10 ); +spi_end (); + +/* TX_AUTO_CRC_ON, default disabled */ +spi_begin (); +spi_send (AT86RF230_REG_WRITE |0x05 ); +spi_send (0x80 ); +spi_end (); +#endif }
@@ -131,10 +144,15 @@ void board_init(void)WDTCSR =1 <<WDCE ;/* Disable watchdog while still enabling change */ -/* We start with a 1 MHz/8 clock. Disable the prescaler. */ -CLKPR =1 <<CLKPCE ; +#ifdef ATUSB +/* We start with a 1 MHz/8 clock. Disable the prescaler. */ CLKPR =0 ; +#endif +#ifdef RZUSB +/* We start with a 16 MHz/8 clock. Put the prescaler to 2. */ +CLKPR =1 <<CLKPS0 ; +#endif get_sernum (); }
atusb/fw/board.h +29 -1
@@ -18,7 +18,7 @@#include <atusb/atusb.h> - +#ifdef ATUSB #define LED_PORT B#define LED_BIT 6#define nRST_RF_PORT C
@@ -38,6 +38,34 @@#define IRQ_RF_PORT D#define IRQ_RF_BIT 0 +#define SPI_WAIT_DONE () while (!(UCSR1A & 1 << RXC1)) +#define SPI_DATA UDR1 + +#endif +#ifdef RZUSB +#define LED_PORT D +#define LED_BIT 7 +#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 SPI_WAIT_DONE () while ((SPSR & (1 << SPIF)) == 0) +#define SPI_DATA SPDR + +#endif #define SET_2 (p, b) PORT##p |= 1 << (b)#define CLR_2 (p, b) PORT##p &= ~(1 << (b))
atusb/fw/board_app.c +16 -2
@@ -154,8 +154,12 @@ static void done(void *user)uint8_t irq_serial; - +#ifdef ATUSB ISR(INT0_vect) +#endif +#ifdef RZUSB +ISR(TIMER1_CAPT_vect) +#endif {if (mac_irq) {if (mac_irq ())
@@ -168,10 +172,20 @@ ISR(INT0_vect) } } - +#ifdef ATUSB void board_app_init (void ) {/* enable INT0, trigger on rising edge */ EICRA =1 <<ISC01 |1 <<ISC00 ;EIMSK =1 <<0 ; } +#endif +#ifdef RZUSB +void board_app_init (void ) +{ +/* enable timer input capture 1, trigger on rising edge */ +TCCR1B = (1 <<ICES1 ); +TIFR1 = (1 <<ICF1 ); +TIMSK1 = (1 <<ICIE1 ); +} +#endif
atusb/fw/mac.c +25 -9
@@ -21,7 +21,6 @@#include "board.h" #include "mac.h" -#define RX_BUFS 3
@@ -102,12 +101,22 @@ 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 );next_buf (&rx_out);usb_next (); +#ifdef RZUSB +/* slap at86rf230 - reduce fragmentation issue */ +change_state (TRX_STATUS_RX_AACK_ON ); +#endif }
@@ -117,10 +126,16 @@ static void receive_frame(void)uint8_t *buf;spi_begin (); +#ifdef ATUSB if (!(spi_io (AT86RF230_BUF_READ ) &RX_CRC_VALID )) {spi_end ();return ; } +#endif +#ifdef RZUSB +spi_io (AT86RF230_BUF_READ ); +#endif + size =spi_recv ();if (!size || (size &0x80 )) {spi_end ();
@@ -169,14 +184,6 @@ static bool handle_irq(void)/* ----- TX/RX ------------------------------------------------------------- */ -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); -} - -bool mac_rx (int on) {if (on) {
@@ -209,12 +216,21 @@ static void do_tx(void *user) }while (status !=TRX_STATUS_RX_ON && status !=TRX_STATUS_RX_AACK_ON ); +#ifdef ATUSB /* * 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 +#ifdef RZUSB +/* +* at86rf230 doesn't support force change, nevetherless this works +* somehow +*/ +reg_write (REG_TRX_STATE ,TRX_CMD_PLL_ON ); +#endif handle_irq ();
atusb/fw/spi.c +20 -9
@@ -34,9 +34,9 @@ void spi_begin(void)uint8_t spi_io (uint8_t v) {// while (!(UCSR1A & 1 << UDRE1)); -UDR1 = v; -while (!(UCSR1A &1 <<RXC1 )); -return UDR1 ; +SPI_DATA = v; +SPI_WAIT_DONE (); +return SPDR ; }
@@ -51,21 +51,26 @@ void spi_recv_block(uint8_t *buf, uint8_t n) {if (!n)return ; -UDR1 =0 ; +SPI_DATA =0 ;while (--n) { -while (!(UCSR1A &1 <<RXC1 )); - *buf++ =UDR1 ; -UDR1 =0 ; +SPI_WAIT_DONE (); + *buf++ =SPI_DATA ; +SPI_DATA =0 ; } -while (!(UCSR1A &1 <<RXC1 )); - *buf++ =UDR1 ; +SPI_WAIT_DONE (); + *buf++ =SPI_DATA ; }void spi_off (void ) { spi_initialized =0 ; +#ifdef ATUSB UCSR1B =0 ; +#endif +#ifdef RZUSB +SPCR &= ~(1 <<SPE ); +#endif }
@@ -77,12 +82,18 @@ void spi_init(void)OUT (nSS);IN (MISO ); +#ifdef ATUSB UBRR1 =0 ;/* set bit rate to zero to begin */ UCSR1C =1 <<UMSEL11 |1 <<UMSEL10 ;/* set MSPI, MSB first, SPI data mode 0 */ UCSR1B =1 <<RXEN1 |1 <<TXEN1 ;/* enable receiver and transmitter */ UBRR1 =0 ;/* reconfirm the bit rate */ +#endif +#ifdef RZUSB +SPCR = (1 <<SPE ) | (1 <<MSTR ); +SPSR = (1 <<SPI2X ); +#endif spi_initialized =1 ; }
atusb/fw/usb/atu2.c +15 -0
@@ -252,12 +252,27 @@ void usb_init(void)USBCON |=1 <<FRZCLK ;/* freeze the clock */ /* enable the PLL and wait for it to lock */ +#ifdef ATUSB PLLCSR &= ~(1 <<PLLP2 |1 <<PLLP1 |1 <<PLLP0 ); +#endif +#ifdef RZUSB +/* TODO sheet page 50 For Atmel AT90USB128x only. Do not use with Atmel AT90USB64x. */ +/* FOR 8 XTAL Mhz only!!! */ +PLLCSR = ((1 <<PLLP1 ) | (1 <<PLLP0 )); +#endif PLLCSR |=1 <<PLLE ;while (!(PLLCSR & (1 <<PLOCK ))); +#ifdef ATUSB USBCON &= ~(1 <<USBE );/* reset the controller */ USBCON |=1 <<USBE ; +#endif +#ifdef RZUSB +UHWCON |= (1 <<UVREGE ); + +USBCON &= ~((1 <<USBE ) | (1 <<OTGPADE ));/* reset the controller */ +USBCON |= ((1 <<USBE ) | (1 <<OTGPADE )); +#endif USBCON &= ~(1 <<FRZCLK );/* thaw the clock */
Signature · 1 line
2.4.1
Hello.
Quoted 4 lines · Alexander Aring
This patch adds support for the rzusbstick for the atusb firmware. More detailed information about this usb stick:
Thanks a lot for working on this. Given that it is still available and the price is good it can help people to play around with ieee802154 a bit more.
Quoted 19 lines
Original I have the rzraven kit:
http://www.atmel.com/tools/rzraven.aspx
Which comes with a special cable and avr dragon programmer. You need some programmer and wires to the programmers pins. To lookup how to connect the programmer to the rzusbstick pinout, see:
http://www.atmel.com/Images/doc8117.pdf
page 22 (schematics of the rzusbstick).
Difference between atusb and rzusbstick(rzusb) is mainly the at86rf231 vs at86rf230 one. The rzusb contains the at86rf230 which is a little bit hard to deal with it (and has a huge errata inside the datasheet). Nevertheless with small schanges the atusb firmware can run now on the rzusb. The rzusb contains also a bigger mcu, so we can maybe cache more pdus for receive handling.
Quoted 7 lines
To compile the rzusb firmware call:
make NAME=rzusbthis will generate the rzusb.bin
then call the programmer (in my case avrdude):
avrdude -P usb -cdragon_jtag-p usb1287 -U flash:w:rzusb.bin
Is there any chance we can get the DFU part of the atusb firmware also running on the rzusb? Sure, it would only work after the initial loading but updating would be more convenient without the need of a dedicated programmer cable. Nothing of priority, just thinking out loud here.
Quoted 3 lines
NOTE: currently there is no chance (I suppose) to ensure that the atusb receive the correct firmware, so don't try to flash the atusb with the rzusb firmware! Also the vendor and product id is the same.
Actually there is some logic inside dfu-util which could handle this. Firmware wise we don't check as far as I know.
With the 0.2 atusb release I added the DFU suffix which has the vendor and product id coded inside the suffix of the firmware to validate if we flash to the correct device and abort if not.
This obviously clashes with re-using same vendor and product ID for rzusb. Something we should avoid anyway as they are two different devices. It should be no problem to get another product id for rzusb (vendor stay same as atusb). Werner should know how the "USB registry" of Qi hardware works. Most likely a simple text file or wiki page.
That way we get a new product id for the firmware image build for rzusb and are able to verify the flashing with DFU. Adding the new product id to the driver table in the atusb driver is easy enough. What so you think?
Quoted 2 lines
This currently a RFC, it's a quick hack and I think we should update more the documentation to support the rzusb.
General comment as Werner already stated. Less ifdef's :)
Try to factor out the parts which are different and have different init calls for example. Some ifdef's will always stay but reducing them would already help.
regards
Stefan Schmidt
Quoted 376 lines
Signed-off-by Alexander Aring <[email protected]>Cc Stefan Schmidt <[email protected]>Cc Werner Almesberger <[email protected]>--- atusb/fw/Makefile | 6 ++++++ atusb/fw/atusb.c | 2 ++ atusb/fw/board.c | 24 +++++++++++++++++++++--- atusb/fw/board.h | 30 +++++++++++++++++++++++++++++- atusb/fw/board_app.c | 18 ++++++++++++++++-- atusb/fw/mac.c | 34 +++++++++++++++++++++++++--------- atusb/fw/spi.c | 29 ++++++++++++++++++++--------- atusb/fw/usb/atu2.c | 15 +++++++++++++++ 8 files changed, 134 insertions(+), 24 deletions(-)atusb/fw/Makefile +6
-0@@ -18,7 +18,13 @@ CFLAGS = -g -mmcu=$(CHIP) -DBOOT_ADDR=$(BOOT_ADDR) \ -Wall -Wextra -Wshadow -Werror -Wno-unused-parameter \ -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes +ifeq ($(NAME),rzusb) +CHIP=at90usb1287 +CFLAGS += -DRZUSB +else CHIP=atmega32u2 +CFLAGS += -DATUSB +endif HOST=jlime BOOT_ADDR=0x7000atusb/fw/atusb.c +2
-0@@ -37,11 +37,13 @@ int main(void)usb_init ();ep0_init (); +#ifdef ATUSB timer_init ();/* move interrupt vectors to 0 */ MCUCR =1 <<IVCE ;MCUCR =0 ; +#endif sei ();atusb/fw/board.c +21
-3@@ -41,11 +41,24 @@ static void set_clkm(void)* clock. The clock switching procedure is described in the ATmega32U2 * data sheet in secton 8.2.2. */ - +#ifdef ATUSB spi_begin ();spi_send (AT86RF230_REG_WRITE |REG_TRX_CTRL_0 );spi_send (CLKM_CTRL_8MHz);spi_end (); +#endif +#ifdef RZUSB +spi_begin (); +spi_send (AT86RF230_REG_WRITE |REG_TRX_CTRL_0 ); +spi_send (0x10 ); +spi_end (); + +/* TX_AUTO_CRC_ON, default disabled */ +spi_begin (); +spi_send (AT86RF230_REG_WRITE |0x05 ); +spi_send (0x80 ); +spi_end (); +#endif }@@ -131,10 +144,15 @@ void board_init(void)WDTCSR =1 <<WDCE ;/* Disable watchdog while still enabling change */ -/* We start with a 1 MHz/8 clock. Disable the prescaler. */ -CLKPR =1 <<CLKPCE ; +#ifdef ATUSB +/* We start with a 1 MHz/8 clock. Disable the prescaler. */ CLKPR =0 ; +#endif +#ifdef RZUSB +/* We start with a 16 MHz/8 clock. Put the prescaler to 2. */ +CLKPR =1 <<CLKPS0 ; +#endif get_sernum (); }atusb/fw/board.h +29
-1@@ -18,7 +18,7 @@#include <atusb/atusb.h> - +#ifdef ATUSB #define LED_PORT B#define LED_BIT 6#define nRST_RF_PORT C@@ -38,6 +38,34 @@#define IRQ_RF_PORT D#define IRQ_RF_BIT 0 +#define SPI_WAIT_DONE () while (!(UCSR1A & 1 << RXC1)) +#define SPI_DATA UDR1 + +#endif +#ifdef RZUSB +#define LED_PORT D +#define LED_BIT 7 +#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 SPI_WAIT_DONE () while ((SPSR & (1 << SPIF)) == 0) +#define SPI_DATA SPDR + +#endif #define SET_2 (p, b) PORT##p |= 1 << (b)#define CLR_2 (p, b) PORT##p &= ~(1 << (b))atusb/fw/board_app.c +16
-2@@ -154,8 +154,12 @@ static void done(void *user)uint8_t irq_serial; - +#ifdef ATUSB ISR(INT0_vect) +#endif +#ifdef RZUSB +ISR(TIMER1_CAPT_vect) +#endif {if (mac_irq) {if (mac_irq ())@@ -168,10 +172,20 @@ ISR(INT0_vect) } } - +#ifdef ATUSB void board_app_init (void ) {/* enable INT0, trigger on rising edge */ EICRA =1 <<ISC01 |1 <<ISC00 ;EIMSK =1 <<0 ; } +#endif +#ifdef RZUSB +void board_app_init (void ) +{ +/* enable timer input capture 1, trigger on rising edge */ +TCCR1B = (1 <<ICES1 ); +TIFR1 = (1 <<ICF1 ); +TIMSK1 = (1 <<ICIE1 ); +} +#endif atusb/fw/mac.c +25
-9@@ -21,7 +21,6 @@#include "board.h" #include "mac.h" -#define RX_BUFS 3@@ -102,12 +101,22 @@ 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 );next_buf (&rx_out);usb_next (); +#ifdef RZUSB +/* slap at86rf230 - reduce fragmentation issue */ +change_state (TRX_STATUS_RX_AACK_ON ); +#endif }@@ -117,10 +126,16 @@ static void receive_frame(void)uint8_t *buf;spi_begin (); +#ifdef ATUSB if (!(spi_io (AT86RF230_BUF_READ ) &RX_CRC_VALID )) {spi_end ();return ; } +#endif +#ifdef RZUSB +spi_io (AT86RF230_BUF_READ ); +#endif + size =spi_recv ();if (!size || (size &0x80 )) {spi_end ();@@ -169,14 +184,6 @@ static bool handle_irq(void)/* ----- TX/RX ------------------------------------------------------------- */ -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); -} - -bool mac_rx (int on) {if (on) {@@ -209,12 +216,21 @@ static void do_tx(void *user) }while (status !=TRX_STATUS_RX_ON && status !=TRX_STATUS_RX_AACK_ON ); +#ifdef ATUSB /* * 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 +#ifdef RZUSB +/* +* at86rf230 doesn't support force change, nevetherless this works +* somehow +*/ +reg_write (REG_TRX_STATE ,TRX_CMD_PLL_ON ); +#endif handle_irq ();atusb/fw/spi.c +20
-9@@ -34,9 +34,9 @@ void spi_begin(void)uint8_t spi_io (uint8_t v) {// while (!(UCSR1A & 1 << UDRE1)); -UDR1 = v; -while (!(UCSR1A &1 <<RXC1 )); -return UDR1 ; +SPI_DATA = v; +SPI_WAIT_DONE (); +return SPDR ; }@@ -51,21 +51,26 @@ void spi_recv_block(uint8_t *buf, uint8_t n) {if (!n)return ; -UDR1 =0 ; +SPI_DATA =0 ;while (--n) { -while (!(UCSR1A &1 <<RXC1 )); - *buf++ =UDR1 ; -UDR1 =0 ; +SPI_WAIT_DONE (); + *buf++ =SPI_DATA ; +SPI_DATA =0 ; } -while (!(UCSR1A &1 <<RXC1 )); - *buf++ =UDR1 ; +SPI_WAIT_DONE (); + *buf++ =SPI_DATA ; }void spi_off (void ) { spi_initialized =0 ; +#ifdef ATUSB UCSR1B =0 ; +#endif +#ifdef RZUSB +SPCR &= ~(1 <<SPE ); +#endif }@@ -77,12 +82,18 @@ void spi_init(void)OUT (nSS);IN (MISO ); +#ifdef ATUSB UBRR1 =0 ;/* set bit rate to zero to begin */ UCSR1C =1 <<UMSEL11 |1 <<UMSEL10 ;/* set MSPI, MSB first, SPI data mode 0 */ UCSR1B =1 <<RXEN1 |1 <<TXEN1 ;/* enable receiver and transmitter */ UBRR1 =0 ;/* reconfirm the bit rate */ +#endif +#ifdef RZUSB +SPCR = (1 <<SPE ) | (1 <<MSTR ); +SPSR = (1 <<SPI2X ); +#endif spi_initialized =1 ; }atusb/fw/usb/atu2.c +15
-0@@ -252,12 +252,27 @@ void usb_init(void)USBCON |=1 <<FRZCLK ;/* freeze the clock */ /* enable the PLL and wait for it to lock */ +#ifdef ATUSB PLLCSR &= ~(1 <<PLLP2 |1 <<PLLP1 |1 <<PLLP0 ); +#endif +#ifdef RZUSB +/* TODO sheet page 50 For Atmel AT90USB128x only. Do not use with Atmel AT90USB64x. */ +/* FOR 8 XTAL Mhz only!!! */ +PLLCSR = ((1 <<PLLP1 ) | (1 <<PLLP0 )); +#endif PLLCSR |=1 <<PLLE ;while (!(PLLCSR & (1 <<PLOCK ))); +#ifdef ATUSB USBCON &= ~(1 <<USBE );/* reset the controller */ USBCON |=1 <<USBE ; +#endif +#ifdef RZUSB +UHWCON |= (1 <<UVREGE ); + +USBCON &= ~((1 <<USBE ) | (1 <<OTGPADE ));/* reset the controller */ +USBCON |= ((1 <<USBE ) | (1 <<OTGPADE )); +#endif USBCON &= ~(1 <<FRZCLK );/* thaw the clock */
Quoted 2 lines · Stefan Schmidt
Actually there is some logic inside dfu-util which could handle this. Firmware wise we don't check as far as I know.
The boot loader (DFU) is also designed such that, when you plug in the device, it always runs first, no matter what you did to the application. The boot loader itself is protected against erasing or overwriting by code running on the chip. So it should be fairly hard to terminally "brick" an atusb or anything using the same architecture.
Quoted 3 lines
Werner should know how the "USB
registry" of Qi hardware works. Most likely a simple text file or wiki page.
Yup. You just add it to the Wiki:
http://en.qi-hardware.com/wiki/USB_product_ID_assignments
Lean bureaucracy ;-)
- Werner
Alexander Aring
maintainerHi,
Quoted 34 lines · Stefan Schmidt
Hello.
Quoted 4 lines · Alexander Aring
This patch adds support for the rzusbstick for the atusb firmware. More detailed information about this usb stick:
Thanks a lot for working on this. Given that it is still available and the price is good it can help people to play around with ieee802154 a bit more.
Quoted 24 lines
Original I have the rzraven kit:
http://www.atmel.com/tools/rzraven.aspx
Which comes with a special cable and avr dragon programmer. You need some programmer and wires to the programmers pins. To lookup how to connect the programmer to the rzusbstick pinout, see:
http://www.atmel.com/Images/doc8117.pdf
page 22 (schematics of the rzusbstick).
Difference between atusb and rzusbstick(rzusb) is mainly the at86rf231 vs at86rf230 one. The rzusb contains the at86rf230 which is a little bit hard to deal with it (and has a huge errata inside the datasheet). Nevertheless with small schanges the atusb firmware can run now on the rzusb. The rzusb contains also a bigger mcu, so we can maybe cache more pdus for receive handling.
To compile the rzusb firmware call:
make NAME=rzusbthis will generate the rzusb.bin
Quoted 8 lines
Quoted 2 lines
then call the programmer (in my case avrdude):
avrdude -P usb -cdragon_jtag-p usb1287 -U flash:w:rzusb.binIs there any chance we can get the DFU part of the atusb firmware also running on the rzusb? Sure, it would only work after the initial loading but updating would be more convenient without the need of a dedicated programmer cable. Nothing of priority, just thinking out loud here.
Using DFU is possible. On the avr device exists room for Bootloader and Application code. I need to figure out how this space is set in the atusb.
This setting is done by a fuse setting (BOOTSZ bits), I really don't like to set fuse bits when I do have one rzusb only. :-) Maybe I can get some more from the same source where I get the current one.
But then I think running DFU in the bootloader section should be possible, maybe without change if we can do exact bootloader space like the atusb. Currently this is also why we don't moving the interrupt vectors in case of rzusb build of atusb firmware.
Quoted 22 lines
Quoted 4 lines
NOTE: currently there is no chance (I suppose) to ensure that the atusb receive the correct firmware, so don't try to flash the atusb with the rzusb firmware! Also the vendor and product id is the same.
Actually there is some logic inside dfu-util which could handle this. Firmware wise we don't check as far as I know.
With the 0.2 atusb release I added the DFU suffix which has the vendor and product id coded inside the suffix of the firmware to validate if we flash to the correct device and abort if not.
This obviously clashes with re-using same vendor and product ID for rzusb. Something we should avoid anyway as they are two different devices. It should be no problem to get another product id for rzusb (vendor stay same as atusb). Werner should know how the "USB registry" of Qi hardware works. Most likely a simple text file or wiki page.
That way we get a new product id for the firmware image build for rzusb and are able to verify the flashing with DFU. Adding the new product id to the driver table in the atusb driver is easy enough. What so you think?
Quoted 9 lines
Quoted 2 lines
This currently a RFC, it's a quick hack and I think we should update more the documentation to support the rzusb.
General comment as Werner already stated. Less ifdef's :)
Try to factor out the parts which are different and have different init calls for example. Some ifdef's will always stay but reducing them would already help.
ok. I will clean it up. Then I would be happy if I can upload a "experimental" firmware on wpan.cakelab.org.
Quoted 34 lines
regards
Stefan SchmidtQuoted 31 lines
Signed-off-by Alexander Aring <[email protected]>Cc Stefan Schmidt <[email protected]>Cc Werner Almesberger <[email protected]>--- atusb/fw/Makefile | 6 ++++++ atusb/fw/atusb.c | 2 ++ atusb/fw/board.c | 24 +++++++++++++++++++++--- atusb/fw/board.h | 30 +++++++++++++++++++++++++++++- atusb/fw/board_app.c | 18 ++++++++++++++++-- atusb/fw/mac.c | 34 +++++++++++++++++++++++++--------- atusb/fw/spi.c | 29 ++++++++++++++++++++--------- atusb/fw/usb/atu2.c | 15 +++++++++++++++ 8 files changed, 134 insertions(+), 24 deletions(-)atusb/fw/Makefile +6
-0@@ -18,7 +18,13 @@ CFLAGS = -g -mmcu=$(CHIP) -DBOOT_ADDR=$(BOOT_ADDR) \ -Wall -Wextra -Wshadow -Werror -Wno-unused-parameter \ -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes +ifeq ($(NAME),rzusb) +CHIP=at90usb1287 +CFLAGS += -DRZUSB +else CHIP=atmega32u2 +CFLAGS += -DATUSB +endif HOST=jlime BOOT_ADDR=0x7000atusb/fw/atusb.c +0
-0
Quoted 8 lines
atusb/fw/atusb.c int main(void) · line 40
Quoted 8 lines
index f526844..1f65d53 100644
atusb/fw/atusb.c +1
-0@@ -37,11 +37,13 @@ int main(void)usb_init ();ep0_init (); +#ifdef ATUSB timer_init ();
I don't know why this timer runs on atusb. This is maybe useful for timing measures, but currently this increments a uint64_t inside some timer isr. I don't think that is really necessary to have some system clock. This will increase overhead when doing atusb main tasks.
Quoted 5 lines
Quoted 5 lines
atusb/fw/atusb.c +1
-0/* move interrupt vectors to 0 */ MCUCR =1 <<IVCE ;MCUCR =0 ; +#endif sei ();
...
Quoted 5 lines
Quoted 5 lines
atusb/fw/atusb.c +1
-1- +#ifdef ATUSB spi_begin ();spi_send (AT86RF230_REG_WRITE |REG_TRX_CTRL_0 );spi_send (CLKM_CTRL_8MHz);
Quoted 8 lines
atusb/fw/atusb.c
Quoted 8 lines
atusb/fw/atusb.c +7
-0spi_end (); +#endif +#ifdef RZUSB +spi_begin (); +spi_send (AT86RF230_REG_WRITE |REG_TRX_CTRL_0 ); +spi_send (0x10 ); +spi_end (); +
This produdes that the at86rf230 will do no clock at CLKM ping but I saw in the rzusb schematic that this is connected to some clock source of AT90USB128x. But it's also connected to an 8 Mhz osc. I don't know the electrical things what they did there, but getting the clock from at86rf230 it's much cleaner clock source I think.
I lookup the contiki code, so far I see, they disable the pin. I already tried to run with a 8Mhz clock and there no much changes, both works. :-)
Quoted 5 lines
atusb/fw/atusb.c
Quoted 5 lines
atusb/fw/atusb.c +5
-0+/* TX_AUTO_CRC_ON, default disabled */ +spi_begin (); +spi_send (AT86RF230_REG_WRITE |0x05 ); +spi_send (0x80 ); +spi_end ();
I move this out of clkm setting, it's just a hack.
- Alex
Hello.
Quoted 47 lines · Alexander Aring
Hi,
Quoted 32 lines · Stefan Schmidt
Hello.
Quoted 4 lines · Alexander Aring
This patch adds support for the rzusbstick for the atusb firmware. More detailed information about this usb stick:
Thanks a lot for working on this. Given that it is still available and the price is good it can help people to play around with ieee802154 a bit more.
Quoted 22 lines
Original I have the rzraven kit:
http://www.atmel.com/tools/rzraven.aspx
Which comes with a special cable and avr dragon programmer. You need some programmer and wires to the programmers pins. To lookup how to connect the programmer to the rzusbstick pinout, see:
http://www.atmel.com/Images/doc8117.pdf
page 22 (schematics of the rzusbstick).
Difference between atusb and rzusbstick(rzusb) is mainly the at86rf231 vs at86rf230 one. The rzusb contains the at86rf230 which is a little bit hard to deal with it (and has a huge errata inside the datasheet). Nevertheless with small schanges the atusb firmware can run now on the rzusb. The rzusb contains also a bigger mcu, so we can maybe cache more pdus for receive handling.
To compile the rzusb firmware call:
make NAME=rzusbQuoted 9 lines
Quoted 4 lines
this will generate the rzusb.bin
then call the programmer (in my case avrdude):
avrdude -P usb -cdragon_jtag-p usb1287 -U flash:w:rzusb.binIs there any chance we can get the DFU part of the atusb firmware also running on the rzusb? Sure, it would only work after the initial loading but updating would be more convenient without the need of a dedicated programmer cable. Nothing of priority, just thinking out loud here.
Using DFU is possible. On the avr device exists room for Bootloader and Application code. I need to figure out how this space is set in the atusb.
Quoted 8 lines
This setting is done by a fuse setting (BOOTSZ bits), I really don't like to set fuse bits when I do have one rzusb only. :-) Maybe I can get some more from the same source where I get the current one.
But then I think running DFU in the bootloader section should be possible, maybe without change if we can do exact bootloader space like the atusb. Currently this is also why we don't moving the interrupt vectors in case of rzusb build of atusb firmware.
Fair enough. No a high priority task anyway. Getting it working fine first is more important. I just think that in long term it would be more convenient to update using DFU instead of avrdude. But this really can wait.
Quoted 23 lines
Quoted 23 lines
Quoted 3 lines
NOTE: currently there is no chance (I suppose) to ensure that the atusb receive the correct firmware, so don't try to flash the atusb with the rzusb firmware! Also the vendor and product id is the same.
Actually there is some logic inside dfu-util which could handle this. Firmware wise we don't check as far as I know.
With the 0.2 atusb release I added the DFU suffix which has the vendor and product id coded inside the suffix of the firmware to validate if we flash to the correct device and abort if not.
This obviously clashes with re-using same vendor and product ID for rzusb. Something we should avoid anyway as they are two different devices. It should be no problem to get another product id for rzusb (vendor stay same as atusb). Werner should know how the "USB registry" of Qi hardware works. Most likely a simple text file or wiki page.
That way we get a new product id for the firmware image build for rzusb and are able to verify the flashing with DFU. Adding the new product id to the driver table in the atusb driver is easy enough. What so you think?
Quoted 2 lines
This currently a RFC, it's a quick hack and I think we should update more the documentation to support the rzusb.
Quoted 8 lines
Quoted 6 lines
General comment as Werner already stated. Less ifdef's :)
Try to factor out the parts which are different and have different init calls for example. Some ifdef's will always stay but reducing them would already help.
ok. I will clean it up. Then I would be happy if I can upload a "experimental" firmware on wpan.cakelab.org.
Yes, that sounds like a good plan.
Quoted 38 lines
Quoted 38 lines
regards
Stefan SchmidtQuoted 35 lines
Signed-off-by Alexander Aring <[email protected]>Cc Stefan Schmidt <[email protected]>Cc Werner Almesberger <[email protected]>--- atusb/fw/Makefile | 6 ++++++ atusb/fw/atusb.c | 2 ++ atusb/fw/board.c | 24 +++++++++++++++++++++--- atusb/fw/board.h | 30 +++++++++++++++++++++++++++++- atusb/fw/board_app.c | 18 ++++++++++++++++-- atusb/fw/mac.c | 34 +++++++++++++++++++++++++--------- atusb/fw/spi.c | 29 ++++++++++++++++++++--------- atusb/fw/usb/atu2.c | 15 +++++++++++++++ 8 files changed, 134 insertions(+), 24 deletions(-)atusb/fw/Makefile +6
-0@@ -18,7 +18,13 @@ CFLAGS = -g -mmcu=$(CHIP) -DBOOT_ADDR=$(BOOT_ADDR) \ -Wall -Wextra -Wshadow -Werror -Wno-unused-parameter \ -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes +ifeq ($(NAME),rzusb) +CHIP=at90usb1287 +CFLAGS += -DRZUSB +else CHIP=atmega32u2 +CFLAGS += -DATUSB +endif HOST=jlime BOOT_ADDR=0x7000atusb/fw/atusb.c +0
-0@@ -37,11 +37,13 @@ int main(void)
Quoted 8 lines
Quoted 4 lines
atusb/fw/atusb.c int main(void) · line 41
Quoted 4 lines
atusb/fw/atusb.c +1
-0usb_init ();ep0_init (); +#ifdef ATUSB timer_init ();I don't know why this timer runs on atusb. This is maybe useful for timing measures, but currently this increments a
uint64_tinside some timer isr. I don't think that is really necessary to have some system clock. This will increase overhead when doing atusb main tasks.
Maybe its a leftover from some debugging or such? Werner would know I think.
Quoted 25 lines
Quoted 5 lines
Quoted 5 lines
atusb/fw/atusb.c +1
-0/* move interrupt vectors to 0 */ MCUCR =1 <<IVCE ;MCUCR =0 ; +#endif sei ();...
Quoted 5 lines
Quoted 5 lines
atusb/fw/atusb.c +1
-1- +#ifdef ATUSB spi_begin ();spi_send (AT86RF230_REG_WRITE |REG_TRX_CTRL_0 );spi_send (CLKM_CTRL_8MHz);Quoted 8 lines
atusb/fw/atusb.c
Quoted 8 lines
spi_end();atusb/fw/atusb.c +7
-0+#endif +#ifdef RZUSB +spi_begin (); +spi_send (AT86RF230_REG_WRITE |REG_TRX_CTRL_0 ); +spi_send (0x10 ); +spi_end (); +This produdes that the at86rf230 will do no clock at CLKM ping but I saw in the rzusb schematic that this is connected to some clock source of AT90USB128x. But it's also connected to an 8 Mhz osc. I don't know the electrical things what they did there, but getting the clock from at86rf230 it's much cleaner clock source I think.
Quoted 4 lines
I lookup the contiki code, so far I see, they disable the pin. I already tried to run with a 8Mhz clock and there no much changes, both works. :-)
ok
Quoted 6 lines
Quoted 5 lines
atusb/fw/atusb.c
Quoted 5 lines
atusb/fw/atusb.c +5
-0+/* TX_AUTO_CRC_ON, default disabled */ +spi_begin (); +spi_send (AT86RF230_REG_WRITE |0x05 ); +spi_send (0x80 ); +spi_end ();I move this out of clkm setting, it's just a hack.
Good.
I looked around to find places to get a rzusb dongle the best offer with stock I found is this:
http://www.digikey.de/product-search/de?vendor=0&keywords=ATAVRRZUSBSTICK
Is this reasonable? Thinking about getting one to have it for testing.
regards
Stefan Schmidt
Alexander Aring
maintainerOn Mon, Jun 01, 2015 at 04:35:02PM +0200, Stefan Schmidt wrote:
...
Quoted 6 lines
I looked around to find places to get a rzusb dongle the best offer with stock I found is this:
http://www.digikey.de/product-search/de?vendor=0&keywords=ATAVRRZUSBSTICKIs this reasonable? Thinking about getting one to have it for testing.
I found [0]. Maybe cheaper, don't know the shipping costs.
We can collect all "Where to buy" on wpan.cakelab.org. But remember you need some programmer for first firmware programming (now always because we don't have DFU).
You see the damn small pinout on pic [1]? That's the programmer pins, this maybe look at digikey what other customers also bought, I think that's maybe some pin header and cable which fits in there. Or you doing this stuff inside your next hackerspace.
- Alex
[0] http://www.element14.com/community/docs/DOC-67532/l/avr-rz-usb-stick-module
[1] http://media.digikey.com/photos/Atmel%20Photos/ATAVRRZUSBSTICK.JPG
Hello.
Quoted 9 lines · Alexander Aring
On Mon, Jun 01, 2015 at 04:35:02PM +0200, Stefan Schmidt wrote:
...Quoted 6 lines
I looked around to find places to get a rzusb dongle the best offer with stock I found is this:
http://www.digikey.de/product-search/de?vendor=0&keywords=ATAVRRZUSBSTICKIs this reasonable? Thinking about getting one to have it for testing.
I found [0]. Maybe cheaper, don't know the shipping costs.
Interesting. Even better. :)
Quoted 8 lines
We can collect all "Where to buy" on wpan.cakelab.org. But remember you need some programmer for first firmware programming (now always because we don't have DFU).
You see the damn small pinout on pic [1]? That's the programmer pins, this maybe look at digikey what other customers also bought, I think that's maybe some pin header and cable which fits in there. Or you doing this stuff inside your next hackerspace.
Yeah, need to think about it. Going to my local hackerspace everytime I want to flash might be a bit annoying for me. :)
regards
Stefan Schmidt
Quoted 4 lines · Alexander Aring
I don't know why this timer runs on atusb. This is maybe useful for timing measures, but currently this increments a
uint64_tinside some timer isr. I don't think that is really necessary to have some system clock. This will increase overhead when doing atusb main tasks.
It's for production testing. The chain is: timer -> timer_read() -> ATUSB_TIMER (USB control message) -> atrf-xtal -> prod/atusb
- Werner