diff options
author | jaseg <git@jaseg.de> | 2020-11-26 12:39:21 +0100 |
---|---|---|
committer | jaseg <git@jaseg.de> | 2020-11-26 12:39:21 +0100 |
commit | 9b5625f12ae067a1583252d41febef848f055588 (patch) | |
tree | 71ce1935254fec9bca064aa08dfe6eb7ef0e0c3e /prototype/fw/src | |
parent | 451904a0c5fae3bd28d35c7128df3a9db1a04b26 (diff) | |
download | ihsm-9b5625f12ae067a1583252d41febef848f055588.tar.gz ihsm-9b5625f12ae067a1583252d41febef848f055588.tar.bz2 ihsm-9b5625f12ae067a1583252d41febef848f055588.zip |
Make firmware build and run
Diffstat (limited to 'prototype/fw/src')
-rw-r--r-- | prototype/fw/src/main.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/prototype/fw/src/main.c b/prototype/fw/src/main.c index a6b265b..de920eb 100644 --- a/prototype/fw/src/main.c +++ b/prototype/fw/src/main.c @@ -2,7 +2,50 @@ #include <global.h> int main(void) { + + RCC->AHBENR |= RCC_AHBENR_GPIOAEN; + RCC->APB2ENR |= RCC_APB2ENR_USART1EN; + + GPIOA->MODER |= (2 << GPIO_MODER_MODER9_Pos); + GPIOA->AFR[1] = (7 << (9-8)*4); + + SystemCoreClockUpdate(); + int apb2_clock = SystemCoreClock / APB2_PRESC; + + int baudrate = 115200; + + USART1->CR1 = USART_CR1_MME | USART_CR1_TE; + USART1->BRR = (apb2_clock + baudrate/2) / baudrate; + USART1->CR1 |= USART_CR1_UE; + + char s[12] = { + '0', '0', '0', '0', '0', + ' ', 'T', 'E', 'S', 'T', + '\n', '\0'}; + int line = 0; + char *c = s; + USART1->TDR = *(c++); /* Kick off transmission */ while (23) { + if (USART1->ISR & USART_ISR_TXE) { + for (int i=0; i<100; i++) + asm volatile ("nop"); + USART1->TDR = *(c++); + if (!*c) { + c = s; + line++; + int tmp = line; + tmp %= 100000; + s[0] = '0' + tmp/10000; + tmp %= 10000; + s[1] = '0' + tmp/1000; + tmp %= 1000; + s[2] = '0' + tmp/100; + tmp %= 100; + s[3] = '0' + tmp/10; + tmp %= 10; + s[4] = '0' + tmp; + } + } } } |