diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -10,7 +10,7 @@ LIBDIR:=libraries
HAL_LIB:=$(LIBDIR)/STM32F0xx_HAL_Driver
USB_LIB:=$(LIBDIR)/STM32_USB_Device_Library
-STARTUP:=$(STMLIB)/CMSIS/Device/ST/STM32F0xx/Source/Templates/gcc_ride7
+STARTUP:=$(STMLIB)/CMSIS/Device/ST/STM32F0xx/Source/Templates/gcc
LINKER_SCRIPT:=$(CURDIR)/stm32-flash.ld
@@ -31,22 +31,24 @@ INCLUDE+=-I$(HAL_LIB)/Inc
# vpath is used so object files are written to the current directory instead
# of the same directory as their source files
-vpath %.c $(DISCOVERY) $(STD_PERIPH)/src \
- $(STMLIB)/USB \
- $(STMLIB)/STM32_USB-FS_Device_Library/Class/hid/src \
- $(STMLIB)/STM32_USB-FS_Device_Library/Core/src
+vpath %.c $(HAL_LIB)/src \
+ $(LIBDIR)/$(USB_LIB) \
+ $(LIBDIR)/$(USB_LIB)/Class/CDC \
+ $(LIBDIR)/$(USB_LIB)/Core
vpath %.s $(STARTUP)
-ASRC=startup_stm32f042.s
+ASRC=startup_stm32f042x6.s
# Project Source Files
SRC=main.c
SRC+=stm32f0xx_it.c
+SRC+=stm32f0xx_hal_msp.c
SRC+=system_stm32f0xx.c
SRC+=ssd1306.c
SRC+=eeprom_min.c
SRC+=gpio.c
SRC+=spi.c
+SRC+=clock.c
SRC+=stringhelpers.c
# Discovery Source Files
diff --git a/eeprom_min.h b/eeprom_min.h
--- a/eeprom_min.h
+++ b/eeprom_min.h
@@ -15,11 +15,12 @@
#define EEPROM_ADDR_UNITS 0x0038
-
+/*
void Minimal_EEPROM_Unlock(void);
void Minimal_EEPROM_Lock(void);
FLASH_Status Minimal_FLASH_GetStatus(void);
FLASH_Status Minimal_FLASH_WaitForLastOperation(uint32_t Timeout);
void Minimal_EEPROM_ProgramWord(uint32_t Address, uint32_t Data);
+*/
#endif
diff --git a/hw_config.c b/hw_config.c
deleted file mode 100644
--- a/hw_config.c
+++ /dev/null
@@ -1,296 +0,0 @@
-/**
- ******************************************************************************
- * @file hw_config.c
- * @author MCD Application Team
- * @version V4.0.0
- * @date 21-January-2013
- * @brief Hardware Configuration & Setup
- ******************************************************************************
- * @attention
- *
- *
© COPYRIGHT 2013 STMicroelectronics
- *
- * Licensed under MCD-ST Liberty SW License Agreement V2, (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.st.com/software_license_agreement_liberty_v2
- *
- * 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.
- *
- ******************************************************************************
- */
-
-/* Includes ------------------------------------------------------------------*/
-
-#include "stm32_it.h"
-#include "usb_lib.h"
-#include "usb_prop.h"
-#include "usb_desc.h"
-#include "hw_config.h"
-#include "usb_pwr.h"
-
-/* Private typedef -----------------------------------------------------------*/
-/* Private define ------------------------------------------------------------*/
-/* Private macro -------------------------------------------------------------*/
-/* Private variables ---------------------------------------------------------*/
-ErrorStatus HSEStartUpStatus;
-EXTI_InitTypeDef EXTI_InitStructure;
-extern __IO uint32_t packet_sent;
-extern __IO uint8_t Send_Buffer[VIRTUAL_COM_PORT_DATA_SIZE] ;
-extern __IO uint32_t packet_receive;
-extern __IO uint8_t Receive_length;
-
-uint8_t Receive_Buffer[64];
-uint32_t Send_length;
-static void IntToUnicode (uint32_t value , uint8_t *pbuf , uint8_t len);
-/* Extern variables ----------------------------------------------------------*/
-
-extern LINE_CODING linecoding;
-
-/* Private function prototypes -----------------------------------------------*/
-/* Private functions ---------------------------------------------------------*/
-/*******************************************************************************
-* Function Name : Set_System
-* Description : Configures Main system clocks & power
-* Input : None.
-* Return : None.
-*******************************************************************************/
-void Set_System(void)
-{
- GPIO_InitTypeDef GPIO_InitStructure;
-
-#if defined(USB_USE_EXTERNAL_PULLUP)
- GPIO_InitTypeDef GPIO_InitStructure;
-#endif /* USB_USE_EXTERNAL_PULLUP */
-
- /*!< At this stage the microcontroller clock setting is already configured,
- this is done through SystemInit() function which is called from startup
- file (startup_stm32f10x_xx.s) before to branch to application main.
- To reconfigure the default setting of SystemInit() function, refer to
- system_stm32f10x.c file
- */
- /* Enable the SYSCFG module clock */
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
-
- /* Enable USB_DISCONNECT GPIO clock */
- //RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIO_DISCONNECT, ENABLE);
-
- /* Configure USB pull-up pin */
- //GPIO_InitStructure.GPIO_Pin = USB_DISCONNECT_PIN;
- //GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
- //GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
- //GPIO_Init(USB_DISCONNECT, &GPIO_InitStructure);
-
-#if defined(USB_USE_EXTERNAL_PULLUP)
- /* Enable the USB disconnect GPIO clock */
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIO_DISCONNECT, ENABLE);
-
- /* USB_DISCONNECT used as USB pull-up */
- GPIO_InitStructure.GPIO_Pin = USB_DISCONNECT_PIN;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
- GPIO_Init(USB_DISCONNECT, &GPIO_InitStructure);
-#endif /* USB_USE_EXTERNAL_PULLUP */
-
- /* Configure the EXTI line 18 connected internally to the USB IP */
- EXTI_ClearITPendingBit(EXTI_Line18);
- EXTI_InitStructure.EXTI_Line = EXTI_Line18;
- EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
- EXTI_InitStructure.EXTI_LineCmd = ENABLE;
- EXTI_Init(&EXTI_InitStructure);
-}
-
-/*******************************************************************************
-* Function Name : Set_USBClock
-* Description : Configures USB Clock input (48MHz)
-* Input : None.
-* Return : None.
-*******************************************************************************/
-void Set_USBClock(void)
-{
- /* Enable USB clock */
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB, ENABLE);
-}
-
-/*******************************************************************************
-* Function Name : Enter_LowPowerMode
-* Description : Power-off system clocks and power while entering suspend mode
-* Input : None.
-* Return : None.
-*******************************************************************************/
-void Enter_LowPowerMode(void)
-{
- /* Set the device state to suspend */
- bDeviceState = SUSPENDED;
-}
-
-/*******************************************************************************
-* Function Name : Leave_LowPowerMode
-* Description : Restores system clocks and power while exiting suspend mode
-* Input : None.
-* Return : None.
-*******************************************************************************/
-void Leave_LowPowerMode(void)
-{
- DEVICE_INFO *pInfo = &Device_Info;
-
- /* Set the device state to the correct state */
- if (pInfo->Current_Configuration != 0)
- {
- /* Device configured */
- bDeviceState = CONFIGURED;
- }
- else
- {
- bDeviceState = ATTACHED;
- }
- /*Enable SystemCoreClock*/
- SystemInit();
-}
-
-/*******************************************************************************
-* Function Name : USB_Interrupts_Config
-* Description : Configures the USB interrupts
-* Input : None.
-* Return : None.
-*******************************************************************************/
-void USB_Interrupts_Config(void)
-{
-NVIC_InitTypeDef NVIC_InitStructure;
-
- /* 2 bit for pre-emption priority, 2 bits for subpriority */
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
-
- /* Enable the USB interrupt */
- NVIC_InitStructure.NVIC_IRQChannel = USB_LP_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
-
- /* Enable the USB Wake-up interrupt */
- NVIC_InitStructure.NVIC_IRQChannel = USB_FS_WKUP_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
-}
-
-/*******************************************************************************
-* Function Name : USB_Cable_Config
-* Description : Software Connection/Disconnection of USB Cable
-* Input : None.
-* Return : Status
-*******************************************************************************/
-void USB_Cable_Config (FunctionalState NewState)
-{
- if (NewState != DISABLE)
- {
- STM32L15_USB_CONNECT;
- }
- else
- {
- STM32L15_USB_DISCONNECT;
- }
-}
-
-/*******************************************************************************
-* Function Name : Get_SerialNum.
-* Description : Create the serial number string descriptor.
-* Input : None.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void Get_SerialNum(void)
-{
- uint32_t Device_Serial0, Device_Serial1, Device_Serial2;
-
- Device_Serial0 = *(uint32_t*)ID1;
- Device_Serial1 = *(uint32_t*)ID2;
- Device_Serial2 = *(uint32_t*)ID3;
-
- Device_Serial0 += Device_Serial2;
-
- if (Device_Serial0 != 0)
- {
- IntToUnicode (Device_Serial0, &Virtual_Com_Port_StringSerial[2] , 8);
- IntToUnicode (Device_Serial1, &Virtual_Com_Port_StringSerial[18], 4);
- }
-}
-
-/*******************************************************************************
-* Function Name : HexToChar.
-* Description : Convert Hex 32Bits value into char.
-* Input : None.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-static void IntToUnicode (uint32_t value , uint8_t *pbuf , uint8_t len)
-{
- uint8_t idx = 0;
-
- for( idx = 0 ; idx < len ; idx ++)
- {
- if( ((value >> 28)) < 0xA )
- {
- pbuf[ 2* idx] = (value >> 28) + '0';
- }
- else
- {
- pbuf[2* idx] = (value >> 28) + 'A' - 10;
- }
-
- value = value << 4;
-
- pbuf[ 2* idx + 1] = 0;
- }
-}
-
-/*******************************************************************************
-* Function Name : Send DATA .
-* Description : send the data received from the STM32 to the PC through USB
-* Input : None.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-uint32_t CDC_Send_DATA (uint8_t *ptrBuffer, uint8_t Send_length)
-{
- /*if max buffer is Not reached*/
- if(Send_length < VIRTUAL_COM_PORT_DATA_SIZE)
- {
- /*Sent flag*/
- packet_sent = 0;
- /* send packet to PMA*/
- UserToPMABufferCopy((unsigned char*)ptrBuffer, ENDP1_TXADDR, Send_length);
- SetEPTxCount(ENDP1, Send_length);
- SetEPTxValid(ENDP1);
- }
- else
- {
- return 0;
- }
- return 1;
-}
-
-/*******************************************************************************
-* Function Name : Receive DATA .
-* Description : receive the data from the PC to STM32 and send it through USB
-* Input : None.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-uint32_t CDC_Receive_DATA(void)
-{
- /*Receive flag*/
- packet_receive = 0;
- SetEPRxValid(ENDP3);
- return 1 ;
-}
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/hw_config.h b/hw_config.h
deleted file mode 100644
--- a/hw_config.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/**
- ******************************************************************************
- * @file hw_config.h
- * @author MCD Application Team
- * @version V4.0.0
- * @date 21-January-2013
- * @brief Hardware Configuration & Setup
- ******************************************************************************
- * @attention
- *
- * © COPYRIGHT 2013 STMicroelectronics
- *
- * Licensed under MCD-ST Liberty SW License Agreement V2, (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.st.com/software_license_agreement_liberty_v2
- *
- * 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.
- *
- ******************************************************************************
- */
-
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef __HW_CONFIG_H
-#define __HW_CONFIG_H
-
-/* Includes ------------------------------------------------------------------*/
-#include "platform_config.h"
-#include "usb_type.h"
-
-/* Exported types ------------------------------------------------------------*/
-/* Exported constants --------------------------------------------------------*/
-/* Exported macro ------------------------------------------------------------*/
-/* Exported define -----------------------------------------------------------*/
-#define MASS_MEMORY_START 0x04002000
-#define BULK_MAX_PACKET_SIZE 0x00000040
-#define LED_ON 0xF0
-#define LED_OFF 0xFF
-
-/* Exported functions ------------------------------------------------------- */
-void Set_System(void);
-void Set_USBClock(void);
-void Enter_LowPowerMode(void);
-void Leave_LowPowerMode(void);
-void USB_Interrupts_Config(void);
-void USB_Cable_Config (FunctionalState NewState);
-void Get_SerialNum(void);
-void LCD_Control(void);
-uint32_t CDC_Send_DATA (uint8_t *ptrBuffer, uint8_t Send_length);
-uint32_t CDC_Receive_DATA(void);
-/* External variables --------------------------------------------------------*/
-
-#endif /*__HW_CONFIG_H*/
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/main.c b/main.c
--- a/main.c
+++ b/main.c
@@ -1,4 +1,5 @@
#include "main.h"
+#include "stm32f0xx_hal_conf.h"
#include "usb_device.h"
#include "ssd1306.h"
#include "config.h"
diff --git a/main.h b/main.h
--- a/main.h
+++ b/main.h
@@ -1,6 +1,8 @@
#ifndef __MAIN_H
#define __MAIN_H
+#define STM32F042x6
+
#include "stm32f0xx_hal_conf.h"
void TimingDelay_Decrement(void);
diff --git a/platform_config.h b/platform_config.h
deleted file mode 100644
--- a/platform_config.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/**
- ******************************************************************************
- * @file platform_config.h
- * @author MCD Application Team
- * @version V4.0.0
- * @date 21-January-2013
- * @brief Evaluation board specific configuration file.
- ******************************************************************************
- * @attention
- *
- * © COPYRIGHT 2013 STMicroelectronics
- *
- * Licensed under MCD-ST Liberty SW License Agreement V2, (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.st.com/software_license_agreement_liberty_v2
- *
- * 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.
- *
- ******************************************************************************
- */
-
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef __PLATFORM_CONFIG_H
-#define __PLATFORM_CONFIG_H
-
-/* Includes ------------------------------------------------------------------*/
-#include "stm32f0xx.h"
-
-/* Exported types ------------------------------------------------------------*/
-
-/*Unique Devices IDs register set*/
-#define ID1 (0x1FF80050)
-#define ID2 (0x1FF80054)
-#define ID3 (0x1FF80064)
-
-#if !defined(USB_USE_EXTERNAL_PULLUP)
- #define STM32L15_USB_CONNECT SYSCFG_USBPuCmd(ENABLE)
- #define STM32L15_USB_DISCONNECT SYSCFG_USBPuCmd(DISABLE)
-
-#elif defined(USB_USE_EXTERNAL_PULLUP)
- /* PA0 is chosen just as illustrating example, you should modify the defines
- below according to your hardware configuration. */
- #define USB_DISCONNECT GPIOA
- #define USB_DISCONNECT_PIN GPIO_Pin_0
- #define RCC_AHBPeriph_GPIO_DISCONNECT RCC_AHBPeriph_GPIOA
- #define STM32L15_USB_CONNECT GPIO_ResetBits(USB_DISCONNECT, USB_DISCONNECT_PIN)
- #define STM32L15_USB_DISCONNECT GPIO_SetBits(USB_DISCONNECT, USB_DISCONNECT_PIN)
-#endif /* USB_USE_EXTERNAL_PULLUP */
-
-/* Exported macro ------------------------------------------------------------*/
-/* Exported functions ------------------------------------------------------- */
-
-#endif /* __PLATFORM_CONFIG_H */
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/