-
Hello, Merry Christmas! I'm trying to adapt the working code of Arduino UNO to compile on STM32F407VGT6, This is the only library (UHS30) I know of that supports a USB HUB (through the MAX3421E shield), so I can use a keyboard with a built-in mouse pad (*). The original HAL library only supports operating Mouse or Keyboard at a time. My idea is to make the MAX3421E IC (USB host controller) work with STM32 and then study how to adapt the original HAL library to use the STM32 hardware without needing the MAX3421E. I noticed that the code manages to compile without the debug logs, so maybe it's not long to get it. The code that generates the error is not identifying the STM32 platform. [I.E. #if defined(--AVR--)] ---> Where can I find which reference to use in place of "--AVR--"? Should I use GenF4? This is the original sketch, below is the code that generates an error:
/* Copyright (C) 2015-2016 Andrew J. Kroll
and
Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact information
-------------------
Circuits At Home, LTD
Web : http://www.circuitsathome.com
e-mail : [email protected]
*/
#ifndef UHS_PRINTF_HELPER_H
#define UHS_PRINTF_HELPER_H
#if defined(LOAD_UHS_PRINTF_HELPER)
#include <Arduino.h>
#ifdef true
#undef true
#endif
#ifdef false
#undef false
#endif
// TO-DO: redirect for ARDUINO_SAMD_ZERO ARDUINO_SAM_DUE ARDUINO_spresense_ast to programmer's choice
#ifndef SERIAL_PORT_MONITOR
// Some don't define this.
#define SERIAL_PORT_MONITOR Serial
#endif
#ifndef SERIAL_PORT_HARDWARE
// Some don't define this.
#define SERIAL_PORT_HARDWARE SERIAL_PORT_MONITOR
#endif
#ifndef USB_HOST_SERIAL
#if defined(SERIAL_PORT_USBVIRTUAL) && defined(LOAD_UHS_KINETIS_FS_HOST)
#define USB_HOST_SERIAL SERIAL_PORT_HARDWARE
#else
#define USB_HOST_SERIAL SERIAL_PORT_MONITOR
#endif
#endif
#ifndef USB_HOST_SERIAL_W
#define USB_HOST_SERIAL_W USB_HOST_SERIAL
#endif
#ifndef USB_HOST_SERIAL_R
#define USB_HOST_SERIAL_R USB_HOST_SERIAL
#endif
#if !defined(STDIO_IS_OK_TO_USE_AS_IS)
#if defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_SAM_DUE) || defined(ARDUINO_spresense_ast)
// STDIO patching not required.
#define STDIO_IS_OK_TO_USE_AS_IS
#endif
#endif
#if !defined(STDIO_IS_OK_TO_USE_AS_IS)
// We need to patch STDIO so it can be used.
#if !defined(NOTUSED)
#define NOTUSED(...) __VA_ARGS__ __attribute__((unused))
#endif
#ifndef __AVR__
#ifndef printf_P
#define printf_P(...) printf(__VA_ARGS__)
#endif
#endif
#if defined(ARDUINO_ARCH_PIC32)
/*
* For printf() output with pic32 Arduino
*/
extern "C" {
void _mon_putc(char s) {
USB_HOST_SERIAL_W.write(s);
}
int _mon_getc() {
while(!USB_HOST_SERIAL_R.available());
return USB_HOST_SERIAL_R.read();
}
}
#elif defined(__AVR__)
extern "C" {
static FILE tty_stdio;
static FILE tty_stderr;
static int NOTUSED(tty_stderr_putc(char c, NOTUSED(FILE *t)));
static int NOTUSED(tty_stderr_flush(NOTUSED(FILE *t)));
static int NOTUSED(tty_std_putc(char c, NOTUSED(FILE *t)));
static int NOTUSED(tty_std_getc(NOTUSED(FILE *t)));
static int NOTUSED(tty_std_flush(NOTUSED(FILE *t)));
static int tty_stderr_putc(char c, NOTUSED(FILE *t)) {
USB_HOST_SERIAL_W.write(c);
return 0;
}
static int tty_stderr_flush(NOTUSED(FILE *t)) {
USB_HOST_SERIAL_W.flush();
return 0;
}
static int tty_std_putc(char c, NOTUSED(FILE *t)) {
USB_HOST_SERIAL_W.write(c);
return 0;
}
static int tty_std_getc(NOTUSED(FILE *t)) {
while(!USB_HOST_SERIAL_R.available());
return USB_HOST_SERIAL_R.read();
}
static int tty_std_flush(NOTUSED(FILE *t)) {
USB_HOST_SERIAL_W.flush();
return 0;
}
}
#elif defined(CORE_TEENSY)
extern "C" {
int _write(int fd, const char *ptr, int len) {
int j;
for(j = 0; j < len; j++) {
if(fd == 1)
USB_HOST_SERIAL_W.write(*ptr++);
else if(fd == 2)
USB_HOST_SERIAL_W.write(*ptr++);
}
return len;
}
int _read(int fd, char *ptr, int len) {
if(len > 0 && fd == 0) {
while(!USB_HOST_SERIAL_R.available());
*ptr = USB_HOST_SERIAL_R.read();
return 1;
}
return 0;
}
#include <sys/stat.h>
int _fstat(int fd, struct stat *st) {
memset(st, 0, sizeof (*st));
st->st_mode = S_IFCHR;
st->st_blksize = 1024; // too big??
return 0;
}
int _isatty(int fd) {
return (fd < 3) ? 1 : 0;
}
}
void UHS_PJRC_printf_HELPER_init(void) {
setvbuf(stdout, NULL, _IONBF, 0);
}
#define UHS_printf_HELPER_init() UHS_PJRC_printf_HELPER_init()
#else
#error no STDIO // **<----------------- Here**
#endif // defined(ARDUINO_ARCH_PIC32)
#if defined(__AVR__)
// The only wierdo in the bunch...
void UHS_AVR_printf_HELPER_init(void) {
// Set up stdio/stderr
tty_stdio.put = tty_std_putc;
tty_stdio.get = tty_std_getc;
tty_stdio.flags = _FDEV_SETUP_RW;
tty_stdio.udata = 0;
tty_stderr.put = tty_stderr_putc;
tty_stderr.get = NULL;
tty_stderr.flags = _FDEV_SETUP_WRITE;
tty_stderr.udata = 0;
stdout = &tty_stdio;
stdin = &tty_stdio;
stderr = &tty_stderr;
}
#define UHS_printf_HELPER_init() UHS_AVR_printf_HELPER_init()
#endif
#endif /* STDIO_IS_OK_TO_USE_AS_IS */
#endif /* load.... */
#if !defined(UHS_printf_HELPER_init)
#define UHS_printf_HELPER_init() (void(0))
#endif
#endif /* UHS_PRINTF_HELPER_H */ Source: https://github.com/felis/UHS30/blob/master/libraries/UHS_host/UHS_printf_HELPER.h |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I found another library, I'll see if I can use it, thanks for now.
|
Beta Was this translation helpful? Give feedback.
I managed to do the test successfully, the touchpad (mouse) and the keyboard worked on the same USB port, project at this address:
https://github.com/rtek1000/STM32F4HUB/tree/master/Project-STM32CubeIDE