knx
ETS configurable knx-stack
stm32_platform.cpp
Go to the documentation of this file.
1 #include "stm32_platform.h"
2 
3 #ifdef ARDUINO_ARCH_STM32
4 #include <EEPROM.h>
5 #include "knx/bits.h"
6 
7 #ifndef KNX_SERIAL
8  #define KNX_SERIAL Serial2
9 #endif
10 
12 #ifndef KNX_NO_DEFAULT_UART
13  : ArduinoPlatform(&KNX_SERIAL)
14 #endif
15 {
16 }
17 
18 Stm32Platform::Stm32Platform( HardwareSerial* s) : ArduinoPlatform(s)
19 {
20 }
21 
23 {
24  delete [] _eepromPtr;
25 }
26 
28 {
29  return HAL_GetUIDw0() ^ HAL_GetUIDw1() ^ HAL_GetUIDw2();
30 }
31 
33 {
34  NVIC_SystemReset();
35 }
36 
37 uint8_t* Stm32Platform::getEepromBuffer(uint32_t size)
38 {
39  // check if the buffer already exists
40  if (_eepromPtr == nullptr) // we need to initialize the buffer first
41  {
42  if (size > E2END + 1)
43  {
44  fatalError();
45  }
46 
47  _eepromSize = size;
48  _eepromPtr = new uint8_t[size];
49  eeprom_buffer_fill();
50 
51  for (uint16_t i = 0; i < size; ++i)
52  _eepromPtr[i] = eeprom_buffered_read_byte(i);
53  }
54 
55  return _eepromPtr;
56 }
57 
59 {
60  if (_eepromPtr == nullptr || _eepromSize == 0)
61  return;
62 
63  for (uint16_t i = 0; i < _eepromSize; ++i)
64  eeprom_buffered_write_byte(i, _eepromPtr[i]);
65 
66  // For some GD32 chips, the flash needs to be unlocked twice
67  // and the first call will fail. If the first call is
68  // successful, the second one (inside eeprom_buffer_flush)
69  // does nothing.
70  HAL_FLASH_Unlock();
71  eeprom_buffer_flush();
72 }
73 
74 #endif
uint32_t uniqueSerialNumber() override
uint8_t * getEepromBuffer(uint32_t size)