Skip to content
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

[STM32F4] Add asynchronous I2C #2622

Merged
merged 8 commits into from
Sep 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions hal/targets.json
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@
"progen": {"target": "nucleo-f401re"},
"detect_code": ["0720"],
"macros": ["TRANSACTION_QUEUE_SIZE_SPI=2"],
"device_has": ["ANALOGIN", "ERROR_RED", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES"],
"device_has": ["ANALOGIN", "ERROR_RED", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES"],
"release_versions": ["2", "5"]
},
"NUCLEO_F410RB": {
Expand All @@ -796,7 +796,7 @@
"progen": {"target": "nucleo-f410rb"},
"macros": ["MBEDTLS_ENTROPY_HARDWARE_ALT", "TRANSACTION_QUEUE_SIZE_SPI=2"],
"detect_code": ["0740"],
"device_has": ["ANALOGIN", "ANALOGOUT", "ERROR_RED", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES"],
"device_has": ["ANALOGIN", "ANALOGOUT", "ERROR_RED", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES"],
"release_versions": ["2", "5"]
},
"NUCLEO_F411RE": {
Expand All @@ -809,7 +809,7 @@
"progen": {"target": "nucleo-f411re"},
"detect_code": ["0740"],
"macros": ["TRANSACTION_QUEUE_SIZE_SPI=2"],
"device_has": ["ANALOGIN", "ERROR_RED", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES"],
"device_has": ["ANALOGIN", "ERROR_RED", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES"],
"release_versions": ["2", "5"]
},
"ELMO_F411RE": {
Expand All @@ -834,7 +834,7 @@
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
"progen": {"target": "nucleo-f429zi"},
"macros": ["MBEDTLS_ENTROPY_HARDWARE_ALT", "DEVICE_RTC_LSI=1", "TRANSACTION_QUEUE_SIZE_SPI=2"],
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "ERROR_RED", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES"],
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "ERROR_RED", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "RTC_LSI", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES"],
"detect_code": ["0796"],
"features": ["IPV4"],
"release_versions": ["2", "5"]
Expand All @@ -849,7 +849,7 @@
"progen": {"target": "nucleo-f446re"},
"detect_code": ["0777"],
"macros": ["TRANSACTION_QUEUE_SIZE_SPI=2"],
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "ERROR_RED", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES"],
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "ERROR_RED", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES"],
"release_versions": ["2", "5"]
},
"NUCLEO_F446ZE": {
Expand All @@ -862,7 +862,8 @@
"progen": {"target": "nucleo-f446ze"},
"detect_code": ["0778"],
"macros": ["TRANSACTION_QUEUE_SIZE_SPI=2"],
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "ERROR_RED", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES"]
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "ERROR_RED", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES"],
"release_versions": ["2", "5"]
},

"B96B_F446VE": {
Expand Down Expand Up @@ -1077,7 +1078,7 @@
"macros": ["MBEDTLS_ENTROPY_HARDWARE_ALT","DEVICE_RTC_LSI=1","TRANSACTION_QUEUE_SIZE_SPI=2"],
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
"progen": {"target": "disco-f429zi"},
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "ERROR_RED", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES"],
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "ERROR_RED", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES"],
"release_versions": ["2", "5"]
},
"DISCO_F469NI": {
Expand All @@ -1090,7 +1091,7 @@
"macros": ["MBEDTLS_ENTROPY_HARDWARE_ALT","TRANSACTION_QUEUE_SIZE_SPI=2"],
"progen": {"target": "disco-f469ni"},
"detect_code": ["0788"],
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "ERROR_RED", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES"],
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "ERROR_RED", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES"],
"release_versions": ["2", "5"]
},
"DISCO_L053C8": {
Expand Down
53 changes: 21 additions & 32 deletions hal/targets/cmsis/TARGET_STM/TARGET_STM32F4/stm32f4xx_hal_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,7 @@ HAL_StatusTypeDef HAL_I2C_Master_Sequential_Transmit_IT(I2C_HandleTypeDef *hi2c,

/* Process Unlocked */
__HAL_UNLOCK(hi2c);

return HAL_TIMEOUT;
}
}
Expand All @@ -1321,7 +1321,7 @@ HAL_StatusTypeDef HAL_I2C_Master_Sequential_Transmit_IT(I2C_HandleTypeDef *hi2c,
hi2c->Devaddress = DevAddress;

Prev_State = hi2c->PreviousState;

/* Generate Start */
if((Prev_State == I2C_STATE_MASTER_BUSY_RX) || (Prev_State == I2C_STATE_NONE))
{
Expand Down Expand Up @@ -3689,7 +3689,7 @@ static HAL_StatusTypeDef I2C_MasterTransmit_TXE(I2C_HandleTypeDef *hi2c)

/* Generate Stop */
hi2c->Instance->CR1 |= I2C_CR1_STOP;

hi2c->PreviousState = I2C_STATE_NONE;
hi2c->State = HAL_I2C_STATE_READY;

Expand Down Expand Up @@ -3840,6 +3840,7 @@ static HAL_StatusTypeDef I2C_MasterTransmit_BTF(I2C_HandleTypeDef *hi2c)
*/
static HAL_StatusTypeDef I2C_MasterReceive_RXNE(I2C_HandleTypeDef *hi2c)
{

if(hi2c->State == HAL_I2C_STATE_BUSY_RX)
{
uint32_t tmp = 0U;
Expand All @@ -3853,34 +3854,24 @@ static HAL_StatusTypeDef I2C_MasterReceive_RXNE(I2C_HandleTypeDef *hi2c)
}
else if((tmp == 2U) || (tmp == 3U))
{
if(hi2c->XferOptions != I2C_NEXT_FRAME)
{
/* Disable Acknowledge */
hi2c->Instance->CR1 &= ~I2C_CR1_ACK;

/* Enable Pos */
hi2c->Instance->CR1 |= I2C_CR1_POS;
}
else
{
/* Enable Acknowledge */
hi2c->Instance->CR1 |= I2C_CR1_ACK;
}
/* Disable Acknowledge */
hi2c->Instance->CR1 &= ~I2C_CR1_ACK;

/* Enable Pos */
hi2c->Instance->CR1 |= I2C_CR1_POS;

/* Disable BUF interrupt */
__HAL_I2C_DISABLE_IT(hi2c, I2C_IT_BUF);
}
else
{
if(hi2c->XferOptions != I2C_NEXT_FRAME)
{
/* Disable Acknowledge */
hi2c->Instance->CR1 &= ~I2C_CR1_ACK;
}
else
/* Disable Acknowledge */
hi2c->Instance->CR1 &= ~I2C_CR1_ACK;

if(hi2c->XferOptions == I2C_NEXT_FRAME)
{
/* Enable Acknowledge */
hi2c->Instance->CR1 |= I2C_CR1_ACK;
/* Enable Pos */
hi2c->Instance->CR1 |= I2C_CR1_POS;
}

/* Disable EVT, BUF and ERR interrupt */
Expand Down Expand Up @@ -3938,15 +3929,13 @@ static HAL_StatusTypeDef I2C_MasterReceive_BTF(I2C_HandleTypeDef *hi2c)
/* Prepare next transfer or stop current transfer */
if((CurrentXferOptions != I2C_FIRST_AND_LAST_FRAME) && (CurrentXferOptions != I2C_LAST_FRAME) && (CurrentXferOptions != I2C_NO_OPTION_FRAME))
{
if(CurrentXferOptions != I2C_NEXT_FRAME)
{
/* Disable Acknowledge */
hi2c->Instance->CR1 &= ~I2C_CR1_ACK;
}
else
/* Disable Acknowledge */
hi2c->Instance->CR1 &= ~I2C_CR1_ACK;

if((CurrentXferOptions == I2C_NEXT_FRAME) || (CurrentXferOptions == I2C_FIRST_FRAME))
{
/* Enable Acknowledge */
hi2c->Instance->CR1 |= I2C_CR1_ACK;
/* Generate Start */
hi2c->Instance->CR1 |= I2C_CR1_START;
}
tmp = (uint32_t)(hi2c->State) & I2C_STATE_MSK;
hi2c->PreviousState = tmp | (uint32_t)(hi2c->Mode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ struct dac_s {
uint8_t channel;
};

struct i2c_s {
I2CName i2c;
uint32_t slave;
};


#include "common_objects.h"
#include "gpio_object.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ struct dac_s {
uint8_t channel;
};

struct i2c_s {
I2CName i2c;
uint32_t slave;
};

struct can_s {
CANName can;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ struct analogin_s {
uint8_t channel;
};

struct i2c_s {
I2CName i2c;
uint32_t slave;
};

#include "common_objects.h"
#include "gpio_object.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ struct dac_s {
uint8_t channel;
};

struct i2c_s {
I2CName i2c;
uint32_t slave;
};

#include "common_objects.h"
#include "gpio_object.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ struct dac_s {
uint8_t channel;
};

struct i2c_s {
I2CName i2c;
uint32_t slave;
};

struct can_s {
CANName can;
int index;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ struct dac_s {
uint8_t channel;
};

struct i2c_s {
I2CName i2c;
uint32_t slave;
};

struct can_s {
CANName can;
int index;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ struct analogin_s {
uint8_t channel;
};

struct i2c_s {
I2CName i2c;
uint32_t slave;
};

#include "common_objects.h"
#include "gpio_object.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ struct analogin_s {
uint8_t channel;
};

struct i2c_s {
I2CName i2c;
uint32_t slave;
};

#include "common_objects.h"
#include "gpio_object.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ struct dac_s {
uint8_t channel;
};

struct i2c_s {
I2CName i2c;
uint32_t slave;
};

#include "common_objects.h"
#include "gpio_object.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ struct analogin_s {
uint8_t channel;
};

struct i2c_s {
I2CName i2c;
uint32_t slave;
};

#include "common_objects.h"
#include "gpio_object.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ struct analogin_s {
uint8_t channel;
};

struct i2c_s {
I2CName i2c;
uint32_t slave;
};

#include "common_objects.h"
#include "gpio_object.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ struct dac_s {
uint8_t channel;
};

struct i2c_s {
I2CName i2c;
uint32_t slave;
};

#include "common_objects.h"
#include "gpio_object.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ struct analogin_s {
uint8_t channel;
};

struct i2c_s {
I2CName i2c;
uint32_t slave;
};

#include "common_objects.h"
#include "gpio_object.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ struct dac_s {
uint8_t channel;
};

struct i2c_s {
I2CName i2c;
uint32_t slave;
};

struct can_s {
CANName can;
int index;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ struct dac_s {
uint8_t channel;
};

struct i2c_s {
I2CName i2c;
uint32_t slave;
};

struct can_s {
CANName can;
int index;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ struct dac_s {
uint8_t channel;
};

struct i2c_s {
I2CName i2c;
uint32_t slave;
};

struct can_s {
CANName can;
int index;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ struct analogin_s {



struct i2c_s {
I2CName i2c;
uint32_t slave;
};

#include "common_objects.h"
struct can_s {
CANName can;
Expand Down
Loading