Master is now using the same FW_Update Methode as the Slaves
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
add_subdirectory(Tasks)
|
||||
add_subdirectory(CLS)
|
||||
add_subdirectory(CLS_BSP)
|
||||
add_subdirectory(BSP)
|
||||
add_subdirectory(BSP)
|
||||
add_subdirectory(ram_loader)
|
||||
@@ -22,4 +22,4 @@ target_sources(${PROJECT_NAME}
|
||||
|
||||
target_include_directories(${PROJECT_NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR})
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC PROTOS CLS)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE Revision CLS_BSP BSP ulog)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE Revision CLS_BSP BSP ulog ram_loader)
|
||||
@@ -10,6 +10,9 @@
|
||||
#include "crc.h"
|
||||
#include "FirmwareUpdate.h"
|
||||
#include "stdbool.h"
|
||||
#include "CLS.h"
|
||||
#include "stdbool.h"
|
||||
#include "ram_loader.h"
|
||||
|
||||
// static memory only for decoding messages
|
||||
static cls_firmware_Start msg_cls_firmware_Start;
|
||||
@@ -58,19 +61,15 @@ void DataSend_FirmwareFileCheck(uint32_t crc, uint32_t device_id, bool ready_for
|
||||
#define CHUNK_SIZE 256 // Change this to the size of chunks you want to read
|
||||
static uint8_t crc_buffer[CHUNK_SIZE];
|
||||
|
||||
void DataClbk_cls_firmware_Start(void *msg, uint32_t length) {
|
||||
DATA_CLBK_SETUP(cls_firmware_Start);
|
||||
fwStartTime = osKernelGetSysTimerCount();
|
||||
fwPackageCounter = 0;
|
||||
|
||||
void fw_Start_Slave( cls_firmware_Start * msg) {
|
||||
|
||||
uint32_t crc = 0;
|
||||
UINT totalRead = 0;
|
||||
UINT bytesRead = 0;
|
||||
|
||||
if(FileOpen) {
|
||||
f_close(&FwFile);
|
||||
}
|
||||
// Check if file already exists
|
||||
if(f_open(&FwFile, msg_cls_firmware_Start.name, FA_READ) == FR_OK) {
|
||||
if(f_open(&FwFile, msg->name, FA_READ) == FR_OK) {
|
||||
|
||||
__HAL_CRC_DR_RESET(&hcrc);
|
||||
do {
|
||||
@@ -80,16 +79,38 @@ void DataClbk_cls_firmware_Start(void *msg, uint32_t length) {
|
||||
} while(bytesRead == CHUNK_SIZE);
|
||||
f_close(&FwFile);
|
||||
|
||||
if(crc == msg_cls_firmware_Start.crc_fw) {
|
||||
if(crc == msg->crc_fw) {
|
||||
// CRC matches, no need for transfer
|
||||
DataSend_FirmwareFileCheck(crc, msg_cls_firmware_Start.device_id, false, totalRead, msg_cls_firmware_Start.name);
|
||||
DataSend_FirmwareFileCheck(crc, msg->device_id, false, totalRead, msg->name);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
fresult_open = f_open(&FwFile, msg_cls_firmware_Start.name, FA_CREATE_ALWAYS | FA_WRITE);
|
||||
fresult_open = f_open(&FwFile, msg->name, FA_CREATE_ALWAYS | FA_WRITE);
|
||||
FileOpen=true;
|
||||
DataSend_FirmwareFileCheck(crc, msg_cls_firmware_Start.device_id, fresult_open==FR_OK, totalRead, msg_cls_firmware_Start.name);
|
||||
DataSend_FirmwareFileCheck(crc, msg->device_id, fresult_open==FR_OK, totalRead, msg->name);
|
||||
}
|
||||
|
||||
void fw_Start_Master( cls_firmware_Start * msg) {
|
||||
fresult_open = f_open(&FwFile, "firm.bin", FA_CREATE_ALWAYS | FA_WRITE);
|
||||
FileOpen=true;
|
||||
DataSend_FirmwareFileCheck(0, msg->device_id, fresult_open==FR_OK, 0, msg->name);
|
||||
}
|
||||
|
||||
void DataClbk_cls_firmware_Start(void *msg, uint32_t length) {
|
||||
DATA_CLBK_SETUP(cls_firmware_Start);
|
||||
fwStartTime = osKernelGetSysTimerCount();
|
||||
fwPackageCounter = 0;
|
||||
|
||||
if(FileOpen) {
|
||||
f_close(&FwFile);
|
||||
}
|
||||
|
||||
if(msg_cls_firmware_Start.device_id == gCLS_DEVICE_ADDRESS) {
|
||||
fw_Start_Master(&msg_cls_firmware_Start);
|
||||
} else {
|
||||
fw_Start_Slave(&msg_cls_firmware_Start);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -133,10 +154,14 @@ void DataClbk_cls_firmware_Done(void *msg, uint32_t length) {
|
||||
fresult_open = 0xFF;
|
||||
FileOpen=false;
|
||||
|
||||
FirmwareUpdateArgs args;
|
||||
args.device = msg_cls_firmware_Done.device_id;
|
||||
memcpy(args.name, msg_cls_firmware_Start.name, sizeof(args.name));
|
||||
if(msg_cls_firmware_Done.device_id == gCLS_DEVICE_ADDRESS) {
|
||||
RamLoader_LoadApplication();
|
||||
} else {
|
||||
|
||||
FirmwareUpdateTask_start(args);
|
||||
|
||||
FirmwareUpdateArgs args;
|
||||
args.device = msg_cls_firmware_Done.device_id;
|
||||
memcpy(args.name, msg_cls_firmware_Start.name, sizeof(args.name));
|
||||
|
||||
FirmwareUpdateTask_start(args);
|
||||
}
|
||||
}
|
||||
@@ -160,7 +160,6 @@ void FirmwareUpdateTask_start(FirmwareUpdateArgs args) {
|
||||
}
|
||||
}
|
||||
|
||||
UsbDataPacket buffer;
|
||||
void CLSFirmwareUpdateTask_func(void *argument) {
|
||||
FirmwareUpdateArgs args;
|
||||
osStatus_t status;
|
||||
|
||||
34
Application/ram_loader/CMakeLists.txt
Normal file
34
Application/ram_loader/CMakeLists.txt
Normal file
@@ -0,0 +1,34 @@
|
||||
# Set the minimum required CMake version
|
||||
cmake_minimum_required(VERSION 3.12)
|
||||
|
||||
# Set the project name
|
||||
project(ram_loader)
|
||||
|
||||
# Add the source files for the library
|
||||
set(SOURCES
|
||||
ram_loader.c
|
||||
)
|
||||
|
||||
# Add the header files for the library
|
||||
set(HEADERS
|
||||
ram_loader.h
|
||||
)
|
||||
|
||||
# Create the library target
|
||||
add_library(ram_loader ${SOURCES} ${HEADERS})
|
||||
|
||||
# Set the include directories for the library
|
||||
target_include_directories(ram_loader PUBLIC ./)
|
||||
|
||||
# Set any additional compiler flags or options
|
||||
# target_compile_options(${PROJECT_NAME} PRIVATE ...)
|
||||
|
||||
# Set any additional linker flags or options
|
||||
# target_link_options(${PROJECT_NAME} PRIVATE ...)
|
||||
|
||||
# Specify any dependencies for the library
|
||||
# target_link_libraries(${PROJECT_NAME} <dependency1> <dependency2> ...)
|
||||
|
||||
# Optionally, add an executable target for testing
|
||||
# add_executable(test_ram_loader test/test_ram_loader.cpp)
|
||||
# target_link_libraries(test_ram_loader ${PROJECT_NAME})
|
||||
110
Application/ram_loader/ram_loader.c
Normal file
110
Application/ram_loader/ram_loader.c
Normal file
@@ -0,0 +1,110 @@
|
||||
#include "fatfs.h"
|
||||
#include "string.h"
|
||||
|
||||
#define RAM_LOADER_BUFFER_SIZE 15*1024
|
||||
#define RAM_LOADER_ADDRESS 0x38000000
|
||||
#define APP_START_ADDRESS RAM_LOADER_ADDRESS
|
||||
uint8_t * ram_loader_buffer = (uint8_t *) RAM_LOADER_ADDRESS;
|
||||
|
||||
void _app_start(void)
|
||||
{
|
||||
__disable_irq();
|
||||
// Reset USB
|
||||
|
||||
//De-init all peripherals
|
||||
//HAL_ADC_DeInit(&hadc1);
|
||||
|
||||
// Disable Systick
|
||||
SysTick->CTRL = 0;
|
||||
SysTick->LOAD = 0;
|
||||
SysTick->VAL = 0;
|
||||
|
||||
// Reset clock to default
|
||||
HAL_RCC_DeInit();
|
||||
|
||||
// Clear all interrupt bits
|
||||
for (uint8_t i = 0; i < sizeof(NVIC->ICER) / sizeof(NVIC->ICER[0]); i++)
|
||||
{
|
||||
NVIC->ICER[i] = 0xFFFFFFFF;
|
||||
NVIC->ICPR[i] = 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
__enable_irq();
|
||||
|
||||
|
||||
// set the vector table offset register
|
||||
SCB->VTOR = APP_START_ADDRESS;
|
||||
|
||||
// get the application stack pointer
|
||||
__set_MSP(((uint32_t *)APP_START_ADDRESS)[0]);
|
||||
|
||||
|
||||
// jump to the application
|
||||
((void (*)(void))((uint32_t *)APP_START_ADDRESS)[1])();
|
||||
|
||||
// the application should never return
|
||||
// ULOG_ERROR("Failed to start application");
|
||||
while (1) {}
|
||||
|
||||
}
|
||||
|
||||
static uint8_t buffer[512];
|
||||
|
||||
void RamLoader_LoadApplication()
|
||||
{
|
||||
|
||||
// check if the file "load.bin" exists
|
||||
FIL file;
|
||||
FRESULT res = f_open(&file, "load.bin", FA_READ);
|
||||
if (res != FR_OK) {
|
||||
// ULOG_ERROR("Failed to open file load.bin");
|
||||
return;
|
||||
}
|
||||
|
||||
UINT size = f_size(&file);
|
||||
// ensure the file is not larger than the buffer
|
||||
if (size > RAM_LOADER_BUFFER_SIZE ) {
|
||||
// ULOG_ERROR("File load.bin is too large");
|
||||
return;
|
||||
}
|
||||
|
||||
// read the file into the buffer
|
||||
UINT bytes_read;
|
||||
uint32_t remaining_bytes = size;
|
||||
uint8_t *destination_ptr = ram_loader_buffer;
|
||||
uint8_t *buffer_ptr = buffer;
|
||||
while (remaining_bytes > 0) {
|
||||
UINT read_size = remaining_bytes > 512 ? 512 : remaining_bytes;
|
||||
res = f_read(&file, buffer_ptr, read_size, &bytes_read);
|
||||
if (res != FR_OK) {
|
||||
// ULOG_ERROR("Failed to read file load.bin");
|
||||
return;
|
||||
}
|
||||
if (bytes_read != read_size) {
|
||||
// ULOG_ERROR("Failed to read file load.bin completely");
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(destination_ptr, buffer_ptr, read_size);
|
||||
remaining_bytes -= read_size;
|
||||
destination_ptr += read_size;
|
||||
}
|
||||
|
||||
// close the file
|
||||
f_close(&file);
|
||||
|
||||
|
||||
// check that the file to flash exists ("firm.bin")
|
||||
res = f_open(&file, "firm.bin", FA_READ);
|
||||
if (res != FR_OK) {
|
||||
// ULOG_ERROR("Failed to open file firm.bin");
|
||||
return;
|
||||
}
|
||||
//close the file
|
||||
f_close(&file);
|
||||
|
||||
|
||||
_app_start();
|
||||
|
||||
|
||||
}
|
||||
3
Application/ram_loader/ram_loader.h
Normal file
3
Application/ram_loader/ram_loader.h
Normal file
@@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
void RamLoader_LoadApplication();
|
||||
Reference in New Issue
Block a user