Merge pull request #178 from felis/STM32F4

Added support for STM32F446 Nucleo board
This commit is contained in:
Kristian Sloth Lauszus 2015-11-07 15:12:39 +01:00
commit fe12f0ede1
6 changed files with 91 additions and 3 deletions

View file

@ -553,7 +553,7 @@ void PS3USB::getMoveCalibration(uint8_t *data) {
// bmRequest = Device to host (0x80) | Class (0x20) | Interface (0x01) = 0xA1, bRequest = Get Report (0x01), Report ID (0x10), Report Type (Feature 0x03), interface (0x00), datalength, datalength, data
pUsb->ctrlReq(bAddress, epInfo[PS3_CONTROL_PIPE].epAddr, bmREQ_HID_IN, HID_REQUEST_GET_REPORT, 0x10, 0x03, 0x00, 49, 49, buf, NULL);
for(byte j = 0; j < 49; j++)
for(uint8_t j = 0; j < 49; j++)
data[49 * i + j] = buf[j];
}
}

View file

@ -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 [NUCLEO-F446RE](http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/LN1847/PF262063) is supported featuring the STM32F446. Take a look at the following example code: <https://github.com/Lauszus/Nucleo_F446RE_USBHost>.
The following boards need to be activated manually in [settings.h](settings.h):

View file

@ -1074,6 +1074,62 @@ MAKE_PIN(P24, Pin_nRF51822_to_Arduino(D24));
#undef MAKE_PIN
#elif defined(STM32F446xx)
// NUCLEO-F446RE
#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_HIGH; \
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"

View file

@ -37,7 +37,7 @@ e-mail : support@circuitsathome.com
sendbyte(a); \
}
static byte lcdPins; //copy of LCD pins
static uint8_t lcdPins; //copy of LCD pins
Max_LCD::Max_LCD(USB *pusb) : pUsb(pusb) {
lcdPins = 0;

View file

@ -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 */

View file

@ -45,6 +45,11 @@ public:
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();
@ -86,7 +91,7 @@ typedef SPi< Pb1, Pb2, Pb3, Pb0 > spi;
typedef SPi< Pb5, Pb3, Pb4, Pb2 > spi;
#elif defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)
typedef SPi< Pb7, Pb5, Pb6, Pb4 > spi;
#elif (defined(CORE_TEENSY) && (defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MKL26Z64__))) || defined(__ARDUINO_X86__) || defined(__MIPSEL__)
#elif (defined(CORE_TEENSY) && (defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MKL26Z64__))) || defined(__ARDUINO_X86__) || defined(__MIPSEL__) || defined(STM32F4)
typedef SPi< P13, P11, P12, P10 > spi;
#elif defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)
typedef SPi< P76, P75, P74, P10 > spi;
@ -162,6 +167,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);
@ -202,6 +212,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) {
@ -252,6 +267,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
@ -295,6 +315,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) {