From 6fc124a8d00b5610fd8180f856a7eb105bbacfa6 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 12 Mar 2015 12:27:06 -0600 Subject: SAMV71-XULT: Enable I2C and the I2C tool in the NSH configuration --- nuttx/arch/arm/src/sama5/sam_twi.c | 6 +- nuttx/arch/arm/src/samv7/sam_twihs.c | 8 +-- nuttx/configs/samv71-xult/README.txt | 104 +++++++++++++++++++++++++++++++- nuttx/configs/samv71-xult/nsh/defconfig | 25 ++++++-- 4 files changed, 131 insertions(+), 12 deletions(-) diff --git a/nuttx/arch/arm/src/sama5/sam_twi.c b/nuttx/arch/arm/src/sama5/sam_twi.c index b53746c09..ed0ad8646 100644 --- a/nuttx/arch/arm/src/sama5/sam_twi.c +++ b/nuttx/arch/arm/src/sama5/sam_twi.c @@ -253,7 +253,7 @@ static int twi_transfer(FAR struct i2c_dev_s *dev, #ifdef CONFIG_I2C_SLAVE static int twi_setownaddress(FAR struct i2c_dev_s *dev, int addr, int nbits); static int twi_registercallback(FAR struct i2c_dev_s *dev, - int (*callback)(void)); + int (*callback)(FAR void *arg), FAR void *arg); #endif /* Initialization */ @@ -1118,8 +1118,8 @@ static int twi_setownaddress(FAR struct i2c_dev_s *dev, int addr, int nbits) *******************************************************************************/ #ifdef CONFIG_I2C_SLAVE -static int twi_registercallback(FAR struct i2c_dev_s *dev, - int (*callback)(void)) +static int twi_registercallback((FAR struct i2c_dev_s *dev, + int (*callback)(FAR void *arg), FAR void *arg) { #error Not implemented return -ENOSYS; diff --git a/nuttx/arch/arm/src/samv7/sam_twihs.c b/nuttx/arch/arm/src/samv7/sam_twihs.c index 344f6ac15..3f53c2f35 100644 --- a/nuttx/arch/arm/src/samv7/sam_twihs.c +++ b/nuttx/arch/arm/src/samv7/sam_twihs.c @@ -246,8 +246,8 @@ static int twi_transfer(FAR struct i2c_dev_s *dev, #endif #ifdef CONFIG_I2C_SLAVE static int twi_setownaddress(FAR struct i2c_dev_s *dev, int addr, int nbits); -static int twi_registercallback(FAR struct i2c_dev_s *dev, - int (*callback)(void)); +static int twi_registercallback((FAR struct i2c_dev_s *dev, + int (*callback)(FAR void *arg), FAR void *arg); #endif /* Initialization */ @@ -1090,8 +1090,8 @@ static int twi_setownaddress(FAR struct i2c_dev_s *dev, int addr, int nbits) *******************************************************************************/ #ifdef CONFIG_I2C_SLAVE -static int twi_registercallback(FAR struct i2c_dev_s *dev, - int (*callback)(void)) +static int twi_registercallback((FAR struct i2c_dev_s *dev, + int (*callback)(FAR void *arg), FAR void *arg) { #error Not implemented return -ENOSYS; diff --git a/nuttx/configs/samv71-xult/README.txt b/nuttx/configs/samv71-xult/README.txt index 86ca768c3..223468435 100644 --- a/nuttx/configs/samv71-xult/README.txt +++ b/nuttx/configs/samv71-xult/README.txt @@ -11,6 +11,7 @@ Contents - Board Features - Serial Console - LEDs and Buttons + - AT24MAC402 Serial EEPROM - Debugging - Configurations @@ -171,6 +172,31 @@ NOTES: use the SW1, PB12 has to be configured as a normal regular I/O pin in the MATRIX module. For more information see the SAM V71 datasheet. +AT24MAC402 Serial EEPROM +======================== + +The SAM V71 Xplained Ultra features one external AT24MAC402 serial EEPROM +with a EIA-48 MAC address connected to the SAM V71 through I2C. This device +contains a MAC address for use with the Ethernet interface. + +Connectivity: + + ------ -------- -------- ------------------------------------------ + SAMV71 SAMV71 I2C Shared + Pin Function Function Functionality + ------ -------- -------- ------------------------------------------ + PA03 TWID0 SDA EXT1, EXT2, EDBG I2C, LCD, Camera, Audio, + MediaLB, and Shield + PA04 TWICK0 SCL EXT1, EXT2, EDBG I2C, LCD, Camera, Audio, + MediaLB, and Shield + ------ -------- -------- ------------------------------------------ + +I2C address: + + The 7-bit address of the AT24 part is is 0b1011AAA where AAA is the state + of the A0, A1, and A3 pins on the part. On the SAMV71-XULT board, these + are all pulled high so the full, 7-bit address is 0x5f. + Debugging ========= @@ -313,7 +339,83 @@ Configuration sub-directories SW1 depressed nsh> - 4. Performance-related Configuration settings: + 4. TWI/I2C + + TWIHS0 is enabled in this configuration. The SAM V71 Xplained Ultra + supports two devices on the one on-board I2C device on the TWIHS0 bus: + (1) The AT24MAC402 serial EEPROM described above and (2) the Wolfson + WM8904 audio CODEC. This device contains a MAC address for use with + the Ethernet interface. + + In this configuration, the I2C tool at apps/system/i2ctool is + enabled. This tools supports interactive access to I2C devices on + the enabled TWIHS bus. Relevant configuration settings: + + CONFIG_SAMV7_TWIHS0=y + CONFIG_SAMV7_TWIHS0_FREQUENCY=100000 + + CONFIG_I2C=y + CONFIG_I2C_TRANSFER=y + + CONFIG_SYSTEM_I2CTOOL=y + CONFIG_I2CTOOL_MINBUS=0 + CONFIG_I2CTOOL_MAXBUS=0 + CONFIG_I2CTOOL_MINADDR=0x03 + CONFIG_I2CTOOL_MAXADDR=0x77 + CONFIG_I2CTOOL_MAXREGADDR=0xff + CONFIG_I2CTOOL_DEFFREQ=400000 + + Example usage: + + nsh> i2c + Usage: i2c [arguments] + Where is one of: + + Show help : ? + List busses : bus + List devices : dev [OPTIONS] + Read register : get [OPTIONS] [] + Show help : help + Write register: set [OPTIONS] [] + Verify access : verf [OPTIONS] [] [] + + Where common "sticky" OPTIONS include: + [-a addr] is the I2C device address (hex). Default: 03 Current: 03 + [-b bus] is the I2C bus number (decimal). Default: 0 Current: 0 + [-r regaddr] is the I2C device register address (hex). Default: 00 Current: 00 + [-w width] is the data width (8 or 16 decimal). Default: 8 Current: 8 + [-s|n], send/don't send start between command and data. Default: -n Current: -n + [-i|j], Auto increment|don't increment regaddr on repititions. Default: NO Current: NO + [-f freq] I2C frequency. Default: 400000 Current: 400000 + + NOTES: + o An environment variable like $PATH may be used for any argument. + o Arguments are "sticky". For example, once the I2C address is + specified, that address will be re-used until it is changed. + + WARNING: + o The I2C dev command may have bad side effects on your I2C devices. + Use only at your own risk. + nsh> i2c bus + BUS EXISTS? + Bus 0: YES + nsh> i2c dev 3 77 + 0 1 2 3 4 5 6 7 8 9 a b c d e f + 00: -- -- -- -- -- -- -- -- -- -- -- -- -- + 10: -- -- -- -- -- -- -- -- -- -- 1a -- -- -- -- -- + 20: -- -- -- -- -- -- -- -- 28 -- -- -- -- -- -- -- + 30: -- -- -- -- -- -- -- 37 -- -- -- -- -- -- -- -- + 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- 4e -- + 50: -- -- -- -- -- -- -- 57 -- -- -- -- -- -- -- 5f + 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- + 70: -- -- -- -- -- -- -- -- + nsh> + + Where 0x1a us the address of the WM8904 Audio CODIE and 0x5f is the + address of the AT24 EEPROM (I am not sure what the others are as + this writing). + + 5. Performance-related Configuration settings: CONFIG_ARMV7M_ICACHE=y : Instruction cache is enabled CONFIG_ARMV7M_DCACHE=y : Data cache is enabled diff --git a/nuttx/configs/samv71-xult/nsh/defconfig b/nuttx/configs/samv71-xult/nsh/defconfig index 13106ffd2..addc07347 100644 --- a/nuttx/configs/samv71-xult/nsh/defconfig +++ b/nuttx/configs/samv71-xult/nsh/defconfig @@ -210,9 +210,9 @@ CONFIG_SAMV7_HAVE_USART2=y # CONFIG_SAMV7_TC10 is not set # CONFIG_SAMV7_TC11 is not set # CONFIG_SAMV7_TRNG is not set -# CONFIG_SAMV7_TWIM0 is not set -# CONFIG_SAMV7_TWIM1 is not set -# CONFIG_SAMV7_TWIM2 is not set +CONFIG_SAMV7_TWIHS0=y +# CONFIG_SAMV7_TWIHS1 is not set +# CONFIG_SAMV7_TWIHS2 is not set # CONFIG_SAMV7_UART0 is not set # CONFIG_SAMV7_UART1 is not set # CONFIG_SAMV7_UART2 is not set @@ -232,6 +232,11 @@ CONFIG_SAMV7_GPIOB_IRQ=y # CONFIG_SAMV7_GPIOD_IRQ is not set # CONFIG_SAMV7_GPIOE_IRQ is not set +# +# TWIHS device driver options +# +CONFIG_SAMV7_TWIHS0_FREQUENCY=100000 + # # Architecture Options # @@ -432,7 +437,12 @@ CONFIG_DEV_NULL=y # CONFIG_ARCH_HAVE_PWM_PULSECOUNT is not set # CONFIG_PWM is not set # CONFIG_ARCH_HAVE_I2CRESET is not set -# CONFIG_I2C is not set +CONFIG_I2C=y +# CONFIG_I2C_SLAVE is not set +CONFIG_I2C_TRANSFER=y +# CONFIG_I2C_WRITEREAD is not set +# CONFIG_I2C_POLLED is not set +# CONFIG_I2C_TRACE is not set CONFIG_SPI=y # CONFIG_SPI_OWNBUS is not set CONFIG_SPI_EXCHANGE=y @@ -912,6 +922,13 @@ CONFIG_NSH_CONSOLE=y # # I2C tool # +CONFIG_SYSTEM_I2CTOOL=y +CONFIG_I2CTOOL_MINBUS=0 +CONFIG_I2CTOOL_MAXBUS=0 +CONFIG_I2CTOOL_MINADDR=0x03 +CONFIG_I2CTOOL_MAXADDR=0x77 +CONFIG_I2CTOOL_MAXREGADDR=0xff +CONFIG_I2CTOOL_DEFFREQ=400000 # # INI File Parser -- cgit v1.2.3