-
-
Notifications
You must be signed in to change notification settings - Fork 896
Add STM32 cores support #1422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Open
Add STM32 cores support #1422
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
257c600
Update .gitignore
KooLru 58e1f0b
STM32 Cores start implementation
KooLru 23adb6f
Cleanup code
KooLru 7249c44
Fix coding style mistakes
KooLru ca6d806
CPUFrequency via HAL_RCC_GetSysClockFreq
KooLru 7f470b9
Fix hwUniqueID and EEPROM
KooLru bef2c93
Code cleanup
KooLru 4c3ac55
Code cleanup
KooLru 13c42ca
Reformat the code
KooLru b641704
Merge branch 'development' into stm32_cores
KooLru 4095c4a
Merge remote-tracking branch 'upstream/development' into development
KooLru df37af9
Merge branch 'development' into stm32_cores
KooLru 633a237
Merge remote-tracking branch 'upstream/development' into stm32_cores
KooLru df9c00a
Add IRQ pin definition for RFM69 radio
KooLru c5a3b8b
Merge remote-tracking branch 'upstream/development' into stm32_cores
KooLru 6390c18
Merge remote-tracking branch 'upstream/development' into stm32_cores
KooLru File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,3 +13,4 @@ doxygen.log | |
| TAGS | ||
| tags | ||
| .DS_Store | ||
| .vs/* | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletions
hal/architecture/STM32/MyHwSTM32.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| /* | ||
| * 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 | ||
| * repeater and gateway builds a routing tables in EEPROM which keeps track of the | ||
| * network topology allowing messages to be routed to nodes. | ||
| * | ||
| * Created by Henrik Ekblad <henrik.ekblad@mysensors.org> | ||
| * Copyright (C) 2013-2020 Sensnology AB | ||
| * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors | ||
| * | ||
| * Documentation: http://www.mysensors.org | ||
| * Support Forum: http://forum.mysensors.org | ||
| * | ||
| * This program is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU General Public License | ||
| * version 2 as published by the Free Software Foundation. | ||
| */ | ||
|
|
||
| #include "MyHwSTM32.h" | ||
|
|
||
| /* | ||
| * Pinout STM32F103C8 dev board: | ||
| * http://wiki.stm32duino.com/images/a/ae/Bluepillpinout.gif | ||
| * | ||
| * Wiring | ||
| * -------------------------------------------------- | ||
| RFM69 CLK MISO MOSI CSN CE IRQ | ||
| SPI1 PA5 PA6 PA7 PA4 NA PA3 (default) | ||
|
|
||
| RF24 CLK MISO MOSI CSN CE IRQ | ||
| SPI1 PA5 PA6 PA7 PA4 PB0 NA | ||
|
|
||
| */ | ||
|
|
||
| bool hwInit(void) | ||
| { | ||
| #if !defined(MY_DISABLED_SERIAL) | ||
| MY_SERIALDEVICE.begin(MY_BAUD_RATE); | ||
| #if defined(MY_GATEWAY_SERIAL) | ||
| while (!MY_SERIALDEVICE) {} | ||
| #endif | ||
| #endif | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| void hwReadConfigBlock(void *buf, void *addr, size_t length) | ||
| { | ||
| uint8_t *dst = static_cast<uint8_t *>(buf); | ||
| int offs = reinterpret_cast<int>(addr); | ||
| eeprom_buffer_fill(); | ||
| while (length-- > 0) { | ||
| *dst++ = eeprom_buffered_read_byte(offs++); | ||
| } | ||
| } | ||
|
|
||
| void hwWriteConfigBlock(void *buf, void *addr, size_t length) | ||
| { | ||
| uint8_t *src = static_cast<uint8_t *>(buf); | ||
| int offs = reinterpret_cast<int>(addr); | ||
| while (length-- > 0) { | ||
| eeprom_buffered_write_byte(offs++, *src++); | ||
| } | ||
| eeprom_buffer_flush(); | ||
| } | ||
|
|
||
| uint8_t hwReadConfig(const int addr) | ||
| { | ||
| uint8_t value; | ||
| hwReadConfigBlock(&value, reinterpret_cast<void *>(addr), 1); | ||
| return value; | ||
| } | ||
|
|
||
| void hwWriteConfig(const int addr, uint8_t value) | ||
| { | ||
| if (hwReadConfig(addr) != value) { | ||
| hwWriteConfigBlock(&value, reinterpret_cast<void *>(addr), 1); | ||
| } | ||
| } | ||
|
|
||
| int8_t hwSleep(uint32_t ms) | ||
| { | ||
| // TODO: Not supported! | ||
| (void)ms; | ||
| return MY_SLEEP_NOT_POSSIBLE; | ||
| } | ||
|
|
||
| int8_t hwSleep(const uint8_t interrupt, const uint8_t mode, uint32_t ms) | ||
| { | ||
| // TODO: Not supported! | ||
| (void)interrupt; | ||
| (void)mode; | ||
| (void)ms; | ||
| return MY_SLEEP_NOT_POSSIBLE; | ||
| } | ||
|
|
||
| int8_t hwSleep(const uint8_t interrupt1, const uint8_t mode1, const uint8_t interrupt2, | ||
| const uint8_t mode2, | ||
| uint32_t ms) | ||
| { | ||
| // TODO: Not supported! | ||
| (void)interrupt1; | ||
| (void)mode1; | ||
| (void)interrupt2; | ||
| (void)mode2; | ||
| (void)ms; | ||
| return MY_SLEEP_NOT_POSSIBLE; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| bool hwUniqueID(unique_id_t *uniqueID) | ||
| { | ||
| // Fill ID with FF | ||
| (void)memset((uint8_t *)uniqueID, 0xFF, 16); | ||
| // Read device ID | ||
| (void)memcpy((uint8_t *)uniqueID, (uint32_t *)UID_BASE, 12); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| uint16_t hwCPUVoltage(void) | ||
| { | ||
| //Not yet implemented | ||
| return FUNCTION_NOT_SUPPORTED; | ||
| } | ||
|
|
||
| uint16_t hwCPUFrequency(void) | ||
| { | ||
| return HAL_RCC_GetSysClockFreq()/1000000UL; | ||
| } | ||
|
|
||
| int8_t hwCPUTemperature(void) | ||
| { | ||
| return FUNCTION_NOT_SUPPORTED; | ||
| } | ||
|
|
||
| uint16_t hwFreeMem(void) | ||
| { | ||
| //Not yet implemented | ||
| return FUNCTION_NOT_SUPPORTED; | ||
| } | ||
|
|
||
|
|
||
| void hwWatchdogReset(void) | ||
| { | ||
| IWatchdog.reload(); | ||
| } | ||
|
|
||
| void hwReboot(void) | ||
| { | ||
| NVIC_SystemReset(); | ||
| while (true) | ||
| ; | ||
| } |
128 changes: 128 additions & 0 deletions
hal/architecture/STM32/MyHwSTM32.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| /* | ||
| * 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 | ||
| * repeater and gateway builds a routing tables in EEPROM which keeps track of the | ||
| * network topology allowing messages to be routed to nodes. | ||
| * | ||
| * Created by Henrik Ekblad <henrik.ekblad@mysensors.org> | ||
| * Copyright (C) 2013-2020 Sensnology AB | ||
| * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors | ||
| * | ||
| * Documentation: http://www.mysensors.org | ||
| * Support Forum: http://forum.mysensors.org | ||
| * | ||
| * This program is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU General Public License | ||
| * version 2 as published by the Free Software Foundation. | ||
| */ | ||
|
|
||
| #ifndef MyHwSTM32_h | ||
| #define MyHwSTM32_h | ||
|
|
||
| #include <IWatchdog.h> | ||
| #include <itoa.h> | ||
| #include <SPI.h> | ||
|
|
||
| #ifdef __cplusplus | ||
| #include <Arduino.h> | ||
| #endif | ||
|
|
||
| #define CRYPTO_LITTLE_ENDIAN | ||
|
|
||
| #ifndef MY_SERIALDEVICE | ||
| // On Nucleo board UART 2 connect to ST-LINK | ||
| #if SERIAL_UART_INSTANCE == 2 | ||
| #define MY_SERIALDEVICE Serial2 | ||
| #else | ||
| #define MY_SERIALDEVICE Serial | ||
| #endif | ||
| #endif | ||
|
|
||
| #ifndef MY_DEBUGDEVICE | ||
| #define MY_DEBUGDEVICE MY_SERIALDEVICE | ||
| #endif | ||
|
|
||
| // SS default | ||
| #ifndef SS | ||
| #define SS PA4 | ||
| #endif | ||
|
|
||
| // mapping | ||
| //#define yield() // not defined | ||
|
|
||
| //#ifndef digitalPinToInterrupt | ||
| //#define digitalPinToInterrupt(__pin) (__pin) | ||
| //#endif | ||
| // redefine 8 bit types of inttypes.h (as of SAMD board defs 1.8.1) | ||
| #undef PRId8 | ||
| #undef PRIi8 | ||
| #undef PRIo8 | ||
| #undef PRIu8 | ||
| #undef PRIx8 | ||
| #undef PRIX8 | ||
| #undef PRIdLEAST8 | ||
| #undef PRIiLEAST8 | ||
| #undef PRIoLEAST8 | ||
| #undef PRIuLEAST8 | ||
| #undef PRIxLEAST8 | ||
| #undef PRIXLEAST8 | ||
| #undef PRIdFAST8 | ||
| #undef PRIiFAST8 | ||
| #undef PRIoFAST8 | ||
| #undef PRIuFAST8 | ||
| #undef PRIxFAST8 | ||
| #undef PRIXFAST8 | ||
| #define PRId8 "d" | ||
| #define PRIi8 "i" | ||
| #define PRIo8 "o" | ||
| #define PRIu8 "u" | ||
| #define PRIx8 "x" | ||
| #define PRIX8 "X" | ||
| #define PRIdLEAST8 "d" | ||
| #define PRIiLEAST8 "i" | ||
| #define PRIoLEAST8 "o" | ||
| #define PRIuLEAST8 "u" | ||
| #define PRIxLEAST8 "x" | ||
| #define PRIXLEAST8 "X" | ||
| #define PRIdFAST8 "d" | ||
| #define PRIiFAST8 "i" | ||
| #define PRIoFAST8 "o" | ||
| #define PRIuFAST8 "u" | ||
| #define PRIxFAST8 "x" | ||
| #define PRIXFAST8 "X" | ||
|
|
||
| #define hwDigitalWrite(__pin, __value) digitalWrite(__pin, __value) | ||
| #define hwDigitalRead(__pin) digitalRead(__pin) | ||
| #define hwPinMode(__pin, __value) pinMode(__pin, __value) | ||
| #define hwMillis() millis() | ||
|
|
||
| //void hwRandomNumberInit(void); | ||
| #define hwRandomNumberInit() randomSeed(analogRead(MY_SIGNING_SOFT_RANDOMSEED_PIN)) | ||
| #define hwGetSleepRemaining() (0ul) | ||
|
|
||
| //extern void serialEventRun(void) __attribute__((weak)); | ||
| bool hwInit(void); | ||
|
|
||
| void hwWatchdogReset(void); | ||
| void hwReboot(void); | ||
|
|
||
| void hwReadConfigBlock(void *buf, void *addr, size_t length); | ||
| void hwWriteConfigBlock(void *buf, void *addr, size_t length); | ||
| void hwWriteConfig(const int addr, uint8_t value); | ||
| uint8_t hwReadConfig(const int addr); | ||
|
|
||
|
|
||
|
|
||
| // SOFTSPI | ||
| #ifdef MY_SOFTSPI | ||
| #error Soft SPI is not available on this architecture! | ||
| #endif | ||
| #define hwSPI SPI //!< hwSPI | ||
|
|
||
|
|
||
| #ifndef DOXYGEN | ||
| #define MY_CRITICAL_SECTION | ||
| #endif /* DOXYGEN */ | ||
|
|
||
| #endif |
66 changes: 66 additions & 0 deletions
hal/architecture/STM32/MyMainSTM32.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| /* | ||
| * 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 | ||
| * repeater and gateway builds a routing tables in EEPROM which keeps track of the | ||
| * network topology allowing messages to be routed to nodes. | ||
| * | ||
| * Created by Henrik Ekblad <henrik.ekblad@mysensors.org> | ||
| * Copyright (C) 2013-2020 Sensnology AB | ||
| * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors | ||
| * | ||
| * Documentation: http://www.mysensors.org | ||
| * Support Forum: http://forum.mysensors.org | ||
| * | ||
| * This program is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU General Public License | ||
| * version 2 as published by the Free Software Foundation. | ||
| */ | ||
|
|
||
| #define ARDUINO_MAIN | ||
| #include "Arduino.h" | ||
|
|
||
| // Force init to be called *first*, i.e. before static object allocation. | ||
| // Otherwise, statically allocated objects that need HAL may fail. | ||
| __attribute__((constructor(101))) void premain() | ||
| { | ||
|
|
||
| // Required by FreeRTOS, see http://www.freertos.org/RTOS-Cortex-M3-M4.html | ||
| #ifdef NVIC_PRIORITYGROUP_4 | ||
| HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4); | ||
| #endif | ||
| #if (__CORTEX_M == 0x07U) | ||
| // Defined in CMSIS core_cm7.h | ||
| #ifndef I_CACHE_DISABLED | ||
| SCB_EnableICache(); | ||
| #endif | ||
| #ifndef D_CACHE_DISABLED | ||
| SCB_EnableDCache(); | ||
| #endif | ||
| #endif | ||
|
|
||
| init(); | ||
| } | ||
|
|
||
| /* | ||
| * \brief Main entry point of Arduino application | ||
| */ | ||
| int main(void) | ||
| { | ||
| initVariant(); | ||
|
|
||
| _begin(); // Startup MySensors library | ||
| for(;;) { | ||
| _process(); // Process incoming data | ||
| #if defined(CORE_CALLBACK) | ||
| CoreCallback(); | ||
| #endif | ||
| if (loop) { | ||
| loop(); // Call sketch loop | ||
| } | ||
| if (serialEventRun) { | ||
| serialEventRun(); | ||
| } | ||
| } | ||
| return 0; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.