cpu/fe310, board/hifive1: SPI support#10833
cpu/fe310, board/hifive1: SPI support#10833pyropeter wants to merge 4 commits intoRIOT-OS:masterfrom
Conversation
Until now fe310's cpu_init() was missing a call to periph_init(). This commit adds this call.
maribu
left a comment
There was a problem hiding this comment.
This looks pretty good to me. I have found something to nitpick about, though ;-)
Sadly I'm unable to test this. Maybe I should consider buying a board...
| USEMODULE += periph_pm | ||
|
|
||
| # include common periph drivers | ||
| USEMODULE += periph_common |
There was a problem hiding this comment.
Anyway, this is not needed, so just remove it.
| /** | ||
| * @brief Allocation device locks | ||
| */ | ||
| static mutex_t lock; |
There was a problem hiding this comment.
Maybe it would make sharing the code with future versions of the CPU that could potentially have multiple SPI interface easier when you use something like that:
#define SPI_INTERFACE_NUM 1
static mutex_t lock[SPI_INTERFACE_NUM];(I'm only suggesting this, not insisting on this.)
|
|
||
| void spi_init_pins(spi_t bus) | ||
| { | ||
| (void) bus; |
There was a problem hiding this comment.
Should not needed because of the assert(bus == 0); below. (I believe both GCC and clang should still be aware that bus was used even when NDEBUG is defined, but I'm not 100% sure about that. So please correct me if I'm wrong.)
|
|
||
| int spi_acquire(spi_t bus, spi_cs_t cs, spi_mode_t mode, spi_clk_t clk) | ||
| { | ||
| (void) bus; |
There was a problem hiding this comment.
I think it would make life easier to also add assert()s for bus and cs here, so that developers are supported in finding their bugs in using the SPI interface.
|
|
||
| void spi_release(spi_t bus) | ||
| { | ||
| (void) bus; |
There was a problem hiding this comment.
Again I would suggest to add an assert()
| uint32_t rxdata = SPI_RXFIFO_EMPTY; | ||
| while (rxdata & SPI_RXFIFO_EMPTY) { | ||
| rxdata = SPI1_REG(SPI_REG_RXFIFO); | ||
| } |
There was a problem hiding this comment.
How about
uint32_t rxdata;
do {
rxdata = SPI1_REG(SPI_REG_RXFIFO);
} while (rxdata & SPI_RXFIFO_EMPTY);|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions. |
|
I'll try to use phillip to test this! |
| USEMODULE += sifive_drivers_fe310 | ||
|
|
||
| USEMODULE += periph | ||
| USEMODULE += periph_common |
There was a problem hiding this comment.
This is not needed, just remove it.
| USEMODULE += periph_pm | ||
|
|
||
| # include common periph drivers | ||
| USEMODULE += periph_common |
There was a problem hiding this comment.
Anyway, this is not needed, so just remove it.
| set_csr(mstatus, MSTATUS_DEFAULT); | ||
|
|
||
| /* trigger static peripheral initialization */ | ||
| periph_init(); |
There was a problem hiding this comment.
This is already in master. Maybe just rebase this PR so this change is dropped from GitHub diff ?
| * #define CLOCK_CORECLOCK (38400000ul) | ||
| */ | ||
| /* As defined in boards/hifive1/board.c CPU_DESIRED_FREQ **/ | ||
| #define CLOCK_CORECLOCK (200000000ul) |
There was a problem hiding this comment.
You might be interested by #12934 where the value of the core clock is automatically computed when using the PLL or HFXOSC.
Maybe rebase this PR on top of it ?
| FEATURES_PROVIDED += periph_rtc | ||
| FEATURES_PROVIDED += periph_rtt | ||
| #FEATURES_PROVIDED += periph_spi | ||
| FEATURES_PROVIDED += periph_spi |
There was a problem hiding this comment.
This could also be applied to the hifive1b (I can test on this board actually).
| DIV_UP(CLOCK_CORECLOCK, 2 * 10000000) - 1, | ||
| }; | ||
| #undef DIV_UP | ||
| #define SPI_NUMOF (1) |
There was a problem hiding this comment.
I would like to have some struct based configuration. See #12917 where I changed the UART to use this scheme. I find this convenient, at least to know which pins are connected the serial interface and it's more consistent with most of other board configurations in RIOT (like STM, SAM, nRF).
|
@aabadie This is quite old, and I forgot most of the details regarding this PR. I also stopped using RIOT and I don't have a lot of time at the moment, so I will not continue working on this PR. Feel free to take the code and do whatever you like with it. (But please update the author and copyright information so that it doesn't look like I alone wrote the resulting code. Where appropriate, feel free to remove my name completely.) |
|
I was planning to write the SPI driver when I saw your PR. I'll use it as a base and will keep your authorship. You have already done most of the work. |
|
The replacement PR is here: #12957. Except the configuration and the reuse of clock improvement from #12934, the initial version was already working well. Thanks for the work @pyropeter. |
Please note: This is not tested as much as I would like. Please wait with merging until I had a look with an oscilloscope.
Contribution description
periph/spioncpu/fe310andboard/hifive1Testing procedure
Issues/PRs references
Depends on and includes PR cpu/fe310: Add call to periph_init() #10825(merged)Depends on and includes PR boards/hifive1: fix CLOCK_CORECLOCK #10805(merged)