Dear all,
Greetings!!!
Am working on a project that I need to complete early this week.
I have already built the project succefully with AVR, Arduino nano, but since there is a need for 32-bit chip space I migrated to stm32f103c series, but now I find it difficult to get thesame results on nano when uploaded to stm32f103c..
In my previous project I use Eeprom.get(), and Eeprom.put(), but since the Roger's Clark library doesn't have class for get() and put() I use write() and update () which is only use for one byte, I will be glad to.have a library class that supports .get() and .put()
So anytime am writing hexdecimal in the eeprom , the results output will be different, my issue now is the secret key(see below for the code), all other seems to work but the secretkey in hex, is not writing correctly on the eeprom.
E.g instead to write
//result on AVR nano
FACTORY SETUP MODE
SN:1234
SC:123456789
SK:A29AB82EDC5FBBC41EC9530F6DAC86B1
It will be writing this
//Result on ARM stm32f103c...
FACTORY SETUP MODE
SN:1234
SC:123456789
SK:22AA88EECCFFBB44EE9933FFDDCC6611
Please see code here.
//Global variable factory setup
uint8_t setupComplete = 0;
uint32_t serialNumber = 0;
uint32_t startingCode = 0;
unsigned char secretKey[16] = {0};
// --- FUNCTIONS - FACTORY SETUP MODE
void handleIncomingChar() {
delay(100); // indispensable to have Serial.available work properly (miscount otherwise)
char incomingChar = getByteSent();
if (incomingChar == '#') {
serialNumber = getSerialNumber();
Serial.print("\nSN:");
Serial.print(serialNumber);
startingCode = getStartingCode();
Serial.print("\nSC:");
Serial.print(startingCode);
updateSecretKey(secretKey);
Serial.print("\nSK:");
for (int i = 0; i < 16; i++) {
if (secretKey <= 0x0F) Serial.print("0");
Serial.print(secretKey, HEX);
}
Serial.println("\n");
Serial.flush();
setupComplete = SETUP_COMPLETE_MAGIC_NUMBER;
}
}
char getByteSent()
/*
* returns the char sent through UART (this function forces to put the key in a char, good practice)
*/
{
char thisIncomingByte = Serial.read(); // read the incoming byte
delay(10);
return(thisIncomingByte);
}
uint32_t getStartingCode()
/*
* get the coming 9 keys pressed and return the corresponding 9 digits number, as a uint32_t
* the starting code is always a 9 digits key
*/
{
int codeArray[9] = {0};
int i;
for (i = 0; i < 9; i++){
char a = getByteSent();
codeArray = (int)(a-'0');
}
getByteSent(); // We read the ";" separator
return(convertArrayToUint32(codeArray));
}
uint32_t getSerialNumber()
/*
* get the coming keys until we see a ";" character appears.
* returns the SN as a uint32_t
*/
{
int codeArray[9] = {0};
int i;
for (i = 0; i < 9; i++){
char a = getByteSent();
if (a == ';') {
int j;
for (j = 8; j > 8-i; j--){ // in case we spot a JUMP and the SN is less than 9 digits , we make sure it is pushed to the right of the tab
codeArray[j] = codeArray[i+j-9];
}
int k;
for (k = 0; k < 9 - i; k++){ // make sure the other
codeArray[k] = 0;
}
return(convertArrayToUint32(codeArray));
}
else{
codeArray = (int)(a-'0');
}
}
return(convertArrayToUint32(codeArray));
}
int updateSecretKey(unsigned char secretKey[16])
/*
* update the array secretKey with the next 16 bytes read
* the uart sends each char in the form of 0xff, therefore we have to read two bytes, then transform it into an int, and store it in the array
* returns updated array
*/
{
int i;
for (i = 0; i < 16; i++){
char char1 = getByteSent();
char char2 = getByteSent();
int sum = 16*(unsigned char)strtol(&char1, NULL, 16) + (unsigned char)strtol(&char2, NULL, 16); // convert the text into the proper int
secretKey = sum;
delay(100);
}
return 0;
}
// Writing on the eeprom
EEPROM.update(SERIAL_NUMBER_ADDRESS, serialNumber);
EEPROM.update(STARTING_CODE_ADDRESS, startingCode);
EEPROM.update(SECRET_KEY_ADDRESS, 'secretKey' );
---------------------------
Thanks, please i need library that supports directly my code to be able to write and get multiple bytes on the eeprom.
Thanks in advance
Emulated eeprom
What could be included in further releases
Return to “Ideas & suggestions”
Jump to
- Announcements
- New users start here
- ↳ Forum rules, FAQs and HowTo's
- ↳ Let us know a bit about you and your projects
- Arduino for STM32
- ↳ General discussion
- ↳ Ideas & suggestions
- ↳ Cores
- ↳ STM32 Core
- ↳ Builds and Announcements
- ↳ Code snippets
- ↳ Ideas & suggestions
- ↳ General discussion
- ↳ Installation and OS related
- ↳ Libraries & Hardware
- ↳ PR's bugs and enhancements
- ↳ LibMaple
- ↳ Builds and Announcements
- ↳ Code snippets
- ↳ General discussion
- ↳ Ideas & suggestions
- ↳ Installation and OS related
- ↳ Libraries & Hardware
- ↳ PR's bugs and enhancements
- ↳ Steve's LibMaple core
- ↳ General discussion
- ↳ PR's bugs and enhancements
- ↳ Projects
- ↳ IDE's
- ↳ Off topic
- Arduino for STM8
- ↳ General discussion
- ↳ Cores
- ↳ STM8 Core
- ↳ Other
- Boards
- ↳ Custom design boards
- ↳ Maple & Maple mini etc
- ↳ STM boards (Discovery, Eval, Nucleo, ...)
- ↳ All other boards
- ↳ STM32F0 based boards
- ↳ STM32F1 based boards
- ↳ STM32F2 based boards
- ↳ STM32F3 based boards
- ↳ STM32F4 based boards
- ↳ STM32F7 based boards
- ↳ STM32G0 based boards
- ↳ STM32G4 based boards
- ↳ STM32H7 based boards
- ↳ STM32L0 based boards
- ↳ STM32L1 based boards
- ↳ STM32L4 based boards
- ↳ STM32L5 based boards
- ↳ STM32MP1 based boards
- ↳ STM32WB based boards
- Bootloaders
- ↳ STM32 HID bootloader
- ↳ USB bootloader
- ↳ STM32 SD-Bootloader
- ↳ STM32 USB CDC bootloader
- Uploaders and debuggers
- ↳ STLink
- ↳ USB to Serial adaptors
- ↳ Black Magic Probe & other
- Dead Thread Graveyard
- ↳ Dead Thread Graveyard