From e3542c12de3fc5c7630147307f04383d36eccc1c Mon Sep 17 00:00:00 2001 From: Balazs Racz Date: Fri, 18 Dec 2020 00:24:58 +0100 Subject: [PATCH 01/12] Adds io board target for the L432. --- .../HwInit.cxx | 1 + .../Makefile | 1 + .../config.hxx | 6 ++-- .../hardware.hxx | 1 + .../main.cxx | 35 ++++++++++++++++--- .../memory_map.ld | 1 + .../startup.c | 1 + .../target.ld | 1 + 8 files changed, 40 insertions(+), 7 deletions(-) create mode 120000 applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/HwInit.cxx create mode 120000 applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/Makefile create mode 120000 applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/hardware.hxx create mode 120000 applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/memory_map.ld create mode 120000 applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/startup.c create mode 120000 applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/target.ld diff --git a/applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/HwInit.cxx b/applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/HwInit.cxx new file mode 120000 index 000000000..8bf2ed18c --- /dev/null +++ b/applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/HwInit.cxx @@ -0,0 +1 @@ +../../../../boards/st-stm32l432kc-nucleo/HwInit.cxx \ No newline at end of file diff --git a/applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/Makefile b/applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/Makefile new file mode 120000 index 000000000..e13c2970c --- /dev/null +++ b/applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/Makefile @@ -0,0 +1 @@ +../../../../boards/st-stm32l432kc-nucleo/Makefile \ No newline at end of file diff --git a/applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/config.hxx b/applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/config.hxx index 1d2ed0d59..24e051c60 100644 --- a/applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/config.hxx +++ b/applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/config.hxx @@ -26,8 +26,8 @@ extern const SimpleNodeStaticValues SNIP_STATIC_DATA = { 4, "OpenMRN", "Test IO Board - STM32F303RE Nucleo", "STM32F091RC-Nucleo", "1.01"}; -#define NUM_OUTPUTS 1 -#define NUM_INPUTS 1 +#define NUM_OUTPUTS 5 +#define NUM_INPUTS 4 /// Declares a repeated group of a given base group and number of repeats. The /// ProducerConfig and ConsumerConfig groups represent the configuration layout @@ -38,7 +38,7 @@ using AllProducers = RepeatedGroup; /// Modify this value every time the EEPROM needs to be cleared on the node /// after an update. -static constexpr uint16_t CANONICAL_VERSION = 0x184a; +static constexpr uint16_t CANONICAL_VERSION = 0x1846; /// Defines the main segment in the configuration CDI. This is laid out at /// origin 128 to give space for the ACDI user data at the beginning. diff --git a/applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/hardware.hxx b/applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/hardware.hxx new file mode 120000 index 000000000..e27187a64 --- /dev/null +++ b/applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/hardware.hxx @@ -0,0 +1 @@ +../../../../boards/st-stm32l432kc-nucleo/hardware.hxx \ No newline at end of file diff --git a/applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/main.cxx b/applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/main.cxx index 238825088..c21b5f7a1 100644 --- a/applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/main.cxx +++ b/applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/main.cxx @@ -47,9 +47,9 @@ // These preprocessor symbols are used to select which physical connections // will be enabled in the main(). See @ref appl_main below. -#define SNIFF_ON_SERIAL +//#define SNIFF_ON_SERIAL //#define SNIFF_ON_USB -//#define HAVE_PHYSICAL_CAN_PORT +#define HAVE_PHYSICAL_CAN_PORT // Changes the default behavior by adding a newline after each gridconnect // packet. Makes it easier for debugging the raw device. @@ -81,7 +81,7 @@ extern const char *const openlcb::CONFIG_FILENAME = "/dev/eeprom"; // The size of the memory space to export over the above device. extern const size_t openlcb::CONFIG_FILE_SIZE = cfg.seg().size() + cfg.seg().offset(); -static_assert(openlcb::CONFIG_FILE_SIZE <= 300, "Need to adjust eeprom size"); +static_assert(openlcb::CONFIG_FILE_SIZE <= 512, "Need to adjust eeprom size"); // The SNIP user-changeable information in also stored in the above eeprom // device. In general this could come from different eeprom segments, but it is // simpler to keep them together. @@ -102,7 +102,7 @@ openlcb::ConfiguredConsumer consumer_green( // Similar syntax for the producers. openlcb::ConfiguredProducer producer_sw1( - stack.node(), cfg.seg().producers().entry<0>(), SW_USER_Pin()); + stack.node(), cfg.seg().producers().entry<0>(), IN_A0_Pin()); // The producers need to be polled repeatedly for changes and to execute the // debouncing algorithm. This class instantiates a refreshloop and adds the two @@ -110,6 +110,33 @@ openlcb::ConfiguredProducer producer_sw1( openlcb::RefreshLoop loop( stack.node(), {producer_sw1.polling()}); +// Object that handles factory reset for our config setup. +class CustomFactoryReset : public DefaultConfigUpdateListener { +public: + void factory_reset(int fd) override + { + // Resets user names. + cfg.userinfo().name().write(fd, "Default user name"); + cfg.userinfo().description().write(fd, "Default user description"); + // Makes the IO pin descriptions empty. + for (unsigned i = 0; i < cfg.seg().consumers().num_repeats(); ++i) { + cfg.seg().consumers().entry(i).description().write(fd, ""); + } + for (unsigned i = 0; i < cfg.seg().producers().num_repeats(); ++i) { + cfg.seg().producers().entry(i).description().write(fd, ""); + cfg.seg().producers().entry(i).debounce().write(fd, 3); + } + } + + UpdateAction apply_configuration( + int fd, bool initial_load, BarrierNotifiable *done) override { + done->notify(); + // Nothing to do; we don't read the configuration. + return UPDATED; + } +} g_custom_factory_reset; + + /** Entry point to application. * @param argc number of command line arguments * @param argv array of command line arguments diff --git a/applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/memory_map.ld b/applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/memory_map.ld new file mode 120000 index 000000000..52c792882 --- /dev/null +++ b/applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/memory_map.ld @@ -0,0 +1 @@ +../../../../boards/st-stm32l432kc-nucleo/memory_map.ld \ No newline at end of file diff --git a/applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/startup.c b/applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/startup.c new file mode 120000 index 000000000..cd5f598b1 --- /dev/null +++ b/applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/startup.c @@ -0,0 +1 @@ +../../../../boards/st-stm32l432kc-nucleo/startup.c \ No newline at end of file diff --git a/applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/target.ld b/applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/target.ld new file mode 120000 index 000000000..403497dce --- /dev/null +++ b/applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/target.ld @@ -0,0 +1 @@ +../../../../boards/st-stm32l432kc-nucleo/target.ld \ No newline at end of file From 74ebf7a66a14b474b57b511e641358e6b315a118 Mon Sep 17 00:00:00 2001 From: Balazs Racz Date: Fri, 18 Dec 2020 00:25:32 +0100 Subject: [PATCH 02/12] Adds L4 support to the eepromemulation. Fixes bugs in the 8-byte-per-write case for STM32 flash. --- .../st/Stm32EEPROMEmulation.cxx | 35 ++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/src/freertos_drivers/st/Stm32EEPROMEmulation.cxx b/src/freertos_drivers/st/Stm32EEPROMEmulation.cxx index f08a7708c..b6aec4bd0 100644 --- a/src/freertos_drivers/st/Stm32EEPROMEmulation.cxx +++ b/src/freertos_drivers/st/Stm32EEPROMEmulation.cxx @@ -35,6 +35,9 @@ #include +#include "stm32f_hal_conf.hxx" + +#if 0 #if defined (STM32F030x6) || defined (STM32F031x6) || defined (STM32F038xx) \ || defined (STM32F030x8) || defined (STM32F030xC) || defined (STM32F042x6) \ || defined (STM32F048xx) || defined (STM32F051x8) || defined (STM32F058xx) \ @@ -45,11 +48,11 @@ #elif defined(STM32F303xC) || defined(STM32F303xE) #include "stm32f3xx_hal_flash.h" #elif defined(STM32F767xx) -#define F7_FLASH #include "stm32f7xx_hal_flash.h" #else #error "stm32EEPROMEmulation unsupported STM32 device" #endif +#endif #if defined (STM32F030x6) || defined (STM32F031x6) || defined (STM32F038xx) \ || defined (STM32F030x8) || defined (STM32F030xC) || defined (STM32F042x6) \ @@ -64,11 +67,19 @@ const size_t EEPROMEmulation::BYTES_PER_BLOCK = 2; const size_t Stm32EEPROMEmulation::PAGE_SIZE = 0x800; const size_t EEPROMEmulation::BLOCK_SIZE = 4; const size_t EEPROMEmulation::BYTES_PER_BLOCK = 2; +#elif defined(STM32L432xx) || defined(STM32L431xx) +const size_t Stm32EEPROMEmulation::PAGE_SIZE = 0x800; +const size_t EEPROMEmulation::BLOCK_SIZE = 8; +const size_t EEPROMEmulation::BYTES_PER_BLOCK = 4; +#define L4_FLASH #elif defined(STM32F767xx) // Note this assumes single-bank usage const size_t Stm32EEPROMEmulation::PAGE_SIZE = 256*1024; const size_t EEPROMEmulation::BLOCK_SIZE = 8; const size_t EEPROMEmulation::BYTES_PER_BLOCK = 4; +#define F7_FLASH +#else +#error "stm32EEPROMEmulation unsupported STM32 device" #endif /** Constructor. @@ -133,7 +144,13 @@ void Stm32EEPROMEmulation::flash_erase(unsigned sector) FLASH_EraseInitTypeDef erase_init; erase_init.TypeErase = FLASH_TYPEERASE_PAGES; +#ifdef L4_FLASH + erase_init.Banks = FLASH_BANK_1; + uint32_t start_page = erase_init.Page = + (((uint32_t)address) - FLASH_BASE) / PAGE_SIZE; +#else erase_init.PageAddress = (uint32_t)address; +#endif erase_init.NbPages = SECTOR_SIZE / PAGE_SIZE; portENTER_CRITICAL(); @@ -142,11 +159,19 @@ void Stm32EEPROMEmulation::flash_erase(unsigned sector) // there. This is to make corruption less likely in case of a power // interruption happens. if (SECTOR_SIZE > PAGE_SIZE) { +#ifdef L4_FLASH + erase_init.Page += 1; +#else erase_init.PageAddress += PAGE_SIZE; +#endif erase_init.NbPages--; HAL_FLASHEx_Erase(&erase_init, &page_error); erase_init.NbPages = 1; +#ifdef L4_FLASH + erase_init.Page = start_page; +#else erase_init.PageAddress = (uint32_t)address; +#endif } HAL_FLASHEx_Erase(&erase_init, &page_error); HAL_FLASH_Lock(); @@ -183,8 +208,8 @@ void Stm32EEPROMEmulation::flash_program( { portENTER_CRITICAL(); HAL_FLASH_Unlock(); -#ifdef F7_FLASH - HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, uint_address, *data); +#if defined(F7_FLASH)|| defined(L4_FLASH) + HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, uint_address, *(uint64_t*)data); #else HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, uint_address, *data); #endif @@ -192,7 +217,7 @@ void Stm32EEPROMEmulation::flash_program( portEXIT_CRITICAL(); count -= BLOCK_SIZE; - uint_address += sizeof(uint32_t); - ++data; + uint_address += BLOCK_SIZE; + data += (BLOCK_SIZE / sizeof(uint32_t)); } } From 246dcc3d20ec62d2ae15abda925ece3189e911e6 Mon Sep 17 00:00:00 2001 From: Balazs Racz Date: Fri, 18 Dec 2020 00:25:43 +0100 Subject: [PATCH 03/12] Reenables compilation of eepromemu for L4. --- .../freertos.armv7m/freertos_drivers/stm32cubel432xx/sources | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/targets/freertos.armv7m/freertos_drivers/stm32cubel432xx/sources b/targets/freertos.armv7m/freertos_drivers/stm32cubel432xx/sources index 768f5cf54..8e574f018 100644 --- a/targets/freertos.armv7m/freertos_drivers/stm32cubel432xx/sources +++ b/targets/freertos.armv7m/freertos_drivers/stm32cubel432xx/sources @@ -89,8 +89,8 @@ CXXSRCS += Stm32Can.cxx \ Stm32Uart.cxx \ Stm32SPI.cxx \ Stm32I2C.cxx \ + Stm32EEPROMEmulation.cxx \ # does not work yet -# Stm32EEPROMEmulation.cxx From 95600bb2624c2ffa0cb1ed3c52f3c15b00934fb2 Mon Sep 17 00:00:00 2001 From: Balazs Racz Date: Fri, 18 Dec 2020 00:25:58 +0100 Subject: [PATCH 04/12] Adds a bunch of input/output pins to the L432 hardware.hxx --- boards/st-stm32l432kc-nucleo/hardware.hxx | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/boards/st-stm32l432kc-nucleo/hardware.hxx b/boards/st-stm32l432kc-nucleo/hardware.hxx index 3b34753f9..0598aa2ba 100644 --- a/boards/st-stm32l432kc-nucleo/hardware.hxx +++ b/boards/st-stm32l432kc-nucleo/hardware.hxx @@ -5,7 +5,20 @@ GPIO_PIN(LED_GREEN_RAW, LedPin, B, 3); -typedef GpioInitializer GpioInit; +GPIO_PIN(IN_A0, GpioInputPU, A, 0); +GPIO_PIN(IN_A1, GpioInputPU, A, 1); +GPIO_PIN(IN_A2, GpioInputPU, A, 3); +GPIO_PIN(IN_A3, GpioInputPU, A, 4); + +GPIO_PIN(OUT_D3, GpioOutputSafeLow, B, 0); +GPIO_PIN(OUT_D4, GpioOutputSafeLow, B, 7); +GPIO_PIN(OUT_D5, GpioOutputSafeLow, B, 6); +GPIO_PIN(OUT_D6, GpioOutputSafeLow, B, 1); + +typedef GpioInitializer + GpioInit; typedef LED_GREEN_RAW_Pin BLINKER_RAW_Pin; typedef BLINKER_Pin LED_GREEN_Pin; From 0c0b6c31edbb94b964390c651fc151d0852f327c Mon Sep 17 00:00:00 2001 From: Balazs Racz Date: Fri, 18 Dec 2020 00:26:10 +0100 Subject: [PATCH 05/12] Reenables eepromemu in the HwINit for the L432. --- boards/st-stm32l432kc-nucleo/HwInit.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/boards/st-stm32l432kc-nucleo/HwInit.cxx b/boards/st-stm32l432kc-nucleo/HwInit.cxx index 675c33298..e62215757 100644 --- a/boards/st-stm32l432kc-nucleo/HwInit.cxx +++ b/boards/st-stm32l432kc-nucleo/HwInit.cxx @@ -61,9 +61,10 @@ static Stm32Uart uart0("/dev/ser0", USART2, USART2_IRQn); static Stm32Can can0("/dev/can0"); /** EEPROM emulation driver. The file size might be made bigger. */ -//static Stm32EEPROMEmulation eeprom0("/dev/eeprom", 512); +static Stm32EEPROMEmulation eeprom0("/dev/eeprom", 512); const size_t EEPROMEmulation::SECTOR_SIZE = 2048; +const bool EEPROMEmulation::SHADOW_IN_RAM = true; extern "C" { From 9bc4ee15828c89920f97da4716904ea2fa5a3843 Mon Sep 17 00:00:00 2001 From: Balazs Racz Date: Fri, 18 Dec 2020 11:50:17 +0100 Subject: [PATCH 06/12] Enables eepromemu for L431 as well. --- .../freertos.armv7m/freertos_drivers/stm32cubel431xx/sources | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/targets/freertos.armv7m/freertos_drivers/stm32cubel431xx/sources b/targets/freertos.armv7m/freertos_drivers/stm32cubel431xx/sources index ee86ad4fc..ddd6657d8 100644 --- a/targets/freertos.armv7m/freertos_drivers/stm32cubel431xx/sources +++ b/targets/freertos.armv7m/freertos_drivers/stm32cubel431xx/sources @@ -89,8 +89,6 @@ CXXSRCS += Stm32Can.cxx \ Stm32Uart.cxx \ Stm32SPI.cxx \ Stm32I2C.cxx \ + Stm32EEPROMEmulation.cxx \ -# does not work yet -# Stm32EEPROMEmulation.cxx - From 8f27ca7a8b73d635d7df03fcbafb41f0b3eeb2f7 Mon Sep 17 00:00:00 2001 From: Balazs Racz Date: Fri, 18 Dec 2020 00:25:32 +0100 Subject: [PATCH 07/12] Adds L4 support to the eepromemulation. Fixes bugs in the 8-byte-per-write case for STM32 flash. --- .../st/Stm32EEPROMEmulation.cxx | 35 ++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/src/freertos_drivers/st/Stm32EEPROMEmulation.cxx b/src/freertos_drivers/st/Stm32EEPROMEmulation.cxx index f08a7708c..b6aec4bd0 100644 --- a/src/freertos_drivers/st/Stm32EEPROMEmulation.cxx +++ b/src/freertos_drivers/st/Stm32EEPROMEmulation.cxx @@ -35,6 +35,9 @@ #include +#include "stm32f_hal_conf.hxx" + +#if 0 #if defined (STM32F030x6) || defined (STM32F031x6) || defined (STM32F038xx) \ || defined (STM32F030x8) || defined (STM32F030xC) || defined (STM32F042x6) \ || defined (STM32F048xx) || defined (STM32F051x8) || defined (STM32F058xx) \ @@ -45,11 +48,11 @@ #elif defined(STM32F303xC) || defined(STM32F303xE) #include "stm32f3xx_hal_flash.h" #elif defined(STM32F767xx) -#define F7_FLASH #include "stm32f7xx_hal_flash.h" #else #error "stm32EEPROMEmulation unsupported STM32 device" #endif +#endif #if defined (STM32F030x6) || defined (STM32F031x6) || defined (STM32F038xx) \ || defined (STM32F030x8) || defined (STM32F030xC) || defined (STM32F042x6) \ @@ -64,11 +67,19 @@ const size_t EEPROMEmulation::BYTES_PER_BLOCK = 2; const size_t Stm32EEPROMEmulation::PAGE_SIZE = 0x800; const size_t EEPROMEmulation::BLOCK_SIZE = 4; const size_t EEPROMEmulation::BYTES_PER_BLOCK = 2; +#elif defined(STM32L432xx) || defined(STM32L431xx) +const size_t Stm32EEPROMEmulation::PAGE_SIZE = 0x800; +const size_t EEPROMEmulation::BLOCK_SIZE = 8; +const size_t EEPROMEmulation::BYTES_PER_BLOCK = 4; +#define L4_FLASH #elif defined(STM32F767xx) // Note this assumes single-bank usage const size_t Stm32EEPROMEmulation::PAGE_SIZE = 256*1024; const size_t EEPROMEmulation::BLOCK_SIZE = 8; const size_t EEPROMEmulation::BYTES_PER_BLOCK = 4; +#define F7_FLASH +#else +#error "stm32EEPROMEmulation unsupported STM32 device" #endif /** Constructor. @@ -133,7 +144,13 @@ void Stm32EEPROMEmulation::flash_erase(unsigned sector) FLASH_EraseInitTypeDef erase_init; erase_init.TypeErase = FLASH_TYPEERASE_PAGES; +#ifdef L4_FLASH + erase_init.Banks = FLASH_BANK_1; + uint32_t start_page = erase_init.Page = + (((uint32_t)address) - FLASH_BASE) / PAGE_SIZE; +#else erase_init.PageAddress = (uint32_t)address; +#endif erase_init.NbPages = SECTOR_SIZE / PAGE_SIZE; portENTER_CRITICAL(); @@ -142,11 +159,19 @@ void Stm32EEPROMEmulation::flash_erase(unsigned sector) // there. This is to make corruption less likely in case of a power // interruption happens. if (SECTOR_SIZE > PAGE_SIZE) { +#ifdef L4_FLASH + erase_init.Page += 1; +#else erase_init.PageAddress += PAGE_SIZE; +#endif erase_init.NbPages--; HAL_FLASHEx_Erase(&erase_init, &page_error); erase_init.NbPages = 1; +#ifdef L4_FLASH + erase_init.Page = start_page; +#else erase_init.PageAddress = (uint32_t)address; +#endif } HAL_FLASHEx_Erase(&erase_init, &page_error); HAL_FLASH_Lock(); @@ -183,8 +208,8 @@ void Stm32EEPROMEmulation::flash_program( { portENTER_CRITICAL(); HAL_FLASH_Unlock(); -#ifdef F7_FLASH - HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, uint_address, *data); +#if defined(F7_FLASH)|| defined(L4_FLASH) + HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, uint_address, *(uint64_t*)data); #else HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, uint_address, *data); #endif @@ -192,7 +217,7 @@ void Stm32EEPROMEmulation::flash_program( portEXIT_CRITICAL(); count -= BLOCK_SIZE; - uint_address += sizeof(uint32_t); - ++data; + uint_address += BLOCK_SIZE; + data += (BLOCK_SIZE / sizeof(uint32_t)); } } From 10911d71cacce938f10832cf8a3b90a31abda64d Mon Sep 17 00:00:00 2001 From: Balazs Racz Date: Fri, 18 Dec 2020 11:55:05 +0100 Subject: [PATCH 08/12] Removes commented out code. --- .../st/Stm32EEPROMEmulation.cxx | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/freertos_drivers/st/Stm32EEPROMEmulation.cxx b/src/freertos_drivers/st/Stm32EEPROMEmulation.cxx index b6aec4bd0..0fc44b1bb 100644 --- a/src/freertos_drivers/st/Stm32EEPROMEmulation.cxx +++ b/src/freertos_drivers/st/Stm32EEPROMEmulation.cxx @@ -37,23 +37,6 @@ #include "stm32f_hal_conf.hxx" -#if 0 -#if defined (STM32F030x6) || defined (STM32F031x6) || defined (STM32F038xx) \ - || defined (STM32F030x8) || defined (STM32F030xC) || defined (STM32F042x6) \ - || defined (STM32F048xx) || defined (STM32F051x8) || defined (STM32F058xx) \ - || defined (STM32F070x6) || defined (STM32F070xB) || defined (STM32F071xB) \ - || defined (STM32F072xB) || defined (STM32F078xx) \ - || defined (STM32F091xC) || defined (STM32F098xx) -#include "stm32f0xx_hal_flash.h" -#elif defined(STM32F303xC) || defined(STM32F303xE) -#include "stm32f3xx_hal_flash.h" -#elif defined(STM32F767xx) -#include "stm32f7xx_hal_flash.h" -#else -#error "stm32EEPROMEmulation unsupported STM32 device" -#endif -#endif - #if defined (STM32F030x6) || defined (STM32F031x6) || defined (STM32F038xx) \ || defined (STM32F030x8) || defined (STM32F030xC) || defined (STM32F042x6) \ || defined (STM32F048xx) || defined (STM32F051x8) || defined (STM32F058xx) From cdb49ee452e23ea4bafef9100adb73150cf725be Mon Sep 17 00:00:00 2001 From: Balazs Racz Date: Fri, 18 Dec 2020 11:55:05 +0100 Subject: [PATCH 09/12] Removes commented out code. --- .../st/Stm32EEPROMEmulation.cxx | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/freertos_drivers/st/Stm32EEPROMEmulation.cxx b/src/freertos_drivers/st/Stm32EEPROMEmulation.cxx index b6aec4bd0..0fc44b1bb 100644 --- a/src/freertos_drivers/st/Stm32EEPROMEmulation.cxx +++ b/src/freertos_drivers/st/Stm32EEPROMEmulation.cxx @@ -37,23 +37,6 @@ #include "stm32f_hal_conf.hxx" -#if 0 -#if defined (STM32F030x6) || defined (STM32F031x6) || defined (STM32F038xx) \ - || defined (STM32F030x8) || defined (STM32F030xC) || defined (STM32F042x6) \ - || defined (STM32F048xx) || defined (STM32F051x8) || defined (STM32F058xx) \ - || defined (STM32F070x6) || defined (STM32F070xB) || defined (STM32F071xB) \ - || defined (STM32F072xB) || defined (STM32F078xx) \ - || defined (STM32F091xC) || defined (STM32F098xx) -#include "stm32f0xx_hal_flash.h" -#elif defined(STM32F303xC) || defined(STM32F303xE) -#include "stm32f3xx_hal_flash.h" -#elif defined(STM32F767xx) -#include "stm32f7xx_hal_flash.h" -#else -#error "stm32EEPROMEmulation unsupported STM32 device" -#endif -#endif - #if defined (STM32F030x6) || defined (STM32F031x6) || defined (STM32F038xx) \ || defined (STM32F030x8) || defined (STM32F030xC) || defined (STM32F042x6) \ || defined (STM32F048xx) || defined (STM32F051x8) || defined (STM32F058xx) From 86fdfeef69b36e0bed3321676eaa2bb90b21df79 Mon Sep 17 00:00:00 2001 From: Balazs Racz Date: Fri, 18 Dec 2020 11:57:21 +0100 Subject: [PATCH 10/12] removes obsolete comment --- .../freertos.armv7m/freertos_drivers/stm32cubel432xx/sources | 3 --- 1 file changed, 3 deletions(-) diff --git a/targets/freertos.armv7m/freertos_drivers/stm32cubel432xx/sources b/targets/freertos.armv7m/freertos_drivers/stm32cubel432xx/sources index 8e574f018..2209fe22a 100644 --- a/targets/freertos.armv7m/freertos_drivers/stm32cubel432xx/sources +++ b/targets/freertos.armv7m/freertos_drivers/stm32cubel432xx/sources @@ -91,6 +91,3 @@ CXXSRCS += Stm32Can.cxx \ Stm32I2C.cxx \ Stm32EEPROMEmulation.cxx \ - -# does not work yet - From 040535c27b14b186368a707c7d44d5569e272ea3 Mon Sep 17 00:00:00 2001 From: Balazs Racz Date: Fri, 18 Dec 2020 12:09:29 +0100 Subject: [PATCH 11/12] Implements all declared input and output pins. --- .../main.cxx | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/main.cxx b/applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/main.cxx index c21b5f7a1..e2e9e3d5f 100644 --- a/applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/main.cxx +++ b/applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/main.cxx @@ -99,16 +99,35 @@ extern const char *const openlcb::SNIP_DYNAMIC_FILENAME = // own GPIO pin. openlcb::ConfiguredConsumer consumer_green( stack.node(), cfg.seg().consumers().entry<0>(), LED_GREEN_Pin()); +openlcb::ConfiguredConsumer consumer_d3( + stack.node(), cfg.seg().consumers().entry<1>(), OUT_D3_Pin()); +openlcb::ConfiguredConsumer consumer_d4( + stack.node(), cfg.seg().consumers().entry<2>(), OUT_D4_Pin()); +openlcb::ConfiguredConsumer consumer_d5( + stack.node(), cfg.seg().consumers().entry<3>(), OUT_D5_Pin()); +openlcb::ConfiguredConsumer consumer_d6( + stack.node(), cfg.seg().consumers().entry<4>(), OUT_D6_Pin()); // Similar syntax for the producers. -openlcb::ConfiguredProducer producer_sw1( +openlcb::ConfiguredProducer producer_a0( stack.node(), cfg.seg().producers().entry<0>(), IN_A0_Pin()); +openlcb::ConfiguredProducer producer_a1( + stack.node(), cfg.seg().producers().entry<1>(), IN_A1_Pin()); +openlcb::ConfiguredProducer producer_a2( + stack.node(), cfg.seg().producers().entry<2>(), IN_A2_Pin()); +openlcb::ConfiguredProducer producer_a3( + stack.node(), cfg.seg().producers().entry<3>(), IN_A3_Pin()); // The producers need to be polled repeatedly for changes and to execute the // debouncing algorithm. This class instantiates a refreshloop and adds the two // producers to it. -openlcb::RefreshLoop loop( - stack.node(), {producer_sw1.polling()}); +openlcb::RefreshLoop loop(stack.node(), + { + producer_a0.polling(), // + producer_a1.polling(), // + producer_a2.polling(), // + producer_a3.polling() // + }); // Object that handles factory reset for our config setup. class CustomFactoryReset : public DefaultConfigUpdateListener { From 5cb2dfdc1e8dfc646340d2c7619d0b5bd7ce7e1e Mon Sep 17 00:00:00 2001 From: Balazs Racz Date: Fri, 18 Dec 2020 14:34:52 +0100 Subject: [PATCH 12/12] Fixes identification and moves the factory reset a bit higher up. --- .../config.hxx | 9 +-- .../main.cxx | 59 ++++++++++--------- 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/config.hxx b/applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/config.hxx index 24e051c60..f93bff471 100644 --- a/applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/config.hxx +++ b/applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/config.hxx @@ -22,9 +22,10 @@ namespace openlcb /// - the generated cdi.xml will include this data /// - the Simple Node Ident Info Protocol will return this data /// - the ACDI memory space will contain this data. -extern const SimpleNodeStaticValues SNIP_STATIC_DATA = { - 4, "OpenMRN", "Test IO Board - STM32F303RE Nucleo", - "STM32F091RC-Nucleo", "1.01"}; +extern const SimpleNodeStaticValues SNIP_STATIC_DATA = {4, "OpenMRN", // + "Test IO Board - STM32L432KC Nucleo", // + "STM32L432KC-Nucleo", // + "1.01"}; #define NUM_OUTPUTS 5 #define NUM_INPUTS 4 @@ -38,7 +39,7 @@ using AllProducers = RepeatedGroup; /// Modify this value every time the EEPROM needs to be cleared on the node /// after an update. -static constexpr uint16_t CANONICAL_VERSION = 0x1846; +static constexpr uint16_t CANONICAL_VERSION = 0x1844; /// Defines the main segment in the configuration CDI. This is laid out at /// origin 128 to give space for the ACDI user data at the beginning. diff --git a/applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/main.cxx b/applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/main.cxx index e2e9e3d5f..4d8bfb6e2 100644 --- a/applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/main.cxx +++ b/applications/io_board/targets/freertos.armv7m.st-stm32l432kc-nucleo/main.cxx @@ -88,6 +88,38 @@ static_assert(openlcb::CONFIG_FILE_SIZE <= 512, "Need to adjust eeprom size"); extern const char *const openlcb::SNIP_DYNAMIC_FILENAME = openlcb::CONFIG_FILENAME; +// Object that handles factory reset for our config setup. +class CustomFactoryReset : public DefaultConfigUpdateListener { +public: + void factory_reset(int fd) override + { + // Resets user names. + cfg.userinfo().name().write(fd, "Default user name"); + cfg.userinfo().description().write(fd, "Default user description"); + // Makes the IO pin descriptions with default value. + cfg.seg().consumers().entry<0>().description().write(fd, "LD3"); + cfg.seg().consumers().entry<1>().description().write(fd, "D3"); + cfg.seg().consumers().entry<2>().description().write(fd, "D4"); + cfg.seg().consumers().entry<3>().description().write(fd, "D5"); + cfg.seg().consumers().entry<4>().description().write(fd, "D6"); + + cfg.seg().producers().entry<0>().description().write(fd, "A0"); + cfg.seg().producers().entry<1>().description().write(fd, "A1"); + cfg.seg().producers().entry<2>().description().write(fd, "A2"); + cfg.seg().producers().entry<3>().description().write(fd, "A3"); + for (unsigned i = 0; i < cfg.seg().producers().num_repeats(); ++i) { + cfg.seg().producers().entry(i).debounce().write(fd, 3); + } + } + + UpdateAction apply_configuration( + int fd, bool initial_load, BarrierNotifiable *done) override { + done->notify(); + // Nothing to do; we don't read the configuration. + return UPDATED; + } +} g_custom_factory_reset; + // Instantiates the actual producer and consumer objects for the given GPIO // pins from above. The ConfiguredConsumer class takes care of most of the // complicated setup and operation requirements. We need to give it the virtual @@ -129,33 +161,6 @@ openlcb::RefreshLoop loop(stack.node(), producer_a3.polling() // }); -// Object that handles factory reset for our config setup. -class CustomFactoryReset : public DefaultConfigUpdateListener { -public: - void factory_reset(int fd) override - { - // Resets user names. - cfg.userinfo().name().write(fd, "Default user name"); - cfg.userinfo().description().write(fd, "Default user description"); - // Makes the IO pin descriptions empty. - for (unsigned i = 0; i < cfg.seg().consumers().num_repeats(); ++i) { - cfg.seg().consumers().entry(i).description().write(fd, ""); - } - for (unsigned i = 0; i < cfg.seg().producers().num_repeats(); ++i) { - cfg.seg().producers().entry(i).description().write(fd, ""); - cfg.seg().producers().entry(i).debounce().write(fd, 3); - } - } - - UpdateAction apply_configuration( - int fd, bool initial_load, BarrierNotifiable *done) override { - done->notify(); - // Nothing to do; we don't read the configuration. - return UPDATED; - } -} g_custom_factory_reset; - - /** Entry point to application. * @param argc number of command line arguments * @param argv array of command line arguments