Master is now using the same FW_Update Methode as the Slaves

This commit is contained in:
2024-05-24 01:58:53 +02:00
parent 66e04c6e06
commit d0544576a3
10 changed files with 198 additions and 89 deletions

View 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})

View 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();
}

View File

@@ -0,0 +1,3 @@
#pragma once
void RamLoader_LoadApplication();