|
|
@ -1,5 +1,4 @@ |
|
|
|
#include "cppmain.h" |
|
|
|
#include "usbd_cdc_if.h" |
|
|
|
#include "usb_device.h" |
|
|
|
|
|
|
|
DAC_HandleTypeDef hdac1; |
|
|
@ -56,7 +55,6 @@ void sysclk_init(void) |
|
|
|
// Configure the main internal regulator output voltage
|
|
|
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); |
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
// Initializes the RCC Oscillators according to the specified parameters
|
|
|
|
// in the RCC_OscInitTypeDef structure.
|
|
|
@ -92,11 +90,8 @@ void sysclk_init(void) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void gpio_init(void) |
|
|
|
void debug_init() |
|
|
|
{ |
|
|
|
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12, GPIO_PIN_RESET); |
|
|
|
|
|
|
|
{ |
|
|
|
// Button Blue
|
|
|
|
GPIO_InitTypeDef conf = { |
|
|
@ -108,6 +103,16 @@ void gpio_init(void) |
|
|
|
HAL_GPIO_Init(GPIOA, &conf); |
|
|
|
} |
|
|
|
|
|
|
|
HAL_NVIC_SetPriority(EXTI0_IRQn, 5, 0); |
|
|
|
HAL_NVIC_EnableIRQ(EXTI0_IRQn); |
|
|
|
|
|
|
|
MX_USB_DEVICE_Init(); // USB first, for logging over serial port
|
|
|
|
} |
|
|
|
|
|
|
|
void gpio_init(void) |
|
|
|
{ |
|
|
|
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12, GPIO_PIN_RESET); |
|
|
|
|
|
|
|
{ |
|
|
|
// LED Green
|
|
|
|
GPIO_InitTypeDef conf = { |
|
|
@ -133,51 +138,6 @@ void gpio_init(void) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void dac_init(void) |
|
|
|
{ |
|
|
|
hdac1.Instance = DAC1; |
|
|
|
if (HAL_DAC_Init(&hdac1) != HAL_OK) { |
|
|
|
Error_Handler(); |
|
|
|
} |
|
|
|
|
|
|
|
DAC_ChannelConfTypeDef conf = { |
|
|
|
.DAC_Trigger = DAC_TRIGGER_T6_TRGO, |
|
|
|
.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE, |
|
|
|
}; |
|
|
|
if (HAL_DAC_ConfigChannel(&hdac1, &conf, DAC_CHANNEL_1) != HAL_OK) { |
|
|
|
Error_Handler(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void dma_init(void) |
|
|
|
{ |
|
|
|
hdma_dac1.Instance = DMA1_Stream5; |
|
|
|
hdma_dac1.Init.Channel = DMA_CHANNEL_7; |
|
|
|
hdma_dac1.Init.Direction = DMA_MEMORY_TO_PERIPH; |
|
|
|
hdma_dac1.Init.PeriphInc = DMA_PINC_DISABLE; |
|
|
|
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.FIFOMode = DMA_FIFOMODE_DISABLE; |
|
|
|
if (HAL_DMA_Init(&hdma_dac1) != HAL_OK) { |
|
|
|
Error_Handler(); |
|
|
|
} |
|
|
|
|
|
|
|
// Originally that was:
|
|
|
|
// __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; |
|
|
|
} |
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------------
|
|
|
|
// Timers
|
|
|
|
// --------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void timer_init(void) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -209,6 +169,9 @@ void timer_init(void) |
|
|
|
Error_Handler(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
HAL_NVIC_SetPriority(TIM2_IRQn, 5, 0); |
|
|
|
HAL_NVIC_EnableIRQ(TIM2_IRQn); |
|
|
|
} |
|
|
|
|
|
|
|
{ |
|
|
@ -251,25 +214,52 @@ void timer_init(void) |
|
|
|
Error_Handler(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
HAL_NVIC_SetPriority(TIM7_IRQn, 5, 0); |
|
|
|
HAL_NVIC_EnableIRQ(TIM7_IRQn); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void irq_init() |
|
|
|
void dac_dma_init(void) |
|
|
|
{ |
|
|
|
// Was for RTOS i guess
|
|
|
|
// HAL_NVIC_SetPriority(PendSV_IRQn, 15, 0);
|
|
|
|
hdac1.Instance = DAC1; |
|
|
|
if (HAL_DAC_Init(&hdac1) != HAL_OK) { |
|
|
|
Error_Handler(); |
|
|
|
} |
|
|
|
|
|
|
|
HAL_NVIC_SetPriority(DMA1_Stream5_IRQn, 1, 0); |
|
|
|
HAL_NVIC_EnableIRQ(DMA1_Stream5_IRQn); |
|
|
|
DAC_ChannelConfTypeDef conf = { |
|
|
|
.DAC_Trigger = DAC_TRIGGER_T6_TRGO, |
|
|
|
.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE, |
|
|
|
}; |
|
|
|
if (HAL_DAC_ConfigChannel(&hdac1, &conf, DAC_CHANNEL_1) != HAL_OK) { |
|
|
|
Error_Handler(); |
|
|
|
} |
|
|
|
|
|
|
|
HAL_NVIC_SetPriority(TIM2_IRQn, 5, 0); |
|
|
|
HAL_NVIC_EnableIRQ(TIM2_IRQn); |
|
|
|
|
|
|
|
HAL_NVIC_SetPriority(TIM7_IRQn, 5, 0); |
|
|
|
HAL_NVIC_EnableIRQ(TIM7_IRQn); |
|
|
|
hdma_dac1.Instance = DMA1_Stream5; |
|
|
|
hdma_dac1.Init.Channel = DMA_CHANNEL_7; |
|
|
|
hdma_dac1.Init.Direction = DMA_MEMORY_TO_PERIPH; |
|
|
|
hdma_dac1.Init.PeriphInc = DMA_PINC_DISABLE; |
|
|
|
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.FIFOMode = DMA_FIFOMODE_DISABLE; |
|
|
|
if (HAL_DMA_Init(&hdma_dac1) != HAL_OK) { |
|
|
|
Error_Handler(); |
|
|
|
} |
|
|
|
|
|
|
|
HAL_NVIC_SetPriority(EXTI0_IRQn, 5, 0); |
|
|
|
HAL_NVIC_EnableIRQ(EXTI0_IRQn); |
|
|
|
// Originally that was:
|
|
|
|
// __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; |
|
|
|
|
|
|
|
HAL_NVIC_SetPriority(DMA1_Stream5_IRQn, 5, 0); |
|
|
|
HAL_NVIC_EnableIRQ(DMA1_Stream5_IRQn); |
|
|
|
} |
|
|
|
|
|
|
|
void rng_init(void) |
|
|
@ -280,17 +270,21 @@ 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(); |
|
|
|
MX_USB_DEVICE_Init(); // USB first, for logging over serial port
|
|
|
|
debug_init(); |
|
|
|
heck_debug_suspend(); |
|
|
|
gpio_init(); |
|
|
|
dac_init(); |
|
|
|
timer_init(); |
|
|
|
dac_dma_init(); |
|
|
|
rng_init(); |
|
|
|
irq_init(); |
|
|
|
dma_init(); |
|
|
|
|
|
|
|
} |
|
|
|