1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

stm32f1: SPI: implement speed setting properly

This commit is contained in:
Thomas Eichinger 2014-08-20 11:08:18 +02:00
parent 6b43b3f587
commit 0e79a01cd2
7 changed files with 70 additions and 60 deletions

View File

@ -16,6 +16,7 @@ export OBJCOPY = $(PREFIX)objcopy
export TERMPROG = $(RIOTBASE)/dist/tools/pyterm/pyterm -p export TERMPROG = $(RIOTBASE)/dist/tools/pyterm/pyterm -p
export FLASHER = $(RIOTBOARD)/$(BOARD)/dist/flash.sh export FLASHER = $(RIOTBOARD)/$(BOARD)/dist/flash.sh
export DEBUGGER = $(RIOTBOARD)/$(BOARD)/dist/debug.sh export DEBUGGER = $(RIOTBOARD)/$(BOARD)/dist/debug.sh
export RESET = $(RIOTBOARD)/$(BOARD)/dist/reset.sh
# define build specific options # define build specific options
export CPU_USAGE = -mcpu=cortex-m3 export CPU_USAGE = -mcpu=cortex-m3

View File

@ -55,32 +55,32 @@ uint8_t at86rf231_get_status(void)
void at86rf231_spi_select(void) void at86rf231_spi_select(void)
{ {
SPI_0_CS_PORT->BRR = (1 << SPI_0_CS_PIN); gpio_clear(SPI_0_CS_GPIO);
} }
void at86rf231_spi_unselect(void) void at86rf231_spi_unselect(void)
{ {
SPI_0_CS_PORT->BSRR = (1 << SPI_0_CS_PIN); gpio_set(SPI_0_CS_GPIO);
} }
void at86rf231_slp_set(void) void at86rf231_slp_set(void)
{ {
SPI_0_SLEEP_PORT->BSRR = (1 << SPI_0_SLEEP_PIN); gpio_set(SPI_0_SLEEP_GPIO);
} }
void at86rf231_slp_clear(void) void at86rf231_slp_clear(void)
{ {
SPI_0_SLEEP_PORT->BRR = (1 << SPI_0_SLEEP_PIN); gpio_clear(SPI_0_SLEEP_GPIO);
} }
void at86rf231_rst_set(void) void at86rf231_rst_set(void)
{ {
SPI_0_RESET_PORT->BRR = (1 << SPI_0_RESET_PIN); gpio_clear(SPI_0_RESET_GPIO);
} }
void at86rf231_rst_clear(void) void at86rf231_rst_clear(void)
{ {
SPI_0_RESET_PORT->BSRR = (1 << SPI_0_RESET_PIN); gpio_set(SPI_0_RESET_GPIO);
} }
void at86rf231_enable_interrupts(void) void at86rf231_enable_interrupts(void)

View File

@ -275,7 +275,11 @@
#define SPI_CPOL_LOW (0x0000) #define SPI_CPOL_LOW (0x0000)
#define SPI_CPHA_1_EDGE (0x0000) #define SPI_CPHA_1_EDGE (0x0000)
#define SPI_NSS_SOFT (0x0200) #define SPI_NSS_SOFT (0x0200)
#define SPI_BR_PRESCALER_8 (0x0010)
#define SPI_BR_PRESCALER_16 (0x0018) #define SPI_BR_PRESCALER_16 (0x0018)
#define SPI_BR_PRESCALER_64 (0x0028)
#define SPI_BR_PRESCALER_128 (0x0030)
#define SPI_BR_PRESCALER_256 (0x0038)
#define SPI_1ST_BIT_MSB (0x0000) #define SPI_1ST_BIT_MSB (0x0000)
#endif /* __PERIPH_CONF_H */ #endif /* __PERIPH_CONF_H */

View File

@ -822,87 +822,85 @@ void gpio_set(gpio_t dev)
switch (dev) { switch (dev) {
#ifdef GPIO_0_EN #ifdef GPIO_0_EN
case GPIO_0: case GPIO_0:
GPIO_0_PORT->ODR |= (1 << GPIO_0_PIN); GPIO_0_PORT->BSRR = (1 << GPIO_0_PIN);
break; break;
#endif #endif
#ifdef GPIO_1_EN #ifdef GPIO_1_EN
case GPIO_1: case GPIO_1:
GPIO_1_PORT->ODR |= (1 << GPIO_1_PIN); GPIO_1_PORT->BSRR = (1 << GPIO_1_PIN);
break; break;
#endif #endif
#ifdef GPIO_2_EN #ifdef GPIO_2_EN
case GPIO_2: case GPIO_2:
GPIO_2_PORT->ODR |= (1 << GPIO_2_PIN); GPIO_2_PORT->BSRR = (1 << GPIO_2_PIN);
break; break;
#endif #endif
#ifdef GPIO_3_EN #ifdef GPIO_3_EN
case GPIO_3: case GPIO_3:
GPIO_3_PORT->ODR |= (1 << GPIO_3_PIN); GPIO_3_PORT->BSRR = (1 << GPIO_3_PIN);
break; break;
#endif #endif
#ifdef GPIO_4_EN #ifdef GPIO_4_EN
case GPIO_4: case GPIO_4:
GPIO_4_PORT->ODR |= (1 << GPIO_4_PIN); GPIO_4_PORT->BSRR = (1 << GPIO_4_PIN);
break; break;
#endif #endif
#ifdef GPIO_5_EN #ifdef GPIO_5_EN
case GPIO_5: case GPIO_5:
GPIO_5_PORT->ODR |= (1 << GPIO_5_PIN); GPIO_5_PORT->BSRR = (1 << GPIO_5_PIN);
break; break;
#endif #endif
#ifdef GPIO_6_EN #ifdef GPIO_6_EN
case GPIO_6: case GPIO_6:
GPIO_6_PORT->ODR |= (1 << GPIO_6_PIN); GPIO_6_PORT->BSRR = (1 << GPIO_6_PIN);
break; break;
#endif #endif
#ifdef GPIO_7_EN #ifdef GPIO_7_EN
case GPIO_7: case GPIO_7:
GPIO_7_PORT->ODR |= (1 << GPIO_7_PIN); GPIO_7_PORT->BSRR = (1 << GPIO_7_PIN);
break; break;
#endif #endif
#ifdef GPIO_8_EN #ifdef GPIO_8_EN
case GPIO_8: case GPIO_8:
GPIO_8_PORT->ODR |= (1 << GPIO_8_PIN); GPIO_8_PORT->BSRR = (1 << GPIO_8_PIN);
break; break;
#endif #endif
#ifdef GPIO_9_EN #ifdef GPIO_9_EN
case GPIO_9: case GPIO_9:
GPIO_9_PORT->ODR |= (1 << GPIO_9_PIN); GPIO_9_PORT->BSRR = (1 << GPIO_9_PIN);
break; break;
#endif #endif
#ifdef GPIO_10_EN #ifdef GPIO_10_EN
case GPIO_10: case GPIO_10:
GPIO_10_PORT->ODR |= (1 << GPIO_10_PIN); GPIO_10_PORT->BSRR = (1 << GPIO_10_PIN);
break; break;
#endif #endif
#ifdef GPIO_11_EN #ifdef GPIO_11_EN
case GPIO_11: case GPIO_11:
GPIO_11_PORT->ODR |= (1 << GPIO_11_PIN); GPIO_11_PORT->BSRR = (1 << GPIO_11_PIN);
break; break;
#endif #endif
#ifdef GPIO_12_EN #ifdef GPIO_12_EN
case GPIO_12: case GPIO_12:
GPIO_12_PORT->ODR |= (1 << GPIO_12_PIN); GPIO_12_PORT->BSRR = (1 << GPIO_12_PIN);
break; break;
#endif #endif
#ifdef GPIO_13_EN #ifdef GPIO_13_EN
case GPIO_13: case GPIO_13:
GPIO_13_PORT->ODR |= (1 << GPIO_13_PIN); GPIO_13_PORT->BSRR = (1 << GPIO_13_PIN);
break; break;
#endif #endif
#ifdef GPIO_14_EN #ifdef GPIO_14_EN
case GPIO_14: case GPIO_14:
GPIO_14_PORT->ODR |= (1 << GPIO_14_PIN); GPIO_14_PORT->BSRR = (1 << GPIO_14_PIN);
break; break;
#endif #endif
#ifdef GPIO_15_EN #ifdef GPIO_15_EN
case GPIO_15: case GPIO_15:
GPIO_15_PORT->ODR |= (1 << GPIO_15_PIN); GPIO_15_PORT->BSRR = (1 << GPIO_15_PIN);
break; break;
#endif #endif
} }
return;
} }
void gpio_clear(gpio_t dev) void gpio_clear(gpio_t dev)
@ -910,87 +908,85 @@ void gpio_clear(gpio_t dev)
switch (dev) { switch (dev) {
#ifdef GPIO_0_EN #ifdef GPIO_0_EN
case GPIO_0: case GPIO_0:
GPIO_0_PORT->ODR &= ~(1 << GPIO_0_PIN); GPIO_0_PORT->BRR = (1 << GPIO_0_PIN);
break; break;
#endif #endif
#ifdef GPIO_1_EN #ifdef GPIO_1_EN
case GPIO_1: case GPIO_1:
GPIO_1_PORT->ODR &= ~(1 << GPIO_1_PIN); GPIO_1_PORT->BRR = (1 << GPIO_1_PIN);
break; break;
#endif #endif
#ifdef GPIO_2_EN #ifdef GPIO_2_EN
case GPIO_2: case GPIO_2:
GPIO_2_PORT->ODR &= ~(1 << GPIO_2_PIN); GPIO_2_PORT->BRR = (1 << GPIO_2_PIN);
break; break;
#endif #endif
#ifdef GPIO_3_EN #ifdef GPIO_3_EN
case GPIO_3: case GPIO_3:
GPIO_3_PORT->ODR &= ~(1 << GPIO_3_PIN); GPIO_3_PORT->BRR = (1 << GPIO_3_PIN);
break; break;
#endif #endif
#ifdef GPIO_4_EN #ifdef GPIO_4_EN
case GPIO_4: case GPIO_4:
GPIO_4_PORT->ODR &= ~(1 << GPIO_4_PIN); GPIO_4_PORT->BRR = (1 << GPIO_4_PIN);
break; break;
#endif #endif
#ifdef GPIO_5_EN #ifdef GPIO_5_EN
case GPIO_5: case GPIO_5:
GPIO_5_PORT->ODR &= ~(1 << GPIO_5_PIN); GPIO_5_PORT->BRR = (1 << GPIO_5_PIN);
break; break;
#endif #endif
#ifdef GPIO_6_EN #ifdef GPIO_6_EN
case GPIO_6: case GPIO_6:
GPIO_6_PORT->ODR &= ~(1 << GPIO_6_PIN); GPIO_6_PORT->BRR = (1 << GPIO_6_PIN);
break; break;
#endif #endif
#ifdef GPIO_7_EN #ifdef GPIO_7_EN
case GPIO_7: case GPIO_7:
GPIO_7_PORT->ODR &= ~(1 << GPIO_7_PIN); GPIO_7_PORT->BRR = (1 << GPIO_7_PIN);
break; break;
#endif #endif
#ifdef GPIO_8_EN #ifdef GPIO_8_EN
case GPIO_8: case GPIO_8:
GPIO_8_PORT->ODR &= ~(1 << GPIO_8_PIN); GPIO_8_PORT->BRR = (1 << GPIO_8_PIN);
break; break;
#endif #endif
#ifdef GPIO_9_EN #ifdef GPIO_9_EN
case GPIO_9: case GPIO_9:
GPIO_9_PORT->ODR &= ~(1 << GPIO_9_PIN); GPIO_9_PORT->BRR = (1 << GPIO_9_PIN);
break; break;
#endif #endif
#ifdef GPIO_10_EN #ifdef GPIO_10_EN
case GPIO_10: case GPIO_10:
GPIO_10_PORT->ODR &= ~(1 << GPIO_10_PIN); GPIO_10_PORT->BRR = (1 << GPIO_10_PIN);
break; break;
#endif #endif
#ifdef GPIO_11_EN #ifdef GPIO_11_EN
case GPIO_11: case GPIO_11:
GPIO_11_PORT->ODR &= ~(1 << GPIO_11_PIN); GPIO_11_PORT->BRR = (1 << GPIO_11_PIN);
break; break;
#endif #endif
#ifdef GPIO_12_EN #ifdef GPIO_12_EN
case GPIO_12: case GPIO_12:
GPIO_12_PORT->ODR &= ~(1 << GPIO_12_PIN); GPIO_12_PORT->BRR = (1 << GPIO_12_PIN);
break; break;
#endif #endif
#ifdef GPIO_13_EN #ifdef GPIO_13_EN
case GPIO_13: case GPIO_13:
GPIO_13_PORT->ODR &= ~(1 << GPIO_13_PIN); GPIO_13_PORT->BRR = (1 << GPIO_13_PIN);
break; break;
#endif #endif
#ifdef GPIO_14_EN #ifdef GPIO_14_EN
case GPIO_14: case GPIO_14:
GPIO_14_PORT->ODR &= ~(1 << GPIO_14_PIN); GPIO_14_PORT->BRR = (1 << GPIO_14_PIN);
break; break;
#endif #endif
#ifdef GPIO_15_EN #ifdef GPIO_15_EN
case GPIO_15: case GPIO_15:
GPIO_15_PORT->ODR &= ~(1 << GPIO_15_PIN); GPIO_15_PORT->BRR = (1 << GPIO_15_PIN);
break; break;
#endif #endif
} }
return;
} }

View File

@ -27,10 +27,10 @@
#define ENABLE_DEBUG (0) #define ENABLE_DEBUG (0)
#include "debug.h" #include "debug.h"
/* TODO: parse and use conf and speed parameter */
int spi_init_master(spi_t dev, spi_conf_t conf, spi_speed_t speed) int spi_init_master(spi_t dev, spi_conf_t conf, spi_speed_t speed)
{ {
SPI_TypeDef *SPIx; SPI_TypeDef *SPIx;
uint16_t br_div = 0;
switch(dev) { switch(dev) {
#ifdef SPI_0_EN #ifdef SPI_0_EN
@ -43,20 +43,32 @@ int spi_init_master(spi_t dev, spi_conf_t conf, spi_speed_t speed)
return -1; return -1;
} }
switch(speed) {
case SPI_SPEED_10MHZ:
br_div = SPI_BR_PRESCALER_8; /* actual speed: 9MHz */
break;
case SPI_SPEED_5MHZ:
br_div = SPI_BR_PRESCALER_16; /* actual speed: 4.5MHz */
break;
case SPI_SPEED_1MHZ:
br_div = SPI_BR_PRESCALER_64; /* actual speed: 1.1MHz */
break;
case SPI_SPEED_400KHZ:
br_div = SPI_BR_PRESCALER_128; /* actual speed: 500kHz */
break;
case SPI_SPEED_100KHZ:
br_div = SPI_BR_PRESCALER_256; /* actual speed: 200kHz */
}
/* set up SPI */ /* set up SPI */
uint16_t tmp = SPIx->CR1; SPIx->CR1 = SPI_2_LINES_FULL_DUPLEX \
tmp &= 0x3040; /* reset value */ | SPI_MASTER_MODE \
| SPI_DATA_SIZE_8B \
| (conf & 0x3) \
| SPI_NSS_SOFT \
| br_div \
| SPI_1ST_BIT_MSB;
tmp |= SPI_2_LINES_FULL_DUPLEX;
tmp |= SPI_MASTER_MODE;
tmp |= SPI_DATA_SIZE_8B;
tmp |= SPI_CPOL_LOW;
tmp |= SPI_CPHA_1_EDGE;
tmp |= SPI_NSS_SOFT;
tmp |= SPI_BR_PRESCALER_16;
tmp |= SPI_1ST_BIT_MSB;
SPIx->CR1 = tmp;
SPIx->I2SCFGR &= 0xF7FF; /* select SPI mode */ SPIx->I2SCFGR &= 0xF7FF; /* select SPI mode */
SPIx->CRCPR = 0x7; /* reset CRC polynomial */ SPIx->CRCPR = 0x7; /* reset CRC polynomial */

View File

@ -29,8 +29,7 @@ QUIET ?= 1
BOARD_INSUFFICIENT_RAM := chronos msb-430h telosb wsn430-v1_3b wsn430-v1_4 z1 redbee-econotag BOARD_INSUFFICIENT_RAM := chronos msb-430h telosb wsn430-v1_3b wsn430-v1_4 z1 redbee-econotag
BOARD_BLACKLIST := arduino-due mbed_lpc1768 msb-430 pttu udoo qemu-i386 \ BOARD_BLACKLIST := arduino-due mbed_lpc1768 msb-430 pttu udoo qemu-i386 \
stm32f0discovery stm32f3discovery stm32f4discovery pca10000 pca10005 \ stm32f0discovery stm32f3discovery stm32f4discovery pca10000 pca10005
iot-lab_M3
# mbed_lpc1768: see https://github.com/RIOT-OS/RIOT/issues/675 # mbed_lpc1768: see https://github.com/RIOT-OS/RIOT/issues/675
# msb-430: see https://github.com/RIOT-OS/RIOT/issues/658 # msb-430: see https://github.com/RIOT-OS/RIOT/issues/658
# pttu: see https://github.com/RIOT-OS/RIOT/issues/659 # pttu: see https://github.com/RIOT-OS/RIOT/issues/659
@ -40,7 +39,6 @@ BOARD_BLACKLIST := arduino-due mbed_lpc1768 msb-430 pttu udoo qemu-i386 \
# stm32f4discovery: no transceiver, yet # stm32f4discovery: no transceiver, yet
# pca10000: no transceiver, yet # pca10000: no transceiver, yet
# pca10005: no transceiver, yet # pca10005: no transceiver, yet
# iot-lab_M3: no RTC implementation, yet
# Modules to include: # Modules to include:

View File

@ -30,7 +30,7 @@ QUIET ?= 1
BOARD_INSUFFICIENT_RAM := chronos msb-430h telosb wsn430-v1_3b wsn430-v1_4 z1 redbee-econotag BOARD_INSUFFICIENT_RAM := chronos msb-430h telosb wsn430-v1_3b wsn430-v1_4 z1 redbee-econotag
BOARD_BLACKLIST := arduino-due mbed_lpc1768 msb-430 pttu udoo qemu-i386 \ BOARD_BLACKLIST := arduino-due mbed_lpc1768 msb-430 pttu udoo qemu-i386 \
stm32f0discovery stm32f3discovery stm32f4discovery \ stm32f0discovery stm32f3discovery stm32f4discovery \
pca10000 pca10005 iot-lab_M3 pca10000 pca10005
# mbed_lpc1768: see https://github.com/RIOT-OS/RIOT/issues/675 # mbed_lpc1768: see https://github.com/RIOT-OS/RIOT/issues/675
# msb-430: see https://github.com/RIOT-OS/RIOT/issues/658 # msb-430: see https://github.com/RIOT-OS/RIOT/issues/658
# pttu: see https://github.com/RIOT-OS/RIOT/issues/659 # pttu: see https://github.com/RIOT-OS/RIOT/issues/659
@ -39,7 +39,6 @@ BOARD_BLACKLIST := arduino-due mbed_lpc1768 msb-430 pttu udoo qemu-i386 \
# stm32f3discovery: no transceiver, yet # stm32f3discovery: no transceiver, yet
# stm32f4discovery: no transceiver, yet # stm32f4discovery: no transceiver, yet
# pca10000/5: no transceiver, yet # pca10000/5: no transceiver, yet
# iot-lab_M3: no RTC implementation, yet
# Modules to include: # Modules to include:
USEMODULE += posix USEMODULE += posix