diff options
Diffstat (limited to 'src/stm32f')
25 files changed, 0 insertions, 1341 deletions
diff --git a/src/stm32f/.gitignore b/src/stm32f/.gitignore deleted file mode 100644 index 6533942..0000000 --- a/src/stm32f/.gitignore +++ /dev/null @@ -1 +0,0 @@ -vc.h diff --git a/src/stm32f/FreeRTOS b/src/stm32f/FreeRTOS deleted file mode 120000 index 51f4e96..0000000 --- a/src/stm32f/FreeRTOS +++ /dev/null @@ -1 +0,0 @@ -../FreeRTOS
\ No newline at end of file diff --git a/src/stm32f/Makefile b/src/stm32f/Makefile deleted file mode 100644 index 29bf265..0000000 --- a/src/stm32f/Makefile +++ /dev/null @@ -1,131 +0,0 @@ -### -# GNU ARM Embedded Toolchain -CC=arm-none-eabi-gcc -LD=arm-none-eabi-ld -AR=arm-none-eabi-ar -AS=arm-none-eabi-as -CP=arm-none-eabi-objcopy -OD=arm-none-eabi-objdump -SIZE=arm-none-eabi-size - -### -# Directory Structure -BINDIR=bin -SRCDIR=. -ODIR=obj - -### -# Find source files -ASOURCES=$(shell find -L $(SRCDIR) -name '*.s') -CSOURCES+=$(shell find -L $(SRCDIR) -name '*.c') -# Find header directories -INC=$(shell find -L . -name '*.h' -exec dirname {} \; | uniq) -INCLUDES=$(INC:%=-I%) -I ../common/includes/ -I ./includes/ -# Create object list -OBJECTS=$(ASOURCES:%.s=%.o) -OBJECTS+=$(CSOURCES:%.c=obj/%.o) -# Define output files ELF & IHEX -BINELF=outp.elf -BINHEX=outp.hex - -### -# MCU FLAGS -MCFLAGS=-mcpu=cortex-m4 -mthumb -mlittle-endian \ --mfpu=fpv4-sp-d16 -mfloat-abi=softfp -mthumb-interwork -# COMPILE FLAGS -DEFS=-DUSE_STDPERIPH_DRIVER -DSTM32F4XX -DARM_MATH_CM4 -D__FPU_PRESENT=1 -CFLAGS =-Wall -ggdb -std=c99 -c $(MCFLAGS) $(DEFS) $(INCLUDES) -# LINKER FLAGS -LDSCRIPT= bsp/stm32_flash.ld -LDFLAGS =-T $(LDSCRIPT) --specs=nosys.specs $(MCFLAGS) -Wl,-Map=$(BINDIR)/outp.map - -### -# Optimizations -OPT?='O2 O3 O6' -# O1 and O4 are irrelevant -# O5 breaks FreeRTOS somehow -# I'm not trusting O7 - -ifneq ($(filter O1,$(OPT)),) -CXXFLAGS+=-fno-exceptions # Uncomment to disable exception handling -DEFS+=-DNO_EXCEPTIONS # The source code has to comply with this rule -endif - -ifneq ($(filter O2,$(OPT)),) -CFLAGS+=-Os # Optimize for size https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html -CXXFLAGS+=-Os -LDFLAGS+=-Os # Optimize for size https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html -endif - -ifneq ($(filter O3,$(OPT)),) -CFLAGS+=-ffunction-sections -fdata-sections # Place each function or data item into its own section in the output file -CXXFLAGS+=-ffunction-sections -fdata-sections # -||- -LDFLAGS+=-Wl,-gc-sections # Remove isolated unused sections -endif - -ifneq ($(filter O4,$(OPT)),) -CFLAGS+=-fno-builtin # Disable C++ exception handling -CXXFLAGS+=-fno-builtin # Disable C++ exception handling -endif - -ifneq ($(filter O5,$(OPT)),) -CFLAGS+=-flto # Enable link time optimization -CXXFLAGS+=-flto # Enable link time optimization -LDFLAGS+=-flto # Enable link time optimization -endif - -ifneq ($(filter O6,$(OPT)),) -CXXFLAGS+=-fno-rtti # Disable type introspection -endif - -ifneq ($(findstring O7,$(OPT)),) -LDFLAGS+=--specs=nano.specs # Use size optimized newlib -endif - -### -# Build Rules -.PHONY: all release debug clean - -all: release - -release: $(BINDIR)/$(BINHEX) - -debug: CFLAGS+=-g -debug: LDFLAGS+=-g -debug: release - -$(BINDIR)/$(BINHEX): $(BINDIR)/$(BINELF) - $(CP) -O ihex $< $@ - -$(BINDIR)/$(BINELF): $(OBJECTS) vc.h - $(CC) $(LDFLAGS) $(OBJECTS) -o $@ - $(SIZE) $(BINDIR)/$(BINELF) - -dir_guard=@mkdir -p $(@D) - -obj/%.o: %.c $(INC) - $(dir_guard) - $(CC) $(CFLAGS) $< -o $@ - -obj/%.o: %.s - $(dir_guard) - $(CC) $(CFLAGS) $< -o $@ - -vc.h: ../../.git/logs/HEAD - echo "// This file is generated by Makefile." > vc.h - echo "// Do not edit this file!" >> vc.h - git log -1 --format="format:#define GIT_VERSION \"%h\"" >> vc.h - echo >> vc.h - echo >> vc.h - -clean: - rm -f $(OBJECTS) $(BINDIR)/$(BINELF) $(BINDIR)/$(BINHEX) - -# Connect to openocd's gdb server on port 3333 -deploy: $(BINDIR)/$(BINELF) -ifeq ($(wildcard /opt/openocd/bin/openocd),) - /usr/bin/openocd -f /usr/share/openocd/scripts/board/stm32f4discovery.cfg -c "program bin/"$(BINELF)" verify reset" -c "init" -c "reset" -c "exit" -else - /opt/openocd/bin/openocd -f /opt/openocd/share/openocd/scripts/board/stm32f4discovery.cfg -c "program bin/"$(BINELF)" verify reset" -c "init" -c "reset" -c "exit" -endif - diff --git a/src/stm32f/bin/.gitignore b/src/stm32f/bin/.gitignore deleted file mode 100644 index d6b7ef3..0000000 --- a/src/stm32f/bin/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore diff --git a/src/stm32f/bsp b/src/stm32f/bsp deleted file mode 120000 index 5d9120a..0000000 --- a/src/stm32f/bsp +++ /dev/null @@ -1 +0,0 @@ -../bsp
\ No newline at end of file diff --git a/src/stm32f/includes/GPIO/leds.h b/src/stm32f/includes/GPIO/leds.h deleted file mode 100644 index 869a032..0000000 --- a/src/stm32f/includes/GPIO/leds.h +++ /dev/null @@ -1,4 +0,0 @@ -#define GPIOD_BOARD_LED_GREEN GPIO_Pin_12 -#define GPIOD_BOARD_LED_ORANGE GPIO_Pin_13 -#define GPIOD_BOARD_LED_RED GPIO_Pin_14 -#define GPIOD_BOARD_LED_BLUE GPIO_Pin_15 diff --git a/src/stm32f/obj/.gitignore b/src/stm32f/obj/.gitignore deleted file mode 100644 index d6b7ef3..0000000 --- a/src/stm32f/obj/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore diff --git a/src/stm32f/src/Audio/audio.c b/src/stm32f/src/Audio/audio.c deleted file mode 100644 index bdb2961..0000000 --- a/src/stm32f/src/Audio/audio.c +++ /dev/null @@ -1,220 +0,0 @@ -#include "GPIO/i2c.h" -#include "stm32f4xx_conf.h" -#include "stm32f4xx.h" - -#include "../../../common/src/Audio/audio.c" - -void audio_initialize_platform(int plln, int pllr, int i2sdiv, int i2sodd, int rate) { - - GPIO_InitTypeDef GPIO_InitStructure; - - // Turn on peripherals. - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE); - RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3, ENABLE); - - // Assume I2C is set up - - // Configure reset pin. - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_Init(GPIOD, &GPIO_InitStructure); - - // Configure I2S MCK, SCK, SD pins. - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_10 | GPIO_Pin_12; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_Init(GPIOC, &GPIO_InitStructure); - - GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_SPI3); - GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_SPI3); - GPIO_PinAFConfig(GPIOC, GPIO_PinSource12, GPIO_AF_SPI3); - - // Configure I2S WS pin. - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_Init(GPIOA, &GPIO_InitStructure); - - GPIO_PinAFConfig(GPIOA, GPIO_PinSource4, GPIO_AF_SPI3); - - // Reset the codec. - GPIO_ResetBits(GPIOD, GPIO_Pin_4); - for (volatile int i = 0; i < 0x4fff; i++) { - __asm__ volatile("nop"); - } - GPIO_SetBits(GPIOD, GPIO_Pin_4); - - // Configure codec. - audio_write_register(0x02, 0x01); // Keep codec powered off. - audio_write_register(0x04, 0xaf); // SPK always off and HP always on. - - audio_write_register(0x05, 0x81); // Clock configuration: Auto detection. - audio_write_register(0x06, 0x04); // Set slave mode and Philips audio standard. - - // Power on the codec. - audio_write_register(0x02, 0x9e); - - // Configure codec for fast shutdown. - audio_write_register(0x0a, 0x00); // Disable the analog soft ramp. - audio_write_register(0x0e, 0x04); // Disable the digital soft ramp. - - audio_write_register(0x27, 0x00); // Disable the limiter attack level. - audio_write_register(0x1f, 0x0f); // Adjust bass and treble levels. - - audio_write_register(0x1a, 0x0a); // Adjust PCM volume level. - audio_write_register(0x1b, 0x0a); - - // Disable I2S. - SPI3 ->I2SCFGR = 0; - - // I2S clock configuration - RCC ->CFGR &= ~RCC_CFGR_I2SSRC; // PLLI2S clock used as I2S clock source. - RCC ->PLLI2SCFGR = (pllr << 28) | (plln << 6); - - // Enable PLLI2S and wait until it is ready. - RCC ->CR |= RCC_CR_PLLI2SON; - while (!(RCC ->CR & RCC_CR_PLLI2SRDY )) - ; - - // Configure I2S. - SPI3 ->I2SPR = i2sdiv | (i2sodd << 8) | SPI_I2SPR_MCKOE; - SPI3 ->I2SCFGR = SPI_I2SCFGR_I2SMOD | SPI_I2SCFGR_I2SCFG_1 - | SPI_I2SCFGR_I2SE; // Master transmitter, Phillips mode, 16 bit values, clock polarity low, enable. - -} - -void audio_on() { - audio_write_register(0x02, 0x9e); - SPI3 ->I2SCFGR = SPI_I2SCFGR_I2SMOD | SPI_I2SCFGR_I2SCFG_1 - | SPI_I2SCFGR_I2SE; // Master transmitter, Phillips mode, 16 bit values, clock polarity low, enable. -} - -void audio_off() { - audio_write_register(0x02, 0x9f); - SPI3 ->I2SCFGR = 0; -} - -void audio_set_volume(int volume) { - audio_write_register(0x20, (volume + 0x19) & 0xff); - audio_write_register(0x21, (volume + 0x19) & 0xff); -} - -void audio_output_sample(int16_t sample) { - while (!(SPI3 ->SR & SPI_SR_TXE )) - ; - SPI3 ->DR = sample; -} - - -void audio_output_sample_without_blocking(int16_t sample) { - SPI3 ->DR = sample; -} - -void audio_play_with_callback(AudioCallbackFunction *callback, void *context) { - audio_stop_dma(); - - NVIC_EnableIRQ(DMA1_Stream7_IRQn); - NVIC_SetPriority(DMA1_Stream7_IRQn, 5); - - SPI3 ->CR2 |= SPI_CR2_TXDMAEN; // Enable I2S TX DMA request. - - callback_function = callback; - callback_context = context; - buffer_number = 0; - - if (callback_function) - callback_function(callback_context, buffer_number); -} - -void audio_stop() { - audio_stop_dma(); - SPI3 ->CR2 &= ~SPI_CR2_TXDMAEN; // Disable I2S TX DMA request. - NVIC_DisableIRQ(DMA1_Stream7_IRQn); - callback_function = NULL; -} - -void audio_provide_buffer(void *samples, int numsamples) { - while (!audio_provide_buffer_without_blocking(samples, numsamples)) - __asm__ volatile ("wfi"); -} - -bool audio_provide_buffer_without_blocking(void *samples, int numsamples) { - if (next_buffer_samples) - return false; - - NVIC_DisableIRQ(DMA1_Stream7_IRQn); - - next_buffer_samples = samples; - next_buffer_length = numsamples; - - if (!dma_running) - audio_start_dma_and_request_buffers(); - - NVIC_EnableIRQ(DMA1_Stream7_IRQn); - - return true; -} - -static void audio_start_dma_and_request_buffers() { - // Configure DMA stream. - DMA1_Stream7 ->CR = (0 * DMA_SxCR_CHSEL_0 ) | // Channel 0 - (1 * DMA_SxCR_PL_0 ) | // Priority 1 - (1 * DMA_SxCR_PSIZE_0 ) | // PSIZE = 16 bit - (1 * DMA_SxCR_MSIZE_0 ) | // MSIZE = 16 bit - DMA_SxCR_MINC | // Increase memory address - (1 * DMA_SxCR_DIR_0 ) | // Memory to peripheral - DMA_SxCR_TCIE; // Transfer complete interrupt - DMA1_Stream7 ->NDTR = next_buffer_length; - DMA1_Stream7 ->PAR = (uint32_t) &SPI3 ->DR; - DMA1_Stream7 ->M0AR = (uint32_t) next_buffer_samples; - DMA1_Stream7 ->FCR = DMA_SxFCR_DMDIS; - DMA1_Stream7 ->CR |= DMA_SxCR_EN; - - // Update state. - next_buffer_samples = NULL; - buffer_number ^= 1; - dma_running = true; - - // Invoke callback if it exists to queue up another buffer. - if (callback_function) - callback_function(callback_context, buffer_number); -} - -static void audio_stop_dma() { - DMA1_Stream7 ->CR &= ~DMA_SxCR_EN; // Disable DMA stream. - while (DMA1_Stream7 ->CR & DMA_SxCR_EN ) - ; // Wait for DMA stream to stop. - - dma_running = false; -} - -void DMA1_Stream7_IRQHandler() { - DMA1 ->HIFCR |= DMA_HIFCR_CTCIF7; // Clear interrupt flag. - - if (next_buffer_samples) { - audio_start_dma_and_request_buffers(); - } else { - dma_running = false; - } -} - -// Warning: don't i2c_write call from IRQ handler ! -static void audio_write_register(uint8_t address, uint8_t value) -{ - const uint8_t device = 0x4a; - const uint8_t data[2] = {address, value}; - i2c_transaction_start(); - i2c_write(device, data, 2); - i2c_transaction_end(); -} - diff --git a/src/stm32f/src/Audio/cw.c b/src/stm32f/src/Audio/cw.c deleted file mode 100644 index 028ae82..0000000 --- a/src/stm32f/src/Audio/cw.c +++ /dev/null @@ -1,4 +0,0 @@ -#include "../../../common/src/Audio/cw.c" - -void cw_message_sent(const char* str) { -} diff --git a/src/stm32f/src/Core/FreeRTOSConfig.h b/src/stm32f/src/Core/FreeRTOSConfig.h deleted file mode 100644 index 8d6f128..0000000 --- a/src/stm32f/src/Core/FreeRTOSConfig.h +++ /dev/null @@ -1,3 +0,0 @@ -#include "../../../common/src/Core/FreeRTOSConfig.h" - -#define configCHECK_FOR_STACK_OVERFLOW 2 // Default: 2 diff --git a/src/stm32f/src/Core/common.c b/src/stm32f/src/Core/common.c deleted file mode 100644 index a647d26..0000000 --- a/src/stm32f/src/Core/common.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <stm32f4xx.h> - -#include "../../../common/src/Core/common.c" - -void hard_fault_handler_extra() { - usart_debug("SCB_SHCSR = %x\n", SCB->SHCSR); -} diff --git a/src/stm32f/src/Core/delay.c b/src/stm32f/src/Core/delay.c deleted file mode 100644 index 59030c4..0000000 --- a/src/stm32f/src/Core/delay.c +++ /dev/null @@ -1,51 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2016 Matthias P. Braendli, Maximilien Cuony - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. -*/ - -#include "delay.h" -#include "stm32f4xx_conf.h" -#include "stm32f4xx.h" - -uint32_t delay_multiplier = 1; - -void delay_us(uint32_t micros) -{ - micros = micros * delay_multiplier - 10; - while (micros--); -} - -void delay_ms(uint32_t millis) -{ - for (int i = 0; i < 1000; i++) { - delay_us(millis); - } -} - -void delay_init() -{ - RCC_ClocksTypeDef RCC_Clocks; - RCC_GetClocksFreq(&RCC_Clocks); - - delay_multiplier = RCC_Clocks.HCLK_Frequency / 4000000; -} - diff --git a/src/stm32f/src/Core/fsm.c b/src/stm32f/src/Core/fsm.c deleted file mode 100644 index 99413ba..0000000 --- a/src/stm32f/src/Core/fsm.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "../../../common/src/Core/fsm.c" - - -void fsm_state_switched(char * new_state) { - usart_debug_puts("FSM: "); - usart_debug_puts(new_state); - usart_debug_puts("\r\n"); -} diff --git a/src/stm32f/src/Core/main.c b/src/stm32f/src/Core/main.c deleted file mode 100644 index d63f540..0000000 --- a/src/stm32f/src/Core/main.c +++ /dev/null @@ -1,69 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2016 Matthias P. Braendli, Maximilien Cuony - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. -*/ - -#include "stm32f4xx_conf.h" - -#include "../../../stm32f/includes/GPIO/leds.h" -#include "../../../common/src/Core/main.c" - - -void init() { - /* Initialise the onboard peripherals - * Four LEDs and one push-button - */ - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); - - // Configure PD12, PD13, PD14 and PD15 in output pushpull mode - GPIO_InitTypeDef GPIO_InitStructure; - GPIO_InitStructure.GPIO_Pin = - GPIOD_BOARD_LED_GREEN | - GPIOD_BOARD_LED_ORANGE | - GPIOD_BOARD_LED_RED | - GPIOD_BOARD_LED_BLUE; - - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_Init(GPIOD, &GPIO_InitStructure); - - // Init PushButton - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; // TODO is there an external pullup ? - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_Init(GPIOA, &GPIO_InitStructure); - - - /* Setup Watchdog - * The IWDG runs at 32kHz. With a prescaler of 32 -> 1kHz. - * Counting to 2000 / 1000 = 2 seconds - */ - IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable); - IWDG_SetPrescaler(IWDG_Prescaler_32); - IWDG_SetReload(2000); - IWDG_Enable(); -} diff --git a/src/stm32f/src/GPIO/i2c.c b/src/stm32f/src/GPIO/i2c.c deleted file mode 100644 index 750f5de..0000000 --- a/src/stm32f/src/GPIO/i2c.c +++ /dev/null @@ -1,350 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2015 Matthias P. Braendli - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. -*/ - -#include "GPIO/i2c.h" -#include "Core/common.h" - -#include "stm32f4xx_conf.h" -#include "stm32f4xx_i2c.h" -#include "stm32f4xx.h" -#include "FreeRTOS.h" -#include "FreeRTOSConfig.h" -#include "task.h" -#include "semphr.h" -#include "GPIO/usart.h" - -/* I2C 1 on PB9 and PB6 - * See pio.txt for PIO allocation details */ -const uint16_t GPIOB_PIN_SDA = GPIO_Pin_9; -const uint16_t GPIOB_PIN_SCL = GPIO_Pin_6; - - -static int i2c_init_done = 0; -static int i2c_error = 0; - -static I2C_TypeDef* const I2Cx = I2C1; - -static SemaphoreHandle_t i2c_semaphore; - -static void i2c_device_init(void); - -/* According to I2C spec UM10204: - * 3.1.16 Bus clear - * In the unlikely event where the clock (SCL) is stuck LOW, the preferential - * procedure is to reset the bus using the HW reset signal if your I2C devices - * have HW reset inputs. If the I2C devices do not have HW reset inputs, cycle - * power to the devices to activate the mandatory internal Power-On Reset (POR) - * circuit. - * - * If the data line (SDA) is stuck LOW, the master should send nine clock - * pulses. The device that held the bus LOW should release it sometime within - * those nine clocks. If not, then use the HW reset or cycle power to clear the - * bus. - */ -static void i2c_recover_from_lockup(void) -{ - usart_debug_puts("ERROR: I2C lockup\r\n"); - - I2C_SoftwareResetCmd(I2Cx, ENABLE); - - // Configure I2C SCL and SDA pins. - GPIO_InitTypeDef GPIO_InitStructure; - GPIO_InitStructure.GPIO_Pin = GPIOB_PIN_SCL | GPIOB_PIN_SDA; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; - GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; - GPIO_Init(GPIOB, &GPIO_InitStructure); - - const TickType_t delay = 5 / portTICK_PERIOD_MS; - - GPIO_SetBits(GPIOB, GPIOB_PIN_SDA | GPIOB_PIN_SCL); - vTaskDelay(delay); - - for (int i = 0; i < 10; i++) { - GPIO_ResetBits(GPIOB, GPIOB_PIN_SCL); - vTaskDelay(delay); - GPIO_SetBits(GPIOB, GPIOB_PIN_SCL); - vTaskDelay(delay); - } - - I2C_SoftwareResetCmd(I2Cx, DISABLE); - - i2c_device_init(); -} - -static void i2c_device_init(void) -{ - // Configure I2C SCL and SDA pins. - GPIO_InitTypeDef GPIO_InitStructure; - GPIO_InitStructure.GPIO_Pin = GPIOB_PIN_SCL | GPIOB_PIN_SDA; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; - GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; - GPIO_Init(GPIOB, &GPIO_InitStructure); - - GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_I2C1); - GPIO_PinAFConfig(GPIOB, GPIO_PinSource9, GPIO_AF_I2C1); - - // Reset I2C. - RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, ENABLE); - RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, DISABLE); - - // configure I2C1 - I2C_InitTypeDef I2C_InitStruct; - I2C_InitStruct.I2C_ClockSpeed = 100000; //Hz - I2C_InitStruct.I2C_Mode = I2C_Mode_I2C; - I2C_InitStruct.I2C_DutyCycle = I2C_DutyCycle_2; // 50% duty cycle - I2C_InitStruct.I2C_OwnAddress1 = 0x00; // not relevant in master mode - - // disable acknowledge when reading (can be changed later on) - I2C_InitStruct.I2C_Ack = I2C_Ack_Disable; - - I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; - I2C_Init(I2C1, &I2C_InitStruct); - - // enable I2C1 - I2C_Cmd(I2C1, ENABLE); -} - -void i2c_init() -{ - if (i2c_init_done == 1) { - return; - } - - i2c_semaphore = xSemaphoreCreateBinary(); - - if ( i2c_semaphore == NULL ) { - trigger_fault(FAULT_SOURCE_I2C); - } - else { - xSemaphoreGive(i2c_semaphore); - } - - RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE); - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); - - i2c_device_init(); - i2c_init_done = 1; -} - -static int i2c_check_busy_flag(void) -{ - const TickType_t i2c_timeout = 1000ul / portTICK_PERIOD_MS; - const TickType_t time_start = xTaskGetTickCount(); - - while (I2C_GetFlagStatus(I2Cx, I2C_FLAG_BUSY)) { - const TickType_t time_now = xTaskGetTickCount(); - - if (time_now - time_start > i2c_timeout) { - i2c_error = 1; - return 0; - } - } - - return 1; -} - -static int i2c_check_event(uint32_t event) -{ - const TickType_t i2c_timeout = 1000ul / portTICK_PERIOD_MS; - const TickType_t time_start = xTaskGetTickCount(); - - while (!I2C_CheckEvent(I2Cx, event)) { - const TickType_t time_now = xTaskGetTickCount(); - - if (time_now - time_start > i2c_timeout) { - i2c_error = 1; - return 0; - } - } - - return 1; -} - -static int i2c_start(uint8_t device, uint8_t direction) -{ - I2C_GenerateSTART(I2Cx, ENABLE); - - // wait for bus free - if (!i2c_check_event(I2C_EVENT_MASTER_MODE_SELECT)) { - I2C_GenerateSTART(I2Cx, DISABLE); - return 0; - } - - I2C_Send7bitAddress(I2Cx, device << 1, direction); - - /* wait for I2C1 EV6, check if - * either Slave has acknowledged Master transmitter or - * Master receiver mode, depending on the transmission - * direction - */ - uint32_t event = 0; - if (direction == I2C_Direction_Transmitter) { - event = I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED; - } - else if (direction == I2C_Direction_Receiver) { - event = I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED; - } - else { - trigger_fault(FAULT_SOURCE_I2C); - } - - if (!i2c_check_event(event)) { - return 0; - } - - return 1; -} - -static int i2c_send(uint8_t data) -{ - I2C_SendData(I2Cx, data); - - // wait for I2C1 EV8_2 --> byte has been transmitted - return i2c_check_event(I2C_EVENT_MASTER_BYTE_TRANSMITTED); -} - -int i2c_write(uint8_t device, const uint8_t *txbuf, int len) -{ - if (i2c_init_done == 0) { - trigger_fault(FAULT_SOURCE_I2C); - } - - int success = i2c_check_busy_flag(); - - if (success) { - success = i2c_start(device, I2C_Direction_Transmitter); - } - - if (success) { - for (int i = 0; i < len; i++) { - success = i2c_send(txbuf[i]); - if (!success) { - break; - } - } - - I2C_GenerateSTOP(I2Cx, ENABLE); - success = i2c_check_event(I2C_EVENT_MASTER_BYTE_TRANSMITTED); - } - - return success; -} - -static int i2c_read_nobuscheck(uint8_t device, uint8_t *rxbuf, int len) -{ - if (i2c_init_done == 0) { - trigger_fault(FAULT_SOURCE_I2C); - } - - if (i2c_start(device, I2C_Direction_Receiver)) { - for (int i = 0; i < len; i++) { - if (i == len-1) { - I2C_AcknowledgeConfig(I2Cx, DISABLE); - } - else { - I2C_AcknowledgeConfig(I2Cx, ENABLE); - } - - // wait until one byte has been received, possibly timout - if (!i2c_check_event(I2C_EVENT_MASTER_BYTE_RECEIVED)) { - I2C_GenerateSTOP(I2Cx, ENABLE); - return 0; - } - - if (i == len-1) { - I2C_GenerateSTOP(I2Cx, ENABLE); - } - - rxbuf[i] = I2C_ReceiveData(I2Cx); - } - return len; - } - - return 0; -} - -int i2c_read(uint8_t device, uint8_t *rxbuf, int len) -{ - int success = i2c_check_busy_flag(); - - if (success) { - success = i2c_read_nobuscheck(device, rxbuf, len); - } - - return success; -} - -int i2c_read_from(uint8_t device, uint8_t address, uint8_t *rxbuf, int len) -{ - if (i2c_init_done == 0) { - trigger_fault(FAULT_SOURCE_I2C); - } - - int success = i2c_check_busy_flag(); - - if (success) { - success = i2c_start(device, I2C_Direction_Transmitter); - } - - if (success) { - success = i2c_send(address); - } - // Don't do a STOP - - if (success) { - success = i2c_read_nobuscheck(device, rxbuf, len); - } - - return success; -} - - - -void i2c_transaction_start() -{ - if (i2c_init_done == 0) { - trigger_fault(FAULT_SOURCE_I2C); - } - xSemaphoreTake(i2c_semaphore, portMAX_DELAY); -} - -void i2c_transaction_end() -{ - if (i2c_init_done == 0) { - trigger_fault(FAULT_SOURCE_I2C); - } - - if ( i2c_error ) { - i2c_recover_from_lockup(); - - i2c_error = 0; - } - - xSemaphoreGive(i2c_semaphore); -} - diff --git a/src/stm32f/src/GPIO/leds.c b/src/stm32f/src/GPIO/leds.c deleted file mode 100644 index 291b650..0000000 --- a/src/stm32f/src/GPIO/leds.c +++ /dev/null @@ -1,42 +0,0 @@ -#include "../../../common/src/GPIO/leds.c" - -#include "stm32f4xx_conf.h" - -#include "../../../stm32f/includes/GPIO/leds.h" - -void leds_turn_on(int l) { - - switch (l) { - case LED_GREEN: - GPIO_SetBits(GPIOD, GPIOD_BOARD_LED_GREEN); - break; - case LED_ORANGE: - GPIO_SetBits(GPIOD, GPIOD_BOARD_LED_ORANGE); - break; - case LED_RED: - GPIO_SetBits(GPIOD, GPIOD_BOARD_LED_RED); - break; - case LED_BLUE: - GPIO_SetBits(GPIOD, GPIOD_BOARD_LED_BLUE); - break; - - } -} - -void leds_turn_off(int l) { - - switch (l) { - case LED_GREEN: - GPIO_ResetBits(GPIOD, GPIOD_BOARD_LED_GREEN); - break; - case LED_ORANGE: - GPIO_ResetBits(GPIOD, GPIOD_BOARD_LED_ORANGE); - break; - case LED_RED: - GPIO_ResetBits(GPIOD, GPIOD_BOARD_LED_RED); - break; - case LED_BLUE: - GPIO_ResetBits(GPIOD, GPIOD_BOARD_LED_BLUE); - break; - } -} diff --git a/src/stm32f/src/GPIO/pio.c b/src/stm32f/src/GPIO/pio.c deleted file mode 100644 index d8780fe..0000000 --- a/src/stm32f/src/GPIO/pio.c +++ /dev/null @@ -1,187 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2015 Matthias P. Braendli - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. -*/ - -#include "stm32f4xx_rcc.h" -#include "stm32f4xx_gpio.h" - -/* See pio.txt for PIO allocation details */ - -/* On GPIO C */ -#define GPIO_PIN_QRP_n GPIO_Pin_1 -#define GPIO_PIN_TX GPIO_Pin_2 -#define GPIO_PIN_1750_n GPIO_Pin_4 -#define GPIO_PIN_MOD_OFF GPIO_Pin_5 -#define GPIO_PIN_SQ_n GPIO_Pin_6 -#define GPIO_PIN_U GPIO_Pin_8 -#define GPIO_PIN_QRP_out GPIO_Pin_9 -#define GPIO_PIN_D GPIO_Pin_11 -#define GPIO_PIN_REPLIE_n GPIO_Pin_13 -#define GPIO_PIN_FAX_n GPIO_Pin_14 - - -#define GPIOC_OUTPUT_PINS ( \ - GPIO_PIN_TX | \ - GPIO_PIN_MOD_OFF | \ - GPIO_PIN_QRP_out | \ - 0) - -#undef GPIOC_OPENDRAIN_PINS -#undef GPIOC_INPUT_PU_PINS - -#define GPIOC_INPUT_PINS ( \ - GPIO_PIN_QRP_n | \ - GPIO_PIN_1750_n | \ - GPIO_PIN_SQ_n | \ - GPIO_PIN_U | \ - GPIO_PIN_D | \ - GPIO_PIN_REPLIE_n | \ - 0 ) - -#include "GPIO/pio.h" -#include "Core/common.h" -#include "FreeRTOS.h" -#include "task.h" -#include "queue.h" -#include "semphr.h" - -void read_fsm_input_task(void *pvParameters); - -struct fsm_input_signals_t pio_signals; - -void pio_init() -{ - GPIO_InitTypeDef GPIO_InitStructure; - - // Init pio - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); - - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; - GPIO_InitStructure.GPIO_Pin = GPIOC_OUTPUT_PINS; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_Init(GPIOC, &GPIO_InitStructure); - -#if defined(GPIOC_OPENDRAIN_PINS) - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; - GPIO_InitStructure.GPIO_Pin = GPIOC_OPENDRAIN_PINS; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; - GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; - GPIO_Init(GPIOC, &GPIO_InitStructure); -#endif - -#if defined(GPIOC_INPUT_PU_PINS) - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; - GPIO_InitStructure.GPIO_Pin = GPIOC_INPUT_PU_PINS; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_Init(GPIOC, &GPIO_InitStructure); -#endif - -#if defined(GPIOC_INPUT_PINS) - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; - GPIO_InitStructure.GPIO_Pin = GPIOC_INPUT_PINS; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_Init(GPIOC, &GPIO_InitStructure); -#endif - - xTaskCreate( - read_fsm_input_task, - "TaskPIO", - configMINIMAL_STACK_SIZE, - (void*) NULL, - tskIDLE_PRIORITY + 2UL, - NULL); -} - -void pio_set_fsm_signals(struct fsm_input_signals_t* sig) -{ - *sig = pio_signals; -} - -void read_fsm_input_task(void *pvParameters) -{ - while (1) { - pio_signals.qrp = - GPIO_ReadInputDataBit(GPIOC, GPIO_PIN_QRP_n) ? 0 : 1; - - pio_signals.tone_1750 = - GPIO_ReadInputDataBit(GPIOC, GPIO_PIN_1750_n) ? 0 : 1; - - pio_signals.sq = - GPIO_ReadInputDataBit(GPIOC, GPIO_PIN_SQ_n) ? 0 : 1; - - pio_signals.discrim_u = - GPIO_ReadInputDataBit(GPIOC, GPIO_PIN_U) ? 1 : 0; - - pio_signals.discrim_d = - GPIO_ReadInputDataBit(GPIOC, GPIO_PIN_D) ? 1 : 0; - - pio_signals.wind_generator_ok = - GPIO_ReadInputDataBit(GPIOC, GPIO_PIN_REPLIE_n) ? 1 : 0; - - pio_signals.sstv_mode = - GPIO_ReadInputDataBit(GPIOC, GPIO_PIN_FAX_n) ? 0 : 1; - - vTaskDelay(100 / portTICK_RATE_MS); - } -} - -void pio_set_tx(int on) -{ - if (on) { - GPIO_SetBits(GPIOC, GPIO_PIN_TX); - } - else { - GPIO_ResetBits(GPIOC, GPIO_PIN_TX); - } -} - -void pio_set_qrp(int on) -{ - if (on) { - GPIO_SetBits(GPIOC, GPIO_PIN_QRP_out); - } - else { - GPIO_ResetBits(GPIOC, GPIO_PIN_QRP_out); - } -} - -void pio_set_mod_off(int mod_off) -{ - if (mod_off) { - GPIO_SetBits(GPIOC, GPIO_PIN_MOD_OFF); - } - else { - GPIO_ResetBits(GPIOC, GPIO_PIN_MOD_OFF); - } -} - -int pio_read_button() { - return GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0) == Bit_SET; -} diff --git a/src/stm32f/src/GPIO/temperature.c b/src/stm32f/src/GPIO/temperature.c deleted file mode 100644 index 780a019..0000000 --- a/src/stm32f/src/GPIO/temperature.c +++ /dev/null @@ -1,93 +0,0 @@ -/* On wire connection: PA1 - */ - -#define TEMPERATURE_ONEWIRE_PIN GPIO_Pin_1 - -#include "stm32f4xx_conf.h" -#include "stm32f4xx.h" - -#include "tm_stm32f4_ds18b20.h" -#include "tm_stm32f4_onewire.h" -#include "Core/delay.h" - - -#include "../../../common/src/GPIO/temperature.c" - -const TickType_t _temperature_delay = 60000 / portTICK_PERIOD_MS; // 60s - -static TM_OneWire_t tm_onewire; - - - -void ds18b20_init() { - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); - - GPIO_InitTypeDef GPIO_InitStructure; - GPIO_InitStructure.GPIO_Pin = TEMPERATURE_ONEWIRE_PIN; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; - GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; - GPIO_Init(GPIOA, &GPIO_InitStructure); - - vTaskSuspendAll(); - TM_OneWire_Init(&tm_onewire, GPIOA, TEMPERATURE_ONEWIRE_PIN); - xTaskResumeAll(); -} - -int ds18b20_gettemp_one(float *temperature) { - - vTaskSuspendAll(); - - uint8_t rom_addr[8]; - - TM_DS18B20_StartAll(&tm_onewire); - int status = TM_OneWire_First(&tm_onewire); - if (status) { - //Save ROM number from device - TM_OneWire_GetFullROM(&tm_onewire, rom_addr); - TM_DS18B20_Start(&tm_onewire, rom_addr); - - // The sensor needs time to do the conversion - xTaskResumeAll(); - delay_ms(100); - vTaskSuspendAll(); - status = TM_DS18B20_Read(&tm_onewire, rom_addr, temperature); - } - - xTaskResumeAll(); - - return status; -} - -int ds18b20_gettemp(float *temperature) { - int status; - for (int i = 0; i < 10; i++) { - status = ds18b20_gettemp_one(temperature); - - if (status) { - break; - } - delay_ms(5); - } - return status; -} - -static void temperature_task(void *pvParameters) { - - while (1) { - - if (!_temperature_valid) { - ds18b20_init(); - } - - if (ds18b20_gettemp(&_temperature_last_value)) { - _temperature_valid = 1; - } else { - _temperature_valid = 0; - } - - vTaskDelay(_temperature_delay); - - } -} diff --git a/src/stm32f/src/GPIO/tm_stm32f4_ds18b20.c b/src/stm32f/src/GPIO/tm_stm32f4_ds18b20.c deleted file mode 120000 index ffa5c2a..0000000 --- a/src/stm32f/src/GPIO/tm_stm32f4_ds18b20.c +++ /dev/null @@ -1 +0,0 @@ -../../../ds18b20/tm_stm32f4_ds18b20.c
\ No newline at end of file diff --git a/src/stm32f/src/GPIO/tm_stm32f4_ds18b20.h b/src/stm32f/src/GPIO/tm_stm32f4_ds18b20.h deleted file mode 120000 index 51c9ece..0000000 --- a/src/stm32f/src/GPIO/tm_stm32f4_ds18b20.h +++ /dev/null @@ -1 +0,0 @@ -../../../ds18b20/tm_stm32f4_ds18b20.h
\ No newline at end of file diff --git a/src/stm32f/src/GPIO/tm_stm32f4_onewire.c b/src/stm32f/src/GPIO/tm_stm32f4_onewire.c deleted file mode 120000 index 241eefa..0000000 --- a/src/stm32f/src/GPIO/tm_stm32f4_onewire.c +++ /dev/null @@ -1 +0,0 @@ -../../../ds18b20/tm_stm32f4_onewire.c
\ No newline at end of file diff --git a/src/stm32f/src/GPIO/tm_stm32f4_onewire.h b/src/stm32f/src/GPIO/tm_stm32f4_onewire.h deleted file mode 120000 index 81ebf8e..0000000 --- a/src/stm32f/src/GPIO/tm_stm32f4_onewire.h +++ /dev/null @@ -1 +0,0 @@ -../../../ds18b20/tm_stm32f4_onewire.h
\ No newline at end of file diff --git a/src/stm32f/src/GPIO/usart.c b/src/stm32f/src/GPIO/usart.c deleted file mode 100644 index d174719..0000000 --- a/src/stm32f/src/GPIO/usart.c +++ /dev/null @@ -1,156 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2016 Matthias P. Braendli - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. -*/ - - -#include <stm32f4xx.h> -#include <stm32f4xx_usart.h> -#include <stm32f4xx_conf.h> - -/* USART 3 on PD8 and PD9 - * See pio.txt for PIO allocation details */ -const uint16_t GPIOD_PIN_USART3_TX = GPIO_Pin_8; -const uint16_t GPIOD_PIN_USART3_RX = GPIO_Pin_9; - -/* USART 2 on PA2 and PA3 */ -const uint16_t GPIOA_PIN_USART2_RX = GPIO_Pin_3; -const uint16_t GPIOA_PIN_USART2_TX = GPIO_Pin_2; - -static void usart_puts(USART_TypeDef*, const char*); - -#include "../../../common/includes/GPIO/usart.h" -#include "../../../common/src/GPIO/usart.c" - - -void usart_init() { - // ============== PC DEBUG USART =========== - RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); - - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.GPIO_Pin = GPIOA_PIN_USART2_RX | GPIOA_PIN_USART2_TX; - GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF; - GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; - GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP; - GPIO_Init(GPIOA, &GPIO_InitStruct); - - GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_USART2); - GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_USART2); - - // Setup USART2 for 9600,8,N,1 - USART_InitTypeDef USART_InitStruct; - USART_InitStruct.USART_BaudRate = 9600; - USART_InitStruct.USART_WordLength = USART_WordLength_8b; - USART_InitStruct.USART_StopBits = USART_StopBits_1; - USART_InitStruct.USART_Parity = USART_Parity_No; - USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None; - USART_InitStruct.USART_Mode = USART_Mode_Tx | USART_Mode_Rx; - USART_Init(USART2, &USART_InitStruct); - -#if USART2_RECEIVE_ENABLE - // enable the USART2 receive interrupt - USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); - - NVIC_InitTypeDef NVIC_InitStructure; - NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; - NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 6; - NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; - NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; - NVIC_Init(&NVIC_InitStructure); - - NVIC_SetPriority(USART2_IRQn, 6); -#endif - - // finally this enables the complete USART2 peripheral - USART_Cmd(USART2, ENABLE); -} - -void usart_gps_specific_init() { - - // ============== GPS USART =========== - // Setup GPIO D and connect to USART 3 - RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); - - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.GPIO_Pin = GPIOD_PIN_USART3_RX | GPIOD_PIN_USART3_TX; - GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF; - GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; - GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP; - GPIO_Init(GPIOD, &GPIO_InitStruct); - - GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_USART3); - GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_USART3); - - // Setup USART3 for 9600,8,N,1 - USART_InitTypeDef USART_InitStruct; - USART_InitStruct.USART_BaudRate = 9600; - USART_InitStruct.USART_WordLength = USART_WordLength_8b; - USART_InitStruct.USART_StopBits = USART_StopBits_1; - USART_InitStruct.USART_Parity = USART_Parity_No; - USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None; - USART_InitStruct.USART_Mode = USART_Mode_Tx | USART_Mode_Rx; - USART_Init(USART3, &USART_InitStruct); - - - // enable the USART3 receive interrupt - USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); - - NVIC_InitTypeDef NVIC_InitStructure; - NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn; - NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 6; - NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; - NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; - NVIC_Init(&NVIC_InitStructure); - - NVIC_SetPriority(USART3_IRQn, 6); - - // finally this enables the complete USART3 peripheral - USART_Cmd(USART3, ENABLE); -} - -// Make sure Tasks are suspended when this is called! -static void usart_puts(USART_TypeDef* USART, const char* str) { - while(*str) { - // wait until data register is empty - USART_SendData(USART, *str); - while(USART_GetFlagStatus(USART, USART_FLAG_TXE) == RESET) ; - str++; - } -} - -void USART3_IRQHandler(void) { - if (USART_GetITStatus(USART3, USART_IT_RXNE)) { - char t = USART3->DR; - usart_gps_process_char(t); - } -} - -void USART2_IRQHandler(void) { - if (USART_GetITStatus(USART2, USART_IT_RXNE)) { - char t = USART2->DR; - usart_process_char(t); - } -} diff --git a/src/stm32f/src/GPS/gps.c b/src/stm32f/src/GPS/gps.c deleted file mode 100644 index 10afe88..0000000 --- a/src/stm32f/src/GPS/gps.c +++ /dev/null @@ -1,4 +0,0 @@ -#include "stm32f4xx_conf.h" -#include "stm32f4xx.h" - -#include "../../../common/src/GPS/gps.c" diff --git a/src/stm32f/src/GPS/minema.c b/src/stm32f/src/GPS/minema.c deleted file mode 100644 index 10df198..0000000 --- a/src/stm32f/src/GPS/minema.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../../common/src/GPS/minmea.c" |