only:f103
This commit is contained in:
parent
395a1edd7d
commit
47d9642e8c
|
@ -116,6 +116,7 @@ include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk
|
|||
# Auto-build files in ./source recursively.
|
||||
include $(CHIBIOS)/tools/mk/autobuild.mk
|
||||
# Other files (optional).
|
||||
include $(CHIBIOS)/os/hal/lib/complex/mfs/hal_mfs.mk
|
||||
include $(CHIBIOS)/os/hal/lib/streams/streams.mk
|
||||
|
||||
# Define linker script file here
|
||||
|
@ -131,6 +132,7 @@ CPPSRC = $(ALLCPPSRC) \
|
|||
main.cpp \
|
||||
spi.cpp \
|
||||
can.cpp \
|
||||
persistence.cpp \
|
||||
uart.cpp
|
||||
|
||||
# List ASM source files here.
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
*/
|
||||
MEMORY
|
||||
{
|
||||
flash0 (rx) : org = 0x08000000, len = 128k
|
||||
flash0 (rx) : org = 0x08000000, len = 60k
|
||||
flash1 (rx) : org = 0x00000000, len = 0
|
||||
flash2 (rx) : org = 0x00000000, len = 0
|
||||
flash3 (rx) : org = 0x00000000, len = 0
|
||||
|
|
|
@ -72,7 +72,7 @@
|
|||
* @brief Enables the EFlash subsystem.
|
||||
*/
|
||||
#if !defined(HAL_USE_EFL) || defined(__DOXYGEN__)
|
||||
#define HAL_USE_EFL FALSE
|
||||
#define HAL_USE_EFL TRUE
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "uart.h"
|
||||
#include "can.h"
|
||||
#include "spi.h"
|
||||
#include "persistence.h"
|
||||
|
||||
#define BL_PORT GPIOC
|
||||
#define BL_PIN 13
|
||||
|
@ -62,6 +63,7 @@ int main(void) {
|
|||
*/
|
||||
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
|
||||
|
||||
InitConfiguration();
|
||||
InitUart();
|
||||
InitCan();
|
||||
InitSpi();
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
#include "hal.h"
|
||||
#include "persistence.h"
|
||||
|
||||
static const MFSConfig mfscfg_1k = {
|
||||
.flashp = (BaseFlash *)&EFLD1,
|
||||
.erased = 0xFFFFFFFFU,
|
||||
/* 128K flash device with 1K pages
|
||||
* use last 8 pages for settings
|
||||
* one bank is 4K */
|
||||
.bank_size = 4096U,
|
||||
.bank0_start = 120U,
|
||||
.bank0_sectors = 4U,
|
||||
.bank1_start = 124U,
|
||||
.bank1_sectors = 4U
|
||||
#ifdef STM32F103xE
|
||||
/* 256K flash device with 2K pages
|
||||
* use last 8 pages for settings
|
||||
* one bank is 8K */
|
||||
.bank_size = 8096U,
|
||||
.bank0_start = 120U,
|
||||
.bank0_sectors = 4U,
|
||||
.bank1_start = 124U,
|
||||
.bank1_sectors = 4U
|
||||
#endif
|
||||
};
|
||||
|
||||
static const MFSConfig mfscfg_2k = {
|
||||
.flashp = (BaseFlash *)&EFLD1,
|
||||
.erased = 0xFFFFFFFFU,
|
||||
/* 256K flash device with 2K pages
|
||||
* use last 8 pages for settings
|
||||
* one bank is 8K */
|
||||
.bank_size = 8096U,
|
||||
.bank0_start = 120U,
|
||||
.bank0_sectors = 4U,
|
||||
.bank1_start = 124U,
|
||||
.bank1_sectors = 4U
|
||||
};
|
||||
|
||||
|
||||
static MFSDriver mfs1;
|
||||
TestConfiguration configuration;
|
||||
|
||||
static uint8_t *GetConfigurationPtr() {
|
||||
return (uint8_t *)&configuration;
|
||||
}
|
||||
|
||||
static size_t GetConfigurationSize() {
|
||||
return sizeof(TestConfiguration);
|
||||
}
|
||||
|
||||
int InitConfiguration() {
|
||||
size_t size = GetConfigurationSize();
|
||||
|
||||
/* Starting EFL driver.*/
|
||||
eflStart(&EFLD1, NULL);
|
||||
|
||||
mfsObjectInit(&mfs1);
|
||||
mfs_error_t err;
|
||||
|
||||
#define FLASH_SIZE_IN_K_ADDRESS 0x1FFFF7E0
|
||||
int flashSize = (*(uint16_t*)FLASH_SIZE_IN_K_ADDRESS);
|
||||
if (flashSize > 128) {
|
||||
err = mfsStart(&mfs1, &mfscfg_1k);
|
||||
} else {
|
||||
err = mfsStart(&mfs1, &mfscfg_2k);
|
||||
}
|
||||
if (err != MFS_NO_ERROR) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
err = mfsReadRecord(&mfs1, MFS_CONFIGURATION_RECORD_ID, &size, GetConfigurationPtr());
|
||||
if ((err != MFS_NO_ERROR) || (size != GetConfigurationSize() || !configuration.IsValid())) {
|
||||
/* load defaults */
|
||||
configuration.resetToDefaults();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void pokeConfiguration() {
|
||||
configuration.version++;
|
||||
// mfsWriteRecord(&mfs1, MFS_CONFIGURATION_RECORD_ID, GetConfigurationSize(), GetConfigurationPtr());
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
#pragma once
|
||||
|
||||
#include "hal_mfs.h"
|
||||
|
||||
#define PERSISTENCE_VERSION 4
|
||||
|
||||
#define MFS_CONFIGURATION_RECORD_ID 1
|
||||
|
||||
struct TestConfiguration {
|
||||
void resetToDefaults() {
|
||||
version = PERSISTENCE_VERSION;
|
||||
updateCounter = 20;
|
||||
}
|
||||
bool IsValid() const
|
||||
{
|
||||
return version == PERSISTENCE_VERSION;
|
||||
}
|
||||
|
||||
int version;
|
||||
int updateCounter;
|
||||
};
|
||||
|
||||
int InitConfiguration();
|
||||
void pokeConfiguration();
|
|
@ -3,6 +3,7 @@
|
|||
#include "chprintf.h"
|
||||
|
||||
#include "uart.h"
|
||||
#include "persistence.h"
|
||||
|
||||
static const UARTConfig uartCfg =
|
||||
{
|
||||
|
@ -26,16 +27,20 @@ static const UARTConfig uartCfg =
|
|||
|
||||
static char printBuffer[200];
|
||||
|
||||
extern TestConfiguration configuration;
|
||||
|
||||
static THD_WORKING_AREA(waUartThread, 256);
|
||||
static void UartThread(void*)
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
|
||||
size_t writeCount = chsnprintf(printBuffer, 200, "%d.%03d\t%d\t%d\r\n", 0, 0, 0, 100);
|
||||
size_t writeCount = chsnprintf(printBuffer, 200, "%d.%03d\t%d\t%d\r\n", 0, 0, configuration.version, 100);
|
||||
uartStartSend(&UARTD1, writeCount, printBuffer);
|
||||
|
||||
chThdSleepMilliseconds(20);
|
||||
pokeConfiguration();
|
||||
|
||||
chThdSleepMilliseconds(200);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue