Browse Source

use SYSINIT and break things out/make more generic and modular...

This gets USB CDC printing working..
main
John-Mark Gurney 2 years ago
parent
commit
606ba3ea78
4 changed files with 59 additions and 21 deletions
  1. +10
    -0
      hal_generic.c
  2. +4
    -0
      mk/boards.mk
  3. +17
    -21
      rs485hid/rs485gw.c
  4. +28
    -0
      si_usb.c

+ 10
- 0
hal_generic.c View File

@@ -0,0 +1,10 @@
#include <stm32f1xx_hal.h>

void
SysTick_Handler(void)
{

HAL_IncTick();

HAL_SYSTICK_IRQHandler();
}

+ 4
- 0
mk/boards.mk View File

@@ -12,6 +12,8 @@ ARMCC?= arm-none-eabi-gcc
#ARMCC?=clang-mp-9.0 #ARMCC?=clang-mp-9.0
#ARMTARGET?= -nostdlib -ffreestanding -target arm-none-eabi -mcpu=cortex-m3 -mfloat-abi=soft -mthumb #ARMTARGET?= -nostdlib -ffreestanding -target arm-none-eabi -mcpu=cortex-m3 -mfloat-abi=soft -mthumb


CFLAGS+= -Wall -Werror

.include <$(.PARSEDIR)/mu.opts.mk> .include <$(.PARSEDIR)/mu.opts.mk>


.if ${MK_SYSINIT} == "yes" .if ${MK_SYSINIT} == "yes"
@@ -50,6 +52,7 @@ ARMTARGET?= -mcpu=cortex-m3 -mthumb
LINKER_SCRIPT=$(STM32)/f103c8t6/STM32F103C8T6_FLASH.ld LINKER_SCRIPT=$(STM32)/f103c8t6/STM32F103C8T6_FLASH.ld


SRCS+= \ SRCS+= \
hal_generic.c \
startup_stm32f103xb.s \ startup_stm32f103xb.s \
stm32f1xx_hal.c \ stm32f1xx_hal.c \
stm32f1xx_hal_cortex.c \ stm32f1xx_hal_cortex.c \
@@ -109,6 +112,7 @@ CFLAGS+= -DSTM32L151xC
.if ${MK_USB_CDC} == "yes" .if ${MK_USB_CDC} == "yes"
.PATH: $(STM32)/usb .PATH: $(STM32)/usb
SRCS+= \ SRCS+= \
si_usb.c \
usb_device.c \ usb_device.c \
usbd_cdc.c \ usbd_cdc.c \
usbd_cdc_if.c \ usbd_cdc_if.c \


+ 17
- 21
rs485hid/rs485gw.c View File

@@ -37,7 +37,7 @@
SYSINIT(hal_init, SI_SUB_HAL, SI_ORDER_FIRST, (void (*)(const void *))HAL_Init, NULL); SYSINIT(hal_init, SI_SUB_HAL, SI_ORDER_FIRST, (void (*)(const void *))HAL_Init, NULL);


static void static void
clkenable(const void *none)
c13led(const void *none)
{ {
GPIO_InitTypeDef GPIO_InitStruct; GPIO_InitTypeDef GPIO_InitStruct;


@@ -54,8 +54,12 @@ clkenable(const void *none)


HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);
} }
SYSINIT(clkenable, SI_SUB_HAL, SI_ORDER_SECOND, clkenable, NULL);
SYSINIT(c13led, SI_SUB_HAL, SI_ORDER_SECOND, c13led, NULL);


/*
* Referenced from:
* Projects/STM32F103RB-Nucleo/Applications/USB_Device/HID_Standalone/Src/main.c
*/
static void static void
oscconfig(const void *none) oscconfig(const void *none)
{ {
@@ -63,7 +67,6 @@ oscconfig(const void *none)
RCC_OscInitTypeDef oscinitstruct; RCC_OscInitTypeDef oscinitstruct;
RCC_PeriphCLKInitTypeDef rccperiphclkinit; RCC_PeriphCLKInitTypeDef rccperiphclkinit;



__HAL_RCC_PWR_CLK_ENABLE(); __HAL_RCC_PWR_CLK_ENABLE();


oscinitstruct = (RCC_OscInitTypeDef){ oscinitstruct = (RCC_OscInitTypeDef){
@@ -78,18 +81,6 @@ oscconfig(const void *none)


HAL_RCC_OscConfig(&oscinitstruct); HAL_RCC_OscConfig(&oscinitstruct);


/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
* clocks dividers */
clkinitstruct.ClockType = RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK |
RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;

clkinitstruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
clkinitstruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
clkinitstruct.APB1CLKDivider = RCC_HCLK_DIV2;
clkinitstruct.APB2CLKDivider = RCC_HCLK_DIV1;
HAL_RCC_ClockConfig(&clkinitstruct, FLASH_LATENCY_2);


/* USB clock selection */ /* USB clock selection */
rccperiphclkinit = (RCC_PeriphCLKInitTypeDef){ rccperiphclkinit = (RCC_PeriphCLKInitTypeDef){
.PeriphClockSelection = RCC_PERIPHCLK_USB, .PeriphClockSelection = RCC_PERIPHCLK_USB,
@@ -255,12 +246,19 @@ int
main(void) main(void)
{ {


//debug_printf("starting...\n");

//clkenable(NULL);
sysinit_run(); sysinit_run();


//Radio.Init(&revents);
//debug_printf("starting...\n");

#if 1
int i;
for (i = 0; i < 5; i++) {
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET);
HAL_Delay(250);
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);
HAL_Delay(250);
}
#endif


setlinebuf(vcp_usb); setlinebuf(vcp_usb);


@@ -277,8 +275,6 @@ main(void)


#endif #endif


uint32_t v;

char inpbuf[1024]; char inpbuf[1024];
char *lastcheck; char *lastcheck;
char *endchr; char *endchr;


+ 28
- 0
si_usb.c View File

@@ -0,0 +1,28 @@
/*
* Code for initalizing USB CDC via the SYSINIT mechanism.
*/

#include <sysinit.h>

#include <usb_device.h>

#if 1
static void
usb_cdc_init(const void *foo)
{

MX_USB_DEVICE_Init();
}

extern PCD_HandleTypeDef hpcd_USB_FS;


void
USB_LP_IRQHandler(void)
{

HAL_PCD_IRQHandler(&hpcd_USB_FS);
}

SYSINIT(abkdkd, SI_SUB_CONSOLE, SI_ORDER_FIRST, usb_cdc_init, NULL);
#endif

Loading…
Cancel
Save