Skip to content

Commit

Permalink
add BSP for STM32L476GDISCOVERY
Browse files Browse the repository at this point in the history
  • Loading branch information
benedekkupper committed Apr 30, 2019
1 parent 9dbb2da commit bb62c88
Show file tree
Hide file tree
Showing 13 changed files with 1,141 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ before_install:
script:
- docker run -v $PWD:/my_files_in_docker --entrypoint /usr/bin/make jumperio/vlab-gcc-arm -C my_files_in_docker SERIES=STM32F4
- docker run -v $PWD:/my_files_in_docker --entrypoint /usr/bin/make jumperio/vlab-gcc-arm -C my_files_in_docker SERIES=STM32F4 OS_DIR=FreeRTOS/FreeRTOS/Source
- docker run -v $PWD:/my_files_in_docker --entrypoint /usr/bin/make jumperio/vlab-gcc-arm -C my_files_in_docker SERIES=STM32L4
- docker run -v $PWD:/my_files_in_docker --entrypoint /usr/bin/make jumperio/vlab-gcc-arm -C my_files_in_docker SERIES=STM32L4 OS_DIR=FreeRTOS/FreeRTOS/Source
47 changes: 47 additions & 0 deletions BSP_STM32L4xx/bsp_io.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
******************************************************************************
* @file bsp_io.c
* @author Benedek Kupper
* @version 0.1
* @date 2018-12-16
* @brief IPoverUSB BSP for I/O pins
*
* Copyright (c) 2018 Benedek Kupper
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <bsp_io.h>

const GPIO_InitType BSP_IOCfg[] =
{
/* USB pins */
{
.Mode = GPIO_MODE_ALTERNATE,
.Pull = GPIO_PULL_FLOAT,
.Output.Type = GPIO_OUTPUT_PUSHPULL,
.Output.Speed = VERY_HIGH,
.AlternateMap = GPIO_OTG_FS_AF10
},
/* PushButton */
{
.Mode = GPIO_MODE_INPUT,
.Pull = GPIO_PULL_FLOAT,
},
/* LED */
{
.Mode = GPIO_MODE_OUTPUT,
.Pull = GPIO_PULL_FLOAT,
.Output.Type = GPIO_OUTPUT_PUSHPULL,
.Output.Speed = HIGH,
},
};
54 changes: 54 additions & 0 deletions BSP_STM32L4xx/bsp_io.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
******************************************************************************
* @file bsp_io.h
* @author Benedek Kupper
* @version 0.1
* @date 2018-12-16
* @brief IPoverUSB BSP for I/O pins
*
* Copyright (c) 2018 Benedek Kupper
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __BSP_IO_H_
#define __BSP_IO_H_

#ifdef __cplusplus
extern "C"
{
#endif

#include <xpd_gpio.h>

#define USB_DP_PIN PA12
#define USB_DM_PIN PA11
#define USB_VBUS_PIN PA9
#define USB_DP_CFG (&BSP_IOCfg[0])
#define USB_DM_CFG (&BSP_IOCfg[0])
#define USB_VBUS_CFG (&BSP_IOCfg[0])

#define BUTTON_PIN PA0
#define BUTTON_CFG (&BSP_IOCfg[1])

#define LED_GREEN_PIN PE8
#define LED_RED_PIN PB2
#define LED_GREEN_CFG (&BSP_IOCfg[2])
#define LED_RED_CFG (&BSP_IOCfg[2])

extern const GPIO_InitType BSP_IOCfg[];

#ifdef __cplusplus
}
#endif

#endif /* __BSP_IO_H_ */
59 changes: 59 additions & 0 deletions BSP_STM32L4xx/bsp_system.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
******************************************************************************
* @file bsp_system.c
* @author Benedek Kupper
* @version 0.1
* @date 2018-12-16
* @brief IPoverUSB BSP for system clocking
*
* Copyright (c) 2018 Benedek Kupper
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <bsp_system.h>
#include <xpd_rcc.h>

static const RCC_MSI_InitType msiconf = {
.ClockFreq = MSI_48MHz,
.State = ENABLE
};

static const RCC_PLL_InitType pllconf = {
.State = ENABLE,
.Source = MSI,
.M = 6,
.N = 20,
.R = 2, /* MSI / 6 * 20 / 2 = PLLR = 80000000 -> SYSCLK */

.Q = 2,
.P = 7
};

/* System clocks configuration */
void SystemClock_Config(void)
{
RCC_eMSI_Config(&msiconf);

#ifdef LSE_VALUE_Hz
/* Use LSE to synchronize MSI */
RCC_eLSE_Config(OSC_ON);
#endif

RCC_ePLL_Config(&pllconf);

/* System clocks configuration */
RCC_eHCLK_Config(PLL, CLK_DIV1, 4);

RCC_vPCLK1_Config(CLK_DIV1);
RCC_vPCLK2_Config(CLK_DIV1);
}
37 changes: 37 additions & 0 deletions BSP_STM32L4xx/bsp_system.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
******************************************************************************
* @file bsp_system.h
* @author Benedek Kupper
* @version 0.1
* @date 2018-12-16
* @brief IPoverUSB BSP for system clocking
*
* Copyright (c) 2018 Benedek Kupper
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __BSP_SYSTEM_H_
#define __BSP_SYSTEM_H_

#ifdef __cplusplus
extern "C"
{
#endif

extern void SystemClock_Config(void);

#ifdef __cplusplus
}
#endif

#endif /* __BSP_SYSTEM_H_ */
70 changes: 70 additions & 0 deletions BSP_STM32L4xx/bsp_usb.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
******************************************************************************
* @file bsp_usb.c
* @author Benedek Kupper
* @version 0.1
* @date 2018-12-16
* @brief IPoverUSB BSP for USB communication
*
* Copyright (c) 2018 Benedek Kupper
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <bsp_io.h>
#include <bsp_usb.h>
#include <xpd_nvic.h>
#include <xpd_pwr.h>

void OTG_FS_IRQHandler(void);

/* USB dependencies initialization */
static void BSP_USB_Init(void * handle)
{
/* GPIO settings */
GPIO_vInitPin(USB_DM_PIN, USB_DM_CFG);
GPIO_vInitPin(USB_DP_PIN, USB_DP_CFG);

NVIC_SetPriorityConfig(OTG_FS_IRQn, 0x6, 0);
NVIC_EnableIRQ(OTG_FS_IRQn);

USB_vClockConfig(USB_CLOCKSOURCE_MSI);

PWR_vVddUSB(ENABLE);
}

/* USB dependencies deinitialization */
static void BSP_USB_Deinit(void * handle)
{
GPIO_vDeinitPin(USB_DM_PIN);
GPIO_vDeinitPin(USB_DP_PIN);
NVIC_DisableIRQ(OTG_FS_IRQn);
PWR_vVddUSB(DISABLE);
}

extern USB_HandleType *const UsbDevice;

void BSP_USB_Bind(void)
{
USB_INST2HANDLE(UsbDevice, USB_OTG_FS);
UsbDevice->Callbacks.DepInit = BSP_USB_Init;
UsbDevice->Callbacks.DepDeinit = BSP_USB_Deinit;
}

/* Common interrupt handler for USB core and WKUP line */
void OTG_FS_IRQHandler(void)
{
EXTI_vClearFlag(USB_OTG_FS_WAKEUP_EXTI_LINE);

/* Handle USB interrupts */
USB_vIRQHandler(UsbDevice);
}
39 changes: 39 additions & 0 deletions BSP_STM32L4xx/bsp_usb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
******************************************************************************
* @file bsp_usb.h
* @author Benedek Kupper
* @version 0.1
* @date 2018-12-16
* @brief IPoverUSB BSP for USB communication
*
* Copyright (c) 2018 Benedek Kupper
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __BSP_USB_H_
#define __BSP_USB_H_

#ifdef __cplusplus
extern "C"
{
#endif

#include <xpd_usb.h>

void BSP_USB_Bind(void);

#ifdef __cplusplus
}
#endif

#endif /* __BSP_USB_H_ */
Loading

0 comments on commit bb62c88

Please sign in to comment.