Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reset to DFU command #280

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions firmware/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ LDSCRIPT=app.ld

# C sources that can be compiled in ARM or THUMB mode depending on the global
# setting.
CSRC = $(ALLCSRC) $(BOARDDIR)/board.c
CSRC = $(ALLCSRC) \
$(BOARDDIR)/board.c \
boards/f1_common/openblt/shared_params.c
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we put boards/f1_common something in shared makefile?


# C++ sources that can be compiled in ARM or THUMB mode depending on the global
# setting.
Expand Down Expand Up @@ -182,7 +184,8 @@ INCDIR = $(CONFDIR) \
console/binary/ \
boards/ \
shared/ \
$(BOARDDIR)/io/
$(BOARDDIR)/io/ \
boards/f1_common/openblt

# Define C warning options here.
CWARN = -Wall -Wextra -Wundef -Wstrict-prototypes
Expand Down Expand Up @@ -231,9 +234,6 @@ ifeq ($(USE_OPENBLT),yes)
# Reserve start of flash for OpenBLT
USE_OPT += -Wl,--defsym=USE_BOOTLOADER=1
DDEFS += -DUSE_OPENBLT=TRUE
# Shared params
INCDIR += boards/f1_common/openblt
CSRC += boards/f1_common/openblt/shared_params.c
endif

#
Expand Down
41 changes: 37 additions & 4 deletions firmware/boards/f1_common/f1_port.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
#include "hal.h"
#include "hal_mfs.h"

#if USE_OPENBLT
/* communication with OpenBLT that is plain C, not to modify external file */
/* communication with OpenBLT that is plain C, not to modify external file
* Same code used to store "DFU-requested" flag */
extern "C" {
#include "openblt/shared_params.h"
};
#endif

// Storage
// TODO: runtime detection?
Expand Down Expand Up @@ -139,7 +138,7 @@ void rebootNow()

void rebootToOpenblt()
{
#if USE_OPENBLT
#ifdef USE_OPENBLT
/* safe to call on already inited shares area */
SharedParamsInit();
/* Store flag to stay in OpenBLT */
Expand All @@ -149,6 +148,40 @@ void rebootToOpenblt()
#endif
}

void rebootToDfu()
{
/* safe to call on already inited shares area */
SharedParamsInit();
/* Store flag to jump to DFU at main FW init */
SharedParamsWriteByIndex(0, 0x02);

rebootNow();
}

// stm32f10x XL-density devices
//#define BOOTLOADER_FW_ADDRESS 0x1FFFE000
// stm32f10x devices
#define BOOTLOADER_FW_ADDRESS 0x1FFFF000

void checkDfuAndJump()
{
uint8_t val;
if (SharedParamsReadByIndex(0, &val) == true) {
if (val == 0x02) {
// reset flag
SharedParamsWriteByIndex(0, 0x00);

// AN2606 says: 2 Kbytes, starting from address 0x1FFFF000 contain the bootloader firmware.
// Point the PC to the System Memory reset vector (+4)
void (*SysMemBootJump)(void) = (void (*)(void)) (*((uint32_t *) (BOOTLOADER_FW_ADDRESS + 4)));
// Pick stack address from vector table
__set_MSP(*(__IO uint32_t*) BOOTLOADER_FW_ADDRESS);
SysMemBootJump();
while (1);
}
}
}

void ToggleESRDriver(SensorType sensor)
{
switch (sensor) {
Expand Down
6 changes: 6 additions & 0 deletions firmware/boards/f1_dual_rev1/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#include "hal.h"
#include "io_pins.h"

//#include "port.h"
extern void checkDfuAndJump();

/**
* @brief PAL setup.
* @details Digital I/O ports static configuration as defined in @p board.h.
Expand All @@ -41,6 +44,9 @@ const PALConfig pal_default_config =
* any other initialization.
*/
void __early_init(void) {
/* Check if requested to jump to DFU */
checkDfuAndJump();

stm32_clock_init();
}

Expand Down
9 changes: 5 additions & 4 deletions firmware/boards/f1_dual_rev1/wideband_layout.ld
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
/* OpenBLT code */
_OpenBLT_Flash_Size = DEFINED(USE_BOOTLOADER) ? 8k : 0;

/* OpenBLT <-> main FW shared area */
_OpenBLT_Shared_Params_Size = DEFINED(USE_BOOTLOADER) ? 16 : 0;
/* OpenBLT <-> main FW shared area same area used to pass some data between restarts
* Now always enabled */
Shared_Params_Size = 16;

MEMORY
{
Expand All @@ -21,8 +22,8 @@ MEMORY
flash5 (rx) : org = 0x00000000, len = 0
flash6 (rx) : org = 0x00000000, len = 0
flash7 (rx) : org = 0x00000000, len = 0
shared (wx) : org = 0x20000000, len = _OpenBLT_Shared_Params_Size
ram0 (wx) : org = 0x20000000 + _OpenBLT_Shared_Params_Size, len = 48k - _OpenBLT_Shared_Params_Size
shared (wx) : org = 0x20000000, len = Shared_Params_Size
ram0 (wx) : org = 0x20000000 + Shared_Params_Size, len = 48k - Shared_Params_Size
ram1 (wx) : org = 0x00000000, len = 0
ram2 (wx) : org = 0x00000000, len = 0
ram3 (wx) : org = 0x00000000, len = 0
Expand Down
3 changes: 3 additions & 0 deletions firmware/boards/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ const char *getTsSignature();

void rebootNow();
void rebootToOpenblt();
void rebootToDfu();

extern "C" void checkDfuAndJump();

// LSU4.2, LSU4.9 or LSU_ADV
SensorType GetSensorType();
Expand Down
6 changes: 1 addition & 5 deletions firmware/console/binary/tunerstudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,23 +208,19 @@ static void handleIoTestCommand(TsChannelBase* tsChannel, ts_response_format_e m
/* index is not used yet */

switch (subsystem) {
#if 0
/* DFU */
case 0xba:
jump_to_bootloader();
rebootToDfu();
break;
#endif

case 0xbb:
rebootNow();
break;

#if USE_OPENBLT
case 0xbc:
/* Jump to OpenBLT if present */
rebootToOpenblt();
break;
#endif

default:
tunerStudioError(tsChannel, "Unexpected IoTest command");
Expand Down