Skip to content

Commit

Permalink
Added support for STM32F446 Nucleo board
Browse files Browse the repository at this point in the history
  • Loading branch information
Lauszus committed Oct 12, 2015
1 parent acfcba6 commit 84f66bc
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ Currently the following boards are supported by the library:
* RedBearLab nRF51822
* Digilent chipKIT
* Please see: <http://www.circuitsathome.com/mcu/usb/running-usb-host-code-on-digilent-chipkit-board>.
* STM32F4
* Currently the [STM32F446 Nucleo board](http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/LN1847/PF262063) is supported.
The following boards need to be activated manually in [settings.h](settings.h):
Expand Down
56 changes: 56 additions & 0 deletions avrpins.h
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,62 @@ MAKE_PIN(P24, Pin_nRF51822_to_Arduino(D24));

#undef MAKE_PIN

#elif defined(STM32F446xx)
// STM32F446 Nucleo board

#define MAKE_PIN(className, port, pin) \
class className { \
public: \
static void Set() { \
HAL_GPIO_WritePin(port, pin, GPIO_PIN_SET); \
} \
static void Clear() { \
HAL_GPIO_WritePin(port, pin, GPIO_PIN_RESET); \
} \
static void SetDirRead() { \
static GPIO_InitTypeDef GPIO_InitStruct; \
GPIO_InitStruct.Pin = pin; \
GPIO_InitStruct.Mode = GPIO_MODE_INPUT; \
GPIO_InitStruct.Pull = GPIO_NOPULL; \
HAL_GPIO_Init(port, &GPIO_InitStruct); \
} \
static void SetDirWrite() { \
static GPIO_InitTypeDef GPIO_InitStruct; \
GPIO_InitStruct.Pin = pin; \
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; \
GPIO_InitStruct.Pull = GPIO_NOPULL; \
GPIO_InitStruct.Speed = GPIO_SPEED_LOW; \
HAL_GPIO_Init(port, &GPIO_InitStruct); \
} \
static GPIO_PinState IsSet() { \
return HAL_GPIO_ReadPin(port, pin); \
} \
};

MAKE_PIN(P0, GPIOA, GPIO_PIN_3); // D0
MAKE_PIN(P1, GPIOA, GPIO_PIN_2); // D1
MAKE_PIN(P2, GPIOA, GPIO_PIN_10); // D2
MAKE_PIN(P3, GPIOB, GPIO_PIN_3); // D3
MAKE_PIN(P4, GPIOB, GPIO_PIN_5); // D4
MAKE_PIN(P5, GPIOB, GPIO_PIN_4); // D5
MAKE_PIN(P6, GPIOB, GPIO_PIN_10); // D6
MAKE_PIN(P7, GPIOA, GPIO_PIN_8); // D7
MAKE_PIN(P8, GPIOA, GPIO_PIN_9); // D8
MAKE_PIN(P9, GPIOC, GPIO_PIN_7); // D9
MAKE_PIN(P10, GPIOB, GPIO_PIN_6); // D10
MAKE_PIN(P11, GPIOA, GPIO_PIN_7); // D11
MAKE_PIN(P12, GPIOA, GPIO_PIN_6); // D12
MAKE_PIN(P13, GPIOA, GPIO_PIN_5); // D13

MAKE_PIN(P14, GPIOA, GPIO_PIN_0); // A0
MAKE_PIN(P15, GPIOA, GPIO_PIN_1); // A1
MAKE_PIN(P16, GPIOA, GPIO_PIN_4); // A2
MAKE_PIN(P17, GPIOB, GPIO_PIN_0); // A3
MAKE_PIN(P18, GPIOC, GPIO_PIN_1); // A4
MAKE_PIN(P19, GPIOC, GPIO_PIN_0); // A5

#undef MAKE_PIN

#else
#error "Please define board in avrpins.h"

Expand Down
5 changes: 5 additions & 0 deletions settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,9 @@ e-mail : support@circuitsathome.com
#include <../../../../hardware/pic32/libraries/SPI/SPI.h> // Hack to use the SPI library
#endif

#ifdef STM32F4
#include "stm32f4xx_hal.h"
extern SPI_HandleTypeDef SPI_Handle; // Needed to be declared in your main.cpp
#endif

#endif /* SETTINGS_H */
27 changes: 27 additions & 0 deletions usbhost.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ template< typename SPI_CLK, typename SPI_MOSI, typename SPI_MISO, typename SPI_S
SPI_SS::SetDirWrite();
SPI_SS::Set();
}
#elif defined(STM32F4)
#warning "You need to initialize the SPI interface manually when using the STM32F4 platform"
static void init() {
// Should be initialized by the user manually for now
}
#elif !defined(SPDR)
static void init() {
SPI_SS::SetDirWrite();
Expand Down Expand Up @@ -92,6 +97,8 @@ typedef SPi< P13, P11, P12, P10 > spi;
typedef SPi< P76, P75, P74, P10 > spi;
#elif defined(RBL_NRF51822)
typedef SPi< P16, P18, P17, P10 > spi;
#elif defined(STM32F4)
typedef SPi< P13, P11, P12, P10 > spi;
#else
#error "No SPI entry in usbhost.h"
#endif
Expand Down Expand Up @@ -162,6 +169,11 @@ void MAX3421e< SPI_SS, INTR >::regWr(uint8_t reg, uint8_t data) {
c[0] = reg | 0x02;
c[1] = data;
SPI.transfer(c, 2);
#elif defined(STM32F4)
uint8_t c[2];
c[0] = reg | 0x02;
c[1] = data;
HAL_SPI_Transmit(&SPI_Handle, c, 2, HAL_MAX_DELAY);
#elif !defined(SPDR)
SPI.transfer(reg | 0x02);
SPI.transfer(data);
Expand Down Expand Up @@ -202,6 +214,11 @@ uint8_t* MAX3421e< SPI_SS, INTR >::bytesWr(uint8_t reg, uint8_t nbytes, uint8_t*
SPI.transfer(reg | 0x02);
SPI.transferBuffer(data_p, NULL, nbytes);
data_p += nbytes;
#elif defined(STM32F4)
uint8_t data = reg | 0x02;
HAL_SPI_Transmit(&SPI_Handle, &data, 1, HAL_MAX_DELAY);
HAL_SPI_Transmit(&SPI_Handle, data_p, nbytes, HAL_MAX_DELAY);
data_p += nbytes;
#elif !defined(SPDR)
SPI.transfer(reg | 0x02);
while(nbytes) {
Expand Down Expand Up @@ -252,6 +269,11 @@ uint8_t MAX3421e< SPI_SS, INTR >::regRd(uint8_t reg) {
spi4teensy3::send(reg);
uint8_t rv = spi4teensy3::receive();
SPI_SS::Set();
#elif defined(STM32F4)
HAL_SPI_Transmit(&SPI_Handle, &reg, 1, HAL_MAX_DELAY);
uint8_t rv = 0;
HAL_SPI_Receive(&SPI_Handle, &rv, 1, HAL_MAX_DELAY);
SPI_SS::Set();
#elif !defined(SPDR) || SPI_HAS_TRANSACTION
SPI.transfer(reg);
uint8_t rv = SPI.transfer(0); // Send empty byte
Expand Down Expand Up @@ -295,6 +317,11 @@ uint8_t* MAX3421e< SPI_SS, INTR >::bytesRd(uint8_t reg, uint8_t nbytes, uint8_t*
SPI.transfer(reg);
SPI.transferBuffer(NULL, data_p, nbytes);
data_p += nbytes;
#elif defined(STM32F4)
HAL_SPI_Transmit(&SPI_Handle, &reg, 1, HAL_MAX_DELAY);
memset(data_p, 0, nbytes); // Make sure we send out empty bytes
HAL_SPI_Receive(&SPI_Handle, data_p, nbytes, HAL_MAX_DELAY);
data_p += nbytes;
#elif !defined(SPDR)
SPI.transfer(reg);
while(nbytes) {
Expand Down

0 comments on commit 84f66bc

Please sign in to comment.