aboutsummaryrefslogtreecommitdiff
path: root/serial1.cpp
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2016-01-02 21:13:31 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2016-01-02 21:13:31 +0100
commitbaedda497d16c5096971eee83a0c467fe663fe6d (patch)
tree2f8925c68d94aed7d5fc7022462abbb359200b9e /serial1.cpp
parent9129af503c8211d713c8a160a3b6f3f86b328639 (diff)
downloadstm32f103-playground-baedda497d16c5096971eee83a0c467fe663fe6d.tar.gz
stm32f103-playground-baedda497d16c5096971eee83a0c467fe663fe6d.tar.bz2
stm32f103-playground-baedda497d16c5096971eee83a0c467fe663fe6d.tar.xz
stm32f103-playground-baedda497d16c5096971eee83a0c467fe663fe6d.zip
o Moving around a lot of files.
Diffstat (limited to 'serial1.cpp')
-rw-r--r--serial1.cpp128
1 files changed, 0 insertions, 128 deletions
diff --git a/serial1.cpp b/serial1.cpp
deleted file mode 100644
index 60e9bc9..0000000
--- a/serial1.cpp
+++ /dev/null
@@ -1,128 +0,0 @@
-#include <stdint.h>
-#include <stm32f10x.h>
-#include <stm32f10x_rcc.h>
-#include <stm32f10x_gpio.h>
-#include <stddef.h>
-#include <stdarg.h>
-#include "debug.h"
-#include "tinyprintf.h"
-
-extern "C" void halt();
-
-#include "stm32f10x_conf.h"
-
-extern "C"
-__attribute__((naked))
-void HardFault_Handler_C(uint32_t *hardfault_args) {
- halt();
-}
-
-size_t strlen(const char *s) {
- size_t size = 0;
- while (*s++ != '\0') size++;
- return size;
-}
-
-int run = 1;
-
-volatile USART_TypeDef *usart1 = (volatile USART_TypeDef *) USART1_BASE;
-
-/*
- * When we get there the stack pointer is set
- */
-int main() {
- SystemInit();
-
- init_printf(nullptr, dbg_putc);
-
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO
- | RCC_APB2Periph_USART1
- | RCC_APB2Periph_GPIOA
- | RCC_APB2Periph_GPIOB
- | RCC_APB2Periph_GPIOC,
- ENABLE);
-
- /* ***************************************** */
-
- // Debug on port B
-
- RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOB, ENABLE);
- RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOB, DISABLE);
-
- // Make Port B's pin #5 the debug output pin
- GPIO_InitTypeDef init;
- GPIO_StructInit(&init);
- init.GPIO_Pin = GPIO_Pin_5;
- init.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_Init(GPIOB, &init);
-
- /* ***************************************** */
-
- RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOA, ENABLE);
- RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOA, DISABLE);
-
- /*
- * PA9 USART1_TX
- * PA10 USART1_RX
- */
-
- // Enable USART1
- RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, ENABLE);
- RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, DISABLE);
-
- // Make the TX pin an output
- GPIO_StructInit(&init);
- init.GPIO_Pin = GPIO_Pin_9;
- init.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_Init(GPIOA, &init);
-
- // 8 bit mode
- USART1->CR1 &= ~USART_CR1_M;
- USART1->CR2 &= ~USART_CR2_STOP_1;
-
- USART1->CR1 |= USART_CR1_UE /* Set UART Enable */
- | USART_CR1_TE; /* Set Transmission Enable */
-
- // Set baud rate
- int mantissa = 39;
- int fraction = static_cast<int>(16 * 0.0625); // == 1
- // 72M / (16*39.0625) = 115200
- USART1->BRR = static_cast<uint16_t >(mantissa << 4 | fraction);
-
- char c = 'A';
- while (run) {
- int txe = USART1->SR & USART_SR_TXE;
-
-// dbg_printf("1:%d?\n", x);
-
-// char mm[100];
-// tfp_sprintf(mm, "2:%d?\n", x);
-// send_command(SYS_WRITE0, mm);
-
-// printf(" %u?\n", usart1->SR);
-// printf(" %u?\n", 1);
-
- if (txe) {
- GPIO_SetBits(GPIOB, GPIO_Pin_All);
- GPIO_ResetBits(GPIOB, GPIO_Pin_All);
-
- USART1->DR = (uint16_t) c;
-// USART1->DR = 0x55;
-
- if (c == 'Z') {
- c = 'a';
- } else if (c == 'z') {
- c = '0';
- } else if (c == '9') {
- c = '\n';
- } else if (c == '\n') {
- c = 'A';
- } else {
- c++;
- }
- }
- }
-
- return 0;
-}
-