Trailing white spaces removed

This commit is contained in:
Martin Jaeger
2019-11-21 07:44:15 +01:00
parent 7952ac99b0
commit 74b765e801
26 changed files with 391 additions and 396 deletions
+22 -22
View File
@@ -1,10 +1,10 @@
/*
* Scene Connect Bootloader
* Copyright (C) 2019 Scene Connect
* Copyright (C) 2019 Scene Connect
* https://www.scene.community/
*
* This code is developed based on the Okra Bootloader from Okra Solar.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
@@ -39,10 +39,10 @@ void flash_unlock(void)
if (HAL_IS_BIT_SET(FLASH->PECR, FLASH_PECR_PELOCK)) {
WRITE_REG(FLASH->PEKEYR, FLASH_PEKEY1);
WRITE_REG(FLASH->PEKEYR, FLASH_PEKEY2);
}
}
/* Unlocking the program memory access */
WRITE_REG(FLASH->PRGKEYR, FLASH_PRGKEY1);
WRITE_REG(FLASH->PRGKEYR, FLASH_PRGKEY2);
WRITE_REG(FLASH->PRGKEYR, FLASH_PRGKEY2);
}
else {
// Error handler
@@ -54,7 +54,7 @@ void flash_unlock(void)
* (1) Perform the data write (32-bit word) at the desired address
* (2) Wait until the BSY bit is reset in the FLASH_SR register
* (3) Check the EOP flag in the FLASH_SR register
* (4) clear it by software by writing it at 1
* (4) clear it by software by writing it at 1
*/
void flash_program(uint32_t address, uint32_t data)
{
@@ -81,31 +81,31 @@ void write_status_reg(BootloaderStatus& status)
// Make sure the status reg is halfword aligned
// Check if this is really required.
static_assert(sizeof(status) % 2 == 0);
// Unlock the FLASH_PECR register access.
// Then unlock the program memory access.
flash_unlock();
flash_unlock();
/*
/*
* Erase a page in the Flash at BOOTLOADER_STATUS_STRUCT_ADDR - For STM32L073RZ
* (1) Set the ERASE and PROG bits in the FLASH_PECR register to enable page erasing
* (2) Write a 32-bit word value in an address of the selected page to start the erase sequence
* (3) Wait until the BSY bit is reset in the FLASH_SR register
* (4) Check the EOP flag in the FLASH_SR register
* (5) Clear EOP flag by software by writing EOP at 1
* (6) Reset the ERASE and PROG bits in the FLASH_PECR register to disable the page erase
* Program and erase control register (FLASH_PECR) - This register can only be written after a
* (1) Set the ERASE and PROG bits in the FLASH_PECR register to enable page erasing
* (2) Write a 32-bit word value in an address of the selected page to start the erase sequence
* (3) Wait until the BSY bit is reset in the FLASH_SR register
* (4) Check the EOP flag in the FLASH_SR register
* (5) Clear EOP flag by software by writing EOP at 1
* (6) Reset the ERASE and PROG bits in the FLASH_PECR register to disable the page erase
* Program and erase control register (FLASH_PECR) - This register can only be written after a
* good write sequence done in FLASH_PEKEYR, resetting the PELOCK bit.
*/
FLASH->PECR |= FLASH_PECR_ERASE | FLASH_PECR_PROG;
*(__IO uint32_t *)BOOTLOADER_STATUS_STRUCT_ADDR = (uint32_t)0;
while ((FLASH->SR & FLASH_SR_BSY) != 0) {
/* For robust implementation, add here time-out management */
}
if ((FLASH->SR & FLASH_SR_EOP) != 0) {
if ((FLASH->SR & FLASH_SR_EOP) != 0) {
FLASH->SR = FLASH_SR_EOP;
}
else {
@@ -123,17 +123,17 @@ void write_status_reg(BootloaderStatus& status)
* (6) Reset the PROG and FPRG bits to disable programming
*/
uint32_t *data = (uint32_t *)&status;
uint32_t address = BOOTLOADER_STATUS_STRUCT_ADDR;
uint32_t address = BOOTLOADER_STATUS_STRUCT_ADDR;
for (unsigned int i = 0; i < sizeof(status) / sizeof(uint32_t); i++) {
flash_program(address, *data);
flash_program(address, *data);
data++;
address += 4;
}
}
// Locking FLASH_PECR register again
// Set the PRGLOCK Bit to lock the FLASH Registers access
SET_BIT(FLASH->PECR, FLASH_PECR_PRGLOCK);
// Set the PRGLOCK Bit to lock the FLASH Registers access
SET_BIT(FLASH->PECR, FLASH_PECR_PRGLOCK);
}
// Called from main
+10 -10
View File
@@ -1,10 +1,10 @@
/*
* Scene Connect Bootloader
* Copyright (C) 2019 Scene Connect
* Copyright (C) 2019 Scene Connect
* https://www.scene.community/
*
* This code is developed based on the Okra Bootloader from Okra Solar.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
@@ -41,14 +41,14 @@ const uint8_t BOOTLADER_NAME_LENGTH = 18;
* Flash address for the bootloader status structure.
* This address must be aligned to a flash page. Each time a new application
* is detected by the bootloader (BootloaderState::newApp),
* the full page is erased, and the updated struct is written to the address
* the full page is erased, and the updated struct is written to the address
*/
const uint32_t BOOTLOADER_STATUS_STRUCT_ADDR = 0x0802FF80; // The last flash page
/**
* Bootloader state enumeration. This state needs to be set to "newApp"
* by the application after an update, and to "stableApp" after the
* first successful boot
* first successful boot
*/
enum BootloaderState {
NO_STATE = 0, ///< State not properly initialized
@@ -57,22 +57,22 @@ enum BootloaderState {
STABLE_APP, ///< Set by App after sucessful boot of the new app
};
/**
/**
* Bootloader status struct. This struct's status field should be updated
* in flash by the app after first boot (stableApp) or after an update of the
* other firmware binary (newApp)
* other firmware binary (newApp)
*/
struct BootloaderStatus {
char bootloader_name[BOOTLADER_NAME_LENGTH];
uint32_t bootloader_version;
uint32_t status; ///< Update this field and write to flash in your app!
uint32_t live_app_select;
uint32_t live_app_select;
uint32_t retry_count;
};
/**
* Write the bootloader status to the flash address 'BOOTLOADER_STATUS_STRUCT_ADDR'.
*
*
* @param status: The struct containing the bootloader status information.
*/
void write_status_reg(BootloaderStatus &status);
@@ -87,8 +87,8 @@ void flash_unlock(void);
* (1) Perform the data write (32-bit word) at the desired address
* (2) Wait until the BSY bit is reset in the FLASH_SR register
* (3) Check the EOP flag in the FLASH_SR register
* (4) clear it by software by writing it at 1
*
* (4) clear it by software by writing it at 1
*
* @param address The flash address to write to.
* @param data The data to write to the flash.
*/
+8 -6
View File
@@ -45,7 +45,7 @@ const uint16_t eeprom_data_objects[] = {
#ifndef UNIT_TEST
uint32_t _calc_crc(uint8_t *buf, size_t len)
uint32_t _calc_crc(const uint8_t *buf, size_t len)
{
RCC->AHBENR |= RCC_AHBENR_CRCEN;
@@ -134,9 +134,9 @@ int eeprom_read (unsigned int addr, uint8_t* ret, int len)
int err = 0;
if (EEPROM_ADDRESS_SIZE == 1) {
// write the address we want to read
// write the address we want to read
buf[0] = addr & 0xFF;
// send memory address without stop (repeated = true)
// send memory address without stop (repeated = true)
err = i2c_eeprom.write(device, (char*)buf, 1, true);
}
else {
@@ -156,7 +156,7 @@ int eeprom_read (unsigned int addr, uint8_t* ret, int len)
#elif defined(STM32L0) // internal EEPROM
int eeprom_write (unsigned int addr, uint8_t* data, int len)
int eeprom_write (unsigned int addr, const uint8_t* data, int len)
{
int timeout = 0;
@@ -171,8 +171,9 @@ int eeprom_write (unsigned int addr, uint8_t* data, int len)
FLASH->PEKEYR = FLASH_PEKEY2;
}
if (addr + len > DATA_EEPROM_BANK1_END - DATA_EEPROM_BASE)
if (addr + len > DATA_EEPROM_BANK1_END - DATA_EEPROM_BASE) {
return -1;
}
// write data byte-wise to EEPROM
for (int i = 0; i < len; i++) {
@@ -191,8 +192,9 @@ int eeprom_write (unsigned int addr, uint8_t* data, int len)
int eeprom_read (unsigned int addr, uint8_t* ret, int len)
{
if (addr + len > DATA_EEPROM_BANK1_END - DATA_EEPROM_BASE)
if (addr + len > DATA_EEPROM_BANK1_END - DATA_EEPROM_BASE) {
return -1;
}
memcpy(ret, ((uint8_t*)addr) + DATA_EEPROM_BASE, len);
return 0;
+2 -2
View File
@@ -26,13 +26,13 @@
*
* @returns 0 for success
*/
int eeprom_write(unsigned int addr, uint8_t* data, int len);
int eeprom_write(unsigned int addr, const uint8_t* data, int len);
/** Read data from EEPROM address
*
* @returns 0 for success
*/
int eeprom_read(unsigned int addr, uint8_t* ret, int len);
int eeprom_read(unsigned int addr, const uint8_t* ret, int len);
/** Store current charge controller data to EEPROM
*/
@@ -135,7 +135,7 @@ class PWM_TIM1
GPIOA->MODER = (GPIOA->MODER & ~(GPIO_MODER_MODER8)) | GPIO_MODER_MODER8_1;
GPIOB->MODER = (GPIOB->MODER & ~(GPIO_MODER_MODER13)) | GPIO_MODER_MODER13_1;
// Select AF2 on PA8 (TIM1_CH1) and PB13 (TIM1_CH1N)
GPIOA->AFR[1] |= 0x2 << GPIO_AFRH_AFSEL8_Pos;
GPIOB->AFR[1] |= 0x2 << GPIO_AFRH_AFSEL13_Pos;
@@ -263,12 +263,12 @@ void half_bridge_init(int freq_kHz, int deadtime_ns, float min_duty, float max_d
{
// timers are counting at system clock
// we are using a mode which counts up and down in each period
// so we need half the impluses as resolution for the given frequency.
_pwm_resolution = SystemCoreClock / (freq_kHz * 1000) / 2;
// so we need half the impluses as resolution for the given frequency.
_pwm_resolution = SystemCoreClock / (freq_kHz * 1000) / 2;
// (clocks per ms * deadtime in ns) / 1000 == (clocks per ms * deadtime in ms)
// although the C operator precedence does the "right thing" to allow deadtime_ns < 1000 to
// be handled nicely, parentheses make this more explicit
// although the C operator precedence does the "right thing" to allow deadtime_ns < 1000 to
// be handled nicely, parentheses make this more explicit
_deadtime_clocks = ((SystemCoreClock / (1000000)) * deadtime_ns) / 1000;
PWM_TIM_HW::_init_registers(_pwm_resolution);
@@ -329,4 +329,3 @@ bool half_bridge_enabled()
{
return _enabled;
}
+1 -1
View File
@@ -78,7 +78,7 @@ void ThingSetStream::process_input()
// backspace
// can be done always unless there is nothing in the buffer
else if (req_pos > 0 && c == '\b') {
else if (req_pos > 0 && c == '\b') {
req_pos--;
}
// we fill the buffer up to all but 1 character
-1
View File
@@ -65,4 +65,3 @@ UExtInterface::UExtInterface() {
}
UExtInterfaceManager uext;
+3 -3
View File
@@ -60,7 +60,7 @@ class UExtInterfaceManager
/**
* Adds an UExtInterface object to the list of managed extensions,
* automatically called by UExtInterface objects during construction
* automatically called by UExtInterface objects during construction
*/
static void add_ext(UExtInterface*);
@@ -72,8 +72,8 @@ class UExtInterfaceManager
*/
static std::vector<UExtInterface*>* interfaces;
/**
* Makes sure there is an internal interfacts vector created, does nothing if it exists
/**
* Makes sure there is an internal interfacts vector created, does nothing if it exists
*/
static void check_list();
};