-
Notifications
You must be signed in to change notification settings - Fork 17
[spi_host] Low-level SD card support #446
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,3 +27,6 @@ __pycache__ | |
| scratch/ | ||
| # clangd | ||
| .cache | ||
|
|
||
| # SD card image file | ||
| sd.img | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,13 +30,21 @@ module top_chip_verilator ( | |
| logic uart_rx; | ||
| logic uart_tx; | ||
|
|
||
| // SPI signals | ||
| // SPI device signals | ||
| logic spi_device_sck; | ||
| logic spi_device_csb; | ||
| logic [3:0] qspi_device_sdo; | ||
| logic [3:0] qspi_device_sdo_en; | ||
| logic spi_device_sdi; | ||
|
|
||
| // SPI host signals | ||
| logic spi_host_sck, spi_host_csb; | ||
| logic spi_host_sck_en, spi_host_csb_en; | ||
| logic spi_host_input; | ||
| logic [3:0] spi_host_sd_output; | ||
| logic [3:0] spi_host_sd_en_output; | ||
| logic microsd_det; | ||
|
|
||
| // Noise source signals | ||
| logic rng_enable; | ||
| logic rng_valid; | ||
|
|
@@ -46,9 +54,6 @@ module top_chip_verilator ( | |
| top_pkg::axi_dram_req_t dram_req; | ||
| top_pkg::axi_dram_resp_t dram_resp; | ||
|
|
||
| logic [3:0] spi_host_sd; | ||
| logic [3:0] spi_host_sd_en; | ||
|
|
||
| // CHERI Mocha top | ||
| top_chip_system #( | ||
| .SramInitFile(""), | ||
|
|
@@ -57,7 +62,7 @@ module top_chip_verilator ( | |
| .clk_i, | ||
| .rst_ni, | ||
|
|
||
| .gpio_i (gpio_inputs), | ||
| .gpio_i ({gpio_inputs[31:10], microsd_det, gpio_inputs[8:0]}), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a little bit ugly because the gpio_input now will just ignore any writes to bit index 9. I'm not sure how to solve it more cleanly though.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, I'm open to better ideas
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only thing I can think of is that it is probably better to put the microSD detection in the most significant bit rather than in the middle. What do you think?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you do change the GPIO, make sure to update this line in the devicetree and regenerate it: https://github.com/lowRISC/mocha/blob/main/sw/device/devicetree/mocha.dts#L76
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Introducing a gap in the range of GPI lines in use might make things trickier on the FPGA-side, where at the moment the input signal is only wide enough for the number of GPI lines assigned to pins. We could change it so that the FPGA GPI input is 32-bits wide and only assign some a subset to pins in the XDC file, or we could adopt #411 and have the mapping of board signals to GPI lines in the RTL rather than constraints, where it would be easier to assign some constant values.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @marnovandermaas your thoughts would be appreciated
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I would go for a gap where the most significant bits are ones you cannot affect by the DPI and any future general purpose inputs that can be affected by the DPI can be added contiguously at the bottom. I'm happy for you to also implement the #411 at the same time if you think that's not too much work.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alright, I'll move the input to a higher index. I might do the rest of the FPGA pin remapping an a subsequent PR. @ziuziakowska Is there documentation you could point me to for how to re-generate the device tree? |
||
| .gpio_o (gpio_outputs), | ||
| .gpio_en_o (gpio_en_outputs), | ||
|
|
||
|
|
@@ -82,17 +87,15 @@ module top_chip_verilator ( | |
| .spi_device_sd_i ({3'h0, spi_device_sdi}), // SPI MOSI = QSPI DQ0 | ||
| .spi_device_tpm_csb_i ('0), | ||
|
|
||
| .spi_host_sck_o ( ), | ||
| .spi_host_sck_en_o ( ), | ||
| .spi_host_csb_o ( ), | ||
| .spi_host_csb_en_o ( ), | ||
| .spi_host_sd_o (spi_host_sd), | ||
| .spi_host_sd_en_o (spi_host_sd_en), | ||
| // Mapping output 0 to input 1 because legacy SPI does not allow | ||
| // bi-directional wires. | ||
| // This only works in standard mode where sd_o[0]=COPI and | ||
| // sd_i[1]=CIPO. | ||
| .spi_host_sd_i ({2'b0, spi_host_sd_en[0] ? spi_host_sd[0] : 1'b0, 1'b0}), | ||
| .spi_host_sck_o (spi_host_sck), | ||
| .spi_host_sck_en_o (spi_host_sck_en), | ||
| .spi_host_csb_o (spi_host_csb), | ||
| .spi_host_csb_en_o (spi_host_csb_en), | ||
| .spi_host_sd_o (spi_host_sd_output), | ||
| .spi_host_sd_en_o (spi_host_sd_en_output), | ||
| // Legacy SPI present in SD cards does not allow bi-directional wires. | ||
| // Work in standard mode where sd_o[0]=COPI and sd_i[1]=CIPO. | ||
| .spi_host_sd_i ({2'b0, spi_host_input, 1'b0}), // SPI CIPO = QSPI DQ1 | ||
|
|
||
| .entropy_src_rng_enable_o (rng_enable), | ||
| .entropy_src_rng_valid_i (rng_valid), | ||
|
|
@@ -108,8 +111,7 @@ module top_chip_verilator ( | |
| ); | ||
|
|
||
| // No support for dual or quad SPI in loopback mode right now. | ||
| logic unused_spi_host = (|spi_host_sd[3:2]) | spi_host_sd[0] | | ||
| (|spi_host_sd_en[3:2]) | spi_host_sd_en[0]; | ||
| logic unused_spi_host = |{spi_host_sd_output[3:1], spi_host_sd_en_output[3:1]}; | ||
|
|
||
| // Virtual GPIO | ||
| gpiodpi #( | ||
|
|
@@ -161,8 +163,25 @@ module top_chip_verilator ( | |
| .spi_device_sck_o (spi_device_sck), | ||
| .spi_device_csb_o (spi_device_csb), | ||
| .spi_device_sdi_o (spi_device_sdi), | ||
| .spi_device_sdo_i (qspi_device_sdo[1]), // SPI MISO = QSPI DQ1 | ||
| .spi_device_sdo_en_i(qspi_device_sdo_en[1]) // SPI MISO = QSPI DQ1 | ||
| .spi_device_sdo_i (qspi_device_sdo[1]), // SPI CIPO = QSPI DQ1 | ||
| .spi_device_sdo_en_i(qspi_device_sdo_en[1]) // SPI CIPO = QSPI DQ1 | ||
| ); | ||
|
|
||
| // Virtual SPI Device - model an SD card (in a limited way) | ||
| spidevicedpi #( | ||
| .ID ("microsd"), | ||
| .NDevices (1), | ||
| .DataW (1), | ||
| .OOB_InW (1), | ||
| .OOB_OutW (1) | ||
| ) u_spidevicedpi_microsd ( | ||
| .rst_ni, | ||
| .sck (spi_host_sck_en ? spi_host_sck : 1'b0), | ||
| .cs (spi_host_csb_en ? spi_host_csb : 1'b0), | ||
| .copi (spi_host_sd_en_output[0] ? spi_host_sd_output[0] : 1'b0), // SPI COPI = QSPI DQ0 | ||
| .cipo (spi_host_input), | ||
| .oob_in ( ), // not used | ||
| .oob_out(microsd_det) | ||
| ); | ||
|
|
||
| `define DUT u_top_chip_system | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.