mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #329 from bcostm/master
[NUCLEO_L152RE_F401RE] Update xxx_free() functions + typo correctionspull/333/head
commit
a2726bf3f0
|
@ -87,7 +87,12 @@ void rtc_init(void) {
|
|||
}
|
||||
|
||||
void rtc_free(void) {
|
||||
RCC_DeInit(); // Resets the RCC clock configuration to the default reset state
|
||||
// Disable RTC, LSE and LSI clocks
|
||||
PWR_BackupAccessCmd(ENABLE); // Allow access to Backup Domain
|
||||
RCC_RTCCLKCmd(DISABLE);
|
||||
RCC_LSEConfig(RCC_LSE_OFF);
|
||||
RCC_LSICmd(DISABLE);
|
||||
|
||||
rtc_inited = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -95,12 +95,15 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
|
|||
// Enable USART clock
|
||||
if (obj->uart == UART_1) {
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
|
||||
obj->index = 0;
|
||||
}
|
||||
if (obj->uart == UART_2) {
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
|
||||
obj->index = 1;
|
||||
}
|
||||
if (obj->uart == UART_3) {
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
|
||||
obj->index = 2;
|
||||
}
|
||||
|
||||
// Configure the UART pins
|
||||
|
@ -118,11 +121,6 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
|
|||
|
||||
init_usart(obj);
|
||||
|
||||
// The index is used by irq
|
||||
if (obj->uart == UART_1) obj->index = 0;
|
||||
if (obj->uart == UART_2) obj->index = 1;
|
||||
if (obj->uart == UART_3) obj->index = 2;
|
||||
|
||||
// For stdio management
|
||||
if (obj->uart == STDIO_UART) {
|
||||
stdio_uart_inited = 1;
|
||||
|
|
|
@ -112,7 +112,7 @@ void i2c_frequency(i2c_t *obj, int hz) {
|
|||
I2cHandle.Init.OwnAddress1 = 0;
|
||||
I2cHandle.Init.OwnAddress2 = 0;
|
||||
HAL_I2C_Init(&I2cHandle);
|
||||
if(obj->slave) {
|
||||
if (obj->slave) {
|
||||
/* Enable Address Acknowledge */
|
||||
I2cHandle.Instance->CR1 |= I2C_CR1_ACK;
|
||||
}
|
||||
|
@ -325,7 +325,7 @@ void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask) {
|
|||
|
||||
void i2c_slave_mode(i2c_t *obj, int enable_slave) {
|
||||
I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
|
||||
if(enable_slave) {
|
||||
if (enable_slave) {
|
||||
obj->slave = 1;
|
||||
/* Enable Address Acknowledge */
|
||||
I2cHandle.Instance->CR1 |= I2C_CR1_ACK;
|
||||
|
@ -341,9 +341,9 @@ void i2c_slave_mode(i2c_t *obj, int enable_slave) {
|
|||
int i2c_slave_receive(i2c_t *obj) {
|
||||
int retValue = NoData;
|
||||
|
||||
if(__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY) == 1) {
|
||||
if(__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_ADDR) == 1) {
|
||||
if(__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_TRA) == 1)
|
||||
if (__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY) == 1) {
|
||||
if (__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_ADDR) == 1) {
|
||||
if (__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_TRA) == 1)
|
||||
retValue = ReadAddressed;
|
||||
else
|
||||
retValue = WriteAddressed;
|
||||
|
@ -352,7 +352,7 @@ int i2c_slave_receive(i2c_t *obj) {
|
|||
}
|
||||
}
|
||||
|
||||
return(retValue);
|
||||
return (retValue);
|
||||
}
|
||||
|
||||
int i2c_slave_read(i2c_t *obj, char *data, int length) {
|
||||
|
@ -362,8 +362,7 @@ int i2c_slave_read(i2c_t *obj, char *data, int length) {
|
|||
|
||||
I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
|
||||
|
||||
while(length > 0)
|
||||
{
|
||||
while (length > 0) {
|
||||
/* Wait until RXNE flag is set */
|
||||
// Wait until the byte is received
|
||||
Timeout = FLAG_TIMEOUT;
|
||||
|
@ -379,7 +378,7 @@ int i2c_slave_read(i2c_t *obj, char *data, int length) {
|
|||
length--;
|
||||
size++;
|
||||
|
||||
if((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BTF) == SET) && (length != 0)){
|
||||
if ((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BTF) == SET) && (length != 0)) {
|
||||
/* Read data from DR */
|
||||
(*data++) = I2cHandle.Instance->DR;
|
||||
length--;
|
||||
|
@ -418,8 +417,7 @@ int i2c_slave_write(i2c_t *obj, const char *data, int length) {
|
|||
|
||||
I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
|
||||
|
||||
while(length > 0)
|
||||
{
|
||||
while (length > 0) {
|
||||
/* Wait until TXE flag is set */
|
||||
Timeout = FLAG_TIMEOUT;
|
||||
while (__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_TXE) == RESET) {
|
||||
|
@ -435,8 +433,7 @@ int i2c_slave_write(i2c_t *obj, const char *data, int length) {
|
|||
length--;
|
||||
size++;
|
||||
|
||||
if((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BTF) == SET) && (length != 0))
|
||||
{
|
||||
if ((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BTF) == SET) && (length != 0)) {
|
||||
/* Write data to DR */
|
||||
I2cHandle.Instance->DR = (*data++);
|
||||
length--;
|
||||
|
|
|
@ -66,6 +66,8 @@ struct serial_s {
|
|||
uint32_t databits;
|
||||
uint32_t stopbits;
|
||||
uint32_t parity;
|
||||
PinName pin_tx;
|
||||
PinName pin_rx;
|
||||
};
|
||||
|
||||
struct spi_s {
|
||||
|
@ -76,6 +78,10 @@ struct spi_s {
|
|||
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 {
|
||||
|
|
|
@ -93,12 +93,15 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
|
|||
// Enable USART clock
|
||||
if (obj->uart == UART_1) {
|
||||
__USART1_CLK_ENABLE();
|
||||
obj->index = 0;
|
||||
}
|
||||
if (obj->uart == UART_2) {
|
||||
__USART2_CLK_ENABLE();
|
||||
obj->index = 1;
|
||||
}
|
||||
if (obj->uart == UART_6) {
|
||||
__USART6_CLK_ENABLE();
|
||||
obj->index = 2;
|
||||
}
|
||||
|
||||
// Configure the UART pins
|
||||
|
@ -113,12 +116,10 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
|
|||
obj->stopbits = UART_STOPBITS_1;
|
||||
obj->parity = UART_PARITY_NONE;
|
||||
|
||||
init_uart(obj);
|
||||
obj->pin_tx = tx;
|
||||
obj->pin_rx = rx;
|
||||
|
||||
// The index is used by irq
|
||||
if (obj->uart == UART_1) obj->index = 0;
|
||||
if (obj->uart == UART_2) obj->index = 1;
|
||||
if (obj->uart == UART_6) obj->index = 2;
|
||||
init_uart(obj);
|
||||
|
||||
// For stdio management
|
||||
if (obj->uart == STDIO_UART) {
|
||||
|
@ -129,6 +130,27 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
|
|||
}
|
||||
|
||||
void serial_free(serial_t *obj) {
|
||||
// Reset UART and disable clock
|
||||
if (obj->uart == UART_1) {
|
||||
__USART1_FORCE_RESET();
|
||||
__USART1_RELEASE_RESET();
|
||||
__USART1_CLK_DISABLE();
|
||||
}
|
||||
if (obj->uart == UART_2) {
|
||||
__USART2_FORCE_RESET();
|
||||
__USART2_RELEASE_RESET();
|
||||
__USART2_CLK_DISABLE();
|
||||
}
|
||||
if (obj->uart == UART_6) {
|
||||
__USART6_FORCE_RESET();
|
||||
__USART6_RELEASE_RESET();
|
||||
__USART6_CLK_DISABLE();
|
||||
}
|
||||
|
||||
// Configure GPIOs
|
||||
pin_function(obj->pin_tx, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
|
||||
pin_function(obj->pin_rx, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
|
||||
|
||||
serial_irq_ids[obj->index] = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -138,6 +138,11 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
|
|||
obj->cpha = SPI_PHASE_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) { // SW NSS Master mode
|
||||
obj->mode = SPI_MODE_MASTER;
|
||||
obj->nss = SPI_NSS_SOFT;
|
||||
|
@ -151,8 +156,30 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
|
|||
}
|
||||
|
||||
void spi_free(spi_t *obj) {
|
||||
SpiHandle.Instance = (SPI_TypeDef *)(obj->spi);
|
||||
HAL_SPI_DeInit(&SpiHandle);
|
||||
// Reset SPI and disable clock
|
||||
if (obj->spi == SPI_1) {
|
||||
__SPI1_FORCE_RESET();
|
||||
__SPI1_RELEASE_RESET();
|
||||
__SPI1_CLK_DISABLE();
|
||||
}
|
||||
|
||||
if (obj->spi == SPI_2) {
|
||||
__SPI2_FORCE_RESET();
|
||||
__SPI2_RELEASE_RESET();
|
||||
__SPI2_CLK_DISABLE();
|
||||
}
|
||||
|
||||
if (obj->spi == SPI_3) {
|
||||
__SPI3_FORCE_RESET();
|
||||
__SPI3_RELEASE_RESET();
|
||||
__SPI3_CLK_DISABLE();
|
||||
}
|
||||
|
||||
// Configure GPIOs
|
||||
pin_function(obj->pin_miso, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
|
||||
pin_function(obj->pin_mosi, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
|
||||
pin_function(obj->pin_sclk, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
|
||||
pin_function(obj->pin_ssel, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
|
||||
}
|
||||
|
||||
void spi_format(spi_t *obj, int bits, int mode, int slave) {
|
||||
|
|
|
@ -54,8 +54,8 @@ void analogout_init(dac_t *obj, PinName pin) {
|
|||
// Configure GPIO
|
||||
pinmap_pinout(pin, PinMap_DAC);
|
||||
|
||||
// Save the channel for the write and read functions
|
||||
obj->channel = pin;
|
||||
// Save the pin for future use
|
||||
obj->pin = pin;
|
||||
|
||||
// Enable DAC clock
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
|
||||
|
@ -66,11 +66,11 @@ void analogout_init(dac_t *obj, PinName pin) {
|
|||
DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bit0;
|
||||
DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable;
|
||||
|
||||
if (obj->channel == PA_4) {
|
||||
if (obj->pin == PA_4) {
|
||||
DAC_Init(DAC_Channel_1, &DAC_InitStructure);
|
||||
DAC_Cmd(DAC_Channel_1, ENABLE);
|
||||
}
|
||||
if (obj->channel == PA_5) {
|
||||
if (obj->pin == PA_5) {
|
||||
DAC_Init(DAC_Channel_2, &DAC_InitStructure);
|
||||
DAC_Cmd(DAC_Channel_2, ENABLE);
|
||||
}
|
||||
|
@ -79,22 +79,24 @@ void analogout_init(dac_t *obj, PinName pin) {
|
|||
}
|
||||
|
||||
void analogout_free(dac_t *obj) {
|
||||
// Configure GPIOs
|
||||
pin_function(obj->pin, STM_PIN_DATA(GPIO_Mode_IN, 0, GPIO_PuPd_NOPULL, 0xFF));
|
||||
}
|
||||
|
||||
static inline void dac_write(dac_t *obj, uint16_t value) {
|
||||
if (obj->channel == PA_4) {
|
||||
if (obj->pin == PA_4) {
|
||||
DAC_SetChannel1Data(DAC_Align_12b_R, value);
|
||||
}
|
||||
if (obj->channel == PA_5) {
|
||||
if (obj->pin == PA_5) {
|
||||
DAC_SetChannel2Data(DAC_Align_12b_R, value);
|
||||
}
|
||||
}
|
||||
|
||||
static inline int dac_read(dac_t *obj) {
|
||||
if (obj->channel == PA_4) {
|
||||
if (obj->pin == PA_4) {
|
||||
return (int)DAC_GetDataOutputValue(DAC_Channel_1);
|
||||
}
|
||||
if (obj->channel == PA_5) {
|
||||
if (obj->pin == PA_5) {
|
||||
return (int)DAC_GetDataOutputValue(DAC_Channel_2);
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -317,10 +317,9 @@ int i2c_slave_receive(i2c_t *obj) {
|
|||
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;
|
||||
|
@ -336,21 +335,21 @@ int i2c_slave_receive(i2c_t *obj) {
|
|||
}
|
||||
|
||||
// clear ADDR
|
||||
if((retValue == WriteAddressed) || (retValue == ReadAddressed)){
|
||||
if ((retValue == WriteAddressed) || (retValue == ReadAddressed)) {
|
||||
i2c->SR1;// read status register 1
|
||||
i2c->SR2;// read status register 2
|
||||
}
|
||||
// clear stopf
|
||||
if(I2C_GetFlagStatus(i2c, I2C_FLAG_STOPF) == SET) {
|
||||
if (I2C_GetFlagStatus(i2c, I2C_FLAG_STOPF) == SET) {
|
||||
i2c->SR1;// read status register 1
|
||||
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) {
|
||||
|
|
|
@ -60,7 +60,7 @@ struct analogin_s {
|
|||
|
||||
struct dac_s {
|
||||
DACName dac;
|
||||
PinName channel;
|
||||
PinName pin;
|
||||
};
|
||||
|
||||
struct serial_s {
|
||||
|
@ -70,6 +70,8 @@ struct serial_s {
|
|||
uint32_t databits;
|
||||
uint32_t stopbits;
|
||||
uint32_t parity;
|
||||
PinName pin_tx;
|
||||
PinName pin_rx;
|
||||
};
|
||||
|
||||
struct spi_s {
|
||||
|
@ -80,6 +82,10 @@ struct spi_s {
|
|||
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 {
|
||||
|
|
|
@ -102,8 +102,8 @@ void pwmout_init(pwmout_t* obj, PinName pin) {
|
|||
}
|
||||
|
||||
void pwmout_free(pwmout_t* obj) {
|
||||
TIM_TypeDef *tim = (TIM_TypeDef *)(obj->pwm);
|
||||
TIM_DeInit(tim);
|
||||
// Configure GPIOs
|
||||
pin_function(obj->pin, STM_PIN_DATA(GPIO_Mode_IN, 0, GPIO_PuPd_NOPULL, 0xFF));
|
||||
}
|
||||
|
||||
void pwmout_write(pwmout_t* obj, float value) {
|
||||
|
|
|
@ -99,18 +99,23 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
|
|||
// Enable USART clock
|
||||
if (obj->uart == UART_1) {
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
|
||||
obj->index = 0;
|
||||
}
|
||||
if (obj->uart == UART_2) {
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
|
||||
obj->index = 1;
|
||||
}
|
||||
if (obj->uart == UART_3) {
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
|
||||
obj->index = 2;
|
||||
}
|
||||
if (obj->uart == UART_4) {
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);
|
||||
obj->index = 3;
|
||||
}
|
||||
if (obj->uart == UART_5) {
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, ENABLE);
|
||||
obj->index = 4;
|
||||
}
|
||||
|
||||
// Configure the UART pins
|
||||
|
@ -125,14 +130,10 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
|
|||
obj->stopbits = USART_StopBits_1;
|
||||
obj->parity = USART_Parity_No;
|
||||
|
||||
init_usart(obj);
|
||||
obj->pin_tx = tx;
|
||||
obj->pin_rx = rx;
|
||||
|
||||
// The index is used by irq
|
||||
if (obj->uart == UART_1) obj->index = 0;
|
||||
if (obj->uart == UART_2) obj->index = 1;
|
||||
if (obj->uart == UART_3) obj->index = 2;
|
||||
if (obj->uart == UART_4) obj->index = 3;
|
||||
if (obj->uart == UART_5) obj->index = 4;
|
||||
init_usart(obj);
|
||||
|
||||
// For stdio management
|
||||
if (obj->uart == STDIO_UART) {
|
||||
|
@ -142,6 +143,37 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
if (obj->uart == UART_4) {
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART4, ENABLE);
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART4, DISABLE);
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, DISABLE);
|
||||
}
|
||||
if (obj->uart == UART_5) {
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART5, ENABLE);
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART5, DISABLE);
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, DISABLE);
|
||||
}
|
||||
|
||||
// Configure GPIOs
|
||||
pin_function(obj->pin_tx, STM_PIN_DATA(GPIO_Mode_IN, 0, GPIO_PuPd_NOPULL, 0xFF));
|
||||
pin_function(obj->pin_rx, STM_PIN_DATA(GPIO_Mode_IN, 0, GPIO_PuPd_NOPULL, 0xFF));
|
||||
|
||||
serial_irq_ids[obj->index] = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -132,6 +132,11 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
|
|||
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;
|
||||
|
@ -145,8 +150,30 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
if (obj->spi == SPI_3) {
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI3, ENABLE);
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI3, DISABLE);
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3, DISABLE);
|
||||
}
|
||||
|
||||
// Configure GPIOs
|
||||
pin_function(obj->pin_miso, STM_PIN_DATA(GPIO_Mode_IN, 0, GPIO_PuPd_NOPULL, 0xFF));
|
||||
pin_function(obj->pin_mosi, STM_PIN_DATA(GPIO_Mode_IN, 0, GPIO_PuPd_NOPULL, 0xFF));
|
||||
pin_function(obj->pin_sclk, STM_PIN_DATA(GPIO_Mode_IN, 0, GPIO_PuPd_NOPULL, 0xFF));
|
||||
pin_function(obj->pin_ssel, STM_PIN_DATA(GPIO_Mode_IN, 0, GPIO_PuPd_NOPULL, 0xFF));
|
||||
}
|
||||
|
||||
void spi_format(spi_t *obj, int bits, int mode, int slave) {
|
||||
|
|
Loading…
Reference in New Issue