Skip to content

Commit dd92ad1

Browse files
authored
Major major Release V2
merge develop into main
2 parents d2e40b5 + 663b66d commit dd92ad1

File tree

164 files changed

+7270
-6916
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

164 files changed

+7270
-6916
lines changed

TODO.md

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,32 @@
1-
# Short Term ToDo's
1+
# MuMo SW V3
2+
## ToDo's
23

3-
* getbatteryChargeFromVoltage table right by doing a discharge test over 24h
4-
5-
* CLI :
6-
- UART2 activeren bij USB connectie
4+
### Priority High
75

6+
* measurementsGroupCollection
7+
* make it work for variable amount of EEPROM memory
8+
* target unit test for wait time after page write into eeprom
89

10+
### Priority Medium
911
* deviceStatusReq doen werken met echte waarden
1012
- ontvangstwaarden van laatste downlink opslaan
1113
- batterijspanning omzetten in uint8 : omrekening toevoegen aan battery
1214

15+
* Power events
16+
when connecting / disconnection USB, this should be logged as an measurement-event and transmitted in the measurements
17+
1318

14-
* wrapping of measurementsCollection : writing and reading measurements
15-
* erase old measurements when space needed for new ones
19+
### Priority Low
20+
* Make ePaper display more lowPower
21+
* use partial update or fast update. Full update once per x updates
1622

23+
* ST HAL
24+
* remove HAL code from C++ wrapper
1725

18-
# Medium Term ToDo's
19-
* integrate qrCode as full static class.
20-
- add unit testing
21-
- move code from screen to graphics
26+
* getbatteryChargeFromVoltage table right by doing a discharge test over 24h
2227

23-
# Long Term ToDo's
2428

29+
* merge hw aes tests into 1, in order to not have too many target unit tests
2530
* make generic unit tests also run on target
26-
* OTAA
27-
* make EEPROM work for multiples of 64K :
28-
- I2C address = 0x50 + address/64K
29-
- address = address % 64K
30-
* target unit test for wait time after page write into eeprom
3131

32-
* report number of measurements on bootscreen
33-
* merge hw aes tests into 1, in order to not have too many target unit tests
34-
* Put some of the aesKey stuff, only needed for SW-AES in conditional compilation, eg key expansion
35-
* read LoRaWAN properties in a safe way to display them in mainController.. I need some getters() io making them public
36-
- frameCount
37-
- devAddr
38-
- keys
32+
* when a certain device/channel is not active, it should not be allowed on the display...

behuizing.md

Lines changed: 0 additions & 4 deletions
This file was deleted.

docs/kmska.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
073
2+
3+
DevAddr : 260B4863
4+
AppSKey : 6E14FDE278291903A94442FF75D8198A
5+
NwkSKey : 93A5743B38DDE35E38B85DD37955D551
6+
7+
8+
9+
074
10+
11+
DevAddr : 260B992D
12+
AppSKey : 9757B56A6296C34084C1CE7BA2BBB6AF
13+
NwkSKey : CBC848CE49A4F8D23F5C2A9624E1C66C
14+
15+
16+
017
17+
18+
UID : 0080E115055045D7
19+
DevAddr : 260B1723
20+
NwkSKey : 687F33B28C045E0412383B50D8853984
21+
AppSKey : 862DDA53CFB9A19169EDF0F4CC31480D

include/stm32wlxx_it.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ extern "C" {
4242

4343
/* Exported macro ------------------------------------------------------------*/
4444
/* USER CODE BEGIN EM */
45-
45+
// WARNING : it is critical for an interrupt handler to be declared here.
46+
// Even if the function is defined (eg in stm32wlxx_it.cpp), it will not be linked when not declared here.
47+
// The result is that a catch-all handler will be used, stopping code execution.
4648
/* USER CODE END EM */
4749

4850
/* Exported functions prototypes ---------------------------------------------*/
@@ -55,10 +57,11 @@ void SVC_Handler(void);
5557
void DebugMon_Handler(void);
5658
void PendSV_Handler(void);
5759
void SysTick_Handler(void);
58-
void TAMP_STAMP_LSECSS_SSRU_IRQHandler(void);
60+
void USART1_IRQHandler(void);
61+
void USART2_IRQHandler(void);
5962
void EXTI3_IRQHandler(void);
63+
void EXTI4_IRQHandler(void);
6064
void RTC_WKUP_IRQHandler(void);
61-
void USART2_IRQHandler(void);
6265
void LPTIM1_IRQHandler(void);
6366
void SUBGHZ_Radio_IRQHandler(void);
6467
/* USER CODE BEGIN EFP */

lib/aes/aesblock.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class aesBlock {
4949
void mixColumns();
5050

5151
union {
52-
uint8_t asByte[lengthInBytes]{}; // interprete the data as 16 bytes
53-
uint32_t asUint32[lengthInWords]; // interprete the data as 4 32bit words
54-
} state; // fancy name for data in the block
52+
uint8_t asByte[lengthInBytes]{}; // interprete the data as 16 bytes
53+
uint32_t asUint32[lengthInWords]; // interprete the data as 4 32bit words
54+
} state; // fancy name for data in the block
5555
};

lib/aes/aeskey.cpp

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,44 @@
44
#include <rcon.hpp>
55
#include <hexascii.hpp>
66

7-
uint8_t* aesKey::asBytes() {
8-
return key.asByte;
9-
}
10-
11-
uint32_t* aesKey::asWords() {
12-
return key.asUint32;
13-
}
14-
157
void aesKey::setFromByteArray(const uint8_t bytes[lengthInBytes]) {
16-
(void)memcpy(key.asByte, bytes, lengthInBytes);
8+
(void)memcpy(keyAsBytes, bytes, lengthInBytes);
9+
syncWordsFromBytes();
10+
syncHexStringFromBytes();
11+
#ifndef HARDWARE_AES
1712
expandKey();
18-
}
19-
20-
void aesKey::setFromWordArray(const uint32_t wordsIn[lengthInWords]) {
21-
for (uint32_t wordIndex = 0; wordIndex < 4; wordIndex++) {
22-
key.asUint32[wordIndex] = wordsIn[wordIndex];
23-
}
13+
#endif
2414
}
2515

2616
void aesKey::setFromHexString(const char* string) {
27-
uint8_t tmpBytes[lengthInBytes];
28-
hexAscii::hexStringToByteArray(tmpBytes, string, 32U);
29-
(void)memcpy(key.asByte, tmpBytes, lengthInBytes);
17+
hexAscii::hexStringToByteArray(keyAsBytes, string, 32U);
18+
syncWordsFromBytes();
19+
syncHexStringFromBytes();
20+
#ifndef HARDWARE_AES
3021
expandKey();
22+
#endif
3123
}
3224

33-
uint32_t aesKey::swapLittleBigEndian( uint32_t wordIn) {
25+
uint32_t aesKey::swapLittleBigEndian(uint32_t wordIn) {
3426
// ARM Cortex-M4 stores uin32_t in little endian format, but STM32WLE5 AES peripheral expects big endian format. This function swaps the bytes in a word.
3527
uint32_t wordOut;
3628
wordOut = (wordIn & 0xFF000000) >> 24 | (wordIn & 0x00FF0000) >> 8 | (wordIn & 0x0000FF00) << 8 | (wordIn & 0x000000FF) << 24;
3729
return wordOut;
3830
}
3931

32+
#ifndef HARDWARE_AES
4033
void aesKey::expandKey() {
41-
(void)memcpy(expandedKey, key.asByte, 16);
34+
for (uint32_t index = 0; index < lengthInBytes; index++) {
35+
expandedKey[index] = keyAsBytes[index];
36+
}
4237
for (uint8_t round = 1; round <= 10; round++) {
4338
(void)memcpy(expandedKey + (round * 16), expandedKey + ((round - 1) * 16), 16);
4439
calculateRoundKey(round);
4540
}
4641
}
42+
#endif
4743

44+
#ifndef HARDWARE_AES
4845
void aesKey::calculateRoundKey(uint8_t round) {
4946
unsigned char temp[4];
5047
uint8_t* expandedKeyPtr = expandedKey + (round * 16);
@@ -61,3 +58,11 @@ void aesKey::calculateRoundKey(uint8_t round) {
6158
temp[index % 4] = expandedKeyPtr[index];
6259
}
6360
}
61+
#endif
62+
63+
void aesKey::syncWordsFromBytes() {
64+
(void)memcpy(keyAsWords, keyAsBytes, lengthInBytes);
65+
}
66+
void aesKey::syncHexStringFromBytes() {
67+
hexAscii::byteArrayToHexString(keyAsHexString, keyAsBytes, lengthInBytes);
68+
}

lib/aes/aeskey.hpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,38 @@ class aesKey {
1010
public:
1111
static constexpr uint32_t lengthInBytes{16};
1212
static constexpr uint32_t lengthInWords{4};
13+
static constexpr uint32_t lengthAsHexAscii{32};
1314

1415
void setFromByteArray(const uint8_t bytes[lengthInBytes]);
15-
void setFromWordArray(const uint32_t wordsIn[lengthInWords]);
1616
void setFromHexString(const char* string);
17-
static uint32_t swapLittleBigEndian(uint32_t wordIn);
1817

19-
uint8_t* asBytes(); // return the key as bytes
20-
uint32_t* asWords(); // return the key as words
18+
uint8_t getAsByte(uint32_t index) const { return keyAsBytes[index]; }
19+
uint32_t getAsWord(uint32_t index) const { return keyAsWords[index]; }
20+
const char* getAsHexString() const { return keyAsHexString; }
21+
22+
static uint32_t swapLittleBigEndian(uint32_t wordIn);
2123

24+
#ifndef HARDWARE_AES
2225
uint8_t expandedKey[176];
26+
#endif
2327

2428
#ifndef unitTesting
2529

2630
private:
2731
#endif
32+
// These are 3 representations of the same key data, in different formats for easy retrieval. They are synced when setting the key.
33+
// representation as hexAscii aligns with how The Things Network shows the AES keys, so copy paste from there is possible.
34+
// representation as bytes : first to hexAscii characters map to first byte of the array
35+
36+
uint8_t keyAsBytes[lengthInBytes]{};
37+
uint32_t keyAsWords[lengthInWords]{};
38+
char keyAsHexString[lengthAsHexAscii + 1]{};
2839

29-
union {
30-
uint8_t asByte[lengthInBytes]{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; // interprete the data as 16 bytes
31-
uint32_t asUint32[lengthInWords]; // interprete the data as 4 32bit words
32-
} key;
40+
void syncWordsFromBytes();
41+
void syncHexStringFromBytes();
3342

43+
#ifndef HARDWARE_AES
3444
void expandKey();
3545
void calculateRoundKey(uint8_t round);
46+
#endif
3647
};

lib/aes/stm32wle5_aes.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
#include <main.h>
44
#endif
55

6-
// #define MODIFY_REG(REG, CLEARMASK, SETMASK) WRITE_REG((REG), (((READ_REG(REG)) & (~(CLEARMASK))) | (SETMASK)))
7-
86
void stm32wle5_aes::initialize(aesMode theMode) {
97
uint32_t aesControlRegisterValue{0};
108
aesControlRegisterValue |= (0b10 << 1); // set dataTypeSelection to byte, for bigEndian / littleEndian conversion
@@ -33,10 +31,10 @@ void stm32wle5_aes::disable() {
3331

3432
void stm32wle5_aes::setKey(aesKey& theKey) {
3533
#ifndef generic
36-
AES->KEYR0 = aesKey::swapLittleBigEndian(theKey.asWords()[3]); // LeastSignificant bits
37-
AES->KEYR1 = aesKey::swapLittleBigEndian(theKey.asWords()[2]);
38-
AES->KEYR2 = aesKey::swapLittleBigEndian(theKey.asWords()[1]);
39-
AES->KEYR3 = aesKey::swapLittleBigEndian(theKey.asWords()[0]); // MostSignificant bits
34+
AES->KEYR0 = aesKey::swapLittleBigEndian(theKey.getAsWord(3));
35+
AES->KEYR1 = aesKey::swapLittleBigEndian(theKey.getAsWord(2));
36+
AES->KEYR2 = aesKey::swapLittleBigEndian(theKey.getAsWord(1));
37+
AES->KEYR3 = aesKey::swapLittleBigEndian(theKey.getAsWord(0));
4038
#endif
4139
}
4240

@@ -67,7 +65,7 @@ void stm32wle5_aes::read(aesBlock& theBlock) {
6765
#endif
6866
}
6967

70-
void stm32wle5_aes::write(uint32_t* wordsIn) {
68+
void stm32wle5_aes::write(const uint32_t* wordsIn) {
7169
#ifndef generic
7270
AES->DINR = wordsIn[0];
7371
AES->DINR = wordsIn[1];

lib/aes/stm32wle5_aes.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class stm32wle5_aes {
2323
static void setInitializationVector( aesBlock& theBlock);
2424
static void write(aesBlock& theBlock);
2525
static void read(aesBlock& theBlock);
26-
static void write(uint32_t *wordsIn);
26+
static void write(const uint32_t *wordsIn);
2727
static void read(uint32_t *wordsOut);
2828
static bool isComputationComplete();
2929
static void clearComputationComplete();

0 commit comments

Comments
 (0)