#include #include #include #include #include #include #include /* * Part number: STM32F030F4C6 */ void tick(void) { for(int i=0; i<50; i++) __asm__("nop"); } void spi_send(int data) { SPI1->DR = data; while (SPI1->SR & SPI_SR_BSY); } void strobe_aux(void) { GPIOA->BSRR = GPIO_BSRR_BS_10; tick(); GPIOA->BSRR = GPIO_BSRR_BR_10; } void strobe_leds(void) { GPIOA->BSRR = GPIO_BSRR_BS_9; tick(); GPIOA->BSRR = GPIO_BSRR_BR_9; } #define SR_COMM 0x0002 #define SR_ERROR 0x0004 #define SR_ID 0x0008 #define SR_ILED_HIGH 0x0080 #define SR_ILED_LOW 0x0040 int main(void) { RCC->CR |= RCC_CR_HSEON; while (!(RCC->CR&RCC_CR_HSERDY)); RCC->CFGR &= ~RCC_CFGR_PLLMUL_Msk & ~RCC_CFGR_SW_Msk; RCC->CFGR |= (2<CFGR2 &= ~RCC_CFGR2_PREDIV_Msk; RCC->CFGR2 |= RCC_CFGR2_PREDIV_DIV2; RCC->CR |= RCC_CR_PLLON; while (!(RCC->CR&RCC_CR_PLLRDY)); RCC->CFGR |= (2<AHBENR |= RCC_AHBENR_GPIOAEN; RCC->APB2ENR |= RCC_APB2ENR_SPI1EN; GPIOA->MODER |= (2<OSPEEDR |= (2<AFR[0] |= (0<I2SCFGR = 0; SPI1->CR2 &= ~SPI_CR2_DS_Msk; SPI1->CR2 &= ~SPI_CR2_DS_Msk; SPI1->CR2 |= LL_SPI_DATAWIDTH_16BIT; /* FIXME maybe try w/o BIDI */ SPI1->CR1 = SPI_CR1_BIDIMODE | SPI_CR1_BIDIOE | SPI_CR1_SSM | SPI_CR1_SSI | SPI_CR1_SPE | (0<BSRR = GPIO_BSRR_BR_6; /* OE */ int j = 0; int ctr = 0; int q = 0; int bval = 0x400; while (42) { for (int i=0; i<8; i++) { spi_send(1<<(ctr&3)); spi_send(1<<((ctr>>1)&3)); strobe_leds(); //spi_send(0x0200 | bval | (0xff^(1<