12 Commits

Author SHA1 Message Date
NIIBE Yutaka
96d2a81331 Version 1.5.
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2017-10-10 13:53:58 +09:00
NIIBE Yutaka
fa7cecc0b4 Support --debug option for exacmple-cdc-gnu-linux. 2017-10-10 12:18:35 +09:00
NIIBE Yutaka
a34937453c New: debug option. 2017-10-10 12:16:03 +09:00
NIIBE Yutaka
dd54b5ff20 Fix example-cdc. 2017-10-10 12:07:02 +09:00
NIIBE Yutaka
c08044e22b Fix sys for STM32F103. 2017-09-29 13:50:06 +09:00
NIIBE Yutaka
5b7c5a9996 Use flash routines in example-cdc-gnu-linux. 2017-09-27 19:24:08 +09:00
NIIBE Yutaka
bc39f0e582 update flash routines for GNU/Linux. 2017-09-27 19:07:14 +09:00
NIIBE Yutaka
e671a539b0 Fix flash routines on GNU/Linux.
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2017-09-08 20:56:23 +09:00
NIIBE Yutaka
2c9191c4b3 Implement flash ROM emulation on GNU/LInux.
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2017-09-08 20:44:56 +09:00
NIIBE Yutaka
af5982507f Define threads stack size by stack-def.h.
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2017-09-05 14:34:25 +09:00
NIIBE Yutaka
a1b993c2e2 Minor changes for SYS.
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2017-09-04 15:23:35 +09:00
NIIBE Yutaka
e73d14ca27 Add muc/sys-gnu-linux.*.
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2017-09-04 15:23:02 +09:00
24 changed files with 1202 additions and 159 deletions

View File

@@ -1,3 +1,42 @@
2017-10-10 NIIBE Yutaka <gniibe@fsij.org>
* VERSION: 1.5.
* doc/chopstx.texi (VERSION): 1.5.
* doc/chopstx-api.texi: Regenerated.
2017-10-09 NIIBE Yutaka <gniibe@fsij.org>
* example-cdc-gnu-linux/sample.c (main): Support debug option.
* mcu/sys-gnu-linux.h (debug): New.
* mcu/sys-gnu-linux.c: Use debug.
* mcu/usb-usbip.c: Use debug.
* example-cdc/sample.ld (.process_stack, .main_stack): Add NOLOAD.
2017-09-29 NIIBE Yutaka <gniibe@fsij.org>
* mcu/sys-stm32f103.c (flash_program_halfword, flash_erase_page)
(flash_write, flash_erase_all_and_exec): Use uintptr_t.
2017-09-08 NIIBE Yutaka <gniibe@fsij.org>
* mcu/sys-gnu-linux.c: Flash emulation implemented.
2017-09-05 NIIBE Yutaka <gniibe@fsij.org>
* example-cdc: Use stack-def.h.
* example-cdc/stack-def.h: New.
2017-09-04 NIIBE Yutaka <gniibe@fsij.org>
* mcu/sys-stm32f103.h (nvic_system_reset): Add noreturn attribute.
* sys.h: Add mcu/sys-gnu-linux.h.
* mcu/sys-gnu-linux.c: New.
* mcu/sys-gnu-linux.h: New.
2017-08-11 NIIBE Yutaka <gniibe@fsij.org>
* VERSION: 1.4.

15
NEWS
View File

@@ -1,6 +1,21 @@
NEWS - Noteworthy changes
* Major changes in Chopstx 1.5
Released 2017-10-10
** Stack size definition by stack-def.h
Stack size of each thread was used to be defined in ldscript.
While emulation on GNU/Linux doesn't use ldscript, it is better
to put those definitions in independent header file. Please see
example-cdc/stack-def.h and example-cdc/sample.ld.
** More support for emulation on GNU/Linux
We have SYS driver for emulation on GNU/Linux. It has flash ROM
emulation.
* Major changes in Chopstx 1.4
Released 2017-08-11

21
README
View File

@@ -1,6 +1,6 @@
Chopstx - Threads and only Threads
Version 1.4
2017-08-11
Version 1.5
2017-10-10
Niibe Yutaka
Flying Stone Technology
@@ -11,12 +11,19 @@ Chopstx is an RT thread library for STM32F103 (ARM Cortex-M3),
STM32F030 (ARM Cortex-M0), MKL27Z (ARM Cortex-M0plus), and
emulation on GNU/Linux.
While most RTOSes come with many features, drivers, and stacks,
Chopstx just offers a simple RT thread library.
While most RTOSes come with many features, drivers, and protocol
stacks, Chopstx just offers a simple RT thread library.
With Chopstx, interrupt handling is also done by a thread. This
enables coherent code for ease of maintenance.
This library is _not_ related to the hand game:
https://en.wikipedia.org/wiki/Chopsticks_(hand_game)
Thanks to Yao Wei and Enrico Zini for giving me the opportunity
visiting the wiki page.
License
=======
@@ -30,8 +37,8 @@ Example code
============
We have some examples in this distribution; Useful ones are LED
blinker and USB CDC-ACM function. For STM32F103, you can build it
USB CDC-ACM demo by:
blinker and USB CDC-ACM device. For STM32F103, you can build it USB
CDC-ACM demo by:
$ cd example-cdc
$ ln -sf ../board/board-olimex-stm32-h103.h board.h
@@ -47,7 +54,7 @@ Future Works
============
Convenience function to determine the bottom of thread stack,
configuration of thread size by comiler's output would be next things
configuration of thread size by compiler's output would be next things
to be done.
Experimental SMP port for Cortex-A7 is under development. For SMP,

View File

@@ -1 +1 @@
release/1.4
release/1.5

View File

@@ -9,7 +9,7 @@ stop further execution of code. It never returns.
@subheading chopstx_create
@anchor{chopstx_create}
@deftypefun {chopstx_t} {chopstx_create} (uint32_t @var{flags_and_prio}, uint32_t @var{stack_addr}, size_t @var{stack_size}, voidfunc @var{thread_entry}, void * @var{arg})
@deftypefun {chopstx_t} {chopstx_create} (uint32_t @var{flags_and_prio}, uintptr_t @var{stack_addr}, size_t @var{stack_size}, voidfunc @var{thread_entry}, void * @var{arg})
@var{flags_and_prio}: Flags and priority
@var{stack_addr}: Stack address

View File

@@ -1,7 +1,7 @@
\input texinfo @c -*-texinfo-*-
@c %**start of header
@setfilename chopstx.info
@set VERSION 1.4
@set VERSION 1.5
@settitle Chopstx Reference Manual
@c Unify some of the indices.
@syncodeindex tp fn

View File

@@ -6,12 +6,12 @@ PROJECT = sample
CHOPSTX = ..
LDSCRIPT=
CSRC = sample.c usb-cdc.c
CSRC = sample.c usb-cdc.c command.c
CHIP=gnu-linux
# USE_SYS = yes
USE_SYS =
USE_SYS = yes
USE_USB = yes
USE_ADC = yes
EMULATION=yes
###################################
@@ -22,7 +22,7 @@ OBJCOPY = $(CROSS)objcopy
MCU = none
CWARN = -Wall -Wextra -Wstrict-prototypes
DEFS = -DGNU_LINUX_EMULATION
DEFS = -DGNU_LINUX_EMULATION -DUSE_SYS_BOARD_ID
OPT = -g # -O3 -Os
LIBS = -lpthread
@@ -34,3 +34,10 @@ board.h:
@exit 1
distclean: clean
build/flash.data: Makefile
@echo 'Generating 8192-byte flash.data'
@/bin/echo -n -e '\xff\xff\xff\xff\xff\xff\xff\xff' >$@
@for i in $(shell seq 1023); do /bin/echo -n -e '\xff\xff\xff\xff\xff\xff\xff\xff' >>$@; done

View File

@@ -1,3 +1,9 @@
(0) Build and generate initial flash data
$ make
$ make build/flash.data
(1) preparation as root
Don't run ModemManager

View File

@@ -0,0 +1,579 @@
#include <string.h>
#include <stdint.h>
#include <chopstx.h>
#include "tty.h"
#include "config.h"
#ifdef ADC_SUPPORT
#include "adc.h"
static int adc_initialized = 0;
#endif
#include "board.h"
#include "sys.h"
struct command_table
{
const char *name;
void (*handler) (struct tty *tty, const char *line);
};
/*
* Put a line (or lines) to TTY.
* LINE should be terminated with newline.
*/
static void
put_line (struct tty *tty, const char *line)
{
tty_send (tty, line, strlen (line));
}
static const char *help_string =
"mdb ADDR [COUNT]; memory display byte\r\n"
"mwh ADDR VALUE [COUNT]; memory write halfword\r\n"
"fes ADDR [COUNT]; flash erase sector\r\n"
"fwh ADDR VALUE [COUNT]; flash write halfword\r\n"
#ifdef CRC32_SUPPORT
"crc32 string; CRC32 calc string\r\n"
#endif
#ifdef ADC_SUPPORT
"adc; get 256-byte from ADC\r\n"
#endif
"sysinfo; system information\r\n"
"help\r\n";
static char hexchar (uint8_t x)
{
x &= 0x0f;
if (x <= 0x09)
return '0' + x;
else if (x <= 0x0f)
return 'a' + x - 10;
else
return '?';
}
#ifdef TOUCH_SUPPORT
static char *
compose_decimal (char *s, int value)
{
uint32_t v;
int col = 1000000000;
int d;
int digit_output = 0;
if (value < 0)
{
*s++ = '-';
v = 1 + ~((uint32_t)value);
}
else
v = (uint32_t)value;
while (col >= 10)
{
if (v >= (uint32_t)col)
{
d = v / col;
v = v - d * col;
*s++ = d + '0';
digit_output = 1;
}
else if (digit_output)
*s++ = '0';
col = col / 10;
}
*s++ = v + '0';
return s;
}
#endif
char *
compose_hex_ptr (char *s, uintptr_t v)
{
s[0] = hexchar (v >> 60);
s[1] = hexchar (v >> 56);
s[2] = hexchar (v >> 52);
s[3] = hexchar (v >> 48);
s[4] = hexchar (v >> 44);
s[5] = hexchar (v >> 40);
s[6] = hexchar (v >> 36);
s[7] = hexchar (v >> 32);
s[8] = hexchar (v >> 28);
s[9] = hexchar (v >> 24);
s[10] = hexchar (v >> 20);
s[11] = hexchar (v >> 16);
s[12] = hexchar (v >> 12);
s[13] = hexchar (v >> 8);
s[14] = hexchar (v >> 4);
s[15] = hexchar (v);
return s+16;
}
static char *
compose_hex (char *s, uint32_t v)
{
s[0] = hexchar (v >> 28);
s[1] = hexchar (v >> 24);
s[2] = hexchar (v >> 20);
s[3] = hexchar (v >> 16);
s[4] = hexchar (v >> 12);
s[5] = hexchar (v >> 8);
s[6] = hexchar (v >> 4);
s[7] = hexchar (v);
return s+8;
}
static char *
compose_hex_byte (char *s, uint8_t v)
{
s[0] = hexchar (v >> 4);
s[1] = hexchar (v);
return s+2;
}
static const char *
get_hex (struct tty *tty, const char *s, uintptr_t *v_p)
{
uintptr_t v = 0;
char c;
if (s[0] == '0' && s[1] == 'x')
s = s + 2;
while (1)
{
c = *s++;
if (c == 0)
{
s--;
break;
}
if (c == ' ')
break;
v = (v << 4);
if (c >= '0' && c <= '9')
v += (c - '0');
else if (c >= 'a' && c <= 'f')
v += (c - 'a') + 10;
else if (c >= 'A' && c <= 'F')
v += (c - 'A') + 10;
else
{
put_line (tty, "hex error\r\n");
return NULL;
}
}
*v_p = v;
return s;
}
#ifdef TOUCH_SUPPORT
#define TOUCH_VALUE_HIGH 100
#define TOUCH_VALUE_LOW 50
static void
cmd_button (struct tty *tty, const char *line)
{
int i = 0;
extern uint16_t touch_get (void);
uint16_t v0 = 0;
int touched = 0;
(void)line;
put_line (tty, "Please touch the bear.\r\n");
while (i < 16)
{
uint16_t v = touch_get ();
v0 = (v0 * 2 + v)/3;
if (touched == 0 && v0 > TOUCH_VALUE_HIGH)
{
tty_send (tty, "!", 1);
touched = 1;
}
else if (touched == 1 && v0 < TOUCH_VALUE_LOW)
{
tty_send (tty, ".", 1);
touched = 0;
i++;
}
chopstx_usec_wait (10*1000);
}
tty_send (tty, "\r\n", 2);
}
static void
cmd_touch (struct tty *tty, const char *line)
{
int i;
extern uint16_t touch_get (void);
(void)line;
put_line (tty, "Please touch the bear.\r\n");
for (i = 0; i < 20; i++)
{
uint16_t v;
char output[8];
char *s;
chopstx_usec_wait (1000*1000);
v = touch_get ();
s = compose_decimal (output, v);
*s++ = '\r';
*s++ = '\n';
tty_send (tty, output, s - output);
}
}
#endif
static void
cmd_mdb (struct tty *tty, const char *line)
{
int i;
uintptr_t addr = 0;
int count = 0;
char c;
const char *s = line;
s = get_hex (tty, s, &addr);
addr &= ~3;
if (s == NULL)
return;
if (*s == 0)
count = 1;
else
{
while (1)
{
c = *s++;
if (c == 0 || c == ' ')
break;
count = count * 10;
if (c >= '0' && c <= '9')
count += c - '0';
else
{
put_line (tty, "mdb error\r\n");
return;
}
}
}
i = 0;
while (i < count)
{
uint8_t v;
char output[68];
char *s;
s = compose_hex_ptr (output, addr);
*s++ = ':';
*s++ = ' ';
while (1)
{
v = *(uint8_t *)addr;
s = compose_hex_byte (s, v);
i++;
addr += 1;
if (i >= count || (i % 16) == 0)
break;
*s++ = ' ';
}
*s++ = '\r';
*s++ = '\n';
tty_send (tty, output, s - output);
}
}
static void
cmd_mwh (struct tty *tty, const char *line)
{
(void)tty;
(void)line;
put_line (tty, "mwh not yet supported\r\n");
}
static void
cmd_fes (struct tty *tty, const char *line)
{
int i;
uintptr_t addr = 0;
int count = 0;
char c;
const char *s = line;
s = get_hex (tty, s, &addr);
if (s == NULL)
return;
if (*s == 0)
count = 1;
else
{
while (1)
{
c = *s++;
if (c == 0 || c == ' ')
break;
count = count * 10;
if (c >= '0' && c <= '9')
count += c - '0';
else
{
put_line (tty, "fww error\r\n");
return;
}
}
}
for (i = 0; i < count; i++)
{
flash_erase_page (addr);
addr += 1024;
}
}
static void
cmd_fwh (struct tty *tty, const char *line)
{
int i;
uintptr_t addr = 0;
uintptr_t d;
uint16_t value = 0;
int count = 0;
char c;
const char *s = line;
s = get_hex (tty, s, &addr);
if (s == NULL)
return;
if (*s == 0)
return;
s = get_hex (tty, s, &d);
value = (uint16_t)d;
if (s == NULL)
return;
if (*s == 0)
count = 1;
else
{
while (1)
{
c = *s++;
if (c == 0 || c == ' ')
break;
count = count * 10;
if (c >= '0' && c <= '9')
count += c - '0';
else
{
put_line (tty, "fww error\r\n");
return;
}
}
}
for (i = 0; i < count; i++)
{
flash_program_halfword (addr, value);
addr += 4;
}
}
#ifdef CRC32_SUPPORT
static unsigned int crc_value;
static void
cmd_crc32 (struct tty *tty, const char *line)
{
uint32_t v;
char string[10];
char *s;
crc32_init (&crc_value);
while (*line)
crc32_u8 (&crc_value, *line++);
v = crc_value ^ 0xffffffff;
s = compose_hex (string, v);
*s++ = '\r';
*s++ = '\n';
tty_send (tty, string, sizeof (string));
}
#endif
#ifdef ADC_SUPPORT
static void
cmd_adc (struct tty *tty, const char *line)
{
int i;
char output[73];
char *s;
(void)line;
if (!adc_initialized)
{
if (adc_init ())
{
put_line (tty, "adc_init error\r\n");
return;
}
else
{
adc_start ();
adc_initialized = 1;
}
}
adc_start_conversion (0, 64);
adc_wait_completion ();
i = 0;
s = output;
while (1)
{
s = compose_hex (s, adc_buf[i]);
i++;
if ((i % 8))
*s++ = ' ';
else
{
*s++ = '\r';
*s++ = '\n';
tty_send (tty, output, s - output);
s = output;
if (i >= 64)
break;
}
}
}
#endif
static void
cmd_sysinfo (struct tty *tty, const char *line)
{
char output[73];
char *s;
int i;
(void)line;
memcpy (output, "SYS version: ", 13);
s = output + 13;
*s++ = sys_version[2];
*s++ = sys_version[4];
*s++ = sys_version[6];
*s++ = '\r';
*s++ = '\n';
tty_send (tty, output, s - output);
memcpy (output, "Board ID: ", 10);
s = output + 10;
s = compose_hex (s, sys_board_id);
*s++ = '\r';
*s++ = '\n';
tty_send (tty, output, s - output);
memcpy (output, "Board name: ", 12);
s = output + 12;
for (i = 0; i < (int)sizeof (output) - 2; i ++)
if ((*s = sys_board_name[i]) == 0)
break;
else
s++;
*s++ = '\r';
*s++ = '\n';
tty_send (tty, output, s - output);
}
static void
cmd_help (struct tty *tty, const char *line)
{
(void)line;
put_line (tty, help_string);
}
struct command_table command_table[] = {
#ifdef TOUCH_SUPPORT
{ "button", cmd_button },
{ "touch", cmd_touch },
#endif
{ "mdb", cmd_mdb },
{ "mwh", cmd_mwh },
{ "fes", cmd_fes },
{ "fwh", cmd_fwh },
#ifdef CRC32_SUPPORT
{ "crc32", cmd_crc32 },
#endif
#ifdef ADC_SUPPORT
{ "adc", cmd_adc },
#endif
{ "sysinfo", cmd_sysinfo },
{ "help", cmd_help },
};
#define N_CMDS (int)(sizeof (command_table) / sizeof (struct command_table))
/*
* Dispatch a command parsing LINE.
* Line is NULL terminated with no newline.
*/
void
cmd_dispatch (struct tty *tty, const char *line)
{
int i;
const char *p;
unsigned int n = 0;
p = line;
while (*p)
{
if (*p++ == ' ')
break;
n++;
}
for (i = 0; i < N_CMDS; i++)
if (n == strlen (command_table[i].name)
&& strncmp ((const char *)line, command_table[i].name, n) == 0)
break;
if (i != N_CMDS)
(*command_table[i].handler) (tty, p);
else
{
char crlf[] = { '\r', '\n' };
put_line (tty, "No such command: ");
tty_send (tty, line, n);
tty_send (tty, crlf, sizeof (crlf));
}
}

View File

@@ -0,0 +1,2 @@
void cmd_dispatch (struct tty *tty, const char *line);
char * compose_hex_ptr (char *s, uintptr_t v);

View File

@@ -0,0 +1,2 @@
#undef CRC32_SUPPORT
#define ADC_SUPPORT

View File

@@ -5,33 +5,15 @@
#include <chopstx.h>
#include "sys.h"
#include "usb_lld.h"
#include "tty.h"
#include "command.h"
#include <unistd.h>
#include <stdio.h>
static void
set_led (int on)
{
#if 0
/* For debugging, no output of LED. */
#if 1
if (on)
write (1, "********\x08\x08\x08\x08\x08\x08\x08\x08", 16);
else
write (1, " \x08\x08\x08\x08\x08\x08\x08\x08", 16);
#else
if (on)
puts ("!");
else
puts ("");
#endif
#else
(void)on;
#endif
}
static chopstx_mutex_t mtx;
static chopstx_cond_t cnd0;
static chopstx_cond_t cnd1;
@@ -114,9 +96,10 @@ main (int argc, const char *argv[])
{
struct tty *tty;
uint8_t count;
uintptr_t addr;
(void)argc;
(void)argv;
if (argc >= 2 && !strncmp (argv[1], "--debug=", 8))
debug = strtol (&argv[1][8], NULL, 10);
chopstx_mutex_init (&mtx);
chopstx_cond_init (&cnd0);
@@ -134,6 +117,9 @@ main (int argc, const char *argv[])
chopstx_cond_signal (&cnd1);
chopstx_mutex_unlock (&mtx);
addr = flash_init ("flash.data");
flash_unlock ();
u = 1;
tty = tty_open ();
@@ -145,6 +131,7 @@ main (int argc, const char *argv[])
{
char s[LINEBUFSIZE];
connection_loop:
u = 1;
tty_wait_connection (tty);
@@ -157,39 +144,52 @@ main (int argc, const char *argv[])
memcpy (s, "xx: Hello, World with Chopstx!\r\n", 32);
s[0] = hexchar (count >> 4);
s[1] = hexchar (count & 0x0f);
count++;
puts("send hello");
if (tty_send (tty, s, 32) < 0)
continue;
s[0] = hexchar (count >> 4);
s[1] = hexchar (count & 0x0f);
s[2] = ':';
s[3] = ' ';
compose_hex_ptr (s+4, addr);
s[20] = '\r';
s[21] = '\n';
count++;
if (tty_send (tty, s, 22) < 0)
continue;
while (1)
{
int size;
uint32_t usec;
puts("recv msg");
usec = 3000000; /* 3.0 seconds */
size = tty_recv (tty, s + 4, &usec);
if (size < 0)
/* Prompt */
if (tty_send (tty, "> ", 2) < 0)
break;
if (size)
usec = 3000000; /* 3.0 seconds */
while (1)
{
size--;
int size = tty_recv (tty, s, &usec);
u ^= 1;
puts("send msg");
s[0] = hexchar (size >> 4);
s[1] = hexchar (size & 0x0f);
s[2] = ':';
s[3] = ' ';
s[size + 4] = '\r';
s[size + 5] = '\n';
if (tty_send (tty, s, size + 6) < 0)
if (size < 0)
goto connection_loop;
if (size == 1)
/* Do nothing but prompt again. */
break;
else if (size)
{
/* Newline into NUL */
s[size - 1] = 0;
cmd_dispatch (tty, (char *)s);
break;
}
}
u ^= 1;
}
}

View File

@@ -61,14 +61,14 @@ blk (void *arg)
#define PRIO_PWM 3
#define PRIO_BLK 2
extern uint8_t __process1_stack_base__[], __process1_stack_size__[];
extern uint8_t __process2_stack_base__[], __process2_stack_size__[];
#define STACK_ADDR_PWM ((uint32_t)__process1_stack_base__)
#define STACK_SIZE_PWM ((uint32_t)__process1_stack_size__)
#define STACK_ADDR_BLK ((uint32_t)__process2_stack_base__)
#define STACK_SIZE_BLK ((uint32_t)__process2_stack_size__)
#define STACK_MAIN
#define STACK_PROCESS_1
#define STACK_PROCESS_2
#include "stack-def.h"
#define STACK_ADDR_PWM ((uint32_t)process1_base)
#define STACK_SIZE_PWM (sizeof process1_base)
#define STACK_ADDR_BLK ((uint32_t)process2_base)
#define STACK_SIZE_BLK (sizeof process2_base)
static char hexchar (uint8_t x)

View File

@@ -1,11 +1,6 @@
/*
* ST32F103 memory setup.
*/
__main_stack_size__ = 0x0100; /* Idle+Exception handlers */
__process0_stack_size__ = 0x0400; /* Main program */
__process1_stack_size__ = 0x0200; /* first thread program */
__process2_stack_size__ = 0x0200; /* second thread program */
__process3_stack_size__ = 0x0200; /* third thread program */
MEMORY
{
@@ -78,34 +73,21 @@ SECTIONS
_etext = .;
_textdata = _etext;
.process_stack :
.process_stack (NOLOAD) :
{
. = ALIGN(8);
__process3_stack_base__ = .;
. += __process3_stack_size__;
*(.process_stack.3)
*(.process_stack.2)
*(.process_stack.1)
*(.process_stack.0)
. = ALIGN(8);
__process3_stack_end__ = .;
__process2_stack_base__ = .;
. += __process2_stack_size__;
. = ALIGN(8);
__process2_stack_end__ = .;
__process1_stack_base__ = .;
. += __process1_stack_size__;
. = ALIGN(8);
__process1_stack_end__ = .;
__process0_stack_base__ = .;
. += __process0_stack_size__;
. = ALIGN(8);
__process0_stack_end__ = .;
} > ram
.main_stack :
.main_stack (NOLOAD) :
{
. = ALIGN(8);
__main_stack_base__ = .;
. += __main_stack_size__;
*(.main_stack)
. = ALIGN(8);
__main_stack_end__ = .;
} > ram
.data :

24
example-cdc/stack-def.h Normal file
View File

@@ -0,0 +1,24 @@
#if defined(STACK_MAIN)
/* Idle+Exception handlers */
char __main_stack_end__[0] __attribute__ ((section(".main_stack")));
char main_base[0x0100] __attribute__ ((section(".main_stack")));
/* Main program */
char __process0_stack_end__[0] __attribute__ ((section(".process_stack.0")));
char process0_base[0x0400] __attribute__ ((section(".process_stack.0")));
#endif
/* First thread program */
#if defined(STACK_PROCESS_1)
char process1_base[0x0200] __attribute__ ((section(".process_stack.1")));
#endif
/* Second thread program */
#if defined(STACK_PROCESS_2)
char process2_base[0x0200] __attribute__ ((section(".process_stack.2")));
#endif
/* Third thread program */
#if defined(STACK_PROCESS_3)
char process3_base[0x0200] __attribute__ ((section(".process_stack.3")));
#endif

View File

@@ -642,9 +642,10 @@ static void *tty_main (void *arg);
#define INTR_REQ_USB 20
#define PRIO_TTY 4
extern uint8_t __process3_stack_base__[], __process3_stack_size__[];
#define STACK_ADDR_TTY ((uint32_t)__process3_stack_base__)
#define STACK_SIZE_TTY ((uint32_t)__process3_stack_size__)
#define STACK_PROCESS_3
#include "stack-def.h"
#define STACK_ADDR_TTY ((uint32_t)process3_base)
#define STACK_SIZE_TTY (sizeof process3_base)
struct tty *
tty_open (void)

View File

@@ -57,7 +57,7 @@ In the development of Gnuk, we developed:
It is now maintained as example-cdc/sys.c.
There is another version in example-led/sys.c, which also support
There is another version in example-led/sys.c, which also supports
STM32F030, as well as STM32F103. But, it wouldn't be useful for
STM32F030. In fact, the file example-fsm-55/sys.c has name sys.c
but it doesn't include any system routines.
@@ -74,7 +74,7 @@ Later on, we add another point.
(3) It is good if the executable of Gnuk could be shared among
different boards.
For (1) and (2), we decided put some useful routines and data which is
For (1) and (2), we decided put some useful routines and data which are
not need to be changed.
Now, the first 4KiB of flash ROM consists of:
@@ -84,7 +84,7 @@ Now, the first 4KiB of flash ROM consists of:
SYS consists of:
Internal: reset entry, end of RAM
Internal: reset entry, address of the end of RAM
Data: board identification
Routines: board specific
board independent
@@ -94,7 +94,7 @@ and here is the list of all.
* Internal routines
reset entry
end of RAM
address of the end of RAM
* Board identification

251
mcu/sys-gnu-linux.c Normal file
View File

@@ -0,0 +1,251 @@
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include "board.h"
#include "sys.h"
const uint8_t sys_version[8] = {
3*2+2, /* bLength */
0x03, /* bDescriptorType = USB_STRING_DESCRIPTOR_TYPE */
/* sys version: "3.0" */
'3', 0, '.', 0, '0', 0,
};
#if defined(USE_SYS3) || defined(USE_SYS_BOARD_ID)
const uint32_t sys_board_id = BOARD_ID;
const uint8_t sys_board_name[] = BOARD_NAME;
#endif
int debug;
void
set_led (int on)
{
if ((debug & DEBUG_LED))
puts (on ? "*": "");
}
static const char *flash_path;
static size_t flash_size;
static void * flash_addr;
static int flash_fd;
uintptr_t
flash_init (const char *f_name)
{
int fd;
struct stat sb;
void *addr;
fd = open (f_name, O_RDONLY);
if (fd < 0)
{
perror ("flash_init: open");
exit (1);
}
if (fstat (fd, &sb) < 0)
{
perror ("flash_init: fstat");
exit (1);
}
addr = mmap (NULL, sb.st_size, PROT_READ, MAP_SHARED, fd, 0);
if (addr == MAP_FAILED)
{
perror ("flash_init: mmap");
exit (1);
}
if (close (fd) < 0)
{
perror ("flash_init: close");
exit (1);
}
flash_path = f_name;
flash_addr = addr;
flash_size = sb.st_size;
return (uintptr_t)addr;
}
void
flash_unlock (void)
{
int fd;
fd = open (flash_path, O_WRONLY);
if (fd < 0)
{
perror ("flash_unlock: open");
exit (1);
}
flash_fd = fd;
}
int
flash_program_halfword (uintptr_t addr, uint16_t data)
{
off_t offset;
char buf[2];
if ((debug & DEBUG_FLASH))
fprintf (stderr, "flash_program_halfword: addr=%016lx, data=%04x\n",
addr, data);
offset = (off_t)(addr - (uintptr_t)flash_addr);
if (offset < 0 || offset >= (off_t)flash_size)
{
perror ("flash_program_halfword");
return 1;
}
offset = lseek (flash_fd, offset, SEEK_SET);
if (offset == (off_t)-1)
{
perror ("flash_program_halfword");
return 1;
}
buf[0] = (data & 0xff);
buf[1] = (data >> 8);
if (write (flash_fd, buf, 2) != 2)
{
perror ("flash_program_halfword");
return 2;
}
return 0;
}
static const uint8_t erased[] = { [0 ... 1023 ] = 0xff };
int
flash_erase_page (uintptr_t addr)
{
off_t offset;
if ((debug & DEBUG_FLASH))
fprintf (stderr, "flash_erase_page: addr=%016lx\n", addr);
offset = (off_t)(addr - (uintptr_t)flash_addr);
if (offset < 0 || offset >= (off_t)flash_size)
{
perror ("flash_erase_page");
return 1;
}
offset = lseek (flash_fd, offset, SEEK_SET);
if (offset == (off_t)-1)
{
perror ("flash_erase_page");
return 1;
}
if (write (flash_fd, erased, sizeof (erased)) != sizeof (erased))
{
perror ("flash_erase_page");
return 2;
}
return 0;
}
int
flash_check_blank (const uint8_t *p_start, size_t size)
{
const uint8_t *p;
if (p_start < (const uint8_t *)flash_addr
|| p_start + size > (const uint8_t *)flash_addr + flash_size)
{
perror ("flash_check_blank");
return 0;
}
for (p = p_start; p < p_start + size; p++)
if (*p != 0xff)
return 0;
return 1;
}
int
flash_write (uintptr_t dst_addr, const uint8_t *src, size_t len)
{
off_t offset;
if ((debug & DEBUG_FLASH))
fprintf (stderr, "flash_write: addr=%016lx, %p, %zd\n",
dst_addr, src, len);
offset = (off_t)(dst_addr - (uintptr_t)flash_addr);
if (offset < 0 || offset >= (off_t)flash_size)
{
perror ("flash_write");
return 1;
}
offset = lseek (flash_fd, offset, SEEK_SET);
if (offset == (off_t)-1)
{
perror ("flash_write");
return 1;
}
if (write (flash_fd, src, len) != (ssize_t)len)
{
perror ("flash_write");
return 2;
}
return 0;
}
int
flash_protect (void)
{
if ((debug & DEBUG_FLASH))
fprintf (stderr, "flash_protect\n");
return 0;
}
void __attribute__((noreturn))
flash_erase_all_and_exec (void (*entry)(void))
{
(void)entry;
exit (1);
}
void
usb_lld_sys_init (void)
{
}
void
usb_lld_sys_shutdown (void)
{
}
void __attribute__((noreturn))
nvic_system_reset (void)
{
exit (0);
}
void
clock_init (void)
{
}
void
gpio_init (void)
{
}

52
mcu/sys-gnu-linux.h Normal file
View File

@@ -0,0 +1,52 @@
extern const uint8_t sys_version[8];
#if defined(USE_SYS3) || defined(USE_SYS_BOARD_ID)
extern const uint32_t sys_board_id;
extern const uint8_t sys_board_name[];
# define SYS_BOARD_ID sys_board_id
#else
# define SYS_BOARD_ID BOARD_ID
#endif
#define DEBUG_LED (1 << 1)
#define DEBUG_FLASH (1 << 2)
#define DEBUG_USB (1 << 3)
extern int debug;
static inline const uint8_t *
unique_device_id (void)
{
/*
* STM32F103 has 96-bit unique device identifier.
* This routine mimics that.
*/
static const uint8_t id[] = { /* My RSA fingerprint */
0x12, 0x41, 0x24, 0xBD, 0x3B, 0x48, 0x62, 0xAF,
0x7A, 0x0A, 0x42, 0xF1, 0x00, 0xB4, 0x5E, 0xBD,
0x4C, 0xA7, 0xBA, 0xBE
};
return id;
}
void set_led (int on);
uintptr_t flash_init (const char *f_name);
void flash_unlock (void);
int flash_program_halfword (uintptr_t addr, uint16_t data);
int flash_erase_page (uintptr_t addr);
int flash_check_blank (const uint8_t *p_start, size_t size);
int flash_write (uintptr_t dst_addr, const uint8_t *src, size_t len);
int flash_protect (void);
void __attribute__((noreturn))
flash_erase_all_and_exec (void (*entry)(void));
void usb_lld_sys_init (void);
void usb_lld_sys_shutdown (void);
void __attribute__((noreturn))
nvic_system_reset (void);
void clock_init (void);
void gpio_init (void);

View File

@@ -111,7 +111,7 @@ usb_lld_sys_shutdown (void)
(*vector[11]) ();
}
static inline void
static inline void __attribute__((noreturn))
nvic_system_reset (void)
{
(*vector[12]) ();

View File

@@ -148,7 +148,7 @@ flash_wait_for_last_operation (uint32_t timeout)
#define FLASH_ERASE_TIMEOUT 0x01000000
static int
flash_program_halfword (uint32_t addr, uint16_t data)
flash_program_halfword (uintptr_t addr, uint16_t data)
{
int status;
@@ -170,7 +170,7 @@ flash_program_halfword (uint32_t addr, uint16_t data)
}
static int
flash_erase_page (uint32_t addr)
flash_erase_page (uintptr_t addr)
{
int status;
@@ -210,13 +210,13 @@ flash_check_blank (const uint8_t *p_start, size_t size)
#define FLASH_SIZE_REG ((uint16_t *)0x1ffff7e0)
static int
flash_write (uint32_t dst_addr, const uint8_t *src, size_t len)
flash_write (uintptr_t dst_addr, const uint8_t *src, size_t len)
{
int status;
#if defined(STM32F103_OVERRIDE_FLASH_SIZE_KB)
uint32_t flash_end = FLASH_START_ADDR + STM32F103_OVERRIDE_FLASH_SIZE_KB*1024;
uintptr_t flash_end = FLASH_START_ADDR + STM32F103_OVERRIDE_FLASH_SIZE_KB*1024;
#else
uint32_t flash_end = FLASH_START_ADDR + (*FLASH_SIZE_REG)*1024;
uintptr_t flash_end = FLASH_START_ADDR + (*FLASH_SIZE_REG)*1024;
#endif
if (dst_addr < FLASH_START || dst_addr + len > flash_end)
@@ -272,11 +272,11 @@ flash_protect (void)
static void __attribute__((naked))
flash_erase_all_and_exec (void (*entry)(void))
{
uint32_t addr = FLASH_START;
uintptr_t addr = FLASH_START;
#if defined(STM32F103_OVERRIDE_FLASH_SIZE_KB)
uint32_t end = FLASH_START_ADDR + STM32F103_OVERRIDE_FLASH_SIZE_KB*1024;
uintptr_t end = FLASH_START_ADDR + STM32F103_OVERRIDE_FLASH_SIZE_KB*1024;
#else
uint32_t end = FLASH_START_ADDR + (*FLASH_SIZE_REG)*1024;
uintptr_t end = FLASH_START_ADDR + (*FLASH_SIZE_REG)*1024;
#endif
uint32_t page_size = 1024;
int r;

View File

@@ -47,17 +47,17 @@ flash_unlock (void)
}
static inline int
flash_program_halfword (uint32_t addr, uint16_t data)
flash_program_halfword (uintptr_t addr, uint16_t data)
{
int (*func) (uint32_t, uint16_t) = (int (*)(uint32_t, uint16_t))vector[4];
int (*func) (uintptr_t, uint16_t) = (int (*)(uintptr_t, uint16_t))vector[4];
return (*func) (addr, data);
}
static inline int
flash_erase_page (uint32_t addr)
flash_erase_page (uintptr_t addr)
{
int (*func) (uint32_t) = (int (*)(uint32_t))vector[5];
int (*func) (uintptr_t) = (int (*)(uintptr_t))vector[5];
return (*func) (addr);
}
@@ -71,10 +71,10 @@ flash_check_blank (const uint8_t *p_start, size_t size)
}
static inline int
flash_write (uint32_t dst_addr, const uint8_t *src, size_t len)
flash_write (uintptr_t dst_addr, const uint8_t *src, size_t len)
{
int (*func) (uint32_t, const uint8_t *, size_t)
= (int (*)(uint32_t, const uint8_t *, size_t))vector[7];
int (*func) (uintptr_t, const uint8_t *, size_t)
= (int (*)(uintptr_t, const uint8_t *, size_t))vector[7];
return (*func) (dst_addr, src, len);
}
@@ -108,7 +108,7 @@ usb_lld_sys_shutdown (void)
(*vector[11]) ();
}
static inline void
static inline void __attribute__((noreturn))
nvic_system_reset (void)
{
(*vector[12]) ();

View File

@@ -51,6 +51,8 @@
#include <alloca.h>
#include "sys.h" /* for debug */
static pthread_t tid_main;
static pthread_t tid_usbip;
@@ -304,17 +306,22 @@ hc_handle_control_urb (struct urb *urb)
uint16_t remain = urb->len;
uint64_t l;
puts ("hcu 0");
if ((debug & DEBUG_USB))
puts ("hcu 0");
usbc_ep0.urb = urb;
r = control_setup_transaction (urb);
if (r < 0)
goto error;
puts ("hcu 1");
if ((debug & DEBUG_USB))
puts ("hcu 1");
if (urb->dir == USBIP_DIR_OUT)
{ /* Output from host to device. */
printf ("hcu: %d\n", r);
if ((debug & DEBUG_USB))
printf ("hcu: %d\n", r);
while (r == 0)
{
if (remain > 64)
@@ -340,7 +347,9 @@ hc_handle_control_urb (struct urb *urb)
}
else
{ /* Input from device to host. */
puts ("hcu 2");
if ((debug & DEBUG_USB))
puts ("hcu 2");
while (1)
{
if (remain > 64)
@@ -353,28 +362,38 @@ hc_handle_control_urb (struct urb *urb)
if (r < 0)
break;
puts ("hcu 3");
if ((debug & DEBUG_USB))
puts ("hcu 3");
remain -= r;
urb->data_p += r;
if (r < 64)
break;
}
puts ("hcu 4");
if ((debug & DEBUG_USB))
puts ("hcu 4");
if (r >= 0)
{
puts ("hcu 5");
if ((debug & DEBUG_USB))
puts ("hcu 5");
read (usbc_ep0.eventfd, &l, sizeof (l));
r = control_read_status_transaction ();
if (r >= 0)
r = remain;
}
puts ("hcu 6");
if ((debug & DEBUG_USB))
puts ("hcu 6");
}
if (r < 0)
{
error:
fprintf (stderr, "hcu 7 %d\n", r);
if ((debug & DEBUG_USB))
printf ("hcu 7 %d\n", r);
/* recovery. */
usbc_ep0.state = USB_STATE_READY;
}
@@ -393,7 +412,9 @@ hc_handle_control_urb (struct urb *urb)
else
urb->len = 0;
printf ("hu-next: %d (%d)\n", urb->len, urb->seq);
if ((debug & DEBUG_USB))
printf ("hu-next: %d (%d)\n", urb->len, urb->seq);
usbc_ep0.urb = NULL;
return r;
}
@@ -452,7 +473,8 @@ usbip_finish_urb (struct urb *urb, int r)
memset (&msg_rep, 0, sizeof (msg_rep));
msg_rep.len = htonl (urb->len);
fprintf (stderr, "ufu: %d (%d)\n", r, urb->seq);
if ((debug & DEBUG_USB))
printf ("ufu: %d (%d)\n", r, urb->seq);
if (r < 0)
msg_rep.status = htonl (r);
@@ -489,7 +511,9 @@ hc_handle_data_urb (struct usb_control *usbc_p)
uint16_t count;
struct urb *urb = usbc_p->urb;
puts ("hc_hdu 0");
if ((debug & DEBUG_USB))
puts ("hc_hdu 0");
if (urb->remain > 64)
count = 64;
else
@@ -497,7 +521,9 @@ hc_handle_data_urb (struct usb_control *usbc_p)
if (urb->dir == USBIP_DIR_OUT)
{ /* Output from host to device. */
puts ("hc_hdu 1");
if ((debug & DEBUG_USB))
puts ("hc_hdu 1");
r = write_data_transaction (usbc_p, urb->ep, urb->data_p, count);
if (r < 0)
return r;
@@ -509,14 +535,17 @@ hc_handle_data_urb (struct usb_control *usbc_p)
{
size_t len = urb->len - urb->remain;
fprintf (stderr, "->data: %lu\n", len);
if ((debug & DEBUG_USB))
printf ("->data: %lu\n", len);
// successfully finished
if (len)
{
char *s = alloca (len + 1);
memcpy (s, urb->data, len);
s[len] = 0;
fprintf (stderr, " : %s\n", s);
if ((debug & DEBUG_USB))
printf (" : %s\n", s);
}
return 0;
}
@@ -525,7 +554,9 @@ hc_handle_data_urb (struct usb_control *usbc_p)
}
else
{ /* Input from device to host. */
puts ("hc_hdu 2");
if ((debug & DEBUG_USB))
puts ("hc_hdu 2");
r = read_data_transaction (usbc_p, urb->ep, urb->data_p, count);
if (r < 0)
return r;
@@ -536,14 +567,17 @@ hc_handle_data_urb (struct usb_control *usbc_p)
{
size_t len = urb->len - urb->remain;
fprintf (stderr, "<-data: %lu %d\n", len, r);
if ((debug & DEBUG_USB))
printf ("<-data: %lu %d\n", len, r);
// successfully finished
if (len)
{
char *s = alloca (len + 1);
memcpy (s, urb->data, len);
s[len] = 0;
fprintf (stderr, " : %s\n", s);
if ((debug & DEBUG_USB))
printf (" : %s\n", s);
}
urb->len = len;
return 0;
@@ -652,8 +686,9 @@ usbip_handle_urb (uint32_t seq)
urb->remain = urb->len = ntohl (msg_cmd.len);
urb->data_p = urb->data;
printf ("URB: dir=%s, ep=%d, len=%d\n", urb->dir==USBIP_DIR_IN? "IN": "OUT",
urb->ep, urb->len);
if ((debug & DEBUG_USB))
printf ("URB: dir=%s, ep=%d, len=%d\n", urb->dir==USBIP_DIR_IN? "IN": "OUT",
urb->ep, urb->len);
if (recv (fd, (char *)urb->setup, sizeof (urb->setup), 0) != sizeof (urb->setup))
{
@@ -663,9 +698,10 @@ usbip_handle_urb (uint32_t seq)
}
if (urb->ep == 0)
printf ("URB: %02x %02x %02x %02x %02x %02x %02x %02x\n",
urb->setup[0], urb->setup[1], urb->setup[2], urb->setup[3],
urb->setup[4], urb->setup[5], urb->setup[6], urb->setup[7]);
if ((debug & DEBUG_USB))
printf ("URB: %02x %02x %02x %02x %02x %02x %02x %02x\n",
urb->setup[0], urb->setup[1], urb->setup[2], urb->setup[3],
urb->setup[4], urb->setup[5], urb->setup[6], urb->setup[7]);
if (urb->dir == USBIP_DIR_OUT && urb->len)
{
@@ -777,7 +813,9 @@ usbip_process_cmd (void)
const char *device_list;
size_t device_list_size;
printf ("Device List\n");
if ((debug & DEBUG_USB))
printf ("Device List\n");
if (attached)
{
fprintf (stderr, "REQ list while attached\n");
@@ -808,7 +846,9 @@ usbip_process_cmd (void)
size_t attach_size;
char busid[32];
printf ("Attach device\n");
if ((debug & DEBUG_USB))
printf ("Attach device\n");
if (attached)
{
fprintf (stderr, "REQ attach while attached\n");
@@ -828,7 +868,8 @@ usbip_process_cmd (void)
if (attach
&& (size_t)send (fd, attach, attach_size, 0) == attach_size)
{
printf ("Attach device!\n");
if ((debug & DEBUG_USB))
printf ("Attach device!\n");
attached = 1;
pthread_mutex_unlock (&fd_mutex);
}
@@ -847,7 +888,8 @@ usbip_process_cmd (void)
return -1;
}
printf ("URB SUBMIT! %d\n", msg.seq);
if ((debug & DEBUG_USB))
printf ("URB SUBMIT! %d\n", msg.seq);
usbip_handle_urb (msg.seq);
}
else if (msg.cmd == CMD_URB_UNLINK)
@@ -908,7 +950,8 @@ usbip_process_cmd (void)
if (found)
msg_rep.status = htonl(-ECONNRESET);
printf ("URB UNLINK! %d: %s\n", seq, found?"o":"x");
if ((debug & DEBUG_USB))
printf ("URB UNLINK! %d: %s\n", seq, found?"o":"x");
pthread_mutex_lock (&fd_mutex);
if ((size_t)send (fd, &msg, sizeof (msg), 0) != sizeof (msg))
@@ -940,7 +983,9 @@ usbip_ep_ready (struct usb_control *usbc_p)
if (!usbc_p->urb)
{
puts ("???usbip_ep_ready");
if ((debug & DEBUG_USB))
puts ("???usbip_ep_ready");
return;
}
@@ -1088,7 +1133,8 @@ usbip_run_server (void *arg)
if ((pollfds[0].revents & POLLNVAL)
|| (pollfds[0].revents & POLLERR))
{
fprintf (stderr, "Error on USBIP client socket: %d\n", pollfds[0].revents);
fprintf (stderr, "Error on USBIP client socket: %d\n",
pollfds[0].revents);
exit (1);
}
if ((pollfds[0].revents & POLLIN))
@@ -1110,7 +1156,9 @@ usbip_run_server (void *arg)
}
if ((pollfds[i*2].revents & POLLIN))
{
puts ("poll in read");
if ((debug & DEBUG_USB))
puts ("poll in read");
usbip_ep_ready (&usbc_ep_in[i]);
}
@@ -1122,7 +1170,9 @@ usbip_run_server (void *arg)
}
if ((pollfds[i*2+1].revents & POLLIN))
{
puts ("poll out read");
if ((debug & DEBUG_USB))
puts ("poll out read");
usbip_ep_ready (&usbc_ep_out[i]);
}
}
@@ -1163,7 +1213,8 @@ control_setup_transaction (struct urb *urb)
r = -EAGAIN;
else
{
fprintf (stderr, "cst error %d\n", usbc_ep0.state);
if ((debug & DEBUG_USB))
printf ("cst error %d\n", usbc_ep0.state);
r = -EPIPE;
}
pthread_mutex_unlock (&usbc_ep0.mutex);
@@ -1187,7 +1238,8 @@ control_write_data_transaction (char *buf, uint16_t count)
{
if (usbc_ep0.len < count)
{
fprintf (stderr, "*** usbc_ep0.len < count");
if ((debug & DEBUG_USB))
printf ("*** usbc_ep0.len < count");
r = -EPIPE;
usbc_ep0.state = USB_STATE_STALL;
}
@@ -1224,9 +1276,12 @@ control_write_status_transaction (void)
pthread_mutex_lock (&usbc_ep0.mutex);
if (usbc_ep0.state == USB_STATE_READY)
{
puts ("control_write_status_transaction");
if ((debug & DEBUG_USB))
puts ("control_write_status_transaction");
if (usbc_ep0.len != 0)
fprintf (stderr, "*** ACK length %d\n", usbc_ep0.len);
if ((debug & DEBUG_USB))
printf ("*** ACK length %d\n", usbc_ep0.len);
usbc_ep0.state = USB_STATE_NAK;
notify_device (USB_INTR_DATA_TRANSFER, 0, USBIP_DIR_IN);
r = 0;
@@ -1255,7 +1310,10 @@ control_read_data_transaction (char *buf, uint16_t count)
if (usbc_ep0.state == USB_STATE_READY)
{
if (usbc_ep0.len > count)
fprintf (stderr, "***c read: length %d > %d\n", usbc_ep0.len, count);
{
if ((debug & DEBUG_USB))
printf ("***c read: length %d > %d\n", usbc_ep0.len, count);
}
else
count = usbc_ep0.len;
@@ -1337,7 +1395,10 @@ read_data_transaction (struct usb_control *usbc_p,
int ep_num, char *buf, uint16_t count)
{
if (usbc_p->len > count)
fprintf (stderr, "*** length %d > %d\n", usbc_p->len, count);
{
if ((debug & DEBUG_USB))
printf ("*** length %d > %d\n", usbc_p->len, count);
}
else
count = usbc_p->len;
@@ -1902,7 +1963,9 @@ static int handle_in0 (struct usb_dev *dev)
== (STANDARD_REQUEST | DEVICE_RECIPIENT)))
{
/* XXX: record the assigned address of this device??? */
printf ("Set Address: %d\n", dev->dev_req.value);
if ((debug & DEBUG_USB))
printf ("Set Address: %d\n", dev->dev_req.value);
r = USB_EVENT_DEVICE_ADDRESSED;
}
else
@@ -1917,7 +1980,9 @@ static int handle_in0 (struct usb_dev *dev)
}
else
{
puts ("handle_in0 error");
if ((debug & DEBUG_USB))
puts ("handle_in0 error");
dev->state = STALLED;
pthread_mutex_lock (&usbc_ep0.mutex);
usbc_ep0.state = USB_STATE_STALL;
@@ -1955,7 +2020,9 @@ static void handle_out0 (struct usb_dev *dev)
* Or else, unexpected state.
* STALL the endpoint, until we receive the next SETUP token.
*/
puts ("handle_out0 error");
if ((debug & DEBUG_USB))
puts ("handle_out0 error");
dev->state = STALLED;
pthread_mutex_lock (&usbc_ep0.mutex);
usbc_ep0.state = USB_STATE_STALL;
@@ -2077,7 +2144,9 @@ usb_lld_current_configuration (struct usb_dev *dev)
void
usb_lld_ctrl_error (struct usb_dev *dev)
{
puts ("ctrl_error");
if ((debug & DEBUG_USB))
puts ("ctrl_error");
dev->state = STALLED;
pthread_mutex_lock (&usbc_ep0.mutex);
usbc_ep0.state = USB_STATE_STALL;
@@ -2134,7 +2203,9 @@ usb_lld_stall_tx (int ep_num)
usbc_p->state = USB_STATE_STALL;
notify_hostcontroller (usbc_p);
pthread_mutex_unlock (&usbc_p->mutex);
printf ("stall tx %d\n", ep_num);
if ((debug & DEBUG_USB))
printf ("stall tx %d\n", ep_num);
}
void
@@ -2146,7 +2217,8 @@ usb_lld_stall_rx (int ep_num)
usbc_p->state = USB_STATE_STALL;
notify_hostcontroller (usbc_p);
pthread_mutex_unlock (&usbc_p->mutex);
printf ("stall rx %d\n", ep_num);
if ((debug & DEBUG_USB))
printf ("stall rx %d\n", ep_num);
}
void
@@ -2161,7 +2233,8 @@ usb_lld_rx_enable_buf (int ep_num, void *buf, size_t len)
notify_hostcontroller (usbc_p);
pthread_mutex_unlock (&usbc_p->mutex);
printf ("usb_lld_rx_enable_buf: %d\n", ep_num);
if ((debug & DEBUG_USB))
printf ("usb_lld_rx_enable_buf: %d\n", ep_num);
}
@@ -2176,5 +2249,6 @@ usb_lld_tx_enable_buf (int ep_num, const void *buf, size_t len)
usbc_p->len = len;
notify_hostcontroller (usbc_p);
pthread_mutex_unlock (&usbc_p->mutex);
printf ("usb_lld_tx_enable_buf: %d %ld\n", ep_num, len);
if ((debug & DEBUG_USB))
printf ("usb_lld_tx_enable_buf: %d %ld\n", ep_num, len);
}

4
sys.h
View File

@@ -1,4 +1,6 @@
#if defined(MCU_KINETIS_L)
#if defined(GNU_LINUX_EMULATION)
#include "mcu/sys-gnu-linux.h"
#elif defined(MCU_KINETIS_L)
#include "mcu/sys-mkl27z.h"
#elif defined(MCU_STM32F0)
#include "mcu/sys-stm32f0.h"