Browse Source

audio engine start

master
heck 2 years ago
parent
commit
c554da4420
  1. 200
      src/cppmain.cc
  2. 7
      src/cppmain.h
  3. 282
      src/init.c
  4. 7
      src/init.h
  5. 6
      src/main.c

200
src/cppmain.cc

@ -4,15 +4,27 @@
//#include "usb_device.h"
//#include "cmsis_os.h"
#include <cmath>
#include <bitset>
#include "limits"
#include <sstream>
#define SAMPLE_FREQ 44200
#define SAMPLE_MAX 4096
#define DOUBLE_BUFFER_SIZE 16
#define BUFFER_SIZE 8
const double pi{ std::acos(-1) };
#define BUFFER_SIZE 512
static u32 double_buffer[DOUBLE_BUFFER_SIZE];
static u64 time{ 0 };
static volatile bool dma_to_dac_half_complete{ false };
static volatile bool dma_to_dac_complete{ false };
static volatile int freq = 100;
namespace Heck {
bool debug_suspend_active = false;
void debug_suspend_continue() {
void debug_suspend_continue()
{
debug_suspend_active = false;
}
@ -28,37 +40,10 @@ namespace Heck {
// DAC
// ---
u32 audio_buffer[BUFFER_SIZE];
void dac1_set(u32 val)
{
HAL_DAC_SetValue(&hdac1, DAC_CHANNEL_1, DAC_ALIGN_12B_R, val);
}
void dac1_toggle()
{
static bool dac_state{ 0 };
dac_state = !dac_state;
if (dac_state) {
dac1_set(0b0000111111111111);
} else {
dac1_set(0b0000000000000000);
}
}
void dac_start_dma()
{
HAL_DAC_Start_DMA(&hdac1, DAC_CHANNEL_1, (u32 *)audio_buffer, BUFFER_SIZE, DAC_ALIGN_12B_R);
}
void dac_stop_dma()
{
HAL_DAC_Stop_DMA(&hdac1, DAC_CHANNEL_1);
}
// LED
// ---
void led_green_toggle()
{
HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_12);
@ -79,15 +64,14 @@ namespace Heck {
void irq1_cb()
{
debug_suspend_continue();
freq += 10;
}
void timer2_cb()
void timer3_cb()
{
led_green_toggle();
}
void timer7_cb() {}
// dont forget to start the DAC
// HAL_DAC_Start(&hdac, DAC_CHANNEL_1);
void bytebeat()
@ -109,68 +93,99 @@ namespace Heck {
ret %= max;
return ret;
}
void buffer_init_noise()
//
// void buffer_init_noise()
// {
// log("buffer_init_noise()");
// for (int i = 0; i < DOUBLE_BUFFER_SIZE; i++) {
// u32 val = random(SAMPLE_MAX);
// double_buffer[i] = val;
// log(std::to_string(val));
// }
// }
//
// void buffer_init_sin()
// {
// log("buffer_init_sin()");
// for (int i = 0; i < DOUBLE_BUFFER_SIZE; i++) {
// float p = float(i) / (float)DOUBLE_BUFFER_SIZE - 0.5;
// u32 val = sin(p) * SAMPLE_MAX;
// double_buffer[i] = val;
// log(std::to_string(val));
// }
// }
//
// void buffer_div(int div)
// {
// log("init_scale()");
// for (int i = 0; i < DOUBLE_BUFFER_SIZE; i++) {
// u32 val = double_buffer[i] / div;
// double_buffer[i] = val;
// log(std::to_string(val));
// }
// }
//
// void buffer_randomize(int max)
// {
// log("buffer_randomize()");
// u32 buf_index = random(DOUBLE_BUFFER_SIZE);
// u32 buf_val = random(max);
// double_buffer[buf_index] = buf_val;
// log("i:" + std::to_string(buf_index) + " v:" + std::to_string(buf_val));
// }
std::string reg_to_string(uint32_t val)
{
log("buffer_init_noise()");
for (int i = 0; i < BUFFER_SIZE; i++) {
u32 val = random(4096);
audio_buffer[i] = val;
log(std::to_string(val));
}
std::stringstream ss{};
const std::bitset<32> x{ val };
ss << "0b" << x.to_string();
ss << " - ";
ss << std::to_string(val);
return ss.str();
}
void buffer_init_sin()
u32 hz_to_samps(float hz)
{
log("buffer_init_sin()");
for (int i = 0; i < BUFFER_SIZE; i++) {
float p = float(i) / (float)BUFFER_SIZE - 0.5;
u32 val = sin(p) * 4096;
audio_buffer[i] = val;
log(std::to_string(val));
}
return (u32)floor((float)SAMPLE_FREQ / (float)hz);
}
void buffer_div(int div)
void calculate_audio(u32 *buffer)
{
log("init_scale()");
log("calculate_audio time: ");
u64 t = time;
u32 samps = hz_to_samps(freq);
for (int i = 0; i < BUFFER_SIZE; i++) {
u32 val = audio_buffer[i] / div;
audio_buffer[i] = val;
log(std::to_string(val));
buffer[i] = t % samps;
t++;
}
}
void buffer_randomize(int max)
{
log("buffer_randomize()");
u32 buf_index = random(BUFFER_SIZE);
u32 buf_val = random(max);
audio_buffer[buf_index] = buf_val;
log("i:" + std::to_string(buf_index) + " v:" + std::to_string(buf_val));
}
void main()
{
heck_debug_suspend();
log("Starting...");
dac_start_dma();
HAL_TIM_Base_Start_IT(&htim2);
HAL_TIM_Base_Start_IT(&htim7);
HAL_TIM_Base_Start(&htim6);
HAL_TIM_Base_Start_IT(&htim_blinky_led);
HAL_DAC_Start_DMA(&hdac1, DAC_CHANNEL_1, (u32 *)double_buffer, DOUBLE_BUFFER_SIZE, DAC_ALIGN_12B_R);
HAL_TIM_Base_Start_IT(&htim_dac1);
// init_buffer_noise();
buffer_init_sin();
buffer_div(10);
log("Entering MainLoop...");
while (true) {
// buffer_randomize(400);
HAL_Delay(10);
if (dma_to_dac_half_complete) {
calculate_audio(&double_buffer[0]);
time += BUFFER_SIZE;
dma_to_dac_half_complete = false;
}
if (dma_to_dac_complete) {
calculate_audio(&double_buffer[BUFFER_SIZE]);
time += BUFFER_SIZE;
dma_to_dac_complete = false;
}
}
}
} // namespace Heck
@ -178,11 +193,12 @@ namespace Heck {
// C Linkage (Bridging)
// ----------------------------------------------------------------------------------------------
extern "C" void heck_debug_suspend(void) {
extern "C" void heck_debug_suspend(void)
{
Heck::debug_suspend_active = true;
while(Heck::debug_suspend_active == true) {
while (Heck::debug_suspend_active == true) {
Heck::log("debug_suspend...");
HAL_Delay(1000);
HAL_Delay(10);
}
}
@ -190,27 +206,21 @@ extern "C" void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if (GPIO_Pin == GPIO_PIN_0) {
Heck::irq1_cb();
} else {
__NOP(); // why NOP? i dont know! was from an example
}
}
extern "C" void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if (htim->Instance == TIM2) {
// Heck::log(
// "TIM2 timer: instance: " + std::to_string(reinterpret_cast<u32>(htim->Instance)) +
// " channel: " + std::to_string(htim->Channel));
// Heck::log(std::to_string(time));
} else if (htim->Instance == TIM3) {
Heck::log(
"TIM2 timer: instance: " + std::to_string(reinterpret_cast<u32>(htim->Instance)) +
" channel: " + std::to_string(htim->Channel));
Heck::timer2_cb();
} else if (htim->Instance == TIM6) {
Heck::log(
"TIM6 timer: instance: " + std::to_string(reinterpret_cast<u32>(htim->Instance)) +
" channel: " + std::to_string(htim->Channel));
} else if (htim->Instance == TIM7) {
Heck::log(
"TIM7 timer: instance: " + std::to_string(reinterpret_cast<u32>(htim->Instance)) +
"TIM3 timer: instance: " + std::to_string(reinterpret_cast<u32>(htim->Instance)) +
" channel: " + std::to_string(htim->Channel));
Heck::timer7_cb();
Heck::timer3_cb();
} else {
Heck::log(
"UNKNOWN timer: instance: " + std::to_string(reinterpret_cast<u32>(htim->Instance)) +
@ -219,11 +229,19 @@ extern "C" void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
}
extern "C" void HAL_DAC_ConvHalfCpltCallbackCh1(DAC_HandleTypeDef *hdac)
{
Heck::log("HAL_DAC_ConvHalfCpltCallbackCh1");
dma_to_dac_half_complete = true;
}
extern "C" void HAL_DAC_ConvCpltCallbackCh1(DAC_HandleTypeDef *hdac)
{
Heck::dac_start_dma();
Heck::log("HAL_DAC_ConvCpltCallbackCh1");
dma_to_dac_complete = true;
}
extern "C" void heck_log(char *msg)
{
Heck::log(std::string(msg));
@ -247,7 +265,7 @@ extern "C" void assert_failed(uint8_t *file, uint32_t line)
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
int str_size = 1024;
char str[str_size];
snprintf(str, str_size, "assert failed: %s:%d",file,line);
snprintf(str, str_size, "assert failed: %s:%d", file, line);
heck_log(str);
}

7
src/cppmain.h

@ -31,6 +31,7 @@ extern "C" {
#include <string>
using u32 = uint32_t;
using u64 = uint64_t;
namespace Heck {
void debug_suspend_continue();
@ -39,9 +40,6 @@ namespace Heck {
// DAC1
void dac1_set(uint32_t val);
void dac1_toggle();
void dac_start_dma();
void dac_stop_dma();
// LED Green
void led_green_toggle();
@ -50,8 +48,7 @@ namespace Heck {
// Callbacks
void irq1_cb();
void timer2_cb();
void timer7_cb();
void timer3_cb();
// misc
void bytebeat();

282
src/init.c

@ -2,10 +2,10 @@
#include "usb_device.h"
DAC_HandleTypeDef hdac1;
TIM_HandleTypeDef htim_dac1;
DMA_HandleTypeDef hdma_dac1;
TIM_HandleTypeDef htim2;
TIM_HandleTypeDef htim6;
TIM_HandleTypeDef htim7;
ADC_HandleTypeDef hadc1;
TIM_HandleTypeDef htim_blinky_led;
RNG_HandleTypeDef hrng;
@ -15,6 +15,10 @@ void sysclk_init(void)
__HAL_RCC_SYSCFG_CLK_ENABLE();
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_RCC_ADC1_CLK_ENABLE();
__HAL_RCC_ADC2_CLK_ENABLE();
__HAL_RCC_ADC3_CLK_ENABLE();
// ALL GPIO Ports
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
@ -109,133 +113,96 @@ void debug_init()
MX_USB_DEVICE_Init(); // USB first, for logging over serial port
}
void gpio_init(void)
void blinky_led_init()
{
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12, GPIO_PIN_RESET);
{
// LED Green
GPIO_InitTypeDef conf = {
.Pin = GPIO_PIN_12,
.Mode = GPIO_MODE_OUTPUT_PP,
.Pull = GPIO_NOPULL,
.Speed = GPIO_SPEED_FREQ_LOW,
};
HAL_GPIO_Init(GPIOD, &conf);
// GPIO
GPIO_InitTypeDef git = {
.Pin = GPIO_PIN_12,
.Mode = GPIO_MODE_OUTPUT_PP,
.Pull = GPIO_NOPULL,
.Speed = GPIO_SPEED_FREQ_LOW,
};
HAL_GPIO_Init(GPIOD, &git);
// Timer
htim_blinky_led.Instance = TIM3;
htim_blinky_led.Init.Prescaler = 0;
htim_blinky_led.Init.CounterMode = TIM_COUNTERMODE_UP;
htim_blinky_led.Init.Period = 1LL << 32;
htim_blinky_led.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim_blinky_led.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim_blinky_led) != HAL_OK) {
Error_Handler();
}
{
// DAC1
GPIO_InitTypeDef conf = {
.Pin = GPIO_PIN_4,
.Mode = GPIO_MODE_ANALOG,
.Pull = GPIO_NOPULL,
.Speed = GPIO_SPEED_FREQ_HIGH,
};
TIM_ClockConfigTypeDef tcc = {
.ClockSource = TIM_CLOCKSOURCE_INTERNAL,
};
if (HAL_TIM_ConfigClockSource(&htim_blinky_led, &tcc) != HAL_OK) {
Error_Handler();
}
HAL_GPIO_Init(GPIOA, &conf);
TIM_MasterConfigTypeDef tmc = {
.MasterOutputTrigger = TIM_TRGO_RESET,
.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE,
};
if (HAL_TIMEx_MasterConfigSynchronization(&htim_blinky_led, &tmc) != HAL_OK) {
Error_Handler();
}
HAL_NVIC_SetPriority(TIM3_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(TIM3_IRQn);
}
void timer_init(void)
void dac_init(void)
{
{
htim2.Instance = TIM2;
htim2.Init.Prescaler = 0;
htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
htim2.Init.Period = 42949000;
htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim2) != HAL_OK) {
Error_Handler();
}
{
TIM_ClockConfigTypeDef conf = {
.ClockSource = TIM_CLOCKSOURCE_INTERNAL,
};
if (HAL_TIM_ConfigClockSource(&htim2, &conf) != HAL_OK) {
Error_Handler();
}
}
{
TIM_MasterConfigTypeDef conf = {
.MasterOutputTrigger = TIM_TRGO_RESET,
.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE,
};
if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &conf) != HAL_OK) {
Error_Handler();
}
}
HAL_NVIC_SetPriority(TIM2_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(TIM2_IRQn);
// DAC1
GPIO_InitTypeDef conf = {
.Pin = GPIO_PIN_4,
.Mode = GPIO_MODE_ANALOG,
.Pull = GPIO_NOPULL,
.Speed = GPIO_SPEED_FREQ_HIGH,
};
HAL_GPIO_Init(GPIOA, &conf);
// timer
htim_dac1.Instance = TIM2;
htim_dac1.Init.Prescaler = 0;
htim_dac1.Init.CounterMode = TIM_COUNTERMODE_UP;
htim_dac1.Init.Period = 2000;// * 10000;
htim_dac1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
if (HAL_TIM_Base_Init(&htim_dac1) != HAL_OK) {
Error_Handler();
}
HAL_NVIC_SetPriority(TIM2_IRQn, 1, 0);
HAL_NVIC_EnableIRQ(TIM2_IRQn);
{
htim6.Instance = TIM6;
htim6.Init.Prescaler = 0;
htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
htim6.Init.Period = 1904;
htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim6) != HAL_OK) {
Error_Handler();
}
{
TIM_MasterConfigTypeDef conf = {
.MasterOutputTrigger = TIM_TRGO_UPDATE,
.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE,
};
if (HAL_TIMEx_MasterConfigSynchronization(&htim6, &conf) != HAL_OK) {
Error_Handler();
}
}
TIM_MasterConfigTypeDef tmc = {
.MasterOutputTrigger = TIM_TRGO_UPDATE,
.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE,
};
if (HAL_TIMEx_MasterConfigSynchronization(&htim_dac1, &tmc) != HAL_OK) {
Error_Handler();
}
{
htim7.Instance = TIM7;
htim7.Init.Prescaler = 10000;
htim7.Init.CounterMode = TIM_COUNTERMODE_UP;
htim7.Init.Period = 429490000;
htim7.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
if (HAL_TIM_Base_Init(&htim7) != HAL_OK) {
Error_Handler();
}
{
TIM_MasterConfigTypeDef conf = {
.MasterOutputTrigger = TIM_TRGO_RESET,
.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE,
};
if (HAL_TIMEx_MasterConfigSynchronization(&htim7, &conf) != HAL_OK) {
Error_Handler();
}
}
HAL_NVIC_SetPriority(TIM7_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(TIM7_IRQn);
}
}
void dac_dma_init(void)
{
// DAC
hdac1.Instance = DAC1;
if (HAL_DAC_Init(&hdac1) != HAL_OK) {
Error_Handler();
}
DAC_ChannelConfTypeDef conf = {
.DAC_Trigger = DAC_TRIGGER_T6_TRGO,
DAC_ChannelConfTypeDef cct = {
.DAC_Trigger = DAC_TRIGGER_T2_TRGO,
.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE,
};
if (HAL_DAC_ConfigChannel(&hdac1, &conf, DAC_CHANNEL_1) != HAL_OK) {
if (HAL_DAC_ConfigChannel(&hdac1, &cct, DAC_CHANNEL_1) != HAL_OK) {
Error_Handler();
}
// DMA
hdma_dac1.Instance = DMA1_Stream5;
hdma_dac1.Init.Channel = DMA_CHANNEL_7;
hdma_dac1.Init.Direction = DMA_MEMORY_TO_PERIPH;
@ -243,25 +210,105 @@ void dac_dma_init(void)
hdma_dac1.Init.MemInc = DMA_MINC_ENABLE;
hdma_dac1.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
hdma_dac1.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
hdma_dac1.Init.Mode = DMA_NORMAL;
hdma_dac1.Init.Priority = DMA_PRIORITY_LOW;
hdma_dac1.Init.Mode = DMA_CIRCULAR;
hdma_dac1.Init.Priority = DMA_PRIORITY_HIGH;
hdma_dac1.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
if (HAL_DMA_Init(&hdma_dac1) != HAL_OK) {
Error_Handler();
}
// Originally that was:
// __HAL_LINKDMA(&hdac1, DMA_Handle1, hdma_dac1);
__HAL_LINKDMA(&hdac1, DMA_Handle1, hdma_dac1);
// Exapanded to:
// hdma_dac1.Parent = &hdac1;
// hdac1.DMA_Handle1 = &hdma_dac1;
// But this seems to be enough:
hdac1.DMA_Handle1 = &hdma_dac1;
// hdac1.DMA_Handle1 = &hdma_dac1;
HAL_NVIC_SetPriority(DMA1_Stream5_IRQn, 5, 0);
HAL_NVIC_SetPriority(DMA1_Stream5_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(DMA1_Stream5_IRQn);
}
void adc_init(void)
{
// GPIO
GPIO_InitTypeDef conf = {
.Pin = GPIO_PIN_4,
.Mode = GPIO_MODE_ANALOG,
.Pull = GPIO_NOPULL,
.Speed = GPIO_SPEED_FREQ_MEDIUM,
};
HAL_GPIO_Init(GPIOC, &conf);
ADC_Common_TypeDef *adc_common = ADC123_COMMON;
ADC_TypeDef *adc1 = ADC1;
// SET_BIT(adc_common->CCR, ADC_CCR_ADCPRE_0);
// CLEAR_BIT(adc_common->CCR, ADC_CCR_ADCPRE_1);
//
// CLEAR_BIT(adc1->CR1, ~ADC_CR1_RES_0);
// CLEAR_BIT(adc1->CR1, ADC_CR1_RES_1);
// SET_BIT(adc1->CR2, ADC_CR2_CONT);
// CLEAR_BIT(adc1->CR2, ADC_CR2_ALIGN);
// SET_BIT(adc1->CR2, ADC_CR2_ADON);
// SET_BIT(adc1->CR2, ADC_CR2_SWSTART);
//
//
// SET_BIT(adc1->SQR1,ADC_SQR1_L_0);
//// CLEAR_BIT(adc1->SQR1,ADC_SQR1_L_1);
//// CLEAR_BIT(adc1->SQR1,ADC_SQR1_L_2);
//// CLEAR_BIT(adc1->SQR1,ADC_SQR1_L_3);
////
//// ADC_SQR3_RK(1,1);
// SET_BIT(adc1->SQR3,ADC_SQR3_SQ1_0);
//// CLEAR_BIT(adc1->SQR3,ADC_SQR3_SQ1_1);
//// CLEAR_BIT(adc1->SQR3,ADC_SQR3_SQ1_2);
//// CLEAR_BIT(adc1->SQR3,ADC_SQR3_SQ1_3);
//// CLEAR_BIT(adc1->SQR3,ADC_SQR3_SQ1_4);
hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
hadc1.Init.ScanConvMode = DISABLE;
hadc1.Init.ContinuousConvMode = ENABLE;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.NbrOfConversion = 1;
hadc1.Init.DMAContinuousRequests = DISABLE;
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
if (HAL_ADC_Init(&hadc1) != HAL_OK) {
Error_Handler();
}
ADC_ChannelConfTypeDef sConfig = {};
sConfig.Channel = ADC_CHANNEL_14;
sConfig.Rank = 1;
sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) {
Error_Handler();
}
// adc1->CR2
while (1) {
// SET_BIT(adc1->CR2, ADC_CR2_ADON);
// SET_BIT(adc1->CR2, ADC_CR2_SWSTART);
HAL_ADC_Start(&hadc1);
// heck_log("ADC123_COMMON->CCR:" + reg_to_string(adc_common->CCR));
// heck_log("ADC1->CR1:" + reg_to_string(adc1->CR1));
// heck_log("ADC1->CR2:" + reg_to_string(adc1->CR2));
// heck_log("ADC1->SQR1:" + reg_to_string(adc1->SQR1));
// heck_log("ADC1->SQR2:" + reg_to_string(adc1->SQR2));
// heck_log("ADC1->SQR3:" + reg_to_string(adc1->SQR3));
// heck_log("ADC1->DR:" + reg_to_string(adc1->DR));
heck_log("\n");
HAL_Delay(100);
}
}
void rng_init(void)
{
hrng.Instance = RNG;
@ -270,21 +317,14 @@ void rng_init(void)
}
}
//void irq_init()
//{
//// This is for RTOS i guess
// HAL_NVIC_SetPriority(PendSV_IRQn, 15, 0);
//}
void heck_init()
{
HAL_Init();
sysclk_init();
debug_init();
heck_debug_suspend();
gpio_init();
timer_init();
dac_dma_init();
// heck_debug_suspend();
blinky_led_init();
dac_init();
adc_init();
rng_init();
}

7
src/init.h

@ -8,10 +8,11 @@
extern "C" {
#endif
extern DAC_HandleTypeDef hdac1;
extern TIM_HandleTypeDef htim_dac1;
extern DMA_HandleTypeDef hdma_dac1;
extern TIM_HandleTypeDef htim2;
extern TIM_HandleTypeDef htim6;
extern TIM_HandleTypeDef htim7;
extern ADC_HandleTypeDef hadc1;
extern TIM_HandleTypeDef htim_blinky_led;
extern RNG_HandleTypeDef hrng;
void heck_init();

6
src/main.c

@ -55,12 +55,12 @@ void DMA1_Stream5_IRQHandler(void)
void TIM2_IRQHandler(void)
{
HAL_TIM_IRQHandler(&htim2);
HAL_TIM_IRQHandler(&htim_dac1);
}
void TIM7_IRQHandler(void)
void TIM3_IRQHandler(void)
{
HAL_TIM_IRQHandler(&htim7);
HAL_TIM_IRQHandler(&htim_blinky_led);
}
void OTG_FS_IRQHandler(void)

Loading…
Cancel
Save