mbed library sources
Fork of mbed-src by
Revision 183:46ae3190e86c, committed 2014-05-07
- Comitter:
- mbed_official
- Date:
- Wed May 07 17:45:07 2014 +0100
- Parent:
- 182:242346c42295
- Child:
- 184:8b5ae2e87659
- Commit message:
- Synchronized with git revision 152b58673f64d18174038282d90ca97e67d44ae2
Full URL: https://github.com/mbedmicro/mbed/commit/152b58673f64d18174038282d90ca97e67d44ae2/
Ensure the NVIC table gets copied to RAM even when it is not at 0x0000
Changed in this revision
--- a/targets/cmsis/TARGET_NXP/TARGET_LPC176X/cmsis_nvic.c Wed May 07 13:30:07 2014 +0100 +++ b/targets/cmsis/TARGET_NXP/TARGET_LPC176X/cmsis_nvic.c Wed May 07 17:45:07 2014 +0100 @@ -13,7 +13,7 @@ uint32_t i; // Copy and switch to dynamic vectors if the first time called - if (SCB->VTOR == NVIC_FLASH_VECTOR_ADDRESS) { + if (SCB->VTOR < NVIC_RAM_VECTOR_ADDRESS) { uint32_t *old_vectors = vectors; vectors = (uint32_t*)NVIC_RAM_VECTOR_ADDRESS; for (i=0; i<NVIC_NUM_VECTORS; i++) {
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE/i2c_api.c Wed May 07 13:30:07 2014 +0100 +++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE/i2c_api.c Wed May 07 17:45:07 2014 +0100 @@ -155,29 +155,101 @@ } int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) { + I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c); + I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c); + int timeout; + int count; + int value; + if (length == 0) return 0; - I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c); + i2c_start(obj); - // Reception process with 5 seconds timeout - if (HAL_I2C_Master_Receive(&I2cHandle, (uint16_t)address, (uint8_t *)data, length, 5000) != HAL_OK) { - return 0; // Error + // Wait until SB flag is set + timeout = FLAG_TIMEOUT; + while (__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_SB) == RESET) { + timeout--; + if (timeout == 0) { + return 0; + } } + + i2c->DR = __HAL_I2C_7BIT_ADD_READ(address); + + + // Wait address is acknowledged + timeout = FLAG_TIMEOUT; + while (__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_ADDR) == RESET) { + timeout--; + if (timeout == 0) { + return 0; + } + } + __HAL_I2C_CLEAR_ADDRFLAG(&I2cHandle); + + // Read all bytes except last one + for (count = 0; count < (length - 1); count++) { + value = i2c_byte_read(obj, 0); + data[count] = (char)value; + } + + // If not repeated start, send stop. + // Warning: must be done BEFORE the data is read. + if (stop) { + i2c_stop(obj); + } + + // Read the last byte + value = i2c_byte_read(obj, 1); + data[count] = (char)value; return length; } int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) { - if (length == 0) return 0; + I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c); + I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c); + int timeout; + int count; - I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c); + if (length == 0) return 0; + i2c_start(obj); - // Transmission process with 5 seconds timeout - if (HAL_I2C_Master_Transmit(&I2cHandle, (uint16_t)address, (uint8_t *)data, length, 5000) != HAL_OK) { - return 0; // Error + // Wait until SB flag is set + timeout = FLAG_TIMEOUT; + while (__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_SB) == RESET) { + timeout--; + if (timeout == 0) { + return 0; + } + } + + i2c->DR = __HAL_I2C_7BIT_ADD_WRITE(address); + + + // Wait address is acknowledged + timeout = FLAG_TIMEOUT; + while (__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_ADDR) == RESET) { + timeout--; + if (timeout == 0) { + return 0; + } + } + __HAL_I2C_CLEAR_ADDRFLAG(&I2cHandle); + + for (count = 0; count < length; count++) { + if (i2c_byte_write(obj, data[count]) != 1) { + i2c_stop(obj); + return 0; + } } - return length; + // If not repeated start, send stop. + if (stop) { + i2c_stop(obj); + } + + return count; } int i2c_byte_read(i2c_t *obj, int last) {