From a4c08dc741dd5a7bd9af04bdc74572503a53fdb3 Mon Sep 17 00:00:00 2001 From: eddyem Date: Wed, 5 Jun 2019 17:04:50 +0300 Subject: [PATCH] add TM1637 writing commands --- F0-nolib/TM1637/Makefile | 134 +++++++++++++++ F0-nolib/TM1637/Readme.md | 26 +++ F0-nolib/TM1637/hardware.c | 68 ++++++++ F0-nolib/TM1637/hardware.h | 26 +++ F0-nolib/TM1637/i2c.c | 105 ++++++++++++ F0-nolib/TM1637/i2c.h | 30 ++++ F0-nolib/TM1637/main.c | 54 ++++++ F0-nolib/TM1637/protocol.c | 189 +++++++++++++++++++++ F0-nolib/TM1637/protocol.h | 24 +++ F0-nolib/TM1637/tm1637.bin | Bin 0 -> 4424 bytes F0-nolib/TM1637/usart.c | 298 +++++++++++++++++++++++++++++++++ F0-nolib/TM1637/usart.h | 56 +++++++ F0-nolib/USBHID/usbhid.bin | Bin 5224 -> 5236 bytes F0-nolib/inc/F0/stm32f0.h | 2 +- F0-nolib/inc/ld/stm32f051x8.ld | 12 ++ 15 files changed, 1023 insertions(+), 1 deletion(-) create mode 100644 F0-nolib/TM1637/Makefile create mode 100644 F0-nolib/TM1637/Readme.md create mode 100644 F0-nolib/TM1637/hardware.c create mode 100644 F0-nolib/TM1637/hardware.h create mode 100644 F0-nolib/TM1637/i2c.c create mode 100644 F0-nolib/TM1637/i2c.h create mode 100644 F0-nolib/TM1637/main.c create mode 100644 F0-nolib/TM1637/protocol.c create mode 100644 F0-nolib/TM1637/protocol.h create mode 100755 F0-nolib/TM1637/tm1637.bin create mode 100644 F0-nolib/TM1637/usart.c create mode 100644 F0-nolib/TM1637/usart.h create mode 100644 F0-nolib/inc/ld/stm32f051x8.ld diff --git a/F0-nolib/TM1637/Makefile b/F0-nolib/TM1637/Makefile new file mode 100644 index 0000000..9cdacee --- /dev/null +++ b/F0-nolib/TM1637/Makefile @@ -0,0 +1,134 @@ +BINARY = tm1637 +BOOTPORT ?= /dev/ttyUSB0 +BOOTSPEED ?= 115200 +# MCU FAMILY +FAMILY = F0 +# MCU code +MCU = F051x8 +DEFS = -DEBUG +# change this linking script depending on particular MCU model, +# for example, if you have STM32F103VBT6, you should write: +LDSCRIPT = stm32f030f.ld + +INDEPENDENT_HEADERS= + +FP_FLAGS ?= -msoft-float +ASM_FLAGS = -mthumb -mcpu=cortex-m0 -march=armv6-m -mtune=cortex-m0 +ARCH_FLAGS = $(ASM_FLAGS) $(FP_FLAGS) + +############################################################################### +# Executables +PREFIX ?= /opt/bin/arm-none-eabi + +RM := rm -f +RMDIR := rmdir +CC := $(PREFIX)-gcc +LD := $(PREFIX)-gcc +AR := $(PREFIX)-ar +AS := $(PREFIX)-as +OBJCOPY := $(PREFIX)-objcopy +OBJDUMP := $(PREFIX)-objdump +GDB := $(PREFIX)-gdb +STFLASH := $(shell which st-flash) +STBOOT := $(shell which stm32flash) + +############################################################################### +# Source files +OBJDIR = mk +LDSCRIPT ?= $(BINARY).ld +SRC := $(wildcard *.c) +OBJS := $(addprefix $(OBJDIR)/, $(SRC:%.c=%.o)) +STARTUP = $(OBJDIR)/startup.o +OBJS += $(STARTUP) +DEPS := $(OBJS:.o=.d) + +INC_DIR ?= ../inc + +INCLUDE := -I$(INC_DIR)/F0 -I$(INC_DIR)/cm +LIB_DIR := $(INC_DIR)/ld + +############################################################################### +# C flags +CFLAGS += -O2 -g -MD -D__thumb2__=1 +CFLAGS += -Wall -Werror -Wextra -Wshadow -Wimplicit-function-declaration +CFLAGS += -Wredundant-decls $(INCLUDE) +# -Wmissing-prototypes -Wstrict-prototypes +CFLAGS += -fno-common -ffunction-sections -fdata-sections + +############################################################################### +# Linker flags +LDFLAGS += --static -nostartfiles +#--specs=nano.specs +LDFLAGS += -L$(LIB_DIR) +LDFLAGS += -T$(LDSCRIPT) +LDFLAGS += -Wl,-Map=$(OBJDIR)/$(BINARY).map +LDFLAGS += -Wl,--gc-sections + +############################################################################### +# Used libraries +LDLIBS += -Wl,--start-group -lc -lgcc -Wl,--end-group +LDLIBS += $(shell $(CC) $(CFLAGS) -print-libgcc-file-name) + +DEFS += -DSTM32$(FAMILY) -DSTM32$(MCU) + +#.SUFFIXES: .elf .bin .hex .srec .list .map .images +#.SECONDEXPANSION: +#.SECONDARY: + +ELF := $(OBJDIR)/$(BINARY).elf +LIST := $(OBJDIR)/$(BINARY).list +BIN := $(BINARY).bin +HEX := $(BINARY).hex + +all: bin list + +elf: $(ELF) +bin: $(BIN) +hex: $(HEX) +list: $(LIST) + +ifneq ($(MAKECMDGOALS),clean) +-include $(DEPS) +endif + +$(OBJDIR): + mkdir $(OBJDIR) + +$(STARTUP): $(INC_DIR)/startup/vector.c + $(CC) $(CFLAGS) $(DEFS) $(INCLUDE) $(ARCH_FLAGS) -o $@ -c $< + +$(OBJDIR)/%.o: %.c + @echo " CC $<" + $(CC) $(CFLAGS) $(DEFS) $(INCLUDE) $(ARCH_FLAGS) -o $@ -c $< + +$(BIN): $(ELF) + @echo " OBJCOPY $(BIN)" + $(OBJCOPY) -Obinary $(ELF) $(BIN) + +$(HEX): $(ELF) + @echo " OBJCOPY $(HEX)" + $(OBJCOPY) -Oihex $(ELF) $(HEX) + +$(LIST): $(ELF) + @echo " OBJDUMP $(LIST)" + $(OBJDUMP) -S $(ELF) > $(LIST) + +$(ELF): $(OBJDIR) $(OBJS) + @echo " LD $(ELF)" + $(LD) $(LDFLAGS) $(ARCH_FLAGS) $(OBJS) $(LDLIBS) -o $(ELF) + +clean: + @echo " CLEAN" + $(RM) $(OBJS) $(DEPS) $(ELF) $(HEX) $(LIST) $(OBJDIR)/*.map + @rmdir $(OBJDIR) 2>/dev/null || true + + +flash: $(BIN) + @echo " FLASH $(BIN)" + $(STFLASH) write $(BIN) 0x8000000 + +boot: $(BIN) + @echo " LOAD $(BIN) through bootloader" + $(STBOOT) -b$(BOOTSPEED) $(BOOTPORT) -w $(BIN) + +.PHONY: clean flash boot diff --git a/F0-nolib/TM1637/Readme.md b/F0-nolib/TM1637/Readme.md new file mode 100644 index 0000000..4978436 --- /dev/null +++ b/F0-nolib/TM1637/Readme.md @@ -0,0 +1,26 @@ +4-digit "time" LED indicator based on TM1637 +============================= + +FOR STM32F051!!! +WARNING! Only writing data!!! Can't read keys state. + +## GPIO +- I2C: PB6 (SCL) & PB7 (SDA) +- USART1: PA9/PA10 + +## UART +115200N1, not more than 100ms between data bytes in command. +To turn ON human terminal (without timeout) send "####". + +## Protocol +All commands are in brackets: `[ command line ]`. + +'[' clears earlier input; '\n', '\r', ' ', '\t' are ignored. +All messages are asynchronous! + +## Commands +0..9 - send data +A - display 'ABCD' +G - get keyboard status (don't work) +Hhex - display 'hex' as hex number +Nnum - display 'num' as decimal number diff --git a/F0-nolib/TM1637/hardware.c b/F0-nolib/TM1637/hardware.c new file mode 100644 index 0000000..d54fa0d --- /dev/null +++ b/F0-nolib/TM1637/hardware.c @@ -0,0 +1,68 @@ +/* + * This file is part of the TM1637 project. + * Copyright 2019 Edward Emelianov . + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include "hardware.h" +#include "usart.h" + + +/** + * @brief gpio_setup - setup GPIOs for external IO + * GPIO pinout: + * PC13 - open drain - onboard LED (blinks when board works) + */ +static inline void gpio_setup(){ + // Enable clocks to the GPIO subsystems + RCC->AHBENR |= RCC_AHBENR_GPIOAEN | RCC_AHBENR_GPIOBEN | RCC_AHBENR_GPIOCEN; + GPIOC->MODER = GPIO_MODER_MODER13_O; + GPIOC->OTYPER = GPIO_OTYPER_OT_13; + /* + // PA6/7 - AF; PB1 - AF + GPIOA->MODER = GPIO_MODER_MODER4_O | GPIO_MODER_MODER6_AF | GPIO_MODER_MODER7_AF; + GPIOA->OTYPER = GPIO_OTYPER_OT_4; + // alternate functions: + // PA6 - TIM3_CH1, PA7 - TIM3_CH2 + GPIOA->AFR[0] = (GPIOA->AFR[0] &~ (GPIO_AFRL_AFRL6 | GPIO_AFRL_AFRL7)) \ + | (1 << (6 * 4)) | (1 << (7 * 4)); + */ +} + +static inline void i2c_setup(){ + I2C1->CR1 = 0; +/* + * GPIO Resources: I2C1_SCL - PB6 (AF1), I2C1_SDA - PB7 (AF1) + */ + GPIOB->MODER |= GPIO_MODER_MODER6_AF | GPIO_MODER_MODER7_AF; // alternate function + GPIOB->AFR[0] = (GPIOB->AFR[0] &~ (GPIO_AFRL_AFRL6 | GPIO_AFRL_AFRL7)) \ + | (1 << (6 * 4)) | (1 << (7 * 4)); + // GPIOB->OTYPER |= GPIO_OTYPER_OT_6 | GPIO_OTYPER_OT_7; // opendrain + // I2C + RCC->APB1ENR |= RCC_APB1ENR_I2C1EN; // timing + RCC->CFGR3 |= RCC_CFGR3_I2C1SW; // use sysclock for timing + // 100kHz + // Clock = 6MHz, 0.16(6)us, need 5us (*30) + // PRESC=4 (f/5), SCLDEL=0 (t_SU=5/6us), SDADEL=0 (t_HD=5/6us), SCLL,SCLH=14 (2.(3)us) + I2C1->TIMINGR = (0xB<<28) | (4<<20) | (2<<16) | (0x12<<8) | (0x11); + I2C1->CR1 = I2C_CR1_PE; // Enable I2C +} + +void hw_setup(){ + sysreset(); + gpio_setup(); + i2c_setup(); + USART1_config(); +} + diff --git a/F0-nolib/TM1637/hardware.h b/F0-nolib/TM1637/hardware.h new file mode 100644 index 0000000..e0a7a63 --- /dev/null +++ b/F0-nolib/TM1637/hardware.h @@ -0,0 +1,26 @@ +/* + * This file is part of the TM1637 project. + * Copyright 2019 Edward Emelianov . + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once +#ifndef HARDWARE_H__ +#define HARDWARE_H__ +#include "stm32f0.h" + +extern volatile uint32_t Tms; +void hw_setup(void); + +#endif // HARDWARE_H__ diff --git a/F0-nolib/TM1637/i2c.c b/F0-nolib/TM1637/i2c.c new file mode 100644 index 0000000..0ed33ae --- /dev/null +++ b/F0-nolib/TM1637/i2c.c @@ -0,0 +1,105 @@ +/* + * geany_encoding=koi8-r + * i2c.c + * + * Copyright 2017 Edward V. Emelianov + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + */ +#include "stm32f0.h" +#include "hardware.h" +#include "i2c.h" +#include "usart.h" + +static uint32_t cntr; + +static uint8_t wri2c(uint8_t byte){ + I2C1->CR2 = byte;// | I2C_CR2_AUTOEND; + if(byte & 1) I2C1->CR2 |= I2C_CR2_RD_WRN; + // now start transfer + I2C1->CR2 |= I2C_CR2_START; + if(I2C1->ISR & I2C_ISR_RXNE) (void) I2C1->RXDR; + cntr = Tms; + while((I2C1->ISR & I2C_ISR_TC) == 0) if(Tms - cntr > I2C_TIMEOUT) return 0; + if(I2C1->ISR & I2C_ISR_RXNE) (void) I2C1->RXDR; + I2C1->ICR = 0xff; // clear all error flags + return 1; +} + +/** + * write command byte to I2C + * @param addr - device address (TSYS01_ADDR0 or TSYS01_ADDR1) + * @param data - byte to write + * @return 0 if error + */ +uint8_t write_i2c(const uint8_t *commands, uint8_t nbytes){ + uint8_t r = 1; + cntr = Tms; + while(I2C1->ISR & I2C_ISR_BUSY) if(Tms - cntr > I2C_TIMEOUT) return 0; // check busy + cntr = Tms; + while(I2C1->CR2 & I2C_CR2_START) if(Tms - cntr > I2C_TIMEOUT) return 0; // check start + for(uint8_t i = 0; i < nbytes; ++i){ + if(!wri2c(commands[i])){ + r = 0; + break; + } + } + I2C1->CR2 |= I2C_CR2_STOP; + return r; +} + +/** + * read nbytes (0..4) of data from I2C line + * @return 1 if all OK, 0 if NACK or no device found + */ +uint8_t read_i2c(uint8_t command, uint8_t *data){ + cntr = Tms; + while(I2C1->ISR & I2C_ISR_BUSY) if(Tms - cntr > 5) return 0; // check busy + cntr = Tms; + while(I2C1->CR2 & I2C_CR2_START) if(Tms - cntr > 5) return 0; // check start + // read 1 byte + if(command & 1){ + I2C1->CR2 = (1<<16) | command | I2C_CR2_RD_WRN; + }else{ + wri2c(command); + /* + I2C1->CR2 = command; + I2C1->CR2 |= I2C_CR2_START; + cntr = Tms; + while((I2C1->ISR & I2C_ISR_TC) == 0) if(Tms - cntr > I2C_TIMEOUT) return 0; + */ + I2C1->CR2 = (1<<16) |0xff | I2C_CR2_RD_WRN; + } + I2C1->CR2 |= I2C_CR2_START; + I2C1->CR2 |= I2C_CR2_STOP; + cntr = Tms; + while(Tms == cntr); +/* + while(!(I2C1->ISR & I2C_ISR_RXNE)){ // wait for data + if(I2C1->ISR & I2C_ISR_NACKF){ + I2C1->ICR |= I2C_ICR_NACKCF; + return 0; + } + if(Tms - cntr > 5) return 0; + } +*/ + if(I2C1->ISR & I2C_ISR_RXNE){ + *data = I2C1->RXDR; + return 1; + } + return 0; + } diff --git a/F0-nolib/TM1637/i2c.h b/F0-nolib/TM1637/i2c.h new file mode 100644 index 0000000..50f2e00 --- /dev/null +++ b/F0-nolib/TM1637/i2c.h @@ -0,0 +1,30 @@ +/* + * This file is part of the TM1637 project. + * Copyright 2019 Edward Emelianov . + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef I2C_H__ +#define I2C_H__ + +#include "stm32f0.h" + +// timeout in ms +#define I2C_TIMEOUT (15) + +uint8_t read_i2c(uint8_t command, uint8_t *data); +uint8_t write_i2c(const uint8_t *commands, uint8_t nbytes); + +#endif // I2C_H__ diff --git a/F0-nolib/TM1637/main.c b/F0-nolib/TM1637/main.c new file mode 100644 index 0000000..8e4f1fb --- /dev/null +++ b/F0-nolib/TM1637/main.c @@ -0,0 +1,54 @@ +/* + * This file is part of the TM1637 project. + * Copyright 2019 Edward Emelianov . + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include "hardware.h" +#include "i2c.h" +#include "protocol.h" +#include "usart.h" +#include + + +volatile uint32_t Tms = 0; + +// Called when systick fires +void sys_tick_handler(void){ + ++Tms; +} + +int main(void){ + uint32_t T = 0, TLED = 0; + char *txt; + hw_setup(); + SysTick_Config(6000, 1); + SEND("LED display controller v0.1\n"); + while (1){ + if(Tms - TLED > 499){ + TLED = Tms; + pin_toggle(GPIOC, 1<<13); + } + if(usart1_getline(&txt)){ // usart1 received command, process it + txt = process_command(txt); + }else txt = NULL; + if(txt){ // text waits for sending + while(ALL_OK != usart1_send(txt, 0)); + } + if(Tms - T > 49){ + T = Tms; + } + usart1_sendbuf(); + } +} diff --git a/F0-nolib/TM1637/protocol.c b/F0-nolib/TM1637/protocol.c new file mode 100644 index 0000000..14502be --- /dev/null +++ b/F0-nolib/TM1637/protocol.c @@ -0,0 +1,189 @@ +/* + * This file is part of the TM1637 project. + * Copyright 2019 Edward Emelianov . + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include "hardware.h" +#include "i2c.h" +#include "protocol.h" +#include "usart.h" + +#define DOT 1 +#define MIN 0b00000010 +#define DIG0 0b11111100 +#define DIG1 0b01100000 +#define DIG2 0b11011010 +#define DIG3 0b11110010 +#define DIG4 0b01100110 +#define DIG5 0b10110110 +#define DIG6 0b10111110 +#define DIG7 0b11100000 +#define DIG8 0b11111110 +#define DIG9 0b11110110 +#define DIGA 0b11101110 +#define DIGB 0b00111110 +#define DIGC 0b10011100 +#define DIGD 0b01111010 +#define DIGE 0b10011110 +#define DIGF 0b10001110 +#define DIGN 0b00000000 + +static const uint8_t digits[] = {DIG0, DIG1, DIG2, DIG3, DIG4, DIG5, DIG6, DIG7, DIG8, DIG9, + DIGA, DIGB, DIGC, DIGD, DIGE, DIGF}; + +static void putdata(uint8_t var){ + put_string("Got: "); + put_char('0'+var); + put_char('\n'); + // 0x40, 0xC0, ff .. 8f ; (0x44, 0xc0, 0x55, 0x89) + const uint8_t commands[] = {2, 3, DIG0, DIG1, DIG2, DIG3, 0xf1, 0x22, 3, 0xaa, 0x91}; + //const uint8_t commands[] = {2, 3, 2, 4, 8, 0x10, 0xf1, 0x22, 3, 0xaa, 0x91}; + const uint8_t commands1[] = {2, 3, DIG4, DIG5|DOT, DIG6, DIG7, 0xf1, 0x22, 3, 0xee, 0x91}; + //const uint8_t commands1[] = {2, 3, 0x20, 0x40|DOT, 0x80, DIG5, 0xf1, 0x22, 3, 0xee, 0x91}; + switch(var){ + case 0: + write_i2c(commands, 1); + write_i2c(&commands[1], 5); + write_i2c(&commands[6], 1); + break; + case 1: + write_i2c(&commands[7], 1); + write_i2c(&commands[8], 2); + write_i2c(&commands[10], 1); + break; + case 2: + write_i2c(commands1, 1); + write_i2c(&commands1[1], 5); + write_i2c(&commands1[6], 1); + break; + case 3: + write_i2c(&commands1[7], 1); + write_i2c(&commands1[8], 2); + write_i2c(&commands1[10], 1); + break; + } +} + +static void getk(){ + //uint8_t k[] = {0x42, 0xff}; + uint8_t k; + if(read_i2c(0x42, &k)){ // 0x42 + //if(write_i2c(k,2)){ + put_string("Keys: "); + put_uint(k); + put_char('\n'); + }else SEND("ERR\n"); +} + +static uint8_t display_number(int32_t N){ + if(N < -999 || N > 9999) return 1; + uint8_t buf[] = {2, 3, DIGN, DIGN, DIGN, DIGN, 0xf1}; + if(N < 0){ + buf[2] = MIN; + N = -N; + } + if(N == 0){ + buf[5] = DIG0; + }else{ + for(uint8_t idx = 5; idx > 1 && N; --idx){ + buf[idx] = digits[N%10]; + N /= 10; + } + } + write_i2c(buf, 1); + write_i2c(&buf[1], 5); + write_i2c(&buf[6], 1); + return 0; +} + +static uint8_t display_hex(int32_t N){ + if(N < -0xfff || N > 0xffff) return 1; + uint8_t buf[] = {2, 3, DIGN, DIGN, DIGN, DIGN, 0xf1}; + if(N < 0){ + buf[2] = MIN; + N = -N; + } + if(N == 0){ + buf[5] = DIG0; + }else{ + for(uint8_t idx = 5; idx > 1 && N; --idx){ + buf[idx] = digits[N&0xf]; + N >>= 4; + } + } + write_i2c(buf, 1); + write_i2c(&buf[1], 5); + write_i2c(&buf[6], 1); + return 0; +} + +static void dispnum(const char *n, uint8_t hex){ + int32_t N = -1; + uint8_t er = 0; + if(!getnum(n, &N)) er = 1; + else{ + if(hex) er = display_hex(N); + else er = display_number(N); + } + if(er) put_string("Wrong number!\n"); +} + +static void dispabcd(){ + uint8_t buf[] = {2, 3, DIGA, DIGB, DIGC, DIGD, 0xf1}; + write_i2c(buf, 1); + write_i2c(&buf[1], 5); + write_i2c(&buf[6], 1); +} + +/** + * @brief process_command - command parser + * @param command - command text (all inside [] without spaces) + * @return text to send over terminal or NULL + */ +char *process_command(const char *command){ + char *ret = NULL; + usart1_sendbuf(); // send buffer (if it is already filled) + if(*command < '0' || *command > '9'){ + switch(*command){ + case '?': // help + SEND_BLK( + "0..9 - send data\n" + "A - display 'ABCD'\n" + "G - get keqboard status\n" + "Hhex - display 'hex'\n" + "Nnum - display 'num'\n" + "R - reset\n" + ); + break; + case 'A': + dispabcd(); + break; + case 'G': + getk(); + break; + case 'H': + dispnum(++command, 1); + break; + case 'N': + dispnum(++command, 0); + break; + case 'R': // reset MCU + NVIC_SystemReset(); + break; + } + }else putdata(*command - '0'); + usart1_sendbuf(); + return ret; +} diff --git a/F0-nolib/TM1637/protocol.h b/F0-nolib/TM1637/protocol.h new file mode 100644 index 0000000..16df922 --- /dev/null +++ b/F0-nolib/TM1637/protocol.h @@ -0,0 +1,24 @@ +/* + * This file is part of the Chiller project. + * Copyright 2018 Edward V. Emelianov . + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef PROTOCOL_H__ +#define PROTOCOL_H__ +#include + +char *process_command(const char *command); + +#endif // PROTOCOL_H__ diff --git a/F0-nolib/TM1637/tm1637.bin b/F0-nolib/TM1637/tm1637.bin new file mode 100755 index 0000000000000000000000000000000000000000..0f7c8f4c26ea11adb01d656913d4b69878cfe0cc GIT binary patch literal 4424 zcmd^CeQ+CBwLf=PiuGY**=k%#R@{}=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fE@NY91()?;rGkASXgNti1ZopF0*PzR-tZQ zEkjOe@Aw1(O9W-d^^xKm<#C*U|DSYkuP^{Jo z+2Yg9mpX=s&cF8$R5B_`YFVR303;(Hf^UwvK!6yXQtFPHSvk zs5vw^Jb2hfqZ0@3A70M^Z0YJU=Kpc%z`c7pG~7LS$cLKN1BdA{v~Ah^PACHh?mc|y T!2bP%hq#XfS2r4d1a1BfHO7MC literal 0 HcmV?d00001 diff --git a/F0-nolib/TM1637/usart.c b/F0-nolib/TM1637/usart.c new file mode 100644 index 0000000..07fcec2 --- /dev/null +++ b/F0-nolib/TM1637/usart.c @@ -0,0 +1,298 @@ +/* + * This file is part of the TM1637 project. + * Copyright 2019 Edward Emelianov . + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include "usart.h" +#include // memcpy + +extern volatile uint32_t Tms; + +static int datalen[2] = {0,0}; // received data line length (including '\n') + +uint8_t bufovr = 0; // input buffer overfull + +static uint8_t linerdy = 0 // received data ready + ,dlen = 0 // length of data in current buffer + ,txrdy = 1 // transmission done +; + +static int rbufno = 0; // current rbuf number +static char rbuf[2][UARTBUFSZ+1], tbuf[UARTBUFSZ]; // receive & transmit buffers +static char *recvdata = NULL; + +static char trbuf[UARTBUFSZ+1]; // auxiliary buffer for data transmission +static int trbufidx = 0; + +int put_char(char c){ + if(trbufidx >= UARTBUFSZ - 1){ + for(int i = 0; i < 72000000 && ALL_OK != usart1_sendbuf(); ++i) + if(i == 72000000) return 1; + } + trbuf[trbufidx++] = c; + return 0; +} +// write zero-terminated string +int put_string(const char *str){ + while(*str){ + if(put_char(*str++)) return 1; //error! shouldn't be!!! + } + return 0; // all OK +} +/** + * Fill trbuf with integer value + * @param N - integer value + * @return 1 if buffer overflow; oterwise return 0 + */ +int put_int(int32_t N){ + if(N < 0){ + if(put_char('-')) return 1; + N = -N; + } + return put_uint((uint32_t) N); +} +int put_uint(uint32_t N){ + char buf[10]; + int L = 0; + if(N){ + while(N){ + buf[L++] = N % 10 + '0'; + N /= 10; + } + while(L--) if(put_char(buf[L])) return 1; + }else if(put_char('0')) return 1; + return 0; +} +/** + * @brief usart1_sendbuf - send temporary transmission buffer (trbuf) over USART + * @return Tx status + */ +TXstatus usart1_sendbuf(){ + int len = trbufidx; + if(len == 0) return ALL_OK; + else if(len > UARTBUFSZ) len = UARTBUFSZ; + TXstatus s = usart1_send(trbuf, len); + if(s == ALL_OK) trbufidx = 0; + return s; +} + +void USART1_config(){ + /* Enable the peripheral clock of GPIOA */ + RCC->AHBENR |= RCC_AHBENR_GPIOAEN; + /* GPIO configuration for USART1 signals */ + /* (1) Select AF mode (10) on PA9 and PA10 */ + /* (2) AF1 for USART1 signals */ + GPIOA->MODER = (GPIOA->MODER & ~(GPIO_MODER_MODER9|GPIO_MODER_MODER10))\ + | (GPIO_MODER_MODER9_1 | GPIO_MODER_MODER10_1); /* (1) */ + GPIOA->AFR[1] = (GPIOA->AFR[1] &~ (GPIO_AFRH_AFRH1 | GPIO_AFRH_AFRH2))\ + | (1 << (1 * 4)) | (1 << (2 * 4)); /* (2) */ + /* Enable the peripheral clock USART1 */ + RCC->APB2ENR |= RCC_APB2ENR_USART1EN; + /* Configure USART1 */ + /* (1) oversampling by 16, 115200 baud */ + /* (2) 8 data bit, 1 start bit, 1 stop bit, no parity */ + USART1->BRR = 480000 / 1152; /* (1) */ + USART1->CR1 = USART_CR1_TE | USART_CR1_RE | USART_CR1_UE; /* (2) */ + /* polling idle frame Transmission */ + while(!(USART1->ISR & USART_ISR_TC)){} + USART1->ICR |= USART_ICR_TCCF; /* clear TC flag */ + USART1->CR1 |= USART_CR1_RXNEIE; /* enable TC, TXE & RXNE interrupt */ + RCC->AHBENR |= RCC_AHBENR_DMA1EN; + DMA1_Channel2->CPAR = (uint32_t) &(USART1->TDR); // periph + DMA1_Channel2->CMAR = (uint32_t) tbuf; // mem + DMA1_Channel2->CCR |= DMA_CCR_MINC | DMA_CCR_DIR | DMA_CCR_TCIE; // 8bit, mem++, mem->per, transcompl irq + USART1->CR3 = USART_CR3_DMAT; + NVIC_SetPriority(DMA1_Channel2_3_IRQn, 3); + NVIC_EnableIRQ(DMA1_Channel2_3_IRQn); + /* Configure IT */ + /* (3) Set priority for USART1_IRQn */ + /* (4) Enable USART1_IRQn */ + NVIC_SetPriority(USART1_IRQn, 0); /* (3) */ + NVIC_EnableIRQ(USART1_IRQn); /* (4) */ +} + +#ifdef EBUG +#define TMO 0 +#else +#define TMO 1 +#endif + +void usart1_isr(){ + static uint8_t timeout = TMO // == 0 for human interface without timeout + ,nctr = 0 // counter of '#' received + ,incmd = 0 // ==1 - inside command + ; + static uint32_t tmout = 0; + if(USART1->ISR & USART_ISR_RXNE){ // RX not emty - receive next char + // read RDR clears flag + uint8_t rb = USART1->RDR; + if(timeout && rb == '#'){ // chek '#' without timeout + if(++nctr == 4){ // "####" received - turn off timeout + timeout = 0; + nctr = 0; + datalen[rbufno] = 0; // reset all incoming data + incmd = 0; + return; + } + }else nctr = 0; + if(!incmd){ + if(rb == '['){ // open command or reset previoud input + datalen[rbufno] = 0; + incmd = 1; + } + return; + } + if(timeout){ // check timeout only inside commands + if(tmout && Tms >= tmout){ // set overflow flag + bufovr = 1; + datalen[rbufno] = 0; + }else{ + tmout = Tms + TIMEOUT_MS; + if(!tmout) tmout = 1; // prevent 0 + } + } + switch(rb){ + case '[': + datalen[rbufno] = 0; + tmout = 0; + break; + case ']': // close command - line ready! + dlen = datalen[rbufno]; + if(dlen){ + linerdy = 1; + incmd = 0; + recvdata = rbuf[rbufno]; + rbuf[rbufno][dlen] = 0; + rbufno = !rbufno; + datalen[rbufno] = 0; + } + tmout = 0; + break; + case '\r': + case '\n': + case ' ': + case '\t': + return; + break; + default: + break; + } + + if(datalen[rbufno] < UARTBUFSZ){ // put next char into buf + rbuf[rbufno][datalen[rbufno]++] = rb; + }else{ // buffer overrun + bufovr = 1; + datalen[rbufno] = 0; + incmd = 0; + tmout = 0; + } + } +} + +void dma1_channel2_3_isr(){ + if(DMA1->ISR & DMA_ISR_TCIF2){ // Tx + DMA1->IFCR |= DMA_IFCR_CTCIF2; // clear TC flag + txrdy = 1; + } +} + +/** + * return length of received data (without trailing zero) + */ +int usart1_getline(char **line){ + if(!linerdy) return 0; + linerdy = 0; + if(bufovr){ + bufovr = 0; + return 0; + } + *line = recvdata; + return dlen; +} + +/** + * @brief usart1_send send buffer `str` adding trailing '\n' + * @param str - string to send (without '\n' at end) + * @param len - its length or 0 to auto count + * @return + */ +TXstatus usart1_send(const char *str, int len){ + if(!txrdy) return LINE_BUSY; + if(len > UARTBUFSZ - 1) return STR_TOO_LONG; + txrdy = 0; + if(len == 0){ + const char *ptr = str; + while(*ptr++) ++len; + } + if(len == 0) return ALL_OK; + DMA1_Channel2->CCR &= ~DMA_CCR_EN; + memcpy(tbuf, str, len); +// tbuf[len++] = '\n'; + DMA1_Channel2->CNDTR = len; + DMA1_Channel2->CCR |= DMA_CCR_EN; // start transmission + return ALL_OK; +} + +TXstatus usart1_send_blocking(const char *str, int len){ + if(!txrdy) return LINE_BUSY; + if(len == 0){ + const char *ptr = str; + while(*ptr++) ++len; + } + if(len == 0) return ALL_OK; + for(int i = 0; i < len; ++i){ + USART1->TDR = *str++; + while(!(USART1->ISR & USART_ISR_TXE)); + } +// USART1->TDR = '\n'; + while(!(USART1->ISR & USART_ISR_TC)); + txrdy = 1; + return ALL_OK; +} + +// read `buf` and get first integer `N` in it +// @return pointer to first non-number if all OK or NULL if first symbol isn't a space or number +char *getnum(const char *buf, int32_t *N){ + char c; + int positive = -1; + int32_t val = 0; + //usart1_send_blocking(buf, 0); + while((c = *buf++)){ + if(c == '\t' || c == ' '){ + if(positive < 0) continue; // beginning spaces + else break; // spaces after number + } + if(c == '-'){ + if(positive < 0){ + positive = 0; + continue; + }else break; // there already was `-` or number + } + if(c < '0' || c > '9') break; + if(positive < 0) positive = 1; + val = val * 10 + (int32_t)(c - '0'); + } + if(positive != -1){ + if(positive == 0){ + if(val == 0) return NULL; // single '-' + val = -val; + } + *N = val; + }else return NULL; +/* usart1_sendbuf(); + put_uint(val); + put_char('\n');*/ + return (char*)buf-1; +} diff --git a/F0-nolib/TM1637/usart.h b/F0-nolib/TM1637/usart.h new file mode 100644 index 0000000..bba6026 --- /dev/null +++ b/F0-nolib/TM1637/usart.h @@ -0,0 +1,56 @@ +/* + * This file is part of the TM1637 project. + * Copyright 2019 Edward Emelianov . + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once +#ifndef __USART_H__ +#define __USART_H__ + +#include "stm32f0.h" + +// input and output buffers size +#define UARTBUFSZ (64) +// timeout between data bytes +#define TIMEOUT_MS (100) + +typedef enum{ + ALL_OK, + LINE_BUSY, + STR_TOO_LONG +} TXstatus; + +#define usart1ovr() (bufovr) + +// send constant string +#define SEND_BLK(x) do{while(LINE_BUSY == usart1_send_blocking(x, sizeof(x)-1)) IWDG->KR = IWDG_REFRESH;}while(0) +#define SEND(x) do{while(LINE_BUSY == usart1_send(x, sizeof(x)-1)) IWDG->KR = IWDG_REFRESH;}while(0) + +extern uint8_t bufovr; + +void USART1_config(); +int usart1_getline(char **line); +TXstatus usart1_send(const char *str, int len); +TXstatus usart1_send_blocking(const char *str, int len); +TXstatus usart1_sendbuf(); + +int put_char(char c); +int put_string(const char *str); +int put_int(int32_t N); +int put_uint(uint32_t N); + +char *getnum(const char *buf, int32_t *N); + +#endif // __USART_H__ diff --git a/F0-nolib/USBHID/usbhid.bin b/F0-nolib/USBHID/usbhid.bin index bdb7faa48699cab8dd4b893cf04b39fb96fcb382..00cde93fab6ab914c13b757c302205b6667ef757 100755 GIT binary patch delta 2897 zcma)83ve6N6}_vEy_RKLj+~%hY_HZIB}zcClM)hIFIxLq);ck?$8#p#z0d0a%geOlT~Jh zr#nw=!f+u ziVn@}vJIJNBV%$pBt30(TO?z?{!+v~>KSeMeP4u&E@#Hv8i}_X*_VR^T^R1x5SJd~ zYz#xwZbBYsXKx2?Zv zKZ>`t19kE&vRY%}O7jQ;r%isU$sz^Ouko4*CrA;+6NOZ9=A@G6Y?nyq5AfYSC*R(( zFG@IfPOE5L2&hut>-F(Rm2PAalQd7o2qQB{a7drb5(?TDw`!A5U^%E+iA z0hUwE5$nOJlH7ed_kzUs`4AgahhpM5da8+(SiF>@au7YFc%wJs-PxgZpmyZvKUP+G zh3Mw;eYeeuN3c`!q|(rGudmaul$ zyAnU}b`abVkUYvFs>+j{|80gEuy!)DM)BjVJ0Kra43rgT zp2@6GG?WFiqnTR8PMI(p&DfP1>ITdn%Phs}V$2R^ObT=YQ-+P2eF?zj0>~NHbltcS zCi|ysHs|8~r9d_`05rHufKUTeEdo-F<60a&7>yW!aTf-UkxDFUeFN1*pF)qDFPoat zlc=VZPsEX`YOYE1P9^BSv}$UyXtjoEQBmvw#8G)`u#pN-p(tubww8w(DzH^uHJ$(A zr8G4N``mw-YH(6ho#YK|=iv-m(so&Mq%xiNqTE?fv3gpdwAP3#p@BUUno42?F|D3(P4d<1 zwI9K8?70)}e@*3$z;GpG=l5q*N)n|KP3ZcIJePoKwsr4Bb+EgyL)&|a@vwbX&4xEi zs@XoWb}4fbXp=dl7WRoTR49%i13ij-=;n=G=Gl^2I1HjmBV62dmgOV04MYi}70#ib zmLI#VfjEP-G0m}py!C7wI?Fbr^{l4$m6EgUAedSCAxF#KA&S_>*=S5VTI3s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^J{Nv zc~yN=_VU8PkLz&)sJzmA7rp3@lOZ+~U4m)!=6uxbZDX_sV0&%Jv~~Az=>al4Sh> zd+0E(D|T#ub=~4PwxuqA;8Nc~{?cB1|G|8`7d+zufBz8g?~MrNTgq_%U&w`~%7{H6 zc}DcMP#Jek)w%tl{x;kOXNk=wY>Pd;Aqz_}S5ry%fUsZO-_jY-^%)Bsq{CFi>-GXI z2XyN#f!w0^Dx^;?-HT79f2p@G2JrrK3%kVbzIn_}EJ*ZSLbrZLA5`HlS&R zlj{+CB5g6$Bktawugv6&W2h4e$R40WFK~v7S3GnmSKsZBx#Bs=b70?yp-7KQsb_>3 z!n!=Srz!+#-BNDxscbiLgn(I4iIb3C$ViCvT2e&JKWM65u0s0n8KAczV!ZQCVieNO zrElkWcRDhyLHd&nkA?eXDycaJ`Nnyrf?;PHgcw}h^$gmK-$=KVME}+{VV2Fj@{jf> z)`+(XmjZc~)i#KmfRuqYxJOarf!yMQS%N0@jqf2?`2b1{=!l(XQqsMXke2d73eKi5`a{s!hFnFllv=E=-X&5i9;W|!u| z_N9y_e_r&XJHEuajANM(V?Z6S_I3BhD6~xfPR|W!trd^nOFhidG)&t^D58D@#;xS*GIuRyYqN_JI7c+DaGartjb~u3je2La`84iV(YE}5 z=5mYgT`OrT&F35btMl`?bG{^*F?Lk|bxr@Z&GYZz+-`F-xg%Z#)XP7BksG<-_q5sm NJu%<8f0jpx{{TMj(V_qV diff --git a/F0-nolib/inc/F0/stm32f0.h b/F0-nolib/inc/F0/stm32f0.h index 3b99a87..4970cc7 100644 --- a/F0-nolib/inc/F0/stm32f0.h +++ b/F0-nolib/inc/F0/stm32f0.h @@ -119,7 +119,7 @@ TRUE_INLINE void StartHSE(){ while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)RCC_CFGR_SWS_PLL){} } */ -#if !defined (STM32F030x4) && !defined (STM32F030x6) && !defined (STM32F030x8) && !defined (STM32F031x6) && !defined (STM32F038xx) && !defined (STM32F030xC) +#if defined (STM32F042x6) || defined (STM32F072xb) TRUE_INLINE void StartHSI48(){ RCC->APB1ENR |= RCC_APB1ENR_CRSEN | RCC_APB1ENR_USBEN; // enable CRS (hsi48 sync) & USB RCC->CFGR3 &= ~RCC_CFGR3_USBSW; // reset USB diff --git a/F0-nolib/inc/ld/stm32f051x8.ld b/F0-nolib/inc/ld/stm32f051x8.ld new file mode 100644 index 0000000..3dc0803 --- /dev/null +++ b/F0-nolib/inc/ld/stm32f051x8.ld @@ -0,0 +1,12 @@ +/* Linker script for STM32F051x8, 64K flash, 8K RAM. */ + +/* Define memory regions. */ +MEMORY +{ + rom (rx) : ORIGIN = 0x08000000, LENGTH = 64K + ram (rwx) : ORIGIN = 0x20000000, LENGTH = 8K +} + +/* Include the common ld script. */ +INCLUDE stm32f01234.ld +