mbed library sources
Dependents: Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more
Superseded
This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.
Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.
If you are looking for a stable and tested release, please import one of the official mbed library releases:
Import librarymbed
The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.
Revision 208:4557f4bb2dd5, committed 2014-05-23
- Comitter:
- mbed_official
- Date:
- Fri May 23 10:30:07 2014 +0100
- Parent:
- 207:05668db47a72
- Child:
- 209:137057ef9d1e
- Commit message:
- Synchronized with git revision bf99806838a107a0a72f7824356e720c46afdc63
Full URL: https://github.com/mbedmicro/mbed/commit/bf99806838a107a0a72f7824356e720c46afdc63/
[NUCLEO_F103RB] Update xxx_free() function + typo corrections
Changed in this revision
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/i2c_api.c Fri May 23 08:45:06 2014 +0100 +++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/i2c_api.c Fri May 23 10:30:07 2014 +0100 @@ -181,7 +181,7 @@ I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c); int timeout; int count; - + i2c_start(obj); // Send slave address for write @@ -245,7 +245,7 @@ I2C_SendData(i2c, (uint8_t)data); // Wait until the byte is transmitted - timeout = FLAG_TIMEOUT; + timeout = FLAG_TIMEOUT; while ((I2C_GetFlagStatus(i2c, I2C_FLAG_TXE) == RESET) && (I2C_GetFlagStatus(i2c, I2C_FLAG_BTF) == RESET)) { timeout--; @@ -299,10 +299,9 @@ uint32_t event; I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c); - event = I2C_GetLastEvent( i2c ); - if(event != 0) - { - switch(event){ + event = I2C_GetLastEvent(i2c); + if (event != 0) { + switch (event) { case I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED: retValue = WriteAddressed; break; @@ -317,24 +316,24 @@ break; } - // clear ADDR - if((retValue == WriteAddressed) || (retValue == ReadAddressed)){ + // clear ADDR + if ((retValue == WriteAddressed) || (retValue == ReadAddressed)) { // read SR to clear ADDR flag i2c->SR1; i2c->SR2; } // clear stopf - if(I2C_GetFlagStatus(i2c, I2C_FLAG_STOPF) == SET) { + if (I2C_GetFlagStatus(i2c, I2C_FLAG_STOPF) == SET) { // read SR1 and write CR1 to clear STOP flag i2c->SR1; - I2C_Cmd(i2c, ENABLE); + I2C_Cmd(i2c, ENABLE); } // clear AF - if(I2C_GetFlagStatus(i2c, I2C_FLAG_AF) == SET) { + if (I2C_GetFlagStatus(i2c, I2C_FLAG_AF) == SET) { I2C_ClearFlag(i2c, I2C_FLAG_AF); - } + } } - return(retValue); + return (retValue); } int i2c_slave_read(i2c_t *obj, char *data, int length) {
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/objects.h Fri May 23 08:45:06 2014 +0100 +++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/objects.h Fri May 23 10:30:07 2014 +0100 @@ -65,6 +65,8 @@ uint32_t databits; uint32_t stopbits; uint32_t parity; + PinName pin_tx; + PinName pin_rx; }; struct spi_s { @@ -75,6 +77,10 @@ uint32_t mode; uint32_t nss; uint32_t br_presc; + PinName pin_miso; + PinName pin_mosi; + PinName pin_sclk; + PinName pin_ssel; }; struct i2c_s {
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/pwmout_api.c Fri May 23 08:45:06 2014 +0100 +++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/pwmout_api.c Fri May 23 10:30:07 2014 +0100 @@ -98,8 +98,8 @@ } void pwmout_free(pwmout_t* obj) { - TIM_TypeDef *tim = (TIM_TypeDef *)(obj->pwm); - TIM_DeInit(tim); + // Configure GPIO + pin_function(obj->pin, STM_PIN_DATA(GPIO_Mode_IN_FLOATING, 0)); } void pwmout_write(pwmout_t* obj, float value) {
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/serial_api.c Fri May 23 08:45:06 2014 +0100 +++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/serial_api.c Fri May 23 10:30:07 2014 +0100 @@ -113,6 +113,9 @@ obj->stopbits = USART_StopBits_1; obj->parity = USART_Parity_No; + obj->pin_tx = tx; + obj->pin_rx = rx; + init_usart(obj); // The index is used by irq @@ -128,6 +131,27 @@ } void serial_free(serial_t *obj) { + // Reset UART and disable clock + if (obj->uart == UART_1) { + RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, ENABLE); + RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, DISABLE); + RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, DISABLE); + } + if (obj->uart == UART_2) { + RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2, ENABLE); + RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2, DISABLE); + RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, DISABLE); + } + if (obj->uart == UART_3) { + RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART3, ENABLE); + RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART3, DISABLE); + RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, DISABLE); + } + + // Configure GPIOs + pin_function(obj->pin_tx, STM_PIN_DATA(GPIO_Mode_IN_FLOATING, 0)); + pin_function(obj->pin_rx, STM_PIN_DATA(GPIO_Mode_IN_FLOATING, 0)); + serial_irq_ids[obj->index] = 0; }
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/spi_api.c Fri May 23 08:45:06 2014 +0100 +++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/spi_api.c Fri May 23 10:30:07 2014 +0100 @@ -119,6 +119,11 @@ obj->cpha = SPI_CPHA_1Edge; obj->br_presc = SPI_BaudRatePrescaler_256; + obj->pin_miso = miso; + obj->pin_mosi = mosi; + obj->pin_sclk = sclk; + obj->pin_ssel = ssel; + if (ssel == NC) { // Master obj->mode = SPI_Mode_Master; obj->nss = SPI_NSS_Soft; @@ -132,8 +137,24 @@ } void spi_free(spi_t *obj) { - SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi); - SPI_I2S_DeInit(spi); + // Reset SPI and disable clock + if (obj->spi == SPI_1) { + RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, ENABLE); + RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, DISABLE); + RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, DISABLE); + } + + if (obj->spi == SPI_2) { + RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI2, ENABLE); + RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI2, DISABLE); + RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, DISABLE); + } + + // Configure GPIOs + pin_function(obj->pin_miso, STM_PIN_DATA(GPIO_Mode_IN_FLOATING, 0)); + pin_function(obj->pin_mosi, STM_PIN_DATA(GPIO_Mode_IN_FLOATING, 0)); + pin_function(obj->pin_sclk, STM_PIN_DATA(GPIO_Mode_IN_FLOATING, 0)); + pin_function(obj->pin_ssel, STM_PIN_DATA(GPIO_Mode_IN_FLOATING, 0)); } void spi_format(spi_t *obj, int bits, int mode, int slave) {