Skip to content

cpu/fe310: add i2c peripheral driver#12946

Merged
fjmolinas merged 4 commits intoRIOT-OS:masterfrom
aabadie:pr/cpu/fe310_i2c
Jan 14, 2020
Merged

cpu/fe310: add i2c peripheral driver#12946
fjmolinas merged 4 commits intoRIOT-OS:masterfrom
aabadie:pr/cpu/fe310_i2c

Conversation

@aabadie
Copy link
Contributor

@aabadie aabadie commented Dec 13, 2019

Contribution description

This PR adds an implementation of the I2C peripheral driver for the RISCV FE310 CPU. This peripheral is only available on the HiFive1b board.

For the moment, I only tested with sensors plugged on the boards (lps22hb and hts221) and both are working well.

Because I had problems with the clock configuration, this PR is based on #12519

NACK is not handled by the driver (yet).

Testing procedure

  • Plug an I2C sensor on I2C pins (visible on the Arduino pinout
  • Ideally test this with PhiliP but I don't have this setup

Issues/PRs references

None

@aabadie aabadie added State: waiting for other PR State: The PR requires another PR to be merged first Area: drivers Area: Device drivers Platform: RISC-V Platform: This PR/issue effects RISC-V-based platforms Area: cpu Area: CPU/MCU ports labels Dec 13, 2019
@aabadie aabadie added the Type: new feature The issue requests / The PR implemements a new feature for RIOT label Dec 16, 2019
@fjmolinas
Copy link
Contributor

@aabadie needs rebase.

@aabadie aabadie added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed State: waiting for other PR State: The PR requires another PR to be merged first labels Jan 11, 2020
@aabadie
Copy link
Contributor Author

aabadie commented Jan 11, 2020

Done

@fjmolinas
Copy link
Contributor

Code looks good, will test on monday.

Copy link
Contributor

@fjmolinas fjmolinas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see a conflict in the used pins with the esp module: UPS this is when testing spi.

2020-01-13 10:01:04,699 # ATE0-->Send Flag Timed Out Busy. Giving Up.
2020-01-13 10:01:06,075 #  Send Flag error: #255 #255 #255 #255 AT+BLEINIT=0-->Send Flag Timed Out Busy. Giving Up.
2020-01-13 10:01:07,451 #  Send Flag error: #255 #255 #255 #255 AT+CWMODE=0-->Send Flag Timed Out Busy. Giving Up.
2020-01-13 10:01:07,455 #  Send Flag error: #255 #255 #255 #255 
2020-01-13 10:01:07,463 # Help: Press s to start test, r to print it is ready

@fjmolinas
Copy link
Contributor

I can't make i2c work, same setup that is working on a nucleo-f410rb.

@aabadie
Copy link
Contributor Author

aabadie commented Jan 13, 2020

Tested locally and I2C driver works for me. But I have other problems with xtimer (related to #9530 unfortunately).

Details
$ make BOARD=hifive1b -C tests/driver_hts221/ flash term
make: Entering directory '/work/riot/RIOT/tests/driver_hts221'
Building application "tests_driver_hts221" for "hifive1b" with MCU "fe310".

"make" -C /work/riot/RIOT/boards/hifive1b
"make" -C /work/riot/RIOT/core
"make" -C /work/riot/RIOT/cpu/fe310
"make" -C /work/riot/RIOT/cpu/fe310/nano
"make" -C /work/riot/RIOT/cpu/fe310/periph
"make" -C /work/riot/RIOT/cpu/fe310/vendor
"make" -C /work/riot/RIOT/drivers
"make" -C /work/riot/RIOT/drivers/hts221
"make" -C /work/riot/RIOT/drivers/periph_common
"make" -C /work/riot/RIOT/sys
"make" -C /work/riot/RIOT/sys/auto_init
"make" -C /work/riot/RIOT/sys/div
"make" -C /work/riot/RIOT/sys/isrpipe
"make" -C /work/riot/RIOT/sys/stdio_uart
"make" -C /work/riot/RIOT/sys/test_utils/interactive_sync
"make" -C /work/riot/RIOT/sys/tsrb
"make" -C /work/riot/RIOT/sys/xtimer
   text	   data	    bss	    dec	    hex	filename
  13824	    136	   2532	  16492	   406c	/work/riot/RIOT/tests/driver_hts221/bin/hifive1b/tests_driver_hts221.elf
/work/riot/RIOT/dist/tools/jlink/jlink.sh flash /work/riot/RIOT/tests/driver_hts221/bin/hifive1b/tests_driver_hts221.bin
### Flashing Target ###
### Flashing at base address 0x20010000 with offset 0 ###
SEGGER J-Link Commander V6.56d (Compiled Dec 12 2019 13:05:00)
DLL version V6.56d, compiled Dec 12 2019 13:04:51

J-Link Commander will now exit on Error

J-Link Command File read successfully.
Processing script file...

J-Link connection not established yet but required for command.
Connecting to J-Link via USB...O.K.
Firmware: J-Link OB-K22-SiFive compiled Dec 12 2019 16:26:28
Hardware version: V1.00
S/N: 979001370
VTref=3.300V
Target connection not established yet but required for command.
Device "FE310" selected.


Connecting to target via JTAG
ConfigTargetSettings() start
ConfigTargetSettings() end
TotalIRLen = 5, IRPrint = 0x01
JTAG chain detection found 1 devices:
 #0 Id: 0x20000913, IRLen: 05, Unknown device
Debug architecture:
  RISC-V debug: 0.13
  AddrBits: 7
  DataBits: 32
  IdleClks: 5
Memory access:
  Via system bus: No
  Via ProgBuf: Yes (16 ProgBuf entries)
DataBuf: 1 entries
  autoexec[0] implemented: Yes
Detected: RV32 core
CSR access via abs. commands: No
Temp. halted CPU for NumHWBP detection
HW instruction/data BPs: 8
Support set/clr BPs while running: No
HW data BPs trigger before execution of inst
RISC-V identified.
Halting CPU for downloading file.
Downloading file [/work/riot/RIOT/tests/driver_hts221/bin/hifive1b/tests_driver_hts221.bin]...
Comparing flash   [100%] Done.
Erasing flash     [100%] Done.
Programming flash [100%] Done.
Verifying flash   [100%] Done.
J-Link: Flash download: Bank 0 @ 0x20000000: 1 range affected (65536 bytes)
J-Link: Flash download: Total time needed: 0.603s (Prepare: 0.103s, Compare: 0.047s, Erase: 0.163s, Program: 0.227s, Verify: 0.045s, Restore: 0.015s)
O.K.

Reset delay: 0 ms
Reset type Normal: Resets core & peripherals using <ndmreset> bit in <dmcontrol> debug register.



Script processing completed.

/work/riot/RIOT/dist/tools/pyterm/pyterm -p "/dev/ttyACM0" -b "115200" 
2020-01-13 12:44:13,087 # Connect to serial port /dev/ttyACM0
s
Welcome to pyterm!
Type '/exit' to exit.
Bench Clock Reset Complete
2020-01-13 12:44:14,093 # 
2020-01-13 12:44:14,121 # ATE0-->ATE0
2020-01-13 12:44:14,138 # OK
2020-01-13 12:44:14,294 # AT+BLEINIT=0-->OK
2020-01-13 12:44:14,425 # AT+CWMODE=0--> Send sync error 
2020-01-13 12:44:14,433 # Help: Press s to start test, r to print it is ready
s
2020-01-13 12:44:15,484 # START
2020-01-13 12:44:15,491 # main(): This is RIOT! (Version: 2020.01-devel-1710-gd2a8d40-pr/cpu/fe310_i2c)
2020-01-13 12:44:15,493 # Init HTS221 on I2C_DEV(0)
2020-01-13 12:44:15,496 # H: 39.4%, T: 29.3°C
2020-01-13 12:44:17,497 # Unhandled trap:
2020-01-13 12:44:17,498 #   mcause: 0x00000001
2020-01-13 12:44:17,500 #   mepc:   0x200106e0
2020-01-13 12:44:17,502 #   mtval:  0x200106e0
2020-01-13 12:44:17,504 # *** RIOT kernel panic:
2020-01-13 12:44:17,505 # Unhandled trap
2020-01-13 12:44:17,506 # 
2020-01-13 12:44:17,506 # *** halted.
2020-01-13 12:44:17,507 # 
2020-01-13 12:44:18,435 # Exiting Pyterm
make: *** [/work/riot/RIOT/tests/driver_hts221/../../Makefile.include:684: term] Interrupt

The crash happens when calling xtimer_sleep();. If I comment the call to xtimer_sleep, it works:

Details
/work/riot/RIOT/dist/tools/pyterm/pyterm -p "/dev/ttyACM0" -b "115200" 
2020-01-13 12:51:13,798 # Connect to serial port /dev/ttyACM0
Welcome to pyterm!
Bench Clock Reset Complete
2020-01-13 12:51:14,802 # 
2020-01-13 12:51:14,832 # ATE0-->ATE0
2020-01-13 12:51:14,849 # OK
2020-01-13 12:51:15,005 # AT+BLEINIT=0-->OK
2020-01-13 12:51:15,162 # AT+CWMODE=0-->OK
2020-01-13 12:51:15,162 # 
2020-01-13 12:51:15,170 # Help: Press s to start test, r to print it is ready
s
2020-01-13 12:51:16,506 # START
2020-01-13 12:51:16,512 # main(): This is RIOT! (Version: 2020.01-devel-1710-gd2a8d40-pr/cpu/fe310_i2c)
2020-01-13 12:51:16,515 # Init HTS221 on I2C_DEV(0)
2020-01-13 12:51:16,518 # H: 37.0%, T: 30.8°C
2020-01-13 12:51:16,566 # H: 36.9%, T: 30.8°C
2020-01-13 12:51:16,646 # H: 36.9%, T: 30.8°C
2020-01-13 12:51:16,726 # H: 37.0%, T: 30.8°C
2020-01-13 12:51:16,806 # H: 36.9%, T: 30.8°C
2020-01-13 12:51:16,886 # H: 37.0%, T: 30.8°C
2020-01-13 12:51:16,966 # H: 37.0%, T: 30.8°C
2020-01-13 12:51:17,047 # H: 36.9%, T: 30.8°C
2020-01-13 12:51:17,127 # H: 37.0%, T: 30.8°C
2020-01-13 12:51:17,207 # H: 37.0%, T: 30.8°C
2020-01-13 12:51:17,287 # H: 37.0%, T: 30.8°C
2020-01-13 12:51:17,367 # H: 37.0%, T: 30.8°C
2020-01-13 12:51:17,447 # H: 37.0%, T: 30.8°C
2020-01-13 12:51:17,528 # H: 36.9%, T: 30.8°C
2020-01-13 12:51:17,608 # H: 37.0%, T: 30.9°C
2020-01-13 12:51:17,688 # H: 36.9%, T: 30.9°C
2020-01-13 12:51:17,768 # H: 37.0%, T: 30.8°C
2020-01-13 12:51:17,848 # H: 37.0%, T: 30.8°C
2020-01-13 12:51:17,929 # H: 36.9%, T: 30.8°C
2020-01-13 12:51:18,009 # H: 36.9%, T: 30.9°C
2020-01-13 12:51:18,089 # H: 36.9%, T: 30.9°C
2020-01-13 12:51:18,169 # H: 37.0%, T: 30.9°C
2020-01-13 12:51:18,249 # H: 36.9%, T: 30.9°C
2020-01-13 12:51:18,329 # H: 36.9%, T: 30.8°C
2020-01-13 12:51:18,410 # H: 36.9%, T: 30.9°C
2020-01-13 12:51:18,490 # H: 36.9%, T: 30.8°C
2020-01-13 12:51:18,570 # H: 37.0%, T: 30.8°C
2020-01-13 12:51:18,650 # H: 36.9%, T: 30.9°C
2020-01-13 12:51:18,730 # H: 36.9%, T: 30.8°C
2020-01-13 12:51:18,811 # H: 36.9%, T: 30.9°C
2020-01-13 12:51:18,891 # H: 36.9%, T: 30.9°C
2020-01-13 12:51:18,971 # H: 36.9%, T: 30.8°C
2020-01-13 12:51:19,051 # H: 36.9%, T: 30.9°C
2020-01-13 12:51:19,131 # H: 36.8%, T: 30.9°C
2020-01-13 12:51:19,212 # H: 36.9%, T: 30.8°C
2020-01-13 12:51:19,292 # H: 36.9%, T: 30.8°C
2020-01-13 12:51:19,372 # H: 36.9%, T: 30.9°C
2020-01-13 12:51:19,452 # H: 36.9%, T: 30.9°C
2020-01-13 12:51:19,532 # H: 36.9%, T: 30.9°C

Copy link
Contributor

@fjmolinas fjmolinas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK, tested removing the xtimer call.

2020-01-14 10:19:49,791 # H: 40.7%, T: 23.7°C
2020-01-14 10:19:49,872 # H: 40.7%, T: 23.7°C
2020-01-14 10:19:49,953 # H: 40.7%, T: 23.7°C
2020-01-14 10:19:50,034 # H: 40.6%, T: 23.7°C
2020-01-14 10:19:50,114 # H: 40.6%, T: 23.7°C
2020-01-14 10:19:50,195 # H: 40.7%, T: 23.7°C
2020-01-14 10:19:50,276 # H: 40.6%, T: 23.7°C
2020-01-14 10:19:50,357 # H: 40.6%, T: 23.7°C
2020-01-14 10:19:50,437 # H: 40.7%, T: 23.7°C
2020-01-14 10:19:50,518 # H: 40.6%, T: 23.7°C
2020-01-14 10:19:50,599 # H: 40.6%, T: 23.7°C
2020-01-14 10:19:50,680 # H: 40.6%, T: 23.7°C

@fjmolinas fjmolinas merged commit a6cf5cf into RIOT-OS:master Jan 14, 2020
@aabadie aabadie deleted the pr/cpu/fe310_i2c branch January 14, 2020 09:27
@aabadie
Copy link
Contributor Author

aabadie commented Jan 14, 2020

Thank you @fjmolinas !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: cpu Area: CPU/MCU ports Area: drivers Area: Device drivers CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: RISC-V Platform: This PR/issue effects RISC-V-based platforms Type: new feature The issue requests / The PR implemements a new feature for RIOT

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants