Minor updates STM32F1 support (#851)

This commit is contained in:
Olivier
2017-05-21 14:20:07 +02:00
committed by GitHub
parent 6c12dddf5a
commit abba1ec377
3 changed files with 41 additions and 21 deletions
+27 -5
View File
@@ -1,4 +1,4 @@
/**
/**
* The MySensors Arduino library handles the wireless radio link and protocol
* between your home built sensors/actuators and HA controller of choice.
* The sensors forms a self healing radio network with optional repeaters. Each
@@ -18,8 +18,6 @@
*/
#include "MyHwSTM32F1.h"
#include <EEPROM.h>
/*
* Pinout STM32F103C8 dev board:
@@ -50,7 +48,6 @@ bool hwInit(void)
MY_SERIALDEVICE.begin(MY_BAUD_RATE);
#endif
if (EEPROM.init() == EEPROM_OK) {
uint16 cnt;
EEPROM.count(&cnt);
if(cnt>=EEPROM.maxcount()) {
@@ -120,6 +117,31 @@ int8_t hwSleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mo
return MY_SLEEP_NOT_POSSIBLE;
}
void hwRandomNumberInit(void)
{
// use internal temperature sensor as noise source
adc_reg_map *regs = ADC1->regs;
regs->CR2 |= ADC_CR2_TSVREFE;
regs->SMPR1 |= ADC_SMPR1_SMP16;
uint32_t seed = 0;
uint16_t currentValue, newValue = 0;
for (uint8_t i = 0; i<32; i++) {
const uint32_t timeout = hwMillis() + 20;
while (timeout >= hwMillis()) {
newValue = adc_read(ADC1, 16);
if (newValue != currentValue) {
currentValue = newValue;
break;
}
}
seed ^= ( (newValue + hwMillis()) & 7) << i;
}
randomSeed(seed);
}
bool hwUniqueID(unique_id_t* uniqueID)
{
(void)memcpy((uint8_t*)uniqueID, (uint32_t*)0x1FFFF7E0, 16);
@@ -142,7 +164,7 @@ uint16_t hwCPUFrequency()
uint16_t hwFreeMem()
{
//Not yet implemented
return 0;
return FUNCTION_NOT_SUPPORTED;
}
void hwDebugPrint(const char *fmt, ...)
+9 -9
View File
@@ -24,7 +24,7 @@
#include <libmaple/iwdg.h>
#include <itoa.h>
#include <EEPROM.h>
#ifdef __cplusplus
#include <Arduino.h>
#endif
@@ -33,37 +33,37 @@
#define snprintf_P snprintf
#define vsnprintf_P vsnprintf
// emulated EEPROM (experimental)
#define EEPROM_PAGE_SIZE (uint16_t)1024
#define EEPROM_SIZE (uint16_t)2048
#define EEPROM_START_ADDRESS ((uint32_t)(0x8000000 + 128 * EEPROM_PAGE_SIZE - 2 * EEPROM_PAGE_SIZE))
#ifndef MY_SERIALDEVICE
#define MY_SERIALDEVICE Serial
#endif
// Define these as macros to save valuable space
#ifndef digitalPinToInterrupt
#define digitalPinToInterrupt(__pin) (__pin)
#endif
#define hwDigitalWrite(__pin, __value) digitalWrite(__pin, __value)
#define hwDigitalRead(__pin) digitalRead(__pin)
#define hwPinMode(__pin, __value) pinMode(__pin, __value)
#define hwWatchdogReset() iwdg_feed()
#define hwReboot() nvic_sys_reset()
#define hwMillis() millis()
void (*serialEventRun)() = NULL;
extern void serialEventRun(void) __attribute__((weak));
//void (*serialEventRun)() = NULL;
bool hwInit(void);
void hwRandomNumberInit(void);
void hwReadConfigBlock(void* buf, void* adr, size_t length);
void hwWriteConfigBlock(void* buf, void* adr, size_t length);
void hwWriteConfig(const int addr, uint8_t value);
uint8_t hwReadConfig(const int addr);
#define hwRandomNumberInit() randomSeed(analogRead(MY_SIGNING_SOFT_RANDOMSEED_PIN))
#ifndef DOXYGEN
#define MY_CRITICAL_SECTION
#endif /* DOXYGEN */
#endif
#endif
+5 -7
View File
@@ -1,4 +1,4 @@
/**
/**
* The MySensors Arduino library handles the wireless radio link and protocol
* between your home built sensors/actuators and HA controller of choice.
* The sensors forms a self healing radio network with optional repeaters. Each
@@ -17,8 +17,6 @@
* version 2 as published by the Free Software Foundation.
*/
// Initialize library and handle sketch functions like we want to
extern "C" void __libc_init_array(void);
// Force init to be called *first*, i.e. before static object allocation.
@@ -28,13 +26,13 @@ __attribute__(( constructor (101))) void premain()
init();
}
// Initialize library and handle sketch functions like we want to
int main(void)
{
_begin();
_begin(); // Startup MySensors library
for(;;) {
_process();
if (loop) {
_process(); // Process incoming data
if (loop) { // Call sketch loop
loop();
}
if (serialEventRun) {