diff options
Diffstat (limited to 'src/stm-demo')
| -rw-r--r-- | src/stm-demo/Makefile | 5 | ||||
| -rw-r--r-- | src/stm-demo/ao_demo.c | 79 | ||||
| -rw-r--r-- | src/stm-demo/ao_pins.h | 5 |
3 files changed, 85 insertions, 4 deletions
diff --git a/src/stm-demo/Makefile b/src/stm-demo/Makefile index 366291c6..c1f49371 100644 --- a/src/stm-demo/Makefile +++ b/src/stm-demo/Makefile @@ -26,7 +26,10 @@ ALTOS_SRC = \ ao_timer.c \ ao_serial_stm.c \ ao_lcd_stm.c \ - ao_lcd_font.c + ao_lcd_font.c \ + ao_mutex.c \ + ao_dma_stm.c \ + ao_spi_stm.c PRODUCT=StmDemo-v0.0 PRODUCT_DEF=-DSTM_DEMO diff --git a/src/stm-demo/ao_demo.c b/src/stm-demo/ao_demo.c index 544f261f..54f7c8f2 100644 --- a/src/stm-demo/ao_demo.c +++ b/src/stm-demo/ao_demo.c @@ -50,6 +50,71 @@ void _lseek() { } void _exit () { } void _read () { } void _fstat() { } + +static void +ao_dma_test(void) { + static char src[20] = "hello, world"; + static char dst[20]; + + dst[0] = '\0'; + ao_dma_set_transfer(STM_DMA_INDEX(1), dst, src, 13, + (1 << STM_DMA_CCR_MEM2MEM) | + (STM_DMA_CCR_PL_LOW << STM_DMA_CCR_PL) | + (STM_DMA_CCR_MSIZE_8 << STM_DMA_CCR_MSIZE) | + (STM_DMA_CCR_PSIZE_8 << STM_DMA_CCR_PSIZE) | + (1 << STM_DMA_CCR_MINC) | + (1 << STM_DMA_CCR_PINC) | + (0 << STM_DMA_CCR_CIRC) | + (STM_DMA_CCR_DIR_MEM_TO_PER << STM_DMA_CCR_DIR)); + ao_dma_start(STM_DMA_INDEX(1)); + cli(); + while (!ao_dma_done[STM_DMA_INDEX(1)]) + ao_sleep(&ao_dma_done[STM_DMA_INDEX(1)]); + sei(); + printf ("copied %s\n", dst); +} + +static void +ao_spi_write(void) { + unsigned char data[] = { 0x55, 0xaa, 0xff, 0x00 }; + int i; + + for (i = 0; i < 10; i++) { + ao_spi_get(0); + stm_gpio_set(&stm_gpioc, 12, 0); + ao_spi_send(data, 1, 0); + stm_gpio_set(&stm_gpioc, 12, 1); + ao_spi_put(0); + printf("."); + flush(); + ao_delay(100); + } +} + +static void +ao_spi_read(void) { + unsigned char data[4]; + int i; + + for (i = 0; i < 10; i++) { + ao_spi_get(0); + stm_gpio_set(&stm_gpioc, 12, 0); + ao_spi_recv(data, 4, 0); + printf("."); + flush(); + stm_gpio_set(&stm_gpioc, 12, 1); + ao_spi_put(0); + ao_delay(100); + } +} + +__code struct ao_cmds ao_demo_cmds[] = { + { ao_dma_test, "D\0DMA test" }, + { ao_spi_write, "W\0SPI write" }, + { ao_spi_read, "R\0SPI read" }, + { 0, NULL } +}; + int main(void) { @@ -57,11 +122,19 @@ main(void) ao_serial_init(); ao_timer_init(); + ao_dma_init(); ao_cmd_init(); - ao_lcd_stm_init(); - ao_lcd_font_init(); - ao_add_task(&demo_task, ao_demo, "demo"); +// ao_lcd_stm_init(); +// ao_lcd_font_init(); + ao_spi_init(); + + ao_cmd_register(&ao_demo_cmds[0]); + stm_rcc.ahbenr |= (1 << STM_RCC_AHBENR_GPIOCEN); + stm_gpio_set(&stm_gpioc, 12, 1); + stm_moder_set(&stm_gpioc, 12, STM_MODER_OUTPUT); + stm_otyper_set(&stm_gpioc, 12, STM_OTYPER_PUSH_PULL); + ao_start_scheduler(); return 0; } diff --git a/src/stm-demo/ao_pins.h b/src/stm-demo/ao_pins.h index 798a292e..09c88f90 100644 --- a/src/stm-demo/ao_pins.h +++ b/src/stm-demo/ao_pins.h @@ -34,6 +34,11 @@ #define SERIAL_3_PC10_PC11 0 #define SERIAL_3_PD8_PD9 1 +#define HAS_SPI_1 1 +#define SPI_1_PB3_PB4_PB5 1 + +#define HAS_SPI_2 0 + #define HAS_USB 0 #define HAS_BEEP 0 #define PACKET_HAS_SLAVE 0 |
