Support for SPI and EEPROM in amc board #249
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds to
embot::hw
the support forSPI
,EEPROM
and the STM chipM95512DF
which is a ... spi EEPROM mounted on theamc
board.This PR also requires this one on
icub-firmware-shared
.The code was tested on the
amc
board on a dedicated project and works fine.IMPORTANT.
The SPI driver with the added configuration features for speed, datasize and shape of the frame is ready to use by a AEA sensor (or other absolute SPI encoder) which can be attached to the J5 connector of the
amc
board. The driver for the AEA is yet to be developed but can follow the guideline that I have used forembot::hw::chip::M95512DF
For this reason, in the
SPI
driver and for theM95512DF
chip I have also added some documentation and for theM95512DF
chip also a test function which describes how to use the chip.Here are some more details.
Configuration of the
embot::hw::spi
driverThe driver can be configured through
embot::hw::spi::Config
which allows, so far, to adaptspeed, datasize and shape of the SPI dataframe.
The pinout of the clock (SCLK), master output/slave input (MOSI), master input/slave output (MISO),
and slave select (SS) are for now not managed in here. They are initted at startup by
embot::hw::bsp::init()
.The
embot::hw::spi::Prescaler
It allows to scale the bus used by SPI to match some discrete speeds.
The
embot::hw::spi::DataSize
It allows to form a dataframe of different sizes.
The
embot::hw::spi::Mode
It shapes the data frame. That can happens in four different modes whiche end up in binary values of
two parameters: the clock polarity (CPOL) and the clock phase (CPHA).
A CPOL = 0 means that the clock line idles low and similarly CPOL = 1 means clock line idles high.
And if CPHA = 0 the bits are sampled on the leading clock edge, else if CPHA = 1 ar ecampled on the trailing ege.
All four possible combinations are shown in the following figure, alongside with the values of
embot::shw::spi::Mode
used in theembot::hw::spi
driver.Figure. Description of
embot::shw::spi::Mode
.Description of the
embot::hw::chip::M95512DF
This class
embot::hw::chip::M95512DF
implements a device driver for the chip M95512-DF which is an SPI EEPROM of size 64 KB and page size 128 B.Figure 1. Logic diagram.
Table 1. Signals.
Basic usage
You can use the following code, as long as the settings for SPI are specified by the bsp of the board.
Code listing. Usage of the class
Code listing. Usage of the class, part 2.
Caveat Emptor
The interface of the device driver is kept intentionally simple and some features are left (for now) inside the private implementation.
References
[1] Datasheet of M95512-W M95512-R M95512-DF, DS4192 - Rev 24 - September 2021