Browse Source

merge and fix builds

master
heck 2 years ago
parent
commit
e9fe227a44
  1. 1
      libs/st_usb/Makefile
  2. 1
      src/Makefile
  3. 25
      src/cppmain.cc
  4. 4
      src/cppmain.h
  5. 126
      src/init.c

1
libs/st_usb/Makefile

@ -6,6 +6,7 @@ TARGET=libst_usb.a
CFLAGS+= -I.
CFLAGS+= -I../cmsis
CFLAGS+= -I../STM32F4xx_HAL_Driver/Inc
CFLAGS+= -I../../src
C_SRC=$(wildcard *.c)
C_OBJ=$(subst .c,.o,$(C_SRC))

1
src/Makefile

@ -7,6 +7,7 @@ TARGET_BIN=$(TARGET).bin
TARGET_MAP=$(TARGET).map
# Includes
INC+= -I.
INC+= -I../libs/cmsis
INC+= -I../libs/STM32F4xx_HAL_Driver/Inc
INC+= -I../libs/st_usb

25
src/cppmain.cc

@ -10,6 +10,12 @@ const double pi{ std::acos(-1) };
#define BUFFER_SIZE 512
namespace Heck {
bool debug_suspend_active = false;
void debug_suspend_continue() {
debug_suspend_active = false;
}
// Serial Logging
// --------------
void log(std::string msg)
@ -72,10 +78,7 @@ namespace Heck {
// CALLBACKS
void irq1_cb()
{
if (!is_running) {
is_running = true;
return;
}
debug_suspend_continue();
}
void timer2_cb()
@ -149,9 +152,7 @@ namespace Heck {
void main()
{
while (!is_running) {
HAL_Delay(1);
}
heck_debug_suspend();
log("Starting...");
dac_start_dma();
@ -177,6 +178,14 @@ namespace Heck {
// C Linkage (Bridging)
// ----------------------------------------------------------------------------------------------
extern "C" void heck_debug_suspend(void) {
Heck::debug_suspend_active = true;
while(Heck::debug_suspend_active == true) {
Heck::log("debug_suspend...");
HAL_Delay(1000);
}
}
extern "C" void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if (GPIO_Pin == GPIO_PIN_0) {
@ -238,7 +247,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");
snprintf(str, str_size, "assert failed: %s:%d",file,line);
heck_log(str);
}

4
src/cppmain.h

@ -12,6 +12,7 @@ extern "C" {
void heck_cppmain(void);
void heck_log(char* msg);
void heck_debug_suspend(void);
void assert_failed(uint8_t* file, uint32_t line);
void Error_Handler(void);
@ -32,8 +33,7 @@ extern "C" {
using u32 = uint32_t;
namespace Heck {
bool is_running{ false };
void debug_suspend_continue();
// Serial Logging
void log(std::string msg);

126
src/init.c

@ -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();
}

Loading…
Cancel
Save