-extern unsigned int _sram_end;
-extern unsigned int _data_vma_start;
-extern unsigned int _data_vma_end;
-extern unsigned int _data_lma_start;
-extern unsigned int _bss_vma_start;
-extern unsigned int _bss_vma_end;
+#include "link.h"
+#include "stm32f411.h"
-#define RCC_AHB1 ((volatile unsigned int * const) 0x40023830)
-#define GPIOC_MODER ((volatile unsigned int * const) 0x40020800)
-#define GPIOC_ODR ((volatile unsigned int * const) 0x40020814)
+const char msg[] = "blink ";
static void
delay (void)
reset_handler (void)
{
unsigned int *src, *dst;
+ unsigned int off;
/* relocate .data to sram */
src = &_data_lma_start;
while (dst < &_bss_vma_end)
*(dst++) = 0;
- /* blink blink */
- *RCC_AHB1 |= (1u << 2);
+ /* (todo) usart pin setup (alt func and enable port clock) */
+
+ /* UE: USART enable */
+ *USART_CR1 |= (1u << 13); /* 1: USART enable */
+ /* M: Word length */
+ *USART_CR1 &= ~(1u << 12); /* 0: 1 Start bit, 8 Data bits, n Stop bit */
+ /* STOP: STOP bits */
+ *USART_CR2 &= ~(3u << 12); /* 00: 1 Stop bit */
+ /* the clock frequnecy is 16mhz initially, so for a baud rate of 115.2 KBps we
+ * need to set USARTDIV=8.6875 */
+ *USART_BRR = (8u << 4) | 11; /* mantissa and fraction (/16) */
+ /* TE: Transmitter enable */
+ *USART_CR1 |= (1u << 3); /* 1: Transmitter is enabled */
+
+ /* blink blink setup */
+ *RCC_AHB1ENR |= (1u << 2);
*GPIOC_MODER &= ~(3u << 26);
*GPIOC_MODER |= (1u << 26);
while (1)
{
+ /* speak */
+ off = 0;
+ do
+ {
+ /* TXE: Transmit data register empty */
+ if (!(*USART_SR & (1u << 7)))
+ continue;
+
+ *USART_DR = msg[off++];
+ }
+ while (off < sizeof msg);
+
+ /* blink */
*GPIOC_ODR ^= (1u << 13);
delay ();
}
}
-__attribute__ ((section (".vtbl"), used))
+__attribute__ ((section (".vector_table"), used))
static unsigned long const vector_table[] = {
(unsigned long) &_sram_end,
(unsigned long) reset_handler,