Skip to content

Commit

Permalink
v1.2.05
Browse files Browse the repository at this point in the history
Use custom hardware library:
- GPT
- PAL (GPIO)
- DMA
- EXT
Move all hardware depend functions in board dir
  • Loading branch information
DiSlord committed Jun 26, 2022
1 parent 38e31fb commit e3d95b5
Show file tree
Hide file tree
Showing 7 changed files with 517 additions and 343 deletions.
8 changes: 4 additions & 4 deletions halconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* @brief Enables the PAL subsystem.
*/
#if !defined(HAL_USE_PAL) || defined(__DOXYGEN__)
#define HAL_USE_PAL TRUE
#define HAL_USE_PAL FALSE
#endif

/**
Expand Down Expand Up @@ -62,14 +62,14 @@
* @brief Enables the EXT subsystem.
*/
#if !defined(HAL_USE_EXT) || defined(__DOXYGEN__)
#define HAL_USE_EXT TRUE
#define HAL_USE_EXT FALSE
#endif

/**
* @brief Enables the GPT subsystem.
*/
#if !defined(HAL_USE_GPT) || defined(__DOXYGEN__)
#define HAL_USE_GPT TRUE
#define HAL_USE_GPT FALSE
#endif

/**
Expand Down Expand Up @@ -170,7 +170,7 @@
#define HAL_USE_WDG FALSE
#endif

#define STM32_DMA_REQUIRED
//#define STM32_DMA_REQUIRED
/*===========================================================================*/
/* ADC driver related settings. */
/*===========================================================================*/
Expand Down
87 changes: 63 additions & 24 deletions hardware.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,69 +22,108 @@
#include "hal.h"
#include "nanovna.h"

#ifndef VNA_ADC_H
#define VNA_ADC_H
// Compact STM32 ADC library
#if HAL_USE_ADC == TRUE
#error "Error VNA use self ADC lib, define HAL_USE_ADC = FALSE in halconf.h"
#endif
// Measure vbat every 5 second
#define VBAT_MEASURE_INTERVAL S2ST(5)
#ifdef NANOVNA_F303
#include "NANOVNA_STM32_F303/adc.c"
#include "NANOVNA_STM32_F303/adc_v3.c"
#else
#include "NANOVNA_STM32_F072/adc.c"
#endif
#include "NANOVNA_STM32_F072/adc_v1.c"
#endif

#ifndef VNA_I2C_H
#define VNA_I2C_H
// Compact STM32 I2C library
#if HAL_USE_I2C == TRUE
#error "Error VNA use self I2C lib, define HAL_USE_I2C = FALSE in halconf.h"
#endif
#ifdef NANOVNA_F303
#include "NANOVNA_STM32_F303/i2c.c"
#include "NANOVNA_STM32_F303/i2c_v2.c"
#else
#include "NANOVNA_STM32_F072/i2c.c"
#endif
#include "NANOVNA_STM32_F072/i2c_v2.c"
#endif

#ifndef VNA_RTC_H
#define VNA_RTC_H
#ifdef __USE_RTC__
// Compact STM32 RTC time library
#if HAL_USE_RTC == TRUE
#error "Error VNA use self RTC lib, define HAL_USE_RTC = FALSE in halconf.h"
#endif
#ifdef NANOVNA_F303
#include "NANOVNA_STM32_F303/rtc.c"
#include "NANOVNA_STM32_F303/rtc_v2.c"
#else
#include "NANOVNA_STM32_F072/rtc.c"
#endif
#include "NANOVNA_STM32_F072/rtc_v2.c"
#endif
#endif

#ifndef VNA_DAC_H
#define VNA_DAC_H
// Compact STM32 DAC library
#if HAL_USE_DAC == TRUE
#error "Need disable HAL_USE_DAC in halconf.h for use VNA_DAC"
#endif

#ifdef NANOVNA_F303
#include "NANOVNA_STM32_F303/dac.c"
#include "NANOVNA_STM32_F303/dac_v1.c"
#else
#include "NANOVNA_STM32_F072/dac.c"
#include "NANOVNA_STM32_F072/dac_v1.c"
#endif

// Compact STM32 I2S library
#if HAL_USE_I2S == TRUE
#error "Need disable HAL_USE_DAC in halconf.h for use VNA_DAC"
#endif
#ifdef NANOVNA_F303
#include "NANOVNA_STM32_F303/i2s.c"
#else
#include "NANOVNA_STM32_F072/i2s.c"
#endif

#ifndef VNA_FLASH_H
#define VNA_FLASH_H
// Compact STM32 flash library
#ifdef NANOVNA_F303
#include "NANOVNA_STM32_F303/flash.c"
#else
#include "NANOVNA_STM32_F072/flash.c"
#endif

// Compact STM32 GPIO library
#if HAL_USE_PAL == FALSE
#ifdef NANOVNA_F303
#include "NANOVNA_STM32_F303/gpio_v2.c"
#else
#include "NANOVNA_STM32_F072/gpio_v2.c"
#endif
#endif

// Compact STM32 DMA library
#ifdef NANOVNA_F303
#include "NANOVNA_STM32_F303/dma_v1.c"
#else
#include "NANOVNA_STM32_F072/dma_v1.c"
#endif

// Compact STM32 EXT library
#if HAL_USE_EXT == FALSE
#ifdef NANOVNA_F303
#include "NANOVNA_STM32_F303/exti_v1.c"
#else
#include "NANOVNA_STM32_F072/exti_v1.c"
#endif
#endif

#if HAL_USE_GPT == FALSE
// Run TIM2 as us timer counter (used as STM32_ST_TIM timer in ChibiOS)
// Run TIM3 as ms timer counter
void initTimers(void) {
// rccEnableTIM2(FALSE);
rccEnableTIM3(FALSE);
// TIM2 use AHB1 bus clock (32 bit timer), use STM32_TIMCLK1 clock source
// TIM2->PSC = STM32_TIMCLK1 / (1000000U) - 1; // 1MHz tick
// TIM3 use AHB1 bus clock (16 bit timer), used in touch period handler
TIM3->PSC = STM32_TIMCLK1 / (1000U) - 1; // 1kHz tick
TIM3->CR2 = 0x20; // Generate TRIGO event for ADC watchdog
}

//
void startTimer(TIM_TypeDef *timer, uint32_t period) {
timer->ARR = period - 1;
timer->EGR = STM32_TIM_EGR_UG;
timer->CNT = 0;
timer->CR1 = STM32_TIM_CR1_URS | STM32_TIM_CR1_CEN;
}
#endif
Loading

0 comments on commit e3d95b5

Please sign in to comment.