Skip to content

Commit

Permalink
Testing hacky DMA workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralim committed Jan 30, 2022
1 parent 969611c commit 5c78958
Showing 1 changed file with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1831,15 +1831,41 @@ HAL_StatusTypeDef HAL_I2C_Master_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint16_t
hi2c->hdmatx->XferHalfCpltCallback = NULL;
hi2c->hdmatx->XferAbortCallback = NULL;

/* Enable the DMA channel */
HAL_DMA_Start_IT(hi2c->hdmatx, (uint32_t)hi2c->pBuffPtr, (uint32_t)&hi2c->Instance->DR, hi2c->XferSize);

/* Enable Acknowledge */
hi2c->Instance->CR1 |= I2C_CR1_ACK;

/* Generate Start */
hi2c->Instance->CR1 |= I2C_CR1_START;

/* Wait until SB flag is set */
if (I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_SB, RESET, HAL_MAX_DELAY, HAL_GetTick()) != HAL_OK) {
__HAL_UNLOCK(hi2c);
return HAL_TIMEOUT;
}

if (hi2c->Init.AddressingMode == I2C_ADDRESSINGMODE_7BIT) {
/* Send slave address */
hi2c->Instance->DR = I2C_7BIT_ADD_WRITE(DevAddress);
} else {
// Not used
}

/* Wait until ADDR flag is set */
if (I2C_WaitOnMasterAddressFlagUntilTimeout(hi2c, I2C_FLAG_ADDR, HAL_MAX_DELAY, HAL_GetTick()) != HAL_OK) {
if (hi2c->ErrorCode == HAL_I2C_ERROR_AF) {
__HAL_UNLOCK(hi2c);
return HAL_ERROR;
} else {
__HAL_UNLOCK(hi2c);
return HAL_TIMEOUT;
}
}
/* Clear ADDR flag */
__HAL_I2C_CLEAR_ADDRFLAG(hi2c);

/* Enable the DMA channel */
HAL_DMA_Start_IT(hi2c->hdmatx, (uint32_t)hi2c->pBuffPtr + 1, (uint32_t)&hi2c->Instance->DR, hi2c->XferSize - 1);

/* Process Unlocked */
__HAL_UNLOCK(hi2c);

Expand Down

0 comments on commit 5c78958

Please sign in to comment.