mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #324 from bcostm/master
[NUCLEO_F103RB] Update xxx_free() function + typo correctionspull/326/head
commit
bf99806838
|
@ -299,10 +299,9 @@ int i2c_slave_receive(i2c_t *obj) {
|
||||||
uint32_t event;
|
uint32_t event;
|
||||||
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
|
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
|
||||||
|
|
||||||
event = I2C_GetLastEvent( i2c );
|
event = I2C_GetLastEvent(i2c);
|
||||||
if(event != 0)
|
if (event != 0) {
|
||||||
{
|
switch (event) {
|
||||||
switch(event){
|
|
||||||
case I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED:
|
case I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED:
|
||||||
retValue = WriteAddressed;
|
retValue = WriteAddressed;
|
||||||
break;
|
break;
|
||||||
|
@ -318,23 +317,23 @@ int i2c_slave_receive(i2c_t *obj) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear ADDR
|
// clear ADDR
|
||||||
if((retValue == WriteAddressed) || (retValue == ReadAddressed)){
|
if ((retValue == WriteAddressed) || (retValue == ReadAddressed)) {
|
||||||
// read SR to clear ADDR flag
|
// read SR to clear ADDR flag
|
||||||
i2c->SR1;
|
i2c->SR1;
|
||||||
i2c->SR2;
|
i2c->SR2;
|
||||||
}
|
}
|
||||||
// clear stopf
|
// 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
|
// read SR1 and write CR1 to clear STOP flag
|
||||||
i2c->SR1;
|
i2c->SR1;
|
||||||
I2C_Cmd(i2c, ENABLE);
|
I2C_Cmd(i2c, ENABLE);
|
||||||
}
|
}
|
||||||
// clear AF
|
// clear AF
|
||||||
if(I2C_GetFlagStatus(i2c, I2C_FLAG_AF) == SET) {
|
if (I2C_GetFlagStatus(i2c, I2C_FLAG_AF) == SET) {
|
||||||
I2C_ClearFlag(i2c, I2C_FLAG_AF);
|
I2C_ClearFlag(i2c, I2C_FLAG_AF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return(retValue);
|
return (retValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
int i2c_slave_read(i2c_t *obj, char *data, int length) {
|
int i2c_slave_read(i2c_t *obj, char *data, int length) {
|
||||||
|
|
|
@ -65,6 +65,8 @@ struct serial_s {
|
||||||
uint32_t databits;
|
uint32_t databits;
|
||||||
uint32_t stopbits;
|
uint32_t stopbits;
|
||||||
uint32_t parity;
|
uint32_t parity;
|
||||||
|
PinName pin_tx;
|
||||||
|
PinName pin_rx;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct spi_s {
|
struct spi_s {
|
||||||
|
@ -75,6 +77,10 @@ struct spi_s {
|
||||||
uint32_t mode;
|
uint32_t mode;
|
||||||
uint32_t nss;
|
uint32_t nss;
|
||||||
uint32_t br_presc;
|
uint32_t br_presc;
|
||||||
|
PinName pin_miso;
|
||||||
|
PinName pin_mosi;
|
||||||
|
PinName pin_sclk;
|
||||||
|
PinName pin_ssel;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct i2c_s {
|
struct i2c_s {
|
||||||
|
|
|
@ -98,8 +98,8 @@ void pwmout_init(pwmout_t* obj, PinName pin) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void pwmout_free(pwmout_t* obj) {
|
void pwmout_free(pwmout_t* obj) {
|
||||||
TIM_TypeDef *tim = (TIM_TypeDef *)(obj->pwm);
|
// Configure GPIO
|
||||||
TIM_DeInit(tim);
|
pin_function(obj->pin, STM_PIN_DATA(GPIO_Mode_IN_FLOATING, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
void pwmout_write(pwmout_t* obj, float value) {
|
void pwmout_write(pwmout_t* obj, float value) {
|
||||||
|
|
|
@ -113,6 +113,9 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
|
||||||
obj->stopbits = USART_StopBits_1;
|
obj->stopbits = USART_StopBits_1;
|
||||||
obj->parity = USART_Parity_No;
|
obj->parity = USART_Parity_No;
|
||||||
|
|
||||||
|
obj->pin_tx = tx;
|
||||||
|
obj->pin_rx = rx;
|
||||||
|
|
||||||
init_usart(obj);
|
init_usart(obj);
|
||||||
|
|
||||||
// The index is used by irq
|
// The index is used by irq
|
||||||
|
@ -128,6 +131,27 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void serial_free(serial_t *obj) {
|
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;
|
serial_irq_ids[obj->index] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -119,6 +119,11 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
|
||||||
obj->cpha = SPI_CPHA_1Edge;
|
obj->cpha = SPI_CPHA_1Edge;
|
||||||
obj->br_presc = SPI_BaudRatePrescaler_256;
|
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
|
if (ssel == NC) { // Master
|
||||||
obj->mode = SPI_Mode_Master;
|
obj->mode = SPI_Mode_Master;
|
||||||
obj->nss = SPI_NSS_Soft;
|
obj->nss = SPI_NSS_Soft;
|
||||||
|
@ -132,8 +137,24 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
|
||||||
}
|
}
|
||||||
|
|
||||||
void spi_free(spi_t *obj) {
|
void spi_free(spi_t *obj) {
|
||||||
SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
|
// Reset SPI and disable clock
|
||||||
SPI_I2S_DeInit(spi);
|
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) {
|
void spi_format(spi_t *obj, int bits, int mode, int slave) {
|
||||||
|
|
Loading…
Reference in New Issue