Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpu/fe310: add spi peripheral driver #12957

Merged
merged 3 commits into from
Jan 14, 2020
Merged

Conversation

aabadie
Copy link
Contributor

@aabadie aabadie commented Dec 16, 2019

Contribution description

this PR is a rework of the original PR #10833 from @pyropeter.

It adds an implementation of the SPI peripheral driver for RISC-V FE310 cpu and configure 2 peripherals on hifive1 and hifive1b boards.

The PR was just tested with success using a bmp280 sensor plugged on the board. I'll try to find time for checking the bus with a logic analyzer.

Testing procedure

Simply plug an SPI device on the SPI pins available on the Arduino pinout and test it.
Example with bmp280:

  • Alter the default BMX280_PARAM_CS value in bmpx280_params.h as follows:
diff --git a/drivers/bmx280/include/bmx280_params.h b/drivers/bmx280/include/bmx280_params.h
index 09296398d0..8f6726b004 100644
--- a/drivers/bmx280/include/bmx280_params.h
+++ b/drivers/bmx280/include/bmx280_params.h
@@ -44,7 +44,7 @@ extern "C" {
 #define BMX280_PARAM_CLK            SPI_CLK_5MHZ
 #endif
 #ifndef BMX280_PARAM_CS
-#define BMX280_PARAM_CS             GPIO_PIN(0, 0)
+#define BMX280_PARAM_CS             GPIO_PIN(0, 2) /* Use Arduino D10 */
 #endif
 #else
 /* I2C configuration */
  • Build and run the test application with the bmp280_spi version:
DRIVER=bmp280_spi make BOARD=hifive1b -C tests/driver_bmx280 flash term
Test output
2019-12-16 10:44:32,568 # main(): This is RIOT! (Version: 2020.01-devel-1427-g2bc10-pr/cpu/fe310_spi)
2019-12-16 10:44:32,570 # BMX280 test application
2019-12-16 10:44:32,570 # 
2019-12-16 10:44:32,574 # +------------Initializing------------+
2019-12-16 10:44:32,578 # Initialization successful
2019-12-16 10:44:32,579 # 
2019-12-16 10:44:32,582 # +------------Calibration Data------------+
2019-12-16 10:44:32,584 # dig_T1: 27404
2019-12-16 10:44:32,586 # dig_T2: 26504
2019-12-16 10:44:32,587 # dig_T3: -1000
2019-12-16 10:44:32,588 # dig_P1: 37215
2019-12-16 10:44:32,589 # dig_P2: -10579
2019-12-16 10:44:32,590 # dig_P3: 3024
2019-12-16 10:44:32,591 # dig_P4: 846
2019-12-16 10:44:32,592 # dig_P5: 302
2019-12-16 10:44:32,593 # dig_P6: 249
2019-12-16 10:44:32,594 # dig_P7: 0
2019-12-16 10:44:32,595 # dig_P8: 0
2019-12-16 10:44:32,596 # dig_P9: 0
2019-12-16 10:44:32,597 # 
2019-12-16 10:44:32,600 # +--------Starting Measurements--------+
2019-12-16 10:44:32,609 # Temperature [°C]: 23.46
2019-12-16 10:44:32,611 #    Pressure [Pa]: 98756
2019-12-16 10:44:32,612 # 
2019-12-16 10:44:32,615 # +-------------------------------------+
2019-12-16 10:44:32,615 # 
2019-12-16 10:44:34,618 # Temperature [°C]: 23.46
2019-12-16 10:44:34,620 #    Pressure [Pa]: 98764
2019-12-16 10:44:34,620 # 
2019-12-16 10:44:34,624 # +-------------------------------------+
2019-12-16 10:44:34,624 # 
2019-12-16 10:44:36,625 # Temperature [°C]: 23.45
2019-12-16 10:44:36,627 #    Pressure [Pa]: 98760
2019-12-16 10:44:36,628 # 
2019-12-16 10:44:36,631 # +-------------------------------------+
2019-12-16 10:44:36,631 # 
2019-12-16 10:44:38,633 # Temperature [°C]: 23.45
2019-12-16 10:44:38,635 #    Pressure [Pa]: 98768
2019-12-16 10:44:38,635 # 
2019-12-16 10:44:38,638 # +-------------------------------------+
2019-12-16 10:44:38,639 # 
2019-12-16 10:44:40,640 # Temperature [°C]: 23.46
2019-12-16 10:44:40,642 #    Pressure [Pa]: 98767
2019-12-16 10:44:40,642 # 
2019-12-16 10:44:40,646 # +-------------------------------------+
2019-12-16 10:44:40,646 # 
2019-12-16 10:44:42,648 # Temperature [°C]: 23.46
2019-12-16 10:44:42,650 #    Pressure [Pa]: 98762
2019-12-16 10:44:42,650 # 
2019-12-16 10:44:42,653 # +-------------------------------------+
2019-12-16 10:44:42,654 # 
2019-12-16 10:44:44,655 # Temperature [°C]: 23.46
2019-12-16 10:44:44,657 #    Pressure [Pa]: 98761
2019-12-16 10:44:44,658 # 
2019-12-16 10:44:44,661 # +-------------------------------------+
2019-12-16 10:44:44,661 # 
2019-12-16 10:44:46,663 # Temperature [°C]: 27.57
2019-12-16 10:44:46,665 #    Pressure [Pa]: 98769
2019-12-16 10:44:46,665 # 
2019-12-16 10:44:46,668 # +-------------------------------------+
2019-12-16 10:44:46,668 # 
2019-12-16 10:44:48,670 # Temperature [°C]: 25.53
2019-12-16 10:44:48,672 #    Pressure [Pa]: 98771
2019-12-16 10:44:48,673 # 
2019-12-16 10:44:48,676 # +-------------------------------------+
2019-12-16 10:44:48,676 # 
2019-12-16 10:44:50,678 # Temperature [°C]: 25.65
2019-12-16 10:44:50,680 #    Pressure [Pa]: 98775
2019-12-16 10:44:50,680 # 
2019-12-16 10:44:50,683 # +-------------------------------------+
2019-12-16 10:44:50,683 # 

Issues/PRs references

Based on #12934, closes #10833

@aabadie aabadie added Type: new feature The issue requests / The PR implemements a new feature for RIOT 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 Area: cpu Area: CPU/MCU ports labels Dec 16, 2019
@aabadie aabadie added the State: waiting for other PR State: The PR requires another PR to be merged first label Dec 16, 2019
@kaspar030
Copy link
Contributor

/opt/gnu-mcu-eclipse/riscv-none-gcc/8.2.0-2.2-20190521-0004/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld: region `ram' overflowed by 0 bytes

0 bytes!! 😉

@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 CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Jan 11, 2020
@aabadie
Copy link
Contributor Author

aabadie commented Jan 11, 2020

rebased

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.

Some comments, will test on monday.

@@ -110,6 +110,23 @@ static const uart_conf_t uart_config[] = {
#define UART_NUMOF ARRAY_SIZE(uart_config)
/** @} */

/**
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like they could share the configuration file no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes and I'm planning to merge them in a common folder once all the new features are in: all other board peripheral configurations could also be shared in fact.

Copy link
Contributor

Choose a reason for hiding this comment

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

So you don't want to address here?

Copy link
Contributor

Choose a reason for hiding this comment

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

But ina follow up?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, otherwise, I'll have to rework all the other ones (i2c, pwm).

Comment on lines +94 to +95
/* setting the CS high before configuring it as an
output should be fine on FE310. */
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm, not really, this was already implemented this way in the original PR. Maybe @pyropeter can give some insight ?

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:

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

Test doesn't work:

2020-01-13 10:27:55,311 # 
2020-01-13 10:27:55,362 # ATE0-->ATE0
2020-01-13 10:27:55,380 # OK
2020-01-13 10:27:55,536 # AT+BLEINIT=0-->OK
2020-01-13 10:27:55,692 # AT+CWMODE=0-->OK
2020-01-13 10:27:55,692 # 
2020-01-13 10:27:55,704 # main(): This is RIOT! (Version: 2020.01-devel-1680-g8dd35-pr-12957)
2020-01-13 10:27:55,708 # Failed to initialize SX127x device, exiting

@aabadie
Copy link
Contributor Author

aabadie commented Jan 13, 2020

I see a conflict in the used pins with the esp module

This is normal, this is the SPI that should be used to control the ESP module.

Test doesn't work

Maybe try with a simpler module, the SX127x needs several gpios to be connected to the boards (and thus requires specific driver params).

@fjmolinas
Copy link
Contributor

Maybe try with a simpler module, the SX127x needs several gpios to be connected to the boards (and thus requires specific driver params).

Ah I did not realize that.

@fjmolinas
Copy link
Contributor

This is normal, this is the SPI that should be used to control the ESP module.

It seems the ESP is getting in the way of any spi initialization, what module did you use to test this?

@aabadie
Copy link
Contributor Author

aabadie commented Jan 13, 2020

Following the testing procedure, it works (without rebase to latest master, e.g not containing the xtimer "enhancements" from #9530):

$ DRIVER=bme280_spi make BOARD=hifive1b -C tests/driver_bmx280 flash term
make: Entering directory '/work/riot/RIOT/tests/driver_bmx280'
Building application "tests_driver_bmx280" 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/bmx280
"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/fmt
"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
  16680	    136	   2524	  19340	   4b8c	/work/riot/RIOT/tests/driver_bmx280/bin/hifive1b/tests_driver_bmx280.elf
/work/riot/RIOT/dist/tools/jlink/jlink.sh flash /work/riot/RIOT/tests/driver_bmx280/bin/hifive1b/tests_driver_bmx280.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_bmx280/bin/hifive1b/tests_driver_bmx280.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.647s (Prepare: 0.103s, Compare: 0.036s, Erase: 0.172s, Program: 0.284s, Verify: 0.033s, 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:57:43,530 # Connect to serial port /dev/ttyACM0
Welcome to pyterm!
Bench Clock Reset Complete
2020-01-13 12:57:44,532 # 
2020-01-13 12:57:45,894 # ATE0-->Send Flag Timed Out Busy. Giving Up.
2020-01-13 12:57:47,270 #  Send Flag error: #255 #255 #255 #255 AT+BLEINIT=0-->Send Flag Timed Out Busy. Giving Up.
2020-01-13 12:57:48,646 #  Send Flag error: #255 #255 #255 #255 AT+CWMODE=0-->Send Flag Timed Out Busy. Giving Up.
2020-01-13 12:57:48,649 #  Send Flag error: #255 #255 #255 #255 
2020-01-13 12:57:48,657 # Help: Press s to start test, r to print it is ready
s
2020-01-13 12:57:50,055 # START
2020-01-13 12:57:50,061 # main(): This is RIOT! (Version: 2020.01-devel-1680-g8dd35-pr/cpu/fe310_spi)
2020-01-13 12:57:50,063 # BMX280 test application
2020-01-13 12:57:50,064 # 
2020-01-13 12:57:50,067 # +------------Initializing------------+
2020-01-13 12:57:50,070 # Initialization successful
2020-01-13 12:57:50,070 # 
2020-01-13 12:57:50,074 # +------------Calibration Data------------+
2020-01-13 12:57:50,075 # dig_T1: 28497
2020-01-13 12:57:50,076 # dig_T2: 26274
2020-01-13 12:57:50,077 # dig_T3: 50
2020-01-13 12:57:50,078 # dig_P1: 37174
2020-01-13 12:57:50,080 # dig_P2: -10773
2020-01-13 12:57:50,081 # dig_P3: 3024
2020-01-13 12:57:50,082 # dig_P4: 9121
2020-01-13 12:57:50,083 # dig_P5: -67
2020-01-13 12:57:50,084 # dig_P6: 249
2020-01-13 12:57:50,085 # dig_P7: 0
2020-01-13 12:57:50,086 # dig_P8: 0
2020-01-13 12:57:50,087 # dig_P9: 0
2020-01-13 12:57:50,087 # dig_H1: 75
2020-01-13 12:57:50,089 # dig_H2: 334
2020-01-13 12:57:50,089 # dig_H3: 0
2020-01-13 12:57:50,090 # dig_H4: 393
2020-01-13 12:57:50,091 # dig_H5: 50
2020-01-13 12:57:50,092 # dig_H6: 30
2020-01-13 12:57:50,093 # 
2020-01-13 12:57:50,096 # +--------Starting Measurements--------+
2020-01-13 12:57:50,098 # Temperature [°C]: 26.61
2020-01-13 12:57:50,100 #    Pressure [Pa]: 99958
2020-01-13 12:57:50,102 #   Humidity [%rH]: 29.91
2020-01-13 12:57:50,103 # 
2020-01-13 12:57:50,106 # +-------------------------------------+
2020-01-13 12:57:50,106 # 
2020-01-13 12:57:52,108 # Temperature [°C]: 26.61
2020-01-13 12:57:52,110 #    Pressure [Pa]: 99963
2020-01-13 12:57:52,112 #   Humidity [%rH]: 29.91
2020-01-13 12:57:52,112 # 
2020-01-13 12:57:52,115 # +-------------------------------------+
2020-01-13 12:57:52,116 # 
2020-01-13 12:57:54,117 # Temperature [°C]: 26.56
2020-01-13 12:57:54,119 #    Pressure [Pa]: 99964
2020-01-13 12:57:54,121 #   Humidity [%rH]: 30.09
2020-01-13 12:57:54,121 # 
2020-01-13 12:57:54,125 # +-------------------------------------+
2020-01-13 12:57:54,125 # 
2020-01-13 12:57:56,126 # Temperature [°C]: 26.52
2020-01-13 12:57:56,128 #    Pressure [Pa]: 99960
2020-01-13 12:57:56,130 #   Humidity [%rH]: 30.14
2020-01-13 12:57:56,130 # 
2020-01-13 12:57:56,134 # +-------------------------------------+
2020-01-13 12:57:56,134 # 
2020-01-13 12:57:58,135 # Temperature [°C]: 26.49
2020-01-13 12:57:58,138 #    Pressure [Pa]: 99957
2020-01-13 12:57:58,140 #   Humidity [%rH]: 30.04
2020-01-13 12:57:58,140 # 
2020-01-13 12:57:58,143 # +-------------------------------------+
2020-01-13 12:57:58,143 # 
2020-01-13 12:58:00,145 # Temperature [°C]: 26.44
2020-01-13 12:58:00,147 #    Pressure [Pa]: 99966
2020-01-13 12:58:00,149 #   Humidity [%rH]: 30.05
2020-01-13 12:58:00,149 # 
2020-01-13 12:58:00,152 # +-------------------------------------+
2020-01-13 12:58:00,153 # 
2020-01-13 12:58:00,261 # Exiting Pyterm

@fjmolinas
Copy link
Contributor

Well.... layer 8 issue had forgotten o apply the patch duh:

2020-01-14 10:54:00,311 # BMX280 test application
2020-01-14 10:54:00,311 # 
2020-01-14 10:54:00,314 # +------------Initializing------------+
2020-01-14 10:54:00,318 # Initialization successful
2020-01-14 10:54:00,318 # 
2020-01-14 10:54:00,322 # +------------Calibration Data------------+
2020-01-14 10:54:00,323 # dig_T1: 28497
2020-01-14 10:54:00,324 # dig_T2: 26274
2020-01-14 10:54:00,325 # dig_T3: 50
2020-01-14 10:54:00,327 # dig_P1: 37174
2020-01-14 10:54:00,328 # dig_P2: -10773
2020-01-14 10:54:00,329 # dig_P3: 3024
2020-01-14 10:54:00,330 # dig_P4: 9121
2020-01-14 10:54:00,331 # dig_P5: -67
2020-01-14 10:54:00,332 # dig_P6: 249
2020-01-14 10:54:00,333 # dig_P7: 0
2020-01-14 10:54:00,334 # dig_P8: 0
2020-01-14 10:54:00,334 # dig_P9: 0
2020-01-14 10:54:00,335 # dig_H1: 75
2020-01-14 10:54:00,336 # dig_H2: 334
2020-01-14 10:54:00,337 # dig_H3: 0
2020-01-14 10:54:00,338 # dig_H4: 393
2020-01-14 10:54:00,339 # dig_H5: 50
2020-01-14 10:54:00,340 # dig_H6: 30
2020-01-14 10:54:00,341 # 
2020-01-14 10:54:00,344 # +--------Starting Measurements--------+
2020-01-14 10:54:00,346 # Temperature [°C]: 24.77
2020-01-14 10:54:00,348 #    Pressure [Pa]: 99252
2020-01-14 10:54:00,350 #   Humidity [%rH]: 29.55
2020-01-14 10:54:00,350 # 
2020-01-14 10:54:00,354 # +-------------------------------------+
2020-01-14 10:54:00,354 # 

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

@fjmolinas fjmolinas merged commit f76f7c7 into RIOT-OS:master Jan 14, 2020
@aabadie aabadie deleted the pr/cpu/fe310_spi branch January 14, 2020 10:06
@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.

4 participants