forked from nRF24/RF24
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added initial support to STM32 (using CubeHAL API).
- Loading branch information
1 parent
89358b2
commit 8656ba7
Showing
5 changed files
with
233 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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,99 @@ | ||
#ifndef RF24_UTILITY_STM32_RF24_ARCH_CONFIG_H | ||
#define RF24_UTILITY_STM32_RF24_ARCH_CONFIG_H | ||
|
||
|
||
#include <cstdint> | ||
#include <memory.h> | ||
|
||
|
||
#if defined(STM32F0) | ||
#include "stm32f0xx_hal.h" | ||
#elif defined(STM32F1) | ||
#include "stm32f1xx_hal.h" | ||
#include "stm32f1xx_hal_gpio.h" | ||
#include "stm32f1xx_hal_spi.h" | ||
#elif defined(STM32F4) | ||
#include "stm32f4xx_hal.h" | ||
#include "stm32f4xx_hal_gpio.h" | ||
#elif defined(STM32L0) | ||
#include "stm32l0xx_hal.h" | ||
#elif defined(STM32L1) | ||
#include "stm32l1xx_hal.h" | ||
#elif defined(STM32L4) | ||
#include "stm32l4xx_hal.h" | ||
#elif defined(STM32F3) | ||
#include "stm32f3xx_hal.h" | ||
#elif defined(STM32H7) | ||
#include "stm32h7xx_hal.h" | ||
#elif defined(STM32F7) | ||
#include "stm32f7xx_hal.h" | ||
#elif defined(STM32G0) | ||
#include "stm32g0xx_hal.h" | ||
#elif defined(STM32G4) | ||
#include "stm32g4xx_hal.h" | ||
#endif | ||
|
||
|
||
#if !defined(PROGMEM) | ||
#define PROGMEM | ||
#endif | ||
|
||
#if !defined(HIGH) | ||
#define HIGH true | ||
#endif | ||
|
||
#if !defined(LOW) | ||
#define LOW false | ||
#endif | ||
|
||
#if !defined(millis) | ||
#define millis HAL_GetTick | ||
#endif | ||
|
||
#if !defined(delayMicroseconds) | ||
void delayMicroseconds(uint32_t usecs); | ||
#endif | ||
|
||
#if !defined(delay) | ||
#define delay(msecs) delayMicroseconds(1000*msecs) | ||
#endif | ||
|
||
#if !defined(_BV) | ||
#define _BV(bit) (1<<(bit)) | ||
#endif | ||
|
||
#if !defined(PSTR) | ||
#define PSTR(x) (x) | ||
#endif | ||
|
||
#if !defined(printf_P) | ||
#define printf_P printf | ||
#endif | ||
|
||
#if !defined(pgm_read_word) | ||
#define pgm_read_word(p) (*(p)) | ||
#endif | ||
|
||
#if !defined(pgm_read_byte) | ||
#define pgm_read_byte(p) (*(p)) | ||
#endif | ||
|
||
#if !defined(pgm_read_ptr) | ||
#define pgm_read_ptr(p) (*(p)) | ||
#endif | ||
|
||
class DummySpi { | ||
public: | ||
DummySpi(SPI_HandleTypeDef* hspi); | ||
void begin(); | ||
uint8_t transfer(uint8_t data_to_send); | ||
uint32_t get_baud(); | ||
private: | ||
SPI_HandleTypeDef* _hspi; | ||
}; | ||
|
||
#define RF24_SPI_PTR | ||
#define _SPI DummySpi | ||
|
||
|
||
#endif //RF24_UTILITY_STM32_RF24_ARCH_CONFIG_H |
This file contains 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,47 @@ | ||
#include "RF24_arch_config.h" | ||
|
||
|
||
static uint32_t rf24_get_time_us() | ||
{ | ||
return 1000 * HAL_GetTick() + 1000 - (SysTick->VAL / (SystemCoreClock / 1000000)); | ||
} | ||
|
||
|
||
void delayMicroseconds(uint32_t usecs) | ||
{ | ||
uint32_t now = rf24_get_time_us(); | ||
uint32_t blocked_until = now + usecs; | ||
while (blocked_until > rf24_get_time_us()) {} | ||
} | ||
|
||
|
||
DummySpi::DummySpi(SPI_HandleTypeDef *hspi) { | ||
_hspi = hspi; | ||
} | ||
|
||
|
||
void DummySpi::begin() { | ||
HAL_SPI_Init(_hspi); | ||
} | ||
|
||
|
||
uint8_t DummySpi::transfer(uint8_t data_to_send) { | ||
const uint16_t size = 1; | ||
uint8_t rx_data; | ||
HAL_SPI_TransmitReceive(_hspi, &data_to_send, &rx_data, size, HAL_MAX_DELAY); | ||
return rx_data; | ||
} | ||
|
||
uint32_t DummySpi::get_baud() { | ||
// This method was tested with stm32f103c8t6. It may be different on other architectures | ||
const uint8_t actual_config = _hspi->Init.BaudRatePrescaler; | ||
uint16_t preescaler = 2; | ||
if ((actual_config & SPI_CR1_BR_0) > 0) | ||
preescaler = 2 * preescaler; | ||
if ((actual_config & SPI_CR1_BR_1) > 0) | ||
preescaler = 4 * preescaler; | ||
if ((actual_config & SPI_CR1_BR_2) > 0) | ||
preescaler = 16 * preescaler; | ||
uint32_t baud = SystemCoreClock / preescaler; | ||
return baud; | ||
} |