mirror of https://github.com/ARMmbed/mbed-os.git
[NUCLEO_F302R8] Update xxx_free() functions + typo
parent
45142e0af4
commit
3529f1dc0a
|
@ -57,7 +57,7 @@ void analogout_init(dac_t *obj, PinName pin) {
|
|||
pinmap_pinout(pin, PinMap_DAC);
|
||||
|
||||
// Save the channel for future use
|
||||
obj->channel = pin;
|
||||
obj->pin = pin;
|
||||
|
||||
// Enable DAC clock
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
|
||||
|
@ -76,7 +76,7 @@ void analogout_free(dac_t *obj) {
|
|||
DAC_DeInit(dac);
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, DISABLE);
|
||||
// Configure GPIO
|
||||
pin_function(obj->channel, STM_PIN_DATA(GPIO_Mode_IN, 0, GPIO_PuPd_NOPULL, 0xFF));
|
||||
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) {
|
||||
|
|
|
@ -124,13 +124,13 @@ void i2c_frequency(i2c_t *obj, int hz) {
|
|||
switch (hz) {
|
||||
case 100000:
|
||||
tim = 0x60302730; // Standard mode
|
||||
break;
|
||||
break;
|
||||
case 200000:
|
||||
tim = 0x00C07AB3; // Fast Mode
|
||||
break;
|
||||
break;
|
||||
case 400000:
|
||||
tim = 0x00C0216C; // Fast Mode
|
||||
break;
|
||||
break;
|
||||
case 1000000:
|
||||
tim = 0x00900B22; // Fast Mode Plus
|
||||
// Enable the Fast Mode Plus capability
|
||||
|
@ -140,13 +140,12 @@ void i2c_frequency(i2c_t *obj, int hz) {
|
|||
if (obj->i2c == I2C_2) {
|
||||
SYSCFG_I2CFastModePlusConfig(SYSCFG_I2CFastModePlus_I2C2, ENABLE);
|
||||
}
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
error("Only 100kHz, 200kHz, 400kHz and 1MHz I2C frequencies are supported.");
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (SystemCoreClock == 72000000) {
|
||||
} else if (SystemCoreClock == 72000000) {
|
||||
switch (hz) {
|
||||
case 100000:
|
||||
tim = 0x10C08DCF; // Standard mode
|
||||
|
@ -171,8 +170,7 @@ void i2c_frequency(i2c_t *obj, int hz) {
|
|||
error("Only 100kHz, 200kHz, 400kHz and 1MHz I2C frequencies are supported.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
error("System clock setting is not supported.");
|
||||
}
|
||||
|
||||
|
@ -235,12 +233,12 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
|
|||
}
|
||||
|
||||
timeout = FLAG_TIMEOUT;
|
||||
while(!I2C_GetFlagStatus(i2c, I2C_FLAG_TC)) {
|
||||
while (!I2C_GetFlagStatus(i2c, I2C_FLAG_TC)) {
|
||||
timeout--;
|
||||
if (timeout == 0) return 0;
|
||||
}
|
||||
|
||||
if(stop) i2c_stop(obj);
|
||||
|
||||
if (stop) i2c_stop(obj);
|
||||
|
||||
return length;
|
||||
}
|
||||
|
@ -262,12 +260,12 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
|
|||
}
|
||||
|
||||
timeout = FLAG_TIMEOUT;
|
||||
while(!I2C_GetFlagStatus(i2c, I2C_FLAG_TC)) {
|
||||
while (!I2C_GetFlagStatus(i2c, I2C_FLAG_TC)) {
|
||||
timeout--;
|
||||
if (timeout == 0) return 0;
|
||||
}
|
||||
|
||||
if(stop) i2c_stop(obj);
|
||||
|
||||
if (stop) i2c_stop(obj);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
@ -331,8 +329,8 @@ void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask) {
|
|||
uint16_t tmpreg;
|
||||
|
||||
// reset own address enable
|
||||
i2c->OAR1 &=~ I2C_OAR1_OA1EN;
|
||||
|
||||
i2c->OAR1 &= ~ I2C_OAR1_OA1EN;
|
||||
|
||||
// Get the old register value
|
||||
tmpreg = i2c->OAR1;
|
||||
// Reset address bits
|
||||
|
@ -356,16 +354,15 @@ void i2c_slave_mode(i2c_t *obj, int enable_slave) {
|
|||
int i2c_slave_receive(i2c_t *obj) {
|
||||
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
|
||||
int event = NoData;
|
||||
|
||||
if(I2C_GetFlagStatus(i2c, I2C_ISR_BUSY) == SET) {
|
||||
if(I2C_GetFlagStatus(i2c, I2C_ISR_ADDR) == SET) {
|
||||
// Check direction
|
||||
|
||||
if (I2C_GetFlagStatus(i2c, I2C_ISR_BUSY) == SET) {
|
||||
if (I2C_GetFlagStatus(i2c, I2C_ISR_ADDR) == SET) {
|
||||
// Check direction
|
||||
if (I2C_GetFlagStatus(i2c, I2C_ISR_DIR) == SET) {
|
||||
event = ReadAddressed;
|
||||
}
|
||||
else event = WriteAddressed;
|
||||
// Clear adress match flag to generate an acknowledge
|
||||
i2c->ICR |= I2C_ICR_ADDRCF;
|
||||
} else event = WriteAddressed;
|
||||
// Clear adress match flag to generate an acknowledge
|
||||
i2c->ICR |= I2C_ICR_ADDRCF;
|
||||
}
|
||||
}
|
||||
return event;
|
||||
|
|
|
@ -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,10 +82,14 @@ 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 {
|
||||
I2CName i2c;
|
||||
I2CName i2c;
|
||||
};
|
||||
|
||||
struct pwmout_s {
|
||||
|
|
|
@ -112,8 +112,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 GPIO
|
||||
pin_function(obj->pin, STM_PIN_DATA(GPIO_Mode_IN, 0, GPIO_PuPd_NOPULL, 0xFF));
|
||||
}
|
||||
|
||||
void pwmout_write(pwmout_t* obj, float value) {
|
||||
|
|
|
@ -49,7 +49,7 @@ void rtc_init(void) {
|
|||
// Reset back up registers
|
||||
RCC_BackupResetCmd(ENABLE);
|
||||
RCC_BackupResetCmd(DISABLE);
|
||||
|
||||
|
||||
// Enable LSE clock
|
||||
RCC_LSEConfig(RCC_LSE_ON);
|
||||
|
||||
|
@ -58,40 +58,48 @@ void rtc_init(void) {
|
|||
LSEStatus = RCC_GetFlagStatus(RCC_FLAG_LSERDY);
|
||||
wait_ms(1);
|
||||
StartUpCounter++;
|
||||
} while((LSEStatus == 0) && (StartUpCounter <= LSE_STARTUP_TIMEOUT));
|
||||
} while ((LSEStatus == 0) && (StartUpCounter <= LSE_STARTUP_TIMEOUT));
|
||||
|
||||
if (StartUpCounter > LSE_STARTUP_TIMEOUT) {
|
||||
// The LSE has not started, use LSI instead.
|
||||
// The RTC Clock may vary due to LSI frequency dispersion.
|
||||
RCC_LSEConfig(RCC_LSE_OFF);
|
||||
// The RTC Clock may vary due to LSI frequency dispersion.
|
||||
RCC_LSEConfig(RCC_LSE_OFF);
|
||||
RCC_LSICmd(ENABLE); // Enable LSI
|
||||
while (RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET) {} // Wait until ready
|
||||
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI); // Select the RTC Clock Source
|
||||
rtc_freq = 40000; // [TODO] To be measured precisely using a timer input capture
|
||||
}
|
||||
else {
|
||||
rtc_freq = 40000; // [TODO] To be measured precisely using a timer input capture
|
||||
} else {
|
||||
// The LSE has correctly started
|
||||
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); // Select the RTC Clock Source
|
||||
rtc_freq = LSE_VALUE;
|
||||
}
|
||||
|
||||
RCC_RTCCLKCmd(ENABLE); // Enable RTC Clock
|
||||
|
||||
|
||||
RCC_RTCCLKCmd(ENABLE); // Enable RTC Clock
|
||||
|
||||
RTC_WaitForSynchro(); // Wait for RTC registers synchronization
|
||||
|
||||
RTC_InitTypeDef RTC_InitStructure;
|
||||
RTC_InitStructure.RTC_AsynchPrediv = 127;
|
||||
RTC_InitStructure.RTC_SynchPrediv = (rtc_freq / 128) - 1;
|
||||
RTC_InitStructure.RTC_SynchPrediv = (rtc_freq / 128) - 1;
|
||||
RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
|
||||
RTC_Init(&RTC_InitStructure);
|
||||
|
||||
|
||||
PWR_BackupAccessCmd(DISABLE); // Disable access to Backup domain
|
||||
|
||||
|
||||
rtc_inited = 1;
|
||||
}
|
||||
|
||||
void rtc_free(void) {
|
||||
RCC_DeInit(); // Resets the RCC clock configuration to the default reset state
|
||||
// Reset RTC
|
||||
PWR_BackupAccessCmd(ENABLE); // Enable access to Backup Domain
|
||||
RTC_DeInit();
|
||||
RCC_BackupResetCmd(ENABLE);
|
||||
RCC_BackupResetCmd(DISABLE);
|
||||
// Disable RTC, LSE and LSI clocks
|
||||
RCC_RTCCLKCmd(DISABLE);
|
||||
RCC_LSEConfig(RCC_LSE_OFF);
|
||||
RCC_LSICmd(DISABLE);
|
||||
|
||||
rtc_inited = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -103,12 +103,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
|
||||
|
@ -123,12 +126,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;
|
||||
init_usart(obj);
|
||||
|
||||
// For stdio management
|
||||
if (obj->uart == STDIO_UART) {
|
||||
|
@ -139,6 +140,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) {
|
||||
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, 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -125,6 +125,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;
|
||||
|
@ -138,8 +143,23 @@ 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_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