Skip to content

Commit d56f942

Browse files
authored
Update spi_api.c
Modified line 145: previously the fill character has been hard coded to 0x00. However in Mbed OS core SPI_FILL_CHAR is defined in the core to be 0xFF by default (one can change that through mbed_app.json for example). This mod allows us to use the same fill character that is defined for Mbed OS. Also modified spi_master_block_write(): previously it called am_hal_iom_blocking_transfer on line 182, but that prevented succesful SD card writing operations. Now i changed that part to am_hal_iom_spi_blocking_fullduplex and SD functionality seems to be working.
1 parent c2bddbb commit d56f942

File tree

1 file changed

+8
-4
lines changed
  • targets/TARGET_Ambiq_Micro/TARGET_Apollo3/device

1 file changed

+8
-4
lines changed

targets/TARGET_Ambiq_Micro/TARGET_Apollo3/device/spi_api.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ void spi_frequency(spi_t *obj, int hz)
142142
int spi_master_write(spi_t *obj, int value)
143143
{
144144
uint32_t rxval = 0;
145-
spi_master_block_write(obj, (const char *)&value, 1, (char *)&rxval, 1, 0x00);
145+
spi_master_block_write(obj, (const char *)&value, 1, (char *)&rxval, 1, SPI_FILL_CHAR);
146146
return rxval;
147147
}
148148

@@ -167,7 +167,7 @@ int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, cha
167167
}
168168

169169
// handle difference between buffers
170-
if (tx_length != rx_length) {
170+
else if (tx_length != rx_length) {
171171
bool Rw = (rx_length >= tx_length);
172172

173173
// set up common config
@@ -177,9 +177,13 @@ int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, cha
177177
xfer.pui32TxBuffer = (Rw) ? NULL : (uint32_t *)(tx_buffer + chars_handled);
178178

179179
uint32_t status = AM_HAL_STATUS_SUCCESS;
180-
if (!Rw || (write_fill == 0x00)) {
180+
if (!Rw || (write_fill == SPI_FILL_CHAR)) {
181181
// when transmitting (w) or reading with a zero fill just use a simplex transfer
182-
status = am_hal_iom_blocking_transfer(obj->spi.iom_obj.iom.handle, &xfer);
182+
uint8_t fill[xfer.ui32NumBytes];
183+
memset(fill, write_fill, xfer.ui32NumBytes);
184+
xfer.eDirection = AM_HAL_IOM_FULLDUPLEX;
185+
xfer.pui32RxBuffer = (uint32_t *)&fill;
186+
uint32_t status = am_hal_iom_spi_blocking_fullduplex(obj->spi.iom_obj.iom.handle, &xfer);
183187
if (AM_HAL_STATUS_SUCCESS != status) {
184188
return chars_handled;
185189
}

0 commit comments

Comments
 (0)