[Style] Fixed style in the newly added F3 code.
This commit is contained in:
@@ -106,4 +106,3 @@ void usart_disable_rx_interrupt(uint32_t usart)
|
||||
{
|
||||
USART_IDR(usart) = USART_CSR_RXRDY;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,4 +30,3 @@ LGPL License Terms @ref lgpl_license
|
||||
|
||||
#include <libopencm3/stm32/spi.h>
|
||||
#include <libopencm3/stm32/common/spi_common_all.h>
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -21,7 +21,8 @@
|
||||
|
||||
#include <libopencm3/stm32/f3/gpio.h>
|
||||
|
||||
void gpio_mode_setup(uint32_t gpioport, uint8_t mode, uint8_t pull_up_down, uint16_t gpios)
|
||||
void gpio_mode_setup(uint32_t gpioport, uint8_t mode, uint8_t pull_up_down,
|
||||
uint16_t gpios)
|
||||
{
|
||||
uint16_t i;
|
||||
uint32_t moder, pupd;
|
||||
@@ -34,8 +35,9 @@ void gpio_mode_setup(uint32_t gpioport, uint8_t mode, uint8_t pull_up_down, uint
|
||||
pupd = GPIO_PUPDR(gpioport);
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
if (!((1 << i) & gpios))
|
||||
if (!((1 << i) & gpios)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
moder &= ~GPIO_MODE_MASK(i);
|
||||
moder |= GPIO_MODE(i, mode);
|
||||
@@ -48,21 +50,24 @@ void gpio_mode_setup(uint32_t gpioport, uint8_t mode, uint8_t pull_up_down, uint
|
||||
GPIO_PUPDR(gpioport) = pupd;
|
||||
}
|
||||
|
||||
void gpio_set_output_options(uint32_t gpioport, uint8_t otype, uint8_t speed, uint16_t gpios)
|
||||
void gpio_set_output_options(uint32_t gpioport, uint8_t otype, uint8_t speed,
|
||||
uint16_t gpios)
|
||||
{
|
||||
uint16_t i;
|
||||
uint32_t ospeedr;
|
||||
|
||||
if (otype == 0x1)
|
||||
if (otype == 0x1) {
|
||||
GPIO_OTYPER(gpioport) |= gpios;
|
||||
else
|
||||
} else {
|
||||
GPIO_OTYPER(gpioport) &= ~gpios;
|
||||
}
|
||||
|
||||
ospeedr = GPIO_OSPEEDR(gpioport);
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
if (!((1 << i) & gpios))
|
||||
if (!((1 << i) & gpios)) {
|
||||
continue;
|
||||
}
|
||||
ospeedr &= ~GPIO_OSPEED_MASK(i);
|
||||
ospeedr |= GPIO_OSPEED(i, speed);
|
||||
}
|
||||
@@ -79,15 +84,17 @@ void gpio_set_af(uint32_t gpioport, uint8_t alt_func_num, uint16_t gpios)
|
||||
afrh = GPIO_AFRH(gpioport);
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
if (!((1 << i) & gpios))
|
||||
if (!((1 << i) & gpios)) {
|
||||
continue;
|
||||
}
|
||||
afrl &= ~GPIO_AFR_MASK(i);
|
||||
afrl |= GPIO_AFR(i, alt_func_num);
|
||||
}
|
||||
|
||||
for (i = 8; i < 16; i++) {
|
||||
if (!((1 << i) & gpios))
|
||||
if (!((1 << i) & gpios)) {
|
||||
continue;
|
||||
}
|
||||
afrl &= ~GPIO_AFR_MASK(i - 8);
|
||||
afrh |= GPIO_AFR(i - 8, alt_func_num);
|
||||
}
|
||||
@@ -137,8 +144,11 @@ void gpio_port_config_lock(uint32_t gpioport, uint16_t gpios)
|
||||
reg32 = GPIO_LCKR(gpioport); /* Read LCKK. */
|
||||
reg32 = GPIO_LCKR(gpioport); /* Read LCKK again. */
|
||||
|
||||
/* Tell the compiler the variable is actually used. It will get optimized out anyways. */
|
||||
reg32 = reg32;
|
||||
/*
|
||||
* Tell the compiler the variable is actually used.
|
||||
* It will get optimized out anyways.
|
||||
*/
|
||||
reg32 = reg32;
|
||||
|
||||
/* If (reg32 & GPIO_LCKK) is true, the lock is now active. */
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ mode, or simply release the bus if in Slave mode.
|
||||
|
||||
void i2c_send_stop(uint32_t i2c)
|
||||
{
|
||||
I2C_CR2(i2c) |= I2C_CR2_STOP;
|
||||
I2C_CR2(i2c) |= I2C_CR2_STOP;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
@@ -173,166 +173,174 @@ void i2c_send_data(uint32_t i2c, uint8_t data)
|
||||
*/
|
||||
uint8_t i2c_get_data(uint32_t i2c)
|
||||
{
|
||||
return(I2C_RXDR(i2c) & 0xff);
|
||||
return I2C_RXDR(i2c) & 0xff;
|
||||
}
|
||||
|
||||
void i2c_enable_analog_filter(uint32_t i2c)
|
||||
{
|
||||
I2C_CR1(i2c) &= ~I2C_CR1_ANFOFF;
|
||||
I2C_CR1(i2c) &= ~I2C_CR1_ANFOFF;
|
||||
}
|
||||
|
||||
void i2c_disable_analog_filter(uint32_t i2c)
|
||||
{
|
||||
I2C_CR1(i2c) |= I2C_CR1_ANFOFF;
|
||||
I2C_CR1(i2c) |= I2C_CR1_ANFOFF;
|
||||
}
|
||||
|
||||
void i2c_set_digital_filter(uint32_t i2c, uint8_t dnf_setting)
|
||||
{
|
||||
I2C_CR1(i2c) = (I2C_CR1(i2c) & ~I2C_CR1_DNF_MASK) | dnf_setting;
|
||||
I2C_CR1(i2c) = (I2C_CR1(i2c) & ~I2C_CR1_DNF_MASK) | dnf_setting;
|
||||
}
|
||||
|
||||
/* t_presc= (presc+1)*t_i2cclk */
|
||||
void i2c_set_prescaler(uint32_t i2c, uint8_t presc)
|
||||
{
|
||||
I2C_TIMINGR(i2c) = (I2C_TIMINGR(i2c) & ~I2C_TIMINGR_PRESC_MASK) | (presc << I2C_TIMINGR_PRESC_SHIFT);
|
||||
I2C_TIMINGR(i2c) = (I2C_TIMINGR(i2c) & ~I2C_TIMINGR_PRESC_MASK) |
|
||||
(presc << I2C_TIMINGR_PRESC_SHIFT);
|
||||
}
|
||||
|
||||
void i2c_set_data_setup_time(uint32_t i2c, uint8_t s_time)
|
||||
{
|
||||
I2C_TIMINGR(i2c) = (I2C_TIMINGR(i2c) & ~I2C_TIMINGR_SCLDEL_MASK) | (s_time << I2C_TIMINGR_SCLDEL_SHIFT);
|
||||
I2C_TIMINGR(i2c) = (I2C_TIMINGR(i2c) & ~I2C_TIMINGR_SCLDEL_MASK) |
|
||||
(s_time << I2C_TIMINGR_SCLDEL_SHIFT);
|
||||
}
|
||||
|
||||
void i2c_set_data_hold_time(uint32_t i2c, uint8_t h_time)
|
||||
{
|
||||
I2C_TIMINGR(i2c) = (I2C_TIMINGR(i2c) & ~I2C_TIMINGR_SDADEL_MASK) | (h_time << I2C_TIMINGR_SDADEL_SHIFT);
|
||||
I2C_TIMINGR(i2c) = (I2C_TIMINGR(i2c) & ~I2C_TIMINGR_SDADEL_MASK) |
|
||||
(h_time << I2C_TIMINGR_SDADEL_SHIFT);
|
||||
}
|
||||
|
||||
void i2c_set_scl_high_period(uint32_t i2c, uint8_t period)
|
||||
{
|
||||
I2C_TIMINGR(i2c) = (I2C_TIMINGR(i2c) & ~I2C_TIMINGR_SCLH_MASK) | (period << I2C_TIMINGR_SCLH_SHIFT);
|
||||
I2C_TIMINGR(i2c) = (I2C_TIMINGR(i2c) & ~I2C_TIMINGR_SCLH_MASK) |
|
||||
(period << I2C_TIMINGR_SCLH_SHIFT);
|
||||
}
|
||||
|
||||
void i2c_set_scl_low_period(uint32_t i2c, uint8_t period)
|
||||
{
|
||||
I2C_TIMINGR(i2c) = (I2C_TIMINGR(i2c) & ~I2C_TIMINGR_SCLL_MASK) | (period << I2C_TIMINGR_SCLL_SHIFT);
|
||||
I2C_TIMINGR(i2c) = (I2C_TIMINGR(i2c) & ~I2C_TIMINGR_SCLL_MASK) |
|
||||
(period << I2C_TIMINGR_SCLL_SHIFT);
|
||||
}
|
||||
|
||||
void i2c_enable_stretching(uint32_t i2c)
|
||||
{
|
||||
I2C_CR1(i2c) &= ~I2C_CR1_NOSTRETCH;
|
||||
I2C_CR1(i2c) &= ~I2C_CR1_NOSTRETCH;
|
||||
}
|
||||
|
||||
void i2c_disable_stretching(uint32_t i2c)
|
||||
{
|
||||
I2C_CR1(i2c) |= I2C_CR1_NOSTRETCH;
|
||||
I2C_CR1(i2c) |= I2C_CR1_NOSTRETCH;
|
||||
}
|
||||
|
||||
void i2c_100khz_i2cclk8mhz(uint32_t i2c)
|
||||
{
|
||||
i2c_set_prescaler(i2c, 1);
|
||||
i2c_set_scl_low_period(i2c, 0x13);
|
||||
i2c_set_scl_high_period(i2c, 0xF);
|
||||
i2c_set_data_hold_time(i2c, 0x2);
|
||||
i2c_set_data_setup_time(i2c, 0x4);
|
||||
i2c_set_prescaler(i2c, 1);
|
||||
i2c_set_scl_low_period(i2c, 0x13);
|
||||
i2c_set_scl_high_period(i2c, 0xF);
|
||||
i2c_set_data_hold_time(i2c, 0x2);
|
||||
i2c_set_data_setup_time(i2c, 0x4);
|
||||
}
|
||||
|
||||
void i2c_set_7bit_addr_mode(uint32_t i2c)
|
||||
{
|
||||
I2C_CR2(i2c) &= ~I2C_CR2_ADD10;
|
||||
I2C_CR2(i2c) &= ~I2C_CR2_ADD10;
|
||||
}
|
||||
|
||||
void i2c_set_10bit_addr_mode(uint32_t i2c)
|
||||
{
|
||||
I2C_CR2(i2c) |= I2C_CR2_ADD10;
|
||||
I2C_CR2(i2c) |= I2C_CR2_ADD10;
|
||||
}
|
||||
|
||||
void i2c_set_7bit_address(uint32_t i2c, uint8_t addr)
|
||||
{
|
||||
I2C_CR2(i2c) = (I2C_CR2(i2c) & ~I2C_CR2_SADD_7BIT_MASK) | ((addr & 0x7F) << I2C_CR2_SADD_7BIT_SHIFT);
|
||||
I2C_CR2(i2c) = (I2C_CR2(i2c) & ~I2C_CR2_SADD_7BIT_MASK) |
|
||||
((addr & 0x7F) << I2C_CR2_SADD_7BIT_SHIFT);
|
||||
}
|
||||
|
||||
void i2c_set_10bit_address(uint32_t i2c, uint16_t addr)
|
||||
{
|
||||
I2C_CR2(i2c) = (I2C_CR2(i2c) & ~I2C_CR2_SADD_10BIT_MASK) | ((addr & 0x3FF) << I2C_CR2_SADD_10BIT_SHIFT);
|
||||
I2C_CR2(i2c) = (I2C_CR2(i2c) & ~I2C_CR2_SADD_10BIT_MASK) |
|
||||
((addr & 0x3FF) << I2C_CR2_SADD_10BIT_SHIFT);
|
||||
}
|
||||
|
||||
void i2c_set_write_transfer_dir(uint32_t i2c)
|
||||
{
|
||||
I2C_CR2(i2c) &= ~I2C_CR2_RD_WRN;
|
||||
I2C_CR2(i2c) &= ~I2C_CR2_RD_WRN;
|
||||
}
|
||||
|
||||
void i2c_set_read_transfer_dir(uint32_t i2c)
|
||||
{
|
||||
I2C_CR2(i2c) |= I2C_CR2_RD_WRN;
|
||||
I2C_CR2(i2c) |= I2C_CR2_RD_WRN;
|
||||
}
|
||||
|
||||
void i2c_set_bytes_to_transfer(uint32_t i2c, uint32_t n_bytes)
|
||||
{
|
||||
I2C_CR2(i2c) = (I2C_CR2(i2c) & ~I2C_CR2_NBYTES_MASK) | (n_bytes << I2C_CR2_NBYTES_SHIFT);
|
||||
I2C_CR2(i2c) = (I2C_CR2(i2c) & ~I2C_CR2_NBYTES_MASK) |
|
||||
(n_bytes << I2C_CR2_NBYTES_SHIFT);
|
||||
}
|
||||
|
||||
uint8_t i2c_is_start(uint32_t i2c)
|
||||
{
|
||||
if ((I2C_CR2(i2c) & I2C_CR2_START) != 0) {
|
||||
return(1);
|
||||
} else {
|
||||
return(0);
|
||||
}
|
||||
if ((I2C_CR2(i2c) & I2C_CR2_START) != 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void i2c_enable_autoend(uint32_t i2c)
|
||||
{
|
||||
I2C_CR2(i2c) |= I2C_CR2_AUTOEND;
|
||||
I2C_CR2(i2c) |= I2C_CR2_AUTOEND;
|
||||
}
|
||||
|
||||
void i2c_disable_autoend(uint32_t i2c)
|
||||
{
|
||||
I2C_CR2(i2c) &= ~I2C_CR2_AUTOEND;
|
||||
I2C_CR2(i2c) &= ~I2C_CR2_AUTOEND;
|
||||
}
|
||||
|
||||
uint8_t i2c_nack(uint32_t i2c)
|
||||
{
|
||||
if ((I2C_ISR(i2c) & I2C_ISR_NACKF) != 0) {
|
||||
return(1);
|
||||
} else {
|
||||
return(0);
|
||||
}
|
||||
if ((I2C_ISR(i2c) & I2C_ISR_NACKF) != 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t i2c_busy(uint32_t i2c)
|
||||
{
|
||||
if ((I2C_ISR(i2c) & I2C_ISR_BUSY) != 0) {
|
||||
return(1);
|
||||
} else {
|
||||
return(0);
|
||||
}
|
||||
if ((I2C_ISR(i2c) & I2C_ISR_BUSY) != 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t i2c_transmit_int_status(uint32_t i2c)
|
||||
{
|
||||
if ((I2C_ISR(i2c) & I2C_ISR_TXIS) != 0) {
|
||||
return(1);
|
||||
} else {
|
||||
return(0);
|
||||
}
|
||||
if ((I2C_ISR(i2c) & I2C_ISR_TXIS) != 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t i2c_transfer_complete(uint32_t i2c)
|
||||
{
|
||||
if ((I2C_ISR(i2c) & I2C_ISR_TC) != 0) {
|
||||
return(1);
|
||||
} else {
|
||||
return(0);
|
||||
}
|
||||
if ((I2C_ISR(i2c) & I2C_ISR_TC) != 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t i2c_received_data(uint32_t i2c)
|
||||
{
|
||||
if ((I2C_ISR(i2c) & I2C_ISR_RXNE) != 0) {
|
||||
return(1);
|
||||
} else {
|
||||
return(0);
|
||||
}
|
||||
if ((I2C_ISR(i2c) & I2C_ISR_RXNE) != 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -398,78 +406,79 @@ void i2c_disable_txdma(uint32_t i2c)
|
||||
I2C_CR1(i2c) &= ~I2C_CR1_TXDMAEN;
|
||||
}
|
||||
|
||||
void write_i2c(uint32_t i2c, uint8_t i2c_addr, uint8_t reg, uint8_t size, uint8_t *data) {
|
||||
int wait;
|
||||
int i;
|
||||
while (i2c_busy(i2c) == 1) {}
|
||||
while (i2c_is_start(i2c) == 1) {}
|
||||
/*Setting transfer properties*/
|
||||
i2c_set_bytes_to_transfer(i2c, size+1);
|
||||
i2c_set_7bit_address(i2c, (i2c_addr & 0x7F));
|
||||
i2c_set_write_transfer_dir(i2c);
|
||||
i2c_enable_autoend(i2c);
|
||||
/*start transfer*/
|
||||
i2c_send_start(i2c);
|
||||
|
||||
wait=true;
|
||||
while (wait) {
|
||||
if (i2c_transmit_int_status(i2c)) {
|
||||
wait=false;
|
||||
}
|
||||
while (i2c_nack(i2c)){}
|
||||
}
|
||||
i2c_send_data(i2c, reg);
|
||||
for (i=0; i<size; i++) {
|
||||
wait=true;
|
||||
while (wait) {
|
||||
if (i2c_transmit_int_status(i2c)) {
|
||||
wait=false;
|
||||
}
|
||||
while (i2c_nack(i2c)){}
|
||||
}
|
||||
i2c_send_data(i2c, data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void read_i2c(uint32_t i2c, uint8_t i2c_addr, uint8_t reg, uint8_t size, uint8_t *data)
|
||||
void write_i2c(uint32_t i2c, uint8_t i2c_addr, uint8_t reg, uint8_t size,
|
||||
uint8_t *data)
|
||||
{
|
||||
int wait;
|
||||
int i;
|
||||
while (i2c_busy(i2c) == 1) {}
|
||||
while (i2c_is_start(i2c) == 1) {}
|
||||
/*Setting transfer properties*/
|
||||
i2c_set_bytes_to_transfer(i2c, 1);
|
||||
i2c_set_7bit_address(i2c, i2c_addr);
|
||||
i2c_set_write_transfer_dir(i2c);
|
||||
i2c_disable_autoend(i2c);
|
||||
/*start transfer*/
|
||||
i2c_send_start(i2c);
|
||||
int wait;
|
||||
int i;
|
||||
while (i2c_busy(i2c) == 1);
|
||||
while (i2c_is_start(i2c) == 1);
|
||||
/*Setting transfer properties*/
|
||||
i2c_set_bytes_to_transfer(i2c, size + 1);
|
||||
i2c_set_7bit_address(i2c, (i2c_addr & 0x7F));
|
||||
i2c_set_write_transfer_dir(i2c);
|
||||
i2c_enable_autoend(i2c);
|
||||
/*start transfer*/
|
||||
i2c_send_start(i2c);
|
||||
|
||||
wait=true;
|
||||
while (wait)
|
||||
{
|
||||
if (i2c_transmit_int_status(i2c)) {
|
||||
wait=false;
|
||||
}
|
||||
while (i2c_nack(i2c)){} /* Some error */
|
||||
}
|
||||
i2c_send_data(i2c, reg);
|
||||
wait = true;
|
||||
while (wait) {
|
||||
if (i2c_transmit_int_status(i2c)) {
|
||||
wait = false;
|
||||
}
|
||||
while (i2c_nack(i2c));
|
||||
}
|
||||
|
||||
while (i2c_is_start(i2c) == 1) {}
|
||||
/*Setting transfer properties*/
|
||||
i2c_set_bytes_to_transfer(i2c, size);
|
||||
i2c_set_7bit_address(i2c, i2c_addr);
|
||||
i2c_set_read_transfer_dir(i2c);
|
||||
i2c_enable_autoend(i2c);
|
||||
/*start transfer*/
|
||||
i2c_send_start(i2c);
|
||||
|
||||
for (i=0; i<size; i++) {
|
||||
while (i2c_received_data(i2c) == 0) {}
|
||||
data[i]=i2c_get_data(i2c);
|
||||
}
|
||||
i2c_send_data(i2c, reg);
|
||||
for (i = 0; i < size; i++) {
|
||||
wait = true;
|
||||
while (wait) {
|
||||
if (i2c_transmit_int_status(i2c)) {
|
||||
wait = false;
|
||||
}
|
||||
while (i2c_nack(i2c));
|
||||
}
|
||||
i2c_send_data(i2c, data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void read_i2c(uint32_t i2c, uint8_t i2c_addr, uint8_t reg, uint8_t size,
|
||||
uint8_t *data)
|
||||
{
|
||||
int wait;
|
||||
int i;
|
||||
while (i2c_busy(i2c) == 1);
|
||||
while (i2c_is_start(i2c) == 1);
|
||||
/*Setting transfer properties*/
|
||||
i2c_set_bytes_to_transfer(i2c, 1);
|
||||
i2c_set_7bit_address(i2c, i2c_addr);
|
||||
i2c_set_write_transfer_dir(i2c);
|
||||
i2c_disable_autoend(i2c);
|
||||
/*start transfer*/
|
||||
i2c_send_start(i2c);
|
||||
|
||||
wait = true;
|
||||
while (wait) {
|
||||
if (i2c_transmit_int_status(i2c)) {
|
||||
wait = false;
|
||||
}
|
||||
while (i2c_nack(i2c)); /* Some error */
|
||||
}
|
||||
i2c_send_data(i2c, reg);
|
||||
|
||||
while (i2c_is_start(i2c) == 1);
|
||||
/*Setting transfer properties*/
|
||||
i2c_set_bytes_to_transfer(i2c, size);
|
||||
i2c_set_7bit_address(i2c, i2c_addr);
|
||||
i2c_set_read_transfer_dir(i2c);
|
||||
i2c_enable_autoend(i2c);
|
||||
/*start transfer*/
|
||||
i2c_send_start(i2c);
|
||||
|
||||
for (i = 0; i < size; i++) {
|
||||
while (i2c_received_data(i2c) == 0);
|
||||
data[i] = i2c_get_data(i2c);
|
||||
}
|
||||
}
|
||||
|
||||
/**@}*/
|
||||
|
||||
|
||||
@@ -30,44 +30,43 @@
|
||||
uint32_t rcc_ppre1_frequency = 8000000;
|
||||
uint32_t rcc_ppre2_frequency = 8000000;
|
||||
|
||||
const clock_scale_t hsi_8mhz[CLOCK_END] =
|
||||
{
|
||||
const clock_scale_t hsi_8mhz[CLOCK_END] = {
|
||||
{ /* 44MHz */
|
||||
.pll= RCC_CFGR_PLLMUL_PLL_IN_CLK_X11,
|
||||
.pllsrc = RCC_CFGR_PLLSRC_HSI_DIV2,
|
||||
.hpre = RCC_CFGR_HPRE_DIV_NONE,
|
||||
.ppre1 = RCC_CFGR_PPRE1_DIV_2,
|
||||
.ppre2 = RCC_CFGR_PPRE2_DIV_NONE,
|
||||
.power_save = 1,
|
||||
.flash_config = FLASH_ACR_PRFTBE | FLASH_ACR_LATENCY_1WS,
|
||||
.apb1_frequency = 22000000,
|
||||
.apb2_frequency = 44000000,
|
||||
.pll = RCC_CFGR_PLLMUL_PLL_IN_CLK_X11,
|
||||
.pllsrc = RCC_CFGR_PLLSRC_HSI_DIV2,
|
||||
.hpre = RCC_CFGR_HPRE_DIV_NONE,
|
||||
.ppre1 = RCC_CFGR_PPRE1_DIV_2,
|
||||
.ppre2 = RCC_CFGR_PPRE2_DIV_NONE,
|
||||
.power_save = 1,
|
||||
.flash_config = FLASH_ACR_PRFTBE | FLASH_ACR_LATENCY_1WS,
|
||||
.apb1_frequency = 22000000,
|
||||
.apb2_frequency = 44000000,
|
||||
},
|
||||
{ /* 48MHz */
|
||||
.pll= RCC_CFGR_PLLMUL_PLL_IN_CLK_X12,
|
||||
.pllsrc = RCC_CFGR_PLLSRC_HSI_DIV2,
|
||||
.hpre = RCC_CFGR_HPRE_DIV_NONE,
|
||||
.ppre1 = RCC_CFGR_PPRE1_DIV_2,
|
||||
.ppre2 = RCC_CFGR_PPRE2_DIV_NONE,
|
||||
.power_save = 1,
|
||||
.flash_config = FLASH_ACR_PRFTBE | FLASH_ACR_LATENCY_1WS,
|
||||
.apb1_frequency = 24000000,
|
||||
.apb2_frequency = 48000000,
|
||||
.pll = RCC_CFGR_PLLMUL_PLL_IN_CLK_X12,
|
||||
.pllsrc = RCC_CFGR_PLLSRC_HSI_DIV2,
|
||||
.hpre = RCC_CFGR_HPRE_DIV_NONE,
|
||||
.ppre1 = RCC_CFGR_PPRE1_DIV_2,
|
||||
.ppre2 = RCC_CFGR_PPRE2_DIV_NONE,
|
||||
.power_save = 1,
|
||||
.flash_config = FLASH_ACR_PRFTBE | FLASH_ACR_LATENCY_1WS,
|
||||
.apb1_frequency = 24000000,
|
||||
.apb2_frequency = 48000000,
|
||||
},
|
||||
{ /* 64MHz */
|
||||
.pll= RCC_CFGR_PLLMUL_PLL_IN_CLK_X16,
|
||||
.pllsrc = RCC_CFGR_PLLSRC_HSI_DIV2,
|
||||
.hpre = RCC_CFGR_HPRE_DIV_NONE,
|
||||
.ppre1 = RCC_CFGR_PPRE1_DIV_2,
|
||||
.ppre2 = RCC_CFGR_PPRE2_DIV_NONE,
|
||||
.power_save = 1,
|
||||
.flash_config = FLASH_ACR_PRFTBE| FLASH_ACR_LATENCY_2WS,
|
||||
.apb1_frequency = 32000000,
|
||||
.apb2_frequency = 64000000,
|
||||
.pll = RCC_CFGR_PLLMUL_PLL_IN_CLK_X16,
|
||||
.pllsrc = RCC_CFGR_PLLSRC_HSI_DIV2,
|
||||
.hpre = RCC_CFGR_HPRE_DIV_NONE,
|
||||
.ppre1 = RCC_CFGR_PPRE1_DIV_2,
|
||||
.ppre2 = RCC_CFGR_PPRE2_DIV_NONE,
|
||||
.power_save = 1,
|
||||
.flash_config = FLASH_ACR_PRFTBE | FLASH_ACR_LATENCY_2WS,
|
||||
.apb1_frequency = 32000000,
|
||||
.apb2_frequency = 64000000,
|
||||
}
|
||||
};
|
||||
|
||||
void rcc_osc_ready_int_clear(osc_t osc)
|
||||
void rcc_osc_ready_int_clear(enum osc osc)
|
||||
{
|
||||
switch (osc) {
|
||||
case PLL:
|
||||
@@ -88,7 +87,7 @@ void rcc_osc_ready_int_clear(osc_t osc)
|
||||
}
|
||||
}
|
||||
|
||||
void rcc_osc_ready_int_enable(osc_t osc)
|
||||
void rcc_osc_ready_int_enable(enum osc osc)
|
||||
{
|
||||
switch (osc) {
|
||||
case PLL:
|
||||
@@ -109,7 +108,7 @@ void rcc_osc_ready_int_enable(osc_t osc)
|
||||
}
|
||||
}
|
||||
|
||||
void rcc_osc_ready_int_disable(osc_t osc)
|
||||
void rcc_osc_ready_int_disable(enum osc osc)
|
||||
{
|
||||
switch (osc) {
|
||||
case PLL:
|
||||
@@ -130,7 +129,7 @@ void rcc_osc_ready_int_disable(osc_t osc)
|
||||
}
|
||||
}
|
||||
|
||||
int rcc_osc_ready_int_flag(osc_t osc)
|
||||
int rcc_osc_ready_int_flag(enum osc osc)
|
||||
{
|
||||
switch (osc) {
|
||||
case PLL:
|
||||
@@ -163,7 +162,7 @@ int rcc_css_int_flag(void)
|
||||
return ((RCC_CIR & RCC_CIR_CSSF) != 0);
|
||||
}
|
||||
|
||||
void rcc_wait_for_osc_ready(osc_t osc)
|
||||
void rcc_wait_for_osc_ready(enum osc osc)
|
||||
{
|
||||
switch (osc) {
|
||||
case PLL:
|
||||
@@ -185,7 +184,7 @@ void rcc_wait_for_osc_ready(osc_t osc)
|
||||
}
|
||||
|
||||
|
||||
void rcc_wait_for_osc_not_ready(osc_t osc)
|
||||
void rcc_wait_for_osc_not_ready(enum osc osc)
|
||||
{
|
||||
switch (osc) {
|
||||
case PLL:
|
||||
@@ -206,7 +205,7 @@ void rcc_wait_for_osc_not_ready(osc_t osc)
|
||||
}
|
||||
}
|
||||
|
||||
void rcc_wait_for_sysclk_status(osc_t osc)
|
||||
void rcc_wait_for_sysclk_status(enum osc osc)
|
||||
{
|
||||
switch (osc) {
|
||||
case PLL:
|
||||
@@ -224,7 +223,7 @@ void rcc_wait_for_sysclk_status(osc_t osc)
|
||||
}
|
||||
}
|
||||
|
||||
void rcc_osc_on(osc_t osc)
|
||||
void rcc_osc_on(enum osc osc)
|
||||
{
|
||||
switch (osc) {
|
||||
case PLL:
|
||||
@@ -245,7 +244,7 @@ void rcc_osc_on(osc_t osc)
|
||||
}
|
||||
}
|
||||
|
||||
void rcc_osc_off(osc_t osc)
|
||||
void rcc_osc_off(enum osc osc)
|
||||
{
|
||||
switch (osc) {
|
||||
case PLL:
|
||||
@@ -276,7 +275,7 @@ void rcc_css_disable(void)
|
||||
RCC_CR &= ~RCC_CR_CSSON;
|
||||
}
|
||||
|
||||
void rcc_osc_bypass_enable(osc_t osc)
|
||||
void rcc_osc_bypass_enable(enum osc osc)
|
||||
{
|
||||
switch (osc) {
|
||||
case HSE:
|
||||
@@ -293,7 +292,7 @@ void rcc_osc_bypass_enable(osc_t osc)
|
||||
}
|
||||
}
|
||||
|
||||
void rcc_osc_bypass_disable(osc_t osc)
|
||||
void rcc_osc_bypass_disable(enum osc osc)
|
||||
{
|
||||
switch (osc) {
|
||||
case HSE:
|
||||
@@ -341,11 +340,11 @@ void rcc_set_sysclk_source(uint32_t clk)
|
||||
|
||||
void rcc_set_pll_source(uint32_t pllsrc)
|
||||
{
|
||||
uint32_t reg32;
|
||||
uint32_t reg32;
|
||||
|
||||
reg32 = RCC_CFGR;
|
||||
reg32 &= ~RCC_CFGR_PLLSRC;
|
||||
RCC_CFGR = (reg32 | (pllsrc << 16));
|
||||
reg32 = RCC_CFGR;
|
||||
reg32 &= ~RCC_CFGR_PLLSRC;
|
||||
RCC_CFGR = (reg32 | (pllsrc << 16));
|
||||
}
|
||||
|
||||
void rcc_set_ppre2(uint32_t ppre2)
|
||||
@@ -378,50 +377,51 @@ void rcc_set_hpre(uint32_t hpre)
|
||||
|
||||
void rcc_set_main_pll_hsi(uint32_t pll)
|
||||
{
|
||||
RCC_CFGR = (~RCC_CFGR_PLLMUL_MASK & RCC_CFGR) | (pll << RCC_CFGR_PLLMUL_SHIFT);
|
||||
RCC_CFGR = (~RCC_CFGR_PLLMUL_MASK & RCC_CFGR) |
|
||||
(pll << RCC_CFGR_PLLMUL_SHIFT);
|
||||
}
|
||||
|
||||
|
||||
uint32_t rcc_get_system_clock_source(void)
|
||||
{
|
||||
/* Return the clock source which is used as system clock. */
|
||||
return ((RCC_CFGR & 0x000c) >> 2);
|
||||
return (RCC_CFGR & 0x000c) >> 2;
|
||||
}
|
||||
|
||||
|
||||
void rcc_clock_setup_hsi(const clock_scale_t *clock)
|
||||
{
|
||||
/* Enable internal high-speed oscillator. */
|
||||
rcc_osc_on(HSI);
|
||||
rcc_wait_for_osc_ready(HSI);
|
||||
/* Select HSI as SYSCLK source. */
|
||||
rcc_set_sysclk_source(RCC_CFGR_SW_HSI); //se cayo
|
||||
rcc_wait_for_sysclk_status(HSI);
|
||||
/* Enable internal high-speed oscillator. */
|
||||
rcc_osc_on(HSI);
|
||||
rcc_wait_for_osc_ready(HSI);
|
||||
/* Select HSI as SYSCLK source. */
|
||||
rcc_set_sysclk_source(RCC_CFGR_SW_HSI); /* XXX: se cayo */
|
||||
rcc_wait_for_sysclk_status(HSI);
|
||||
|
||||
rcc_osc_off(PLL);
|
||||
rcc_wait_for_osc_not_ready(PLL);
|
||||
rcc_set_pll_source(clock->pllsrc);
|
||||
rcc_set_main_pll_hsi(clock->pll);
|
||||
/* Enable PLL oscillator and wait for it to stabilize. */
|
||||
rcc_osc_on(PLL);
|
||||
rcc_wait_for_osc_ready(PLL);
|
||||
/*
|
||||
* Set prescalers for AHB, ADC, ABP1, ABP2.
|
||||
* Do this before touching the PLL (TODO: why?).
|
||||
*/
|
||||
rcc_set_hpre(clock->hpre);
|
||||
rcc_set_ppre2(clock->ppre2);
|
||||
rcc_set_ppre1(clock->ppre1);
|
||||
/* Configure flash settings. */
|
||||
flash_set_ws(clock->flash_config);
|
||||
/* Select PLL as SYSCLK source. */
|
||||
rcc_set_sysclk_source(RCC_CFGR_SW_PLL); //se cayo
|
||||
/* Wait for PLL clock to be selected. */
|
||||
rcc_wait_for_sysclk_status(PLL);
|
||||
rcc_osc_off(PLL);
|
||||
rcc_wait_for_osc_not_ready(PLL);
|
||||
rcc_set_pll_source(clock->pllsrc);
|
||||
rcc_set_main_pll_hsi(clock->pll);
|
||||
/* Enable PLL oscillator and wait for it to stabilize. */
|
||||
rcc_osc_on(PLL);
|
||||
rcc_wait_for_osc_ready(PLL);
|
||||
/*
|
||||
* Set prescalers for AHB, ADC, ABP1, ABP2.
|
||||
* Do this before touching the PLL (TODO: why?).
|
||||
*/
|
||||
rcc_set_hpre(clock->hpre);
|
||||
rcc_set_ppre2(clock->ppre2);
|
||||
rcc_set_ppre1(clock->ppre1);
|
||||
/* Configure flash settings. */
|
||||
flash_set_ws(clock->flash_config);
|
||||
/* Select PLL as SYSCLK source. */
|
||||
rcc_set_sysclk_source(RCC_CFGR_SW_PLL); /* XXX: se cayo */
|
||||
/* Wait for PLL clock to be selected. */
|
||||
rcc_wait_for_sysclk_status(PLL);
|
||||
|
||||
/* Set the peripheral clock frequencies used. */
|
||||
rcc_ppre1_frequency = clock->apb1_frequency;
|
||||
rcc_ppre2_frequency = clock->apb2_frequency;
|
||||
/* Set the peripheral clock frequencies used. */
|
||||
rcc_ppre1_frequency = clock->apb1_frequency;
|
||||
rcc_ppre2_frequency = clock->apb2_frequency;
|
||||
}
|
||||
|
||||
|
||||
@@ -434,35 +434,37 @@ void rcc_backupdomain_reset(void)
|
||||
RCC_BDCR &= ~RCC_BDCR_BDRST;
|
||||
}
|
||||
|
||||
void rcc_set_i2c_clock_hsi(uint32_t i2c) {
|
||||
if (i2c==I2C1) {
|
||||
RCC_CFGR3 &= ~RCC_CFGR3_I2C1SW;
|
||||
}
|
||||
if (i2c==I2C2) {
|
||||
RCC_CFGR3 &= ~RCC_CFGR3_I2C2SW;
|
||||
}
|
||||
void rcc_set_i2c_clock_hsi(uint32_t i2c)
|
||||
{
|
||||
if (i2c == I2C1) {
|
||||
RCC_CFGR3 &= ~RCC_CFGR3_I2C1SW;
|
||||
}
|
||||
if (i2c == I2C2) {
|
||||
RCC_CFGR3 &= ~RCC_CFGR3_I2C2SW;
|
||||
}
|
||||
}
|
||||
|
||||
void rcc_set_i2c_clock_sysclk(uint32_t i2c) {
|
||||
if (i2c==I2C1) {
|
||||
RCC_CFGR3 |= RCC_CFGR3_I2C1SW;
|
||||
}
|
||||
if (i2c==I2C2) {
|
||||
RCC_CFGR3 |= RCC_CFGR3_I2C2SW;
|
||||
}
|
||||
void rcc_set_i2c_clock_sysclk(uint32_t i2c)
|
||||
{
|
||||
if (i2c == I2C1) {
|
||||
RCC_CFGR3 |= RCC_CFGR3_I2C1SW;
|
||||
}
|
||||
if (i2c == I2C2) {
|
||||
RCC_CFGR3 |= RCC_CFGR3_I2C2SW;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t rcc_get_i2c_clocks(void)
|
||||
{
|
||||
return(RCC_CFGR3 & (RCC_CFGR3_I2C1SW | RCC_CFGR3_I2C2SW));
|
||||
return RCC_CFGR3 & (RCC_CFGR3_I2C1SW | RCC_CFGR3_I2C2SW);
|
||||
}
|
||||
|
||||
void rcc_usb_prescale_1_5(void)
|
||||
{
|
||||
RCC_CFGR &= ~RCC_CFGR_USBPRES;
|
||||
RCC_CFGR &= ~RCC_CFGR_USBPRES;
|
||||
}
|
||||
|
||||
void rcc_usb_prescale_1(void)
|
||||
{
|
||||
RCC_CFGR |= RCC_CFGR_USBPRES;
|
||||
RCC_CFGR |= RCC_CFGR_USBPRES;
|
||||
}
|
||||
|
||||
@@ -57,4 +57,4 @@ void spi_fifo_reception_threshold_16bit(uint32_t spi)
|
||||
void spi_i2s_mode_spi_mode(uint32_t spi)
|
||||
{
|
||||
SPI_I2SCFGR(spi) &= ~SPI_I2SCFGR_I2SMOD;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ usart_reg_base
|
||||
|
||||
bool usart_get_interrupt_source(uint32_t usart, uint32_t flag)
|
||||
{
|
||||
uint32_t flag_set = (USART_ISR(usart) & flag);
|
||||
uint32_t flag_set = (USART_ISR(usart) & flag);
|
||||
/* IDLE, RXNE, TC, TXE interrupts */
|
||||
if ((flag >= USART_ISR_IDLE) && (flag <= USART_ISR_TXE)) {
|
||||
return ((flag_set & USART_CR1(usart)) != 0);
|
||||
@@ -138,4 +138,4 @@ bool usart_get_interrupt_source(uint32_t usart, uint32_t flag)
|
||||
return false;
|
||||
}
|
||||
|
||||
/**@}*/
|
||||
/**@}*/
|
||||
|
||||
Reference in New Issue
Block a user