Skip to content

Commit

Permalink
Develop (#20)
Browse files Browse the repository at this point in the history
* Refactor (#19)

* refactor code

* Refactor code

* refactor

* refactor

* fixed auto-power off

* added read information from TrueRamaining Capacity register in bq27441

* time measurements during charging

* fix auto power off

* Update CMake

* added tinyprinf for embedded applications

* refactor&optimisation code

* need debug tinyprintf

* added copy eeprom data in FullFW.bin adress 1FC00, physical adress in STM 0x801FC00

* added configuration files for OpenOCD debuger

* refactor CMake, add variable for seek memory via 128kb or 64kb flash (for last page, where is eeprom)

* update gitignore

* clean & refactor main.c .h

* update gitignore

* refactor & fix up calculate mah, init app

* update version
  • Loading branch information
cvetaevvitaliy authored Aug 31, 2020
1 parent ef99001 commit 12b2bd5
Show file tree
Hide file tree
Showing 25 changed files with 1,317 additions and 778 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,5 @@ fabric.properties
.osx.project
.project
CMakeLists_template.txt
.idea/misc.xml
/build/
23 changes: 11 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ cmake_minimum_required(VERSION 3.7)

set(VERSION_RELEASE 1)
set(VERSION_MAJOR 0)
set(VERSION_MINOR 7)
set(VERSION_MINOR 8)
set(VERSION_FW "${VERSION_RELEASE}.${VERSION_MAJOR}.${VERSION_MINOR}")
set(FIRMWARE_NAME firmware)

add_definitions(-DSOFTWARE_VERSION=\"${VERSION_FW}\")
if (DEBUG STREQUAL ON)
add_definitions(-DUSE_USB_DEBUG_PRINTF)
set(OPTIMIZATION_LEVEL -g)
else()
else()
set(OPTIMIZATION_LEVEL -O2)
endif()

Expand Down Expand Up @@ -50,7 +50,7 @@ set(SIZE arm-none-eabi-size)
#SET(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/STM32F103TBUx_FLASH.ld)

SET(COMMON_FLAGS
"-mcpu=cortex-m3 ${FPU_FLAGS} -mthumb -mthumb-interwork -ffunction-sections -fdata-sections \
"-mcpu=cortex-m3 ${FPU_FLAGS} -mthumb -mthumb-interwork -ffunction-sections -fdata-sections \
${OPTIMIZATION_LEVEL} -fno-common -fmessage-length=0 -specs=nosys.specs -specs=nano.specs")

SET(CMAKE_CXX_FLAGS_INIT "${COMMON_FLAGS} -std=c++11")
Expand Down Expand Up @@ -90,25 +90,24 @@ include_directories(Inc
add_executable(${PROJECT_NAME}.elf ${SOURCES} ${LINKER_SCRIPT})

set(CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS} -Wl,-u,_printf_float,-Map=${PROJECT_BINARY_DIR}/${PROJECT_NAME}.map")
"${CMAKE_EXE_LINKER_FLAGS} -Wl,-u,_printf_float,-Map=${PROJECT_BINARY_DIR}/${PROJECT_NAME}.map")


set(BIN_FILE ${PROJECT_BINARY_DIR}/${FIRMWARE_NAME}-${VERSION_RELEASE}.${VERSION_MAJOR}.${VERSION_MINOR}.bin)

add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD
COMMAND ${SIZE} --format=berkeley ${PROJECT_NAME}.elf
COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${PROJECT_NAME}.elf> ${BIN_FILE}
COMMAND echo
#COMMAND ${CMAKE_OBJDUMP} -x $<TARGET_FILE:${PROJECT_NAME}.elf>
COMMAND echo \"*****************************************************************\"
COMMAND echo Start create Full firmware for flash via SWD
COMMAND echo Address in Flash 0x8000000 bootloader.bin
COMMAND echo Address in Flash 0x8000800 ${FIRMWARE_NAME}-${VERSION_RELEASE}.${VERSION_MAJOR}.${VERSION_MINOR}.bin
COMMAND echo Address in Flash ${EEPROM} eeprom.bin
COMMAND echo In Flash memory 0x8000000 bootloader.bin
COMMAND echo In Flash memory 0x8000800 ${FIRMWARE_NAME}-${VERSION_RELEASE}.${VERSION_MAJOR}.${VERSION_MINOR}.bin
COMMAND echo In Flash memory 0x801FC00 eeprom data for STM32F103TBU and 0x800FC00 for STM32F103T8U
COMMAND dd if=${PROJECT_SOURCE_DIR}/bootloader.bin of=FullFW.bin bs=1 count=2048
COMMAND dd if=${PROJECT_BINARY_DIR}/${FIRMWARE_NAME}-${VERSION_RELEASE}.${VERSION_MAJOR}.${VERSION_MINOR}.bin of=FullFW.bin bs=1 seek=2048
COMMAND dd if=${PROJECT_SOURCE_DIR}/eeprom.bin of=FullFW.bin bs=1 seek=${SEEK_DATA}
COMMAND echo \"\\033[1;34mFinish create file FullFW.bin for flash via SWD complete\\033[0m\"
COMMAND echo \"\\033[1;34mBut please use ${FIRMWARE_NAME}-${VERSION_RELEASE}.${VERSION_MAJOR}.${VERSION_MINOR}.bin for update firmware via bootloader \\033[0m\"
COMMAND echo Full patch ${PROJECT_BINARY_DIR}/FullFW.bin
COMMAND echo File FullFW.bin created complete
COMMAND echo \"*****************************************************************\"
COMMENT "Building complete: ${BIN_FILE}")
COMMENT "Building ${HEX_FILE}
Building ${BIN_FILE}")
53 changes: 25 additions & 28 deletions FatShark_Power_V1.ioc
Original file line number Diff line number Diff line change
Expand Up @@ -65,33 +65,32 @@ Mcu.Name=STM32F103T(8-B)Ux
Mcu.Package=VFQFPN36
Mcu.Pin0=PD0-OSC_IN
Mcu.Pin1=PD1-OSC_OUT
Mcu.Pin10=PB2
Mcu.Pin11=PA8
Mcu.Pin12=PA11
Mcu.Pin13=PA12
Mcu.Pin14=PA13
Mcu.Pin15=PA14
Mcu.Pin16=PA15
Mcu.Pin17=PB3
Mcu.Pin18=PB4
Mcu.Pin19=PB5
Mcu.Pin10=PA8
Mcu.Pin11=PA11
Mcu.Pin12=PA12
Mcu.Pin13=PA13
Mcu.Pin14=PA14
Mcu.Pin15=PA15
Mcu.Pin16=PB3
Mcu.Pin17=PB4
Mcu.Pin18=PB5
Mcu.Pin19=PB6
Mcu.Pin2=PA0-WKUP
Mcu.Pin20=PB6
Mcu.Pin21=PB7
Mcu.Pin22=VP_ADC1_TempSens_Input
Mcu.Pin23=VP_RTC_VS_RTC_Activate
Mcu.Pin24=VP_SYS_VS_Systick
Mcu.Pin25=VP_TIM1_VS_ClockSourceINT
Mcu.Pin26=VP_TIM2_VS_ClockSourceINT
Mcu.Pin27=VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS
Mcu.Pin20=PB7
Mcu.Pin21=VP_ADC1_TempSens_Input
Mcu.Pin22=VP_RTC_VS_RTC_Activate
Mcu.Pin23=VP_SYS_VS_Systick
Mcu.Pin24=VP_TIM1_VS_ClockSourceINT
Mcu.Pin25=VP_TIM2_VS_ClockSourceINT
Mcu.Pin26=VP_USB_DEVICE_VS_USB_DEVICE_CDC_FS
Mcu.Pin3=PA1
Mcu.Pin4=PA2
Mcu.Pin5=PA4
Mcu.Pin6=PA5
Mcu.Pin7=PA7
Mcu.Pin8=PB0
Mcu.Pin9=PB1
Mcu.PinsNb=28
Mcu.PinsNb=27
Mcu.ThirdPartyNb=0
Mcu.UserConstants=
Mcu.UserName=STM32F103TBUx
Expand All @@ -103,6 +102,7 @@ NVIC.DMA1_Channel6_IRQn=true\:0\:0\:false\:false\:true\:false
NVIC.DMA1_Channel7_IRQn=true\:0\:0\:false\:false\:true\:false
NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false
NVIC.EXTI15_10_IRQn=true\:0\:0\:false\:false\:true\:true
NVIC.EXTI1_IRQn=true\:0\:0\:false\:false\:true\:true
NVIC.EXTI2_IRQn=true\:0\:0\:false\:false\:true\:true
NVIC.EXTI9_5_IRQn=true\:0\:0\:false\:false\:true\:true
NVIC.FLASH_IRQn=true\:0\:0\:false\:false\:true\:true
Expand All @@ -121,10 +121,10 @@ NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false
PA0-WKUP.Mode=SYS_WakeUp0
PA0-WKUP.Signal=SYS_WKUP
PA1.GPIOParameters=GPIO_PuPd,GPIO_Label
PA1.GPIO_Label=Button1
PA1.GPIO_Label=Button_Menu
PA1.GPIO_PuPd=GPIO_PULLDOWN
PA1.Locked=true
PA1.Signal=GPIO_Input
PA1.Signal=GPXTI1
PA11.Mode=Device
PA11.Signal=USB_DM
PA12.Mode=Device
Expand All @@ -139,10 +139,10 @@ PA15.GPIO_PuPd=GPIO_PULLDOWN
PA15.Locked=true
PA15.Signal=GPXTI15
PA2.GPIOParameters=GPIO_PuPd,GPIO_Label
PA2.GPIO_Label=Button2
PA2.GPIO_Label=Button_Select
PA2.GPIO_PuPd=GPIO_PULLDOWN
PA2.Locked=true
PA2.Signal=GPIO_Input
PA2.Signal=GPXTI2
PA4.GPIOParameters=GPIO_Label
PA4.GPIO_Label=USB_En
PA4.Locked=true
Expand All @@ -161,11 +161,6 @@ PA8.GPIO_Label=PWM_Buzz
PA8.Signal=S_TIM1_CH1
PB0.Signal=ADCx_IN8
PB1.Signal=ADCx_IN9
PB2.GPIOParameters=GPIO_PuPd,GPIO_Label
PB2.GPIO_Label=IRQ_BAT_LOW
PB2.GPIO_PuPd=GPIO_PULLDOWN
PB2.Locked=true
PB2.Signal=GPXTI2
PB3.GPIOParameters=GPIO_Label
PB3.GPIO_Label=LCD_En
PB3.Locked=true
Expand Down Expand Up @@ -248,6 +243,8 @@ SH.ADCx_IN8.0=ADC1_IN8,IN8
SH.ADCx_IN8.ConfNb=1
SH.ADCx_IN9.0=ADC1_IN9,IN9
SH.ADCx_IN9.ConfNb=1
SH.GPXTI1.0=GPIO_EXTI1
SH.GPXTI1.ConfNb=1
SH.GPXTI15.0=GPIO_EXTI15
SH.GPXTI15.ConfNb=1
SH.GPXTI2.0=GPIO_EXTI2
Expand Down
89 changes: 7 additions & 82 deletions Inc/main.h
Original file line number Diff line number Diff line change
@@ -1,78 +1,21 @@
/**
******************************************************************************
* @file : main.h
* @brief : Header for main.c file.
* This file contains the common defines of the application.
******************************************************************************
* This notice applies to any and all portions of this file
* that are not between comment pairs USER CODE BEGIN and
* USER CODE END. Other portions of this file, whether
* inserted by the user or by software development tools
* are owned by their respective copyright owners.
*
* Copyright (c) 2020 STMicroelectronics International N.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted, provided that the following conditions are met:
*
* 1. Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of other
* contributors to this software may be used to endorse or promote products
* derived from this software without specific written permission.
* 4. This software, including modifications and/or derivative works of this
* software, must execute solely and exclusively on microcontroller or
* microprocessor devices manufactured by or for STMicroelectronics.
* 5. Redistribution and use of this software other than as permitted under
* this license is void and will automatically terminate your rights under
* this license.
*
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
* SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAIN_H__
#define __MAIN_H__

/* Includes ------------------------------------------------------------------*/

/* USER CODE BEGIN Includes */
//#define USE_USB_DEBUG_PRINTF
/* USER CODE END Includes */

/* Private define ------------------------------------------------------------*/
#define Error_Handler() _Error_Handler(__FILE__, __LINE__)

#define Button1_Pin GPIO_PIN_1
#define Button1_GPIO_Port GPIOA
#define Button2_Pin GPIO_PIN_2
#define Button2_GPIO_Port GPIOA
#define Button_Menu_Pin GPIO_PIN_1
#define ButtonMenu_GPIO_Port GPIOA
#define ButtonMenu_EXTI_IRQn EXTI1_IRQn
#define Button_Select_Pin GPIO_PIN_2
#define ButtonSelect_GPIO_Port GPIOA
#define ButtonSelect_EXTI_IRQn EXTI2_IRQn
#define USB_En_Pin GPIO_PIN_4
#define USB_En_GPIO_Port GPIOA
#define Bust_En_Pin GPIO_PIN_5
#define Bust_En_GPIO_Port GPIOA
#define CHG_Pin GPIO_PIN_7
#define CHG_GPIO_Port GPIOA
#define CHG_EXTI_IRQn EXTI9_5_IRQn
#define IRQ_BAT_LOW_Pin GPIO_PIN_2
#define IRQ_BAT_LOW_GPIO_Port GPIOB
#define IRQ_BAT_LOW_EXTI_IRQn EXTI2_IRQn
#define PWM_Buzz_Pin GPIO_PIN_8
#define PWM_Buzz_GPIO_Port GPIOA
#define Vbus_detect_Pin GPIO_PIN_15
Expand All @@ -85,27 +28,9 @@
#define Vout_En_12V_Pin GPIO_PIN_5
#define Vout_En_12V_GPIO_Port GPIOB

/* ########################## Assert Selection ############################## */
/**
* @brief Uncomment the line below to expanse the "assert_param" macro in the
* HAL drivers code
*/
/* #define USE_FULL_ASSERT 1U */

/* USER CODE BEGIN Private defines */
//#define USE_USB_DEBUG_PRINTF
/* USER CODE END Private defines */

#ifdef __cplusplus
extern "C" {
#endif
void _Error_Handler(char *, int);

#define Error_Handler() _Error_Handler(__FILE__, __LINE__)
#ifdef __cplusplus
}
#endif

#endif /* __MAIN_H__ */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
1 change: 1 addition & 0 deletions Inc/stm32f1xx_it.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ void PendSV_Handler(void);
void SysTick_Handler(void);
void FLASH_IRQHandler(void);
void RCC_IRQHandler(void);
void EXTI1_IRQHandler(void);
void EXTI2_IRQHandler(void);
void DMA1_Channel1_IRQHandler(void);
void DMA1_Channel6_IRQHandler(void);
Expand Down
Loading

0 comments on commit 12b2bd5

Please sign in to comment.