move files to stm32/ folder
This commit is contained in:
Родитель
0470ecfeba
Коммит
487ca96aad
|
@ -0,0 +1,18 @@
|
|||
file(GLOB DS_FILES
|
||||
stm32/*.c
|
||||
)
|
||||
|
||||
add_library(jacdac-stm32 STATIC
|
||||
${DS_FILES}
|
||||
)
|
||||
|
||||
target_include_directories(jacdac-stm32 PUBLIC
|
||||
stm32
|
||||
${STM32_CUBE_${FAMILY}_PATH}/Drivers/STM32${FAMILY}xx_HAL_Driver/Inc
|
||||
${STM32_CUBE_${FAMILY}_PATH}/Drivers/CMSIS/Device/ST/STM32L4xx/Include
|
||||
${STM32_CUBE_${FAMILY}_PATH}/Drivers/CMSIS/Core/Include
|
||||
)
|
||||
|
||||
target_link_libraries(jacdac-stm32 PUBLIC
|
||||
jacdac
|
||||
)
|
48
stm32/adc.c
48
stm32/adc.c
|
@ -1,9 +1,10 @@
|
|||
#include "jdstm.h"
|
||||
#include "dmesg.h"
|
||||
|
||||
#ifndef STM32L4
|
||||
|
||||
static bool adc_calibrated;
|
||||
|
||||
#ifdef STM32L
|
||||
#ifdef STM32WL
|
||||
#define ADC1 ADC
|
||||
#endif
|
||||
|
||||
|
@ -17,14 +18,6 @@ static bool adc_calibrated;
|
|||
static bool configured_fixed = false;
|
||||
#endif
|
||||
|
||||
static void set_sampling_time(uint32_t time) {
|
||||
#if NEW_ADC
|
||||
LL_ADC_SetSamplingTimeCommonChannels(ADC1, LL_ADC_SAMPLINGTIME_COMMON_1, time);
|
||||
#else
|
||||
LL_ADC_SetSamplingTimeCommonChannels(ADC1, time);
|
||||
#endif
|
||||
}
|
||||
|
||||
uint16_t adc_convert(void) {
|
||||
if ((LL_ADC_IsEnabled(ADC1) == 1) && (LL_ADC_IsDisableOngoing(ADC1) == 0) &&
|
||||
(LL_ADC_REG_IsConversionOngoing(ADC1) == 0)) {
|
||||
|
@ -99,6 +92,17 @@ static void set_channel(uint32_t chan) {
|
|||
;
|
||||
}
|
||||
|
||||
static void set_sampling_time(uint32_t time, uint32_t chan) {
|
||||
#ifdef STM32L4
|
||||
LL_ADC_SetChannelSamplingTime(ADC1, chan, time);
|
||||
#elif NEW_ADC
|
||||
LL_ADC_SetSamplingTimeCommonChannels(ADC1, LL_ADC_SAMPLINGTIME_COMMON_1, time);
|
||||
#else
|
||||
LL_ADC_SetSamplingTimeCommonChannels(ADC1, time);
|
||||
#endif
|
||||
set_channel(chan);
|
||||
}
|
||||
|
||||
static void set_temp_ref(int t) {
|
||||
while (LL_ADC_IsDisableOngoing(ADC1))
|
||||
;
|
||||
|
@ -125,8 +129,6 @@ uint32_t bl_adc_random_seed(void) {
|
|||
LL_ADC_REG_SetSequencerConfigurable(ADC1, LL_ADC_REG_SEQ_CONFIGURABLE);
|
||||
#endif
|
||||
|
||||
// set_sampling_time(LL_ADC_SAMPLINGTIME_1CYCLE_5); // get maximum noise
|
||||
|
||||
ADC1->CFGR2 = LL_ADC_CLOCK_SYNC_PCLK_DIV2;
|
||||
|
||||
#if NEW_ADC
|
||||
|
@ -176,11 +178,9 @@ void adc_init_random(void) {
|
|||
LL_ADC_REG_SetSequencerConfigurable(ADC1, LL_ADC_REG_SEQ_CONFIGURABLE);
|
||||
#endif
|
||||
|
||||
set_sampling_time(LL_ADC_SAMPLINGTIME_1CYCLE_5); // get maximum noise
|
||||
|
||||
ADC1->CFGR2 = LL_ADC_CLOCK_SYNC_PCLK_DIV2;
|
||||
|
||||
set_channel(LL_ADC_CHANNEL_TEMPSENSOR);
|
||||
set_sampling_time(LL_ADC_SAMPLINGTIME_1CYCLE_5, LL_ADC_CHANNEL_TEMPSENSOR); // get maximum noise
|
||||
|
||||
uint32_t h = 0x811c9dc5;
|
||||
for (int i = 0; i < 1000; ++i) {
|
||||
|
@ -227,12 +227,14 @@ static const uint32_t channels_PB[] = {
|
|||
#endif
|
||||
|
||||
uint16_t adc_read_temp(void) {
|
||||
#if NEW_ADC
|
||||
set_sampling_time(LL_ADC_SAMPLINGTIME_160CYCLES_5);
|
||||
#ifdef STM32L4
|
||||
set_sampling_time(LL_ADC_SAMPLINGTIME_247CYCLES_5, LL_ADC_CHANNEL_TEMPSENSOR);
|
||||
#elif NEW_ADC
|
||||
set_sampling_time(LL_ADC_SAMPLINGTIME_160CYCLES_5, LL_ADC_CHANNEL_TEMPSENSOR);
|
||||
#else
|
||||
set_sampling_time(LL_ADC_SAMPLINGTIME_71CYCLES_5); // min. sampling time for temp is 4us
|
||||
set_sampling_time(LL_ADC_SAMPLINGTIME_71CYCLES_5,
|
||||
LL_ADC_CHANNEL_TEMPSENSOR); // min. sampling time for temp is 4us
|
||||
#endif
|
||||
set_channel(LL_ADC_CHANNEL_TEMPSENSOR);
|
||||
set_temp_ref(1);
|
||||
|
||||
uint16_t r = adc_convert() >> 4;
|
||||
|
@ -285,12 +287,10 @@ void adc_prep_read_pin(uint8_t pin) {
|
|||
pin_setup_analog_input(pin);
|
||||
|
||||
#if NEW_ADC
|
||||
set_sampling_time(LL_ADC_SAMPLINGTIME_39CYCLES_5);
|
||||
set_sampling_time(LL_ADC_SAMPLINGTIME_39CYCLES_5, chan);
|
||||
#else
|
||||
set_sampling_time(LL_ADC_SAMPLINGTIME_41CYCLES_5);
|
||||
set_sampling_time(LL_ADC_SAMPLINGTIME_41CYCLES_5, chan);
|
||||
#endif
|
||||
|
||||
set_channel(chan);
|
||||
}
|
||||
|
||||
void adc_disable() {
|
||||
|
@ -303,3 +303,5 @@ uint16_t adc_read_pin(uint8_t pin) {
|
|||
adc_disable();
|
||||
return r;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
#include "jd_protocol.h"
|
||||
|
||||
#include "dmesg.h"
|
||||
#include "pinnames.h"
|
||||
|
||||
#include "services/interfaces/jd_oled.h"
|
||||
|
@ -18,7 +17,6 @@ uint64_t tim_get_micros(void);
|
|||
void tim_set_timer(int delta, cb_t cb);
|
||||
|
||||
#include "tinyhw.h"
|
||||
#include "dmesg.h"
|
||||
|
||||
#define RTC_ALRM_US 10000
|
||||
|
|
@ -36,8 +36,10 @@ static ctx_t ctx_;
|
|||
#define RTC_IRQHandler RTC_Alarm_IRQHandler
|
||||
#define EXTI_LINE LL_EXTI_LINE_17
|
||||
#define LL_EXTI_ClearRisingFlag_0_31 LL_EXTI_ClearFlag_0_31
|
||||
#ifdef STM32WL
|
||||
#define LL_PWR_ClearFlag_SB LL_PWR_ClearFlag_C1STOP_C1STB
|
||||
#define LL_PWR_IsActiveFlag_SB LL_PWR_IsActiveFlag_C1SB
|
||||
#endif
|
||||
#else
|
||||
#define EXTI_LINE LL_EXTI_LINE_17
|
||||
#define LL_EXTI_ClearRisingFlag_0_31 LL_EXTI_ClearFlag_0_31
|
||||
|
@ -163,9 +165,11 @@ void RTC_IRQHandler(void) {
|
|||
static void rtc_config(uint8_t p0, uint16_t p1) {
|
||||
#ifdef STM32G0
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR | LL_APB1_GRP1_PERIPH_RTC);
|
||||
#elif defined(STM32L)
|
||||
#elif defined(STM32WL)
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_RTCAPB);
|
||||
// LL_C2_APB1_GRP1_EnableClock(LL_C2_APB1_GRP1_PERIPH_RTCAPB);
|
||||
#elif defined(STM32L4)
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR);
|
||||
#else
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR);
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
#ifndef __STM_H
|
||||
#define __STM_H
|
||||
|
||||
#include "board.h"
|
||||
|
||||
#define STM32L4 1
|
||||
#define STM32L 1
|
||||
|
||||
#include "stm32l4xx.h"
|
||||
|
||||
#include "stm32l4xx_hal_def.h"
|
||||
#include "stm32l4xx_hal_rcc.h"
|
||||
|
||||
#include "stm32l4xx_ll_crc.h"
|
||||
#include "stm32l4xx_ll_bus.h"
|
||||
#include "stm32l4xx_ll_gpio.h"
|
||||
#include "stm32l4xx_ll_exti.h"
|
||||
#include "stm32l4xx_ll_dma.h"
|
||||
#include "stm32l4xx_ll_rcc.h"
|
||||
#include "stm32l4xx_ll_system.h"
|
||||
#include "stm32l4xx_ll_cortex.h"
|
||||
#include "stm32l4xx_ll_utils.h"
|
||||
#include "stm32l4xx_ll_pwr.h"
|
||||
#include "stm32l4xx_ll_usart.h"
|
||||
#include "stm32l4xx_ll_tim.h"
|
||||
#include "stm32l4xx_ll_lptim.h"
|
||||
#include "stm32l4xx_ll_spi.h"
|
||||
#include "stm32l4xx_ll_adc.h"
|
||||
#include "stm32l4xx_ll_rtc.h"
|
||||
#include "stm32l4xx_ll_i2c.h"
|
||||
#include "stm32l4xx_ll_dmamux.h"
|
||||
|
||||
|
||||
#define HSI_MHZ 16
|
||||
|
||||
// run at 48 MHz for compatibility with F0
|
||||
#define PLL_MHZ 48
|
||||
|
||||
#define LL_EXTI_ClearFallingFlag_0_31 LL_EXTI_ClearFlag_0_31
|
||||
#define LL_EXTI_IsActiveFallingFlag_0_31 LL_EXTI_IsActiveFlag_0_31
|
||||
|
||||
#define TIM17_IRQn TIM1_TRG_COM_TIM17_IRQn
|
||||
#define TIM17_IRQHandler TIM1_TRG_COM_TIM17_IRQHandler
|
||||
|
||||
#endif
|
|
@ -1,9 +1,30 @@
|
|||
#pragma once
|
||||
|
||||
#include "blhw.h"
|
||||
#include "jd_config.h"
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "hwconfig.h"
|
||||
#include "services/interfaces/jd_pins.h"
|
||||
#include "services/interfaces/jd_flash.h"
|
||||
|
||||
#include "services/interfaces/jd_adc.h"
|
||||
#include "jacdac/dist/c/ledstrip.h"
|
||||
|
||||
// without #, GCC now appends "aw",@progbits'
|
||||
// with the #, GCC comments out this appended directive
|
||||
// see: https://gcc.gnu.org/legacy-ml/gcc-help/2010-09/msg00088.html
|
||||
#define RAM_FUNC __attribute__((noinline, long_call, section(".data#")))
|
||||
|
||||
// init.c
|
||||
bool clk_is_pll(void);
|
||||
void clk_set_pll(int on);
|
||||
void clk_setup_pll(void);
|
||||
|
||||
__attribute__((noreturn)) void hw_panic(void);
|
||||
__attribute__((noreturn)) void target_reset(void);
|
||||
void target_wait_us(uint32_t n);
|
||||
|
||||
|
||||
#ifndef RTC_SECOND_IN_US
|
||||
// use a little more than 10ms, so we don't have issues with wrap around
|
||||
// also, use value that converts evenly to 32768Hz crystal
|
Загрузка…
Ссылка в новой задаче