Kenji Arai
/
NucleoF401_motor_test_simple
DRV8830/TI Motor Driver sample program.\\ This program can control two motors.
Revision 4:58734155cd29, committed 2014-08-24
- Comitter:
- kenjiArai
- Date:
- Sun Aug 24 00:52:11 2014 +0000
- Parent:
- 3:db817fb05ba7
- Commit message:
- DRV8830/TI Motor Driver sample program
Changed in this revision
diff -r db817fb05ba7 -r 58734155cd29 DRV8830.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DRV8830.lib Sun Aug 24 00:52:11 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/kenjiArai/code/DRV8830/#05db098cf4f8
diff -r db817fb05ba7 -r 58734155cd29 main.cpp --- a/main.cpp Sat Jul 12 11:55:37 2014 +0000 +++ b/main.cpp Sun Aug 24 00:52:11 2014 +0000 @@ -1,11 +1,14 @@ /* - * mbed Application program for the mbed ST NUCLEO F401RE Board + * mbed Application program for the mbed + * Brushed DC Motor control + * Texas Instruments / DRV8830 H-Bridge Voltage-Controlled Motor Driver + * http://www.ti.com/product/drv8830 * * Copyright (c) 2014 Kenji Arai / JH1PJL * http://www.page.sannet.ne.jp/kenjia/index.html * http://mbed.org/users/kenjiArai/ * Created: July 12th, 2014 - * Revised: July 12th, 2014 + * Revised: August 24th, 2014 * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE @@ -16,37 +19,305 @@ // Include --------------------------------------------------------------------------------------- #include "mbed.h" -#include "rtos.h" +#include "DRV8830.h" // Object ---------------------------------------------------------------------------------------- -DigitalOut myled(LED1); -DigitalIn usr_sw(PC_13); +DigitalOut myled(LED1); +DigitalIn usr_sw(PC_13); +Serial pc(USBTX, USBRX); // Communication with Host +I2C i2c(PB_9,PB_8); // SDA, SCL +DRV8830 right_mtr(i2c, (uint8_t)DRV8830ADDR_00); +DRV8830 left_mtr(i2c, (uint8_t)DRV8830ADDR_01); + +// Definition ------------------------------------------------------------------------------------ +#define BAUD(x) pc.baud(x) +#define GETC(x) pc.getc(x) +#define PUTC(x) pc.putc(x) +#define PRINTF(...) pc.printf(__VA_ARGS__) +#define READABLE(x) pc.readable(x) + +#define DO_DEBUG +#ifdef DO_DEBUG +#define DEBUG(...) printf(__VA_ARGS__) +#else +#define DEBUG(...) {;} +#endif + +// RAM ------------------------------------------------------------------------------------------- +char lb[32]; + +// ROM / Constant data --------------------------------------------------------------------------- +static char *const msg0 = "Brushed DC Motor Control by JH1PJL, created on "__DATE__""; // Function prototypes --------------------------------------------------------------------------- -extern int mon( void); //------------------------------------------------------------------------------------------------- // Control Program //------------------------------------------------------------------------------------------------- -int read_sw (void){ - if (usr_sw == 0){ return 1; - } else { return 0;} +// Communication with Host PC --------------------------------------------------------------------- +// Put \r\n +void put_rn ( void ){ PUTC('\r'); PUTC('\n');} + +// Put \r +void put_r ( void ){ PUTC('\r');} + +// Put ", " +void put_lin ( void ){ PRINTF(", ");} + +// Put space n +void put_spc( uint8_t n){ for(;n > 0; n--){ PUTC(' '); }} + +// Change string -> number +int xatoi (char **str, int32_t *res){ +unsigned long val; +unsigned char c, radix, s = 0; + + while ((c = **str) == ' '){ (*str)++;} + if (c == '-') { + s = 1; + c = *(++(*str)); + } else if (c == '+') { + s = 0; + c = *(++(*str)); + } + if (c == '0') { + c = *(++(*str)); + if (c <= ' ') { *res = 0; return 1; } + if (c == 'x') { + radix = 16; + c = *(++(*str)); + } else { + if (c == 'b') { + radix = 2; + c = *(++(*str)); + } else { + if ((c >= '0')&&(c <= '9')){ + radix = 8; + } else { + return 0; + } + } + } + } else { + if ((c < '1')||(c > '9')){ return 0;} + radix = 10; + } + val = 0; + while (c > ' ') { + if (c >= 'a'){ c -= 0x20;} + c -= '0'; + if (c >= 17){ + c -= 7; + if (c <= 9){ return 0;} + } + if (c >= radix){ return 0;} + val = val * radix + c; + c = *(++(*str)); + } + if (s){ val = -val;} + *res = val; + return 1; } -// Monitor program -void mon_thread(void const *args){ - while (true){ mon(); } +// Get key input data +void get_line (char *buff, int len){ +char c; +int idx = 0; + + for (;;) { + c = GETC(); + if (c == '\r') { + buff[idx++] = c; + break; + } + if ((c == '\b') && idx) { + idx--; + PUTC(c); + PUTC(' '); + PUTC(c); + } + if (((uint8_t)c >= ' ') && (idx < len - 1)) { + buff[idx++] = c; + PUTC(c); + } + } + buff[idx] = 0; + PUTC('\n'); +} + +void help(void){ + PRINTF("0 -> select Right motor"); + put_rn(); + PRINTF("1 -> select Left motor"); + put_rn(); + PRINTF("2 -> select Both motors"); + put_rn(); + PRINTF("m +/-<speed> x100, e.g. -0.35 -> enter -35"); + put_rn(); + PRINTF("c -> Change spped automatically"); + put_rn(); + PRINTF("s -> Stop"); + put_rn(); + PRINTF("e -> Check error status"); + put_rn(); + PRINTF("r -> Reset error"); + put_rn(); +} + +// Motor control ---------------------------------------------------------------------------------- +void ctrl_speed(float spd, uint8_t mtr_selct){ + switch (mtr_selct){ + case 0 : + right_mtr.speed(spd); + break; + case 1 : + left_mtr.speed(spd); + break; + case 2 : + right_mtr.speed(spd); + wait(0.001); + left_mtr.speed(spd); + break; + default: + ; + } } -// Thread definition -osThreadDef(mon_thread, osPriorityNormal, 2048); +void show_status(uint8_t status){ + PRINTF("Status:0x%02x ->", status); + if (status & DRV8830_F_FAULT){ + PRINTF("Faulted "); + if (status & DRV8830_F_ILIMIT){ + PRINTF("/Current limit "); + } + if (status & DRV8830_F_OTS){ + PRINTF("/Over temp. "); + } + if (status & DRV8830_F_UVLO){ + PRINTF("/Under V lockout "); + } + if (status & DRV8830_F_OCP){ + PRINTF("/Over current "); + } + } else { + PRINTF(" No fault"); + } + put_rn(); +} +// Main control ----------------------------------------------------------------------------------- int main() { - // Starts 1st thread - osThreadCreate(osThread(mon_thread), NULL); - while(1) { - myled = !myled; - Thread::wait(1000); +int32_t p1; +char *ptr; +float spd = 0.0; +uint8_t status; +uint8_t stop_flag = 0; +uint8_t mtr_selct = 0; + + put_rn(); + PRINTF(msg0); + put_rn(); + for (;;) { + put_r(); + PUTC('>'); + myled = 0; + ptr = lb; + get_line(ptr, sizeof(lb)); + myled = 1; + switch (*ptr++){ + case '0' : + put_r(); + mtr_selct = 0; + PRINTF("Select Right Motor"); + put_rn(); + break; + case '1' : + put_r(); + mtr_selct = 1; + PRINTF("Select Left Motor"); + put_rn(); + break; + case '2' : + put_r(); + mtr_selct = 2; + PRINTF("Select Both Motors"); + put_rn(); + break; + case 'e' : + put_r(); + PRINTF("Right "); + status = right_mtr.status(); + show_status(status); + PRINTF("Left "); + status = left_mtr.status(); + show_status(status); + break; + case 'm' : + if (xatoi(&ptr, &p1)) { + spd = (float)p1 / 100; + } + ctrl_speed(spd, mtr_selct); + put_r(); + PRINTF("Run "); + put_rn(); + break; + case 'r' : + put_r(); + left_mtr.reset(); + PRINTF("Reset error"); + put_rn(); + right_mtr.reset(); + break; + case 'c' : + put_r(); + PRINTF("CW ++speed"); + put_rn(); + for (spd = 0.0; spd <= 1.0; spd += 0.02){ + ctrl_speed(spd, mtr_selct); + if (READABLE()){ GETC(); stop_flag =1; break;} + wait(0.1); + } + if (stop_flag){ stop_flag =0; break;} + PRINTF("CW --speed"); + put_rn(); + for (spd = 1.0; spd >= 0.1; spd -= 0.02){ + ctrl_speed(spd, mtr_selct); + if (READABLE()){ GETC(); stop_flag =1; break;} + wait(0.1); + } + if (stop_flag){ stop_flag =0; break;} + PRINTF("CCW ++speed"); + put_rn(); + for (spd = 0.0; spd >= -1.0; spd -= 0.02){ + ctrl_speed(spd, mtr_selct); + if (READABLE()){ GETC(); stop_flag =1; break;} + wait(0.1); + } + if (stop_flag){ stop_flag =0; break;} + PRINTF("CCW --speed"); + put_rn(); + for (spd = -1.0; spd <= 0.0; spd += 0.02){ + ctrl_speed(spd, mtr_selct); + if (READABLE()){ GETC(); stop_flag =1; break;} + wait(0.1); + } + if (stop_flag){ stop_flag =0; break;} + // break; + case 's' : + ctrl_speed(0.0, mtr_selct); + put_r(); + PRINTF("Stop"); + put_rn(); + break; + case '?' : + put_r(); + help(); + break; + default: + put_r(); + PRINTF("Help ->?"); + put_rn(); + help(); + } } } - \ No newline at end of file
diff -r db817fb05ba7 -r 58734155cd29 mbed-rtos.lib --- a/mbed-rtos.lib Sat Jul 12 11:55:37 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/mbed_official/code/mbed-rtos/#ff95651f53c7
diff -r db817fb05ba7 -r 58734155cd29 mbed.bld --- a/mbed.bld Sat Jul 12 11:55:37 2014 +0000 +++ b/mbed.bld Sun Aug 24 00:52:11 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/04dd9b1680ae \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/9327015d4013 \ No newline at end of file
diff -r db817fb05ba7 -r 58734155cd29 mon.cpp --- a/mon.cpp Sat Jul 12 11:55:37 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,233 +0,0 @@ -/* - * mbed Application program - * - * Copyright (c) 2010-2014 Kenji Arai / JH1PJL - * http://www.page.sannet.ne.jp/kenjia/index.html - * http://mbed.org/users/kenjiArai/ - * Created: May 15th, 2010 - * Spareted: June 25th, 2014 mon() & mon_hw() - * Ported: July 12th, 2014 from L152RE - * Revised: July 12th, 2014 - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE - * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -// Include --------------------------------------------------------------------------------------- -#include "mbed.h" - -// Object ---------------------------------------------------------------------------------------- -Serial pc(SERIAL_TX, SERIAL_RX); - -// Definition ------------------------------------------------------------------------------------ -#define BAUD(x) pc.baud(x) -#define GETC(x) pc.getc(x) -#define PUTC(x) pc.putc(x) -#define PRINTF(...) pc.printf(__VA_ARGS__) -#define READABLE(x) pc.readable(x) - -// RAM ------------------------------------------------------------------------------------------- -char linebuf[64]; -int buf_size = sizeof(linebuf); - -// ROM / Constant data --------------------------------------------------------------------------- -static char *const mon_msg = "Monitor for mbed system, created on "__DATE__""; - -// Function prototypes --------------------------------------------------------------------------- -extern void mon_hw(void); -extern int read_sw (void); -extern void baro_read (void); - -//------------------------------------------------------------------------------------------------- -// Control Program -//------------------------------------------------------------------------------------------------- -// Put \r\n -void put_rn ( void ){ PUTC('\r'); PUTC('\n');} - -// Put \r -void put_r ( void ){ PUTC('\r');} - -// Put ", " -void put_lin ( void ){ PRINTF(", ");} - -// Put space n -void put_spc( uint8_t n){ for(;n > 0; n--){ PUTC(' '); }} - -// Change string -> integer -int xatoi (char **str, unsigned long *res){ -unsigned long val; -unsigned char c, radix, s = 0; - - while ((c = **str) == ' ') (*str)++; - if (c == '-') { - s = 1; - c = *(++(*str)); - } - if (c == '0') { - c = *(++(*str)); - if (c <= ' ') { *res = 0; return 1; } - if (c == 'x') { - radix = 16; - c = *(++(*str)); - } else { - if (c == 'b') { - radix = 2; - c = *(++(*str)); - } else { - if ((c >= '0')&&(c <= '9')){ radix = 8; - } else { return 0;} - } - } - } else { - if ((c < '1')||(c > '9')){ return 0;} - radix = 10; - } - val = 0; - while (c > ' ') { - if (c >= 'a') c -= 0x20; - c -= '0'; - if (c >= 17) { - c -= 7; - if (c <= 9) return 0; - } - if (c >= radix) return 0; - val = val * radix + c; - c = *(++(*str)); - } - if (s) val = -val; - *res = val; - return 1; -} - -//------------------------------------------------------------------------------------------------- -// Monitor -//------------------------------------------------------------------------------------------------- -// Help Massage -void msg_hlp (void){ - PRINTF(mon_msg); put_rn(); - PRINTF("s - Show USER Button"); put_rn(); - PRINTF("t - Check and set RTC"); put_rn(); - PRINTF("x - Goto HW monitor"); put_rn(); - PRINTF("q - Return to main"); put_rn(); -} - -// Get key input data -void get_line (char *buff, int len){ -char c; -int idx = 0; - - for (;;) { - c = GETC(); - // Added by Kenji Arai / JH1PJL May 9th, 2010 - if (c == '\r') { - buff[idx++] = c; - break; - } - if ((c == '\b') && idx) { - idx--; - PUTC(c); - PUTC(' '); - PUTC(c); - } - if (((uint8_t)c >= ' ') && (idx < len - 1)) { - buff[idx++] = c; - PUTC(c); - } - } - buff[idx] = 0; - PUTC('\n'); -} - -// RTC related subroutines -void chk_and_set_time(char *ptr){ -unsigned long p1; -struct tm t; -time_t seconds; -char buf[40]; - - if (xatoi(&ptr, &p1)){ - t.tm_year = (uint8_t)p1 + 100; - PRINTF("Year:%d ",p1); - xatoi( &ptr, &p1 ); - t.tm_mon = (uint8_t)p1 - 1; - PRINTF("Month:%d ",p1); - xatoi( &ptr, &p1 ); - t.tm_mday = (uint8_t)p1; - PRINTF("Day:%d ",p1); - xatoi( &ptr, &p1 ); - t.tm_hour = (uint8_t)p1; - PRINTF("Hour:%d ",p1); - xatoi( &ptr, &p1 ); - t.tm_min = (uint8_t)p1; - PRINTF("Min:%d ",p1); - xatoi( &ptr, &p1 ); - t.tm_sec = (uint8_t)p1; - PRINTF("Sec: %d \r\n",p1); - seconds = mktime(&t); - set_time(seconds); - } - seconds = time(NULL); - strftime(buf, 40, "%B %d,'%y, %H:%M:%S", localtime(&seconds)); - PRINTF("Date: %s\r\n", buf); -} - -// ---------- Program starts here! --------------------------------------------------------------- -int mon(void) { -char *ptr; - - BAUD(9600); - put_rn(); - put_rn(); - PRINTF("%s [Help:'?' key]", mon_msg); - put_rn(); - for (;;) { - put_r(); - PUTC('>'); - ptr = linebuf; - get_line(ptr, sizeof(linebuf)); - switch (*ptr++) { - //--------------------------------------------------------------------------------- - // Show switch status - //--------------------------------------------------------------------------------- - case 's' : - put_r(); - PRINTF("USER_Button = "); - if (read_sw() == 1) { PRINTF("ON"); - } else { PRINTF("OFF"); - } - put_rn(); - break; - //--------------------------------------------------------------------------------- - // check and set RTC - //--------------------------------------------------------------------------------- - case 't' : - put_r(); - chk_and_set_time(ptr); - break; - //--------------------------------------------------------------------------------- - // help - //--------------------------------------------------------------------------------- - case '?' : - put_r(); - msg_hlp(); - break; - //--------------------------------------------------------------------------------- - // Go to special command - //--------------------------------------------------------------------------------- - case 'x' : - mon_hw(); - PRINTF("->Came back monitor\r\n"); - break; - //--------------------------------------------------------------------------------- - // Go back to main() - //--------------------------------------------------------------------------------- - case 'q' : // Quit - PRINTF("\rReturn to main\r\n"); - PRINTF("cannot control anymore from here\r\n"); - return 0; - } - } -}
diff -r db817fb05ba7 -r 58734155cd29 mon_hw.cpp --- a/mon_hw.cpp Sat Jul 12 11:55:37 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,981 +0,0 @@ -/* - * mbed Application program for the ST NUCLEO F401RE Board - * Monitor program Ver.3 for only STM32F401RE - * - * Copyright (c) 2010-2014 Kenji Arai / JH1PJL - * http://www.page.sannet.ne.jp/kenjia/index.html - * http://mbed.org/users/kenjiArai/ - * Created: May 15th, 2010 - * Spareted: June 25th, 2014 mon() & mon_hw() - * Ported: July 12th, 2014 from L152RE - * Revised: July 12th, 2014 - * - * Function - * Show Memory contents, Digital port, Analog input port, CPU clock, RTC/Time and others - * in the mbed board - * Connection - * uart USB Vertual com - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE - * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -// Include --------------------------------------------------------------------------------------- -#include "mbed.h" -#include "rtos.h" -#include "mon_hw.h" - -// Object ---------------------------------------------------------------------------------------- -extern Serial pcx(SERIAL_TX, SERIAL_RX); -extern DigitalIn usr_swx(PC_13); - -// Definition ------------------------------------------------------------------------------------ -#define BAUD_RATE 9600 - -// Range check status -#define ERR_NOTHING 0 -#define ERR_MODIFY_SIZ 1 -#define ERR_OUT_OF_RANGE 2 - -// Reg. Size -#define SIZE8 8 -#define SIZE16 16 -#define SIZE32 32 - -#define BAUD(x) pcx.baud(x) -#define GETC(x) pcx.getc(x) -#define PUTC(x) pcx.putc(x) -#define PRINTF(...) pcx.printf(__VA_ARGS__) -#define READABLE(x) pcx.readable(x) - -// RAM ------------------------------------------------------------------------------------------- -typedef struct{ - unsigned long mstr; - unsigned long msiz; - unsigned long mtmp; - unsigned long mold; - unsigned char mflg; - unsigned char mbhw; -} MEMO; - -static MEMO mem; -unsigned long SystemFrequency; - -extern char linebuf[]; -extern int buf_size; - -// ROM / Constant data --------------------------------------------------------------------------- -const uint32_t mem_range[][2] = { // Memory access range - { 0x08000000, 0x0807ffff }, // On-chip Flash memory, 512KB Flash - { 0x1ff00000, 0x1fff7a0f }, // System memory - { 0x1ffc0000, 0x1ffc0007 }, // Option bytes - { 0x20000000, 0x20017fff }, // Main Embedded SRAM, 96KB SRAM - { 0x40000000, 0x5003ffff } // IO area -}; - -// Function prototypes --------------------------------------------------------------------------- -extern void put_rn ( void ); -extern void put_r ( void ); -extern void put_lin ( void ); -extern void put_spc( uint8_t n); -extern void get_line (char *buff, int len); -extern int xatoi (char **str, unsigned long *res); - -//------------------------------------------------------------------------------------------------- -// Control Program -//------------------------------------------------------------------------------------------------- -// No function -static void not_yet_impliment( void ){ - PRINTF(xmsg0); - put_rn(); -} - -// Help Massage -void hw_msg_hlp ( void ){ - PRINTF(mon_msg); put_rn(); - PRINTF(hmsg0); put_rn(); - PRINTF(hmsg1); put_rn(); - PRINTF(hmsg6); put_rn(); - PRINTF(hmsg7); put_rn(); - PRINTF(hmsg2); put_rn(); - PRINTF(hmsg3); put_rn(); - PRINTF(hmsg4); put_rn(); - PRINTF(hmsg5); put_rn(); -} - -// Show 16bit register contents -void reg_print(uint16_t size, uint16_t reg){ -uint16_t i, j, k, n; - - switch (size){ - case SIZE8: - PRINTF(rgmsg0); - put_rn(); - i = 8; - n = 0x80; - break; - case SIZE16: - PRINTF("%s%s", rgmsg1, rgmsg0); - put_rn(); - i = 16; - n = 0x8000; - break; - case SIZE32: - PRINTF("0x%08x", reg); - return; - default : - ; - } - PUTC(' '); - for (; i>0; i--){ - k = n >> (size-i); - j = reg & k; - if (j){ - PUTC('1'); - } else { - PUTC('0'); - } - PUTC(' '); - PUTC(' '); - } - PRINTF(" (0x%04x)", reg); -} - -// Range check for Memory dump -static void check_range( MEMO * mem ){ -uint8_t i; -uint32_t m; - - mem->mflg = ERR_NOTHING; - for ( i = 0 ; i < 5 ; i++ ) { - if ( mem->mstr >= mem_range[i][0]) { - if ( mem->mstr < mem_range[i][1] ) { - m = mem->mstr + mem->msiz; - if ( m < mem_range[i][1]) { - return; // no modification - } else { - m = mem_range[i][1]; - mem->msiz = m - mem->mstr + 1; - mem->mflg = ERR_MODIFY_SIZ; - return; // modified size - } - } - } - } - mem->mflg = ERR_OUT_OF_RANGE; - mem->mstr = 0; - mem->msiz = 0; - return ; -} - -// Memory dump error massage -void error_print ( unsigned char flg ){ - switch (flg) { - case ERR_MODIFY_SIZ : - put_r(); - PRINTF(amsg2); - put_rn(); - break; - case ERR_OUT_OF_RANGE : - put_r(); - PRINTF(amsg3); - put_rn(); - break; - case ERR_NOTHING : - default : - ; - } -} - -// Print memory contents -void put_dump (const unsigned char *buff, unsigned long ofs, int cnt){ -int n; - - PRINTF("%08lX ", ofs); - for(n = 0; n < cnt; n++) { // show hex - PRINTF(" %02X", buff[n]); - } - for(; n < 16; n++) { // fullfil remained space - PRINTF(" "); - } - PUTC(' '); - for(n = 0; n < cnt; n++) { // show char - if ((buff[n] < 0x20)||(buff[n] >= 0x7F)) { - PUTC('.'); - } else { - PUTC(buff[n]); - } - } - put_rn(); -} - -// dump memory with error check -void dump_w_err_ckeck ( char **ptr, MEMO * mem ){ - check_range (mem); - for (*ptr=(char*)mem->mstr; mem->msiz >= 16; *ptr += 16, mem->msiz -= 16) { - put_r(); - put_dump((unsigned char*)*ptr, (unsigned int)*ptr, 16); - } - if (mem->msiz) { - put_dump((unsigned char*)*ptr, (unsigned int)*ptr, mem->msiz); - } - error_print(mem->mflg); -} - -void i2c_reg( I2C_TypeDef* I2Cx ){ -uint16_t reg; - - put_rn(); - reg = I2Cx->CR1; - reg_print( SIZE32, reg ); - PRINTF( rnmsg0 ); - PRINTF( imsg2 ); - put_rn(); - reg = I2Cx->CR2; - reg_print( SIZE32, reg ); - PRINTF( rnmsg1 ); - PRINTF( imsg2 ); - put_rn(); - reg = I2Cx->SR1; - reg_print( SIZE32, reg ); - PRINTF( rnmsg5 ); - PRINTF( imsg3 ); - put_rn(); - reg = I2Cx->SR2; - reg_print( SIZE32, reg ); - PRINTF( rnmsg6 ); - PRINTF( imsg3 ); - put_rn(); - reg = I2Cx->DR; - reg_print( SIZE32, reg ); - PRINTF( rnmsg2 ); - PRINTF( imsg4 ); - put_rn(); - reg = I2Cx->OAR1; - reg_print( SIZE32, reg ); - PRINTF( rnmsg7 ); - PRINTF( imsg6 ); - put_rn(); - reg = I2Cx->OAR2; - reg_print( SIZE32, reg ); - PRINTF( rnmsg8 ); - PRINTF( imsg6 ); - put_rn(); - reg = I2Cx->CCR; - reg_print( SIZE32, reg ); - PRINTF( rnmsg9 ); - PRINTF( imsg7 ); - put_rn(); - reg = I2Cx->TRISE; - reg_print( SIZE32, reg ); - PRINTF( rnmsg10 ); - PRINTF( imsg8 ); - put_rn(); -} - -void spi_reg( SPI_TypeDef* SPIx ){ -uint16_t reg; - - put_rn(); - reg = SPIx->CR1; - reg_print( SIZE32, reg ); - PRINTF( rnmsg0 ); - PRINTF( imsg2 ); - put_rn(); - reg = SPIx->CR2; - reg_print( SIZE32, reg ); - PRINTF( rnmsg1 ); - PRINTF( imsg2 ); - put_rn(); - reg = SPIx->SR; - reg_print( SIZE32, reg ); - PRINTF( rnmsg3 ); - PRINTF( imsg3 ); - put_rn(); - reg = SPIx->DR; - reg_print( SIZE32, reg ); - PRINTF( rnmsg2 ); - PRINTF( imsg4 ); - put_rn(); -} - -void usart_reg( USART_TypeDef* USARTx ){ -uint16_t reg; - - put_rn(); - reg = USARTx->SR; - reg_print( SIZE32, reg ); - PRINTF( rnmsg3 ); - PRINTF( imsg3 ); - put_rn(); - reg = USARTx->DR; - reg_print( SIZE32, reg ); - PRINTF( rnmsg2 ); - PRINTF( imsg4 ); - put_rn(); - reg = USARTx->BRR; - reg_print( SIZE32, reg ); - PRINTF( rnmsg4 ); - PRINTF( imsg5 ); - put_rn(); - reg = USARTx->CR1; - reg_print( SIZE32, reg ); - PRINTF( rnmsg0 ); - PRINTF( imsg2 ); - put_rn(); - reg = USARTx->CR2; - reg_print( SIZE32, reg ); - PRINTF( rnmsg1 ); - PRINTF( imsg2 ); - put_rn(); -} - -void rpt_port_one( GPIO_TypeDef* GPIOx ){ -uint32_t i; - - PRINTF( " " ); - i = GPIOx->MODER; - PRINTF( "0x%08x",i ); - i = GPIOx->OTYPER; - PRINTF( " 0x%04x",i ); - i = GPIOx->OSPEEDR; - PRINTF( " 0x%08x",i ); - i = GPIOx->PUPDR; - PRINTF( " 0x%08x",i ); - i = GPIOx->IDR; - PRINTF( " 0x%04x",i ); - i = GPIOx->ODR; - PRINTF( " 0x%04x",i ); - put_rn(); -} - -void rpt_port( void ){ - PRINTF( pnmsg0 ); - PRINTF( pnmsg1 ); - put_rn(); - PRINTF( pnmsga ); - rpt_port_one( GPIOA ); - PRINTF( pnmsgb ); - rpt_port_one( GPIOB ); - PRINTF( pnmsgc ); - rpt_port_one( GPIOC ); - PRINTF( pnmsgd ); - rpt_port_one( GPIOD ); - PRINTF( pnmsge ); - rpt_port_one( GPIOE ); - PRINTF( pnmsgh ); - rpt_port_one( GPIOH ); -} - -void port_inf_one( char *ptr ){ -GPIO_TypeDef* GPIOx; -uint32_t i,j; -uint32_t pinpos; - - PRINTF( pnmsg2 ); - switch ( *ptr ){ - case 'a': GPIOx = GPIOA; PUTC( 'A' ); break; - case 'b': GPIOx = GPIOB; PUTC( 'B' ); break; - case 'c': GPIOx = GPIOC; PUTC( 'C' ); break; - case 'd': GPIOx = GPIOD; PUTC( 'D' ); break; - case 'e': GPIOx = GPIOE; PUTC( 'E' ); break; - case 'h': GPIOx = GPIOH; PUTC( 'H' ); break; - } - i = GPIOx->MODER; - put_rn(); - PRINTF( "-->Mode Reg. (0x%08x)\r\n",i ); -#if 0 - for ( pinpos = 0x00; pinpos < 16; pinpos++ ){ - j = GPIO_MODER_MODER0 & (i >> (pinpos * 2)); - switch (j){ - case GPIO_Mode_IN: PRINTF( "%2d= in", pinpos ); break; - case GPIO_Mode_OUT: PRINTF( "%2d=out", pinpos ); break; - case GPIO_Mode_AF: PRINTF( "%2d=alt", pinpos ); break; - case GPIO_Mode_AN: PRINTF( "%2d=ana", pinpos ); break; - default: break; - } - if ( (pinpos == 3) && (*ptr == 'h') ){ - break; - } else { - if ( pinpos == 7 ){ - put_rn(); - } else if ( pinpos == 15 ){;} else { PRINTF(", ");} - } - } -#else - PRINTF("TBD"); - put_rn(); -#endif - i = GPIOx->OTYPER; - put_rn(); - PRINTF( "%s type 1=push-pull, 0= open-drain", pnmsg4 ); - put_rn(); - reg_print( SIZE32,i); - i = GPIOx->OSPEEDR; - PRINTF( "%s speed [MHz] (0x%08x)", pnmsg4, i ); - put_rn(); -#if 0 - for ( pinpos = 0x00; pinpos < 16; pinpos++ ){ - j = GPIO_OSPEEDER_OSPEEDR0 & (i >> (pinpos * 2)); - switch (j){ - case GPIO_Speed_400KHz: PRINTF( "%2d=0.4", pinpos ); break; - case GPIO_Speed_2MHz: PRINTF( "%2d= 2", pinpos ); break; - case GPIO_Speed_10MHz: PRINTF( "%2d= 10", pinpos ); break; - case GPIO_Speed_40MHz: PRINTF( "%2d= 40", pinpos ); break; - default: break; - } - if ( (pinpos == 3) && (*ptr == 'h') ){ break;} - else { - if ( pinpos == 7 ){ put_rn();} - else if ( pinpos == 15){;} else { PRINTF(", ");} - } - } -#else - PRINTF("TBD"); - put_rn(); -#endif - i = GPIOx->PUPDR; - put_rn(); - PRINTF( "-->Pullup(pup)/down(pdn) none(no)(0x%08x)",i ); - put_rn(); -#if 0 - for ( pinpos = 0x00; pinpos < 16; pinpos++ ){ - j = GPIO_PUPDR_PUPDR0 & (i >> (pinpos * 2)); - switch (j){ - case GPIO_PuPd_NOPULL: PRINTF( "%2d= no", pinpos ); break; - case GPIO_PuPd_UP: PRINTF( "%2d=pup", pinpos ); break; - case GPIO_PuPd_DOWN: PRINTF( "%2d=pdn", pinpos ); break; - default: break; - } - if ( (pinpos == 3) && (*ptr == 'h') ){ break;} - else { - if ( pinpos == 7 ){ put_rn();} - else if ( pinpos == 15 ){;} else { PRINTF(", ");} - } - } -#else - PRINTF("TBD"); -#endif - put_rn(); - PRINTF( "%s %s", pnmsg5, pnmsg6); - i = GPIOx->IDR; - reg_print( SIZE32,i); - put_rn(); - PRINTF( "%s %s", pnmsg4, pnmsg6); - i = GPIOx->ODR; - reg_print( SIZE32,i); - put_rn(); -} - -#if 0 -void cpu_inf ( void ){ -unsigned long m1, m2; - - m1 = SCB->CPUID; - m2 = ( m1 >> 24 ); - if ( m2 == 0x41 ) { - put_r(); - PRINTF("%s%s ", amsg0, amsg4); - } else { - put_r(); - PRINTF("%s%s%s ", amsg0, amsg5, amsg4); - } - m2 = ( m1 >> 4 ) & 0xfff; - if ( m2 == 0xc23 ) { - PRINTF(amsg1); - put_rn(); - } else { - PRINTF("%s%s", amsg5, amsg1); - put_rn(); - } - m2 = ( m1 >> 20 ) & 0x0f; - PRINTF("%s%x",amsg6, m2); - put_rn(); - m2 = m1 & 0x7; - PRINTF("%s%x",amsg7, m2); - put_rn(); -} -#endif - -static __I uint8_t PLLMulTable[9] = {3, 4, 6, 8, 12, 16, 24, 32, 48}; - -static void cpu_inf( char *ptr ){ -#if 0 -uint32_t m1, m2, m3, m4, m5; -RCC_ClocksTypeDef RCC_Clocks; - - switch (*ptr++) { - case 'f' : // sc - show system clock frequency - m1 = RCC->CR; PRINTF( "CR = 0x%08x\r\n", m1 ); - m1 = RCC->ICSCR; PRINTF( "ICSCR = 0x%08x\r\n", m1 ); - m1 = RCC->CFGR; PRINTF( "CFGR = 0x%08x\r\n", m1 ); - m1 = RCC->CIR; PRINTF( "CIR = 0x%08x\r\n", m1 ); - m1 = RCC->AHBRSTR; PRINTF( "AHBRSTR = 0x%08x\r\n", m1 ); - m1 = RCC->APB2RSTR; PRINTF( "APB2RSTR = 0x%08x\r\n", m1 ); - m1 = RCC->APB1RSTR; PRINTF( "APB1RSTR = 0x%08x\r\n", m1 ); - m1 = RCC->AHBENR; PRINTF( "AHBENR = 0x%08x\r\n", m1 ); - m1 = RCC->APB2ENR; PRINTF( "APB2ENR = 0x%08x\r\n", m1 ); - m1 = RCC->APB2LPENR; PRINTF( "APB2LPENR= 0x%08x\r\n", m1 ); - m1 = RCC->APB1LPENR; PRINTF( "APB1LPENR= 0x%08x\r\n", m1 ); - m1 = RCC->CSR; PRINTF( "CSR = 0x%08x\r\n", m1 ); - //put_rn(); - m1 = RCC->CFGR & RCC_CFGR_SWS; /* Get SYSCLK source */ - switch (m1){ - case 0x00: // MSI used as system clock - m4 = ( RCC->ICSCR & RCC_ICSCR_MSIRANGE ) >> 13; - m2 = (32768 * (1 << (m4 + 1))); - PRINTF( "%s, %s%dHz", cmsg0, cmsg1, m2); - break; - case 0x04: // HSI used as system clock - PRINTF( "%s, %s%dHz", cmsg2, cmsg1,HSI_VALUE ); - m2 = HSI_VALUE; - break; - case 0x08: // HSE used as system clock - PRINTF( "%s, %s%dHz", cmsg3, cmsg1, HSE_VALUE ); - m2 = HSE_VALUE; - break; - case 0x0C: // PLL used as system clock - // Get PLL clock source and multiplication factor - m5 = RCC->CFGR & RCC_CFGR_PLLMUL; - m1 = RCC->CFGR & RCC_CFGR_PLLDIV; - m5 = PLLMulTable[(m5 >> 18)]; - m1 = (m1 >> 22) + 1; - PRINTF( "%s Mul=%d, Div=%d\r\n", cmsg4, m5, m1 ); - m3 = RCC->CFGR & RCC_CFGR_PLLSRC; - if ( m3 == 0x00 ){ - // HSI oscillator clock selected as PLL clock source - m2 = (((HSI_VALUE) * m5) / m1); - PRINTF( "%s, RC=%dHz", cmsg2, HSI_VALUE ); - } else { - // HSE selected as PLL clock source - m2 = (((HSE_VALUE) * m5) / m1); - PRINTF( "%s, Xtal=%dHz", cmsg3, HSE_VALUE ); - } - put_rn(); - PRINTF( "PLL %s%dHz", cmsg1, m2 ); - break; - default: // Not come here - PRINTF( cmsg5 ); - break; - } - put_rn(); - RCC_GetClocksFreq( &RCC_Clocks ); - PRINTF( "SYSCLK %s%dHz\r\n", cmsg6, RCC_Clocks.SYSCLK_Frequency ); - PRINTF( "HCLK %s%dHz\r\n", cmsg6, RCC_Clocks.HCLK_Frequency ); - PRINTF( "PCLK1 %s%dHz\r\n", cmsg6, RCC_Clocks.PCLK1_Frequency ); - PRINTF( "PCLK2 %s%dHz\r\n", cmsg6, RCC_Clocks.PCLK2_Frequency ); - put_rn(); - m1 = RCC->CSR & RCC_CSR_RTCSEL; - // Check RTC & LCD Clock - PRINTF( cmsg11 ); - put_rn(); - switch (m1){ - case RCC_CSR_RTCSEL_NOCLOCK: - PRINTF( cmsg7 ); - break; - case RCC_CSR_RTCSEL_LSE: - PRINTF( cmsg8 ); - break; - case RCC_CSR_RTCSEL_LSI: - PRINTF( cmsg9 ); - break; - case RCC_CSR_RTCSEL_HSE: - PRINTF( cmsg10 ); - break; - default: // Not come here - PRINTF( cmsg5 ); - break; - } - put_rn(); - put_rn(); - PRINTF( cmsg12 ); - put_rn(); - m1 = PWR->CR; PRINTF( "CR = 0x%08x\r\n", m1 ); - m1 = PWR->CSR; PRINTF( "CSR = 0x%08x\r\n", m1 ); - break; - case 'c' : // sc - show system CPU information - m1 = SCB->CPUID; - m2 = ( m1 >> 24 ); - if ( m2 == 0x41 ){ PRINTF( "CPU = ARM " ); - } else { PRINTF( "CPU = NOT ARM " );} - m2 = ( m1 >> 4 ) & 0xfff; - if ( m2 == 0xc23 ){ PRINTF( "Cortex-M3\r\n" ); - } else { PRINTF( "NOT Cortex-M3\r\n" );} - m2 = ( m1 >> 20 ) & 0x0f; - PRINTF( "Variant:%x\r\n", m2 ); - m2 = m1 & 0x7; - PRINTF( "Revision:%x\r\n", m2 ); - m1 = *(__IO uint32_t *)((uint32_t)0x1ff80064); - PRINTF("Unique device ID(94bits):(1) 0x%08x ", m1); - m1 = *(__IO uint32_t *)((uint32_t)0x1ff80054); - PRINTF("(2) 0x%08x ", m1); - m1 = *(__IO uint32_t *)((uint32_t)0x1ff80050); - PRINTF( "(3) 0x%08x\r\n", m1 ); - break; - case '?' : - default: - PRINTF( "sc - System CPU information\r\n" ); - PRINTF( "sf - System Clock\r\n" ); - } -#else - PRINTF("TBD"); - put_rn(); -#endif -} - -//----------------------------------------------------------------------------- -// Monitor Main Program -//----------------------------------------------------------------------------- -int mon_hw(void){ -char *ptr; - - put_r(); - PRINTF("%s [Help:'?' key]", mon_msg); - put_rn(); - for (;;) { - put_r(); - PUTC('>'); - ptr = linebuf; - get_line(ptr, buf_size); - put_r(); - switch (*ptr++) { - //------------------------------------------------------------------------------------- - // Memory - //------------------------------------------------------------------------------------- - case 'm' : - put_r(); - PRINTF(mmmsg0); - put_rn(); - mem.mstr = mem_range[0][0]; // default start address = Flash - mem.msiz =256; - mem.mold = 0; - mem.mtmp = 0; - mem.mflg = 0; - for (; mem.mflg != 0xff;) { - PRINTF("m>"); - ptr = linebuf; - get_line(ptr, buf_size); - put_r(); - switch(*ptr++){ - case 'd' : // d <address> [<count>] - Dump memory - mem.mtmp = mem.mstr; - if (!xatoi(&ptr, &mem.mstr)) { - mem.mstr = mem.mtmp; - } - if (!xatoi(&ptr, &mem.msiz)) { - mem.msiz = 256; - } - mem.mtmp = mem.msiz; - dump_w_err_ckeck(&ptr, &mem); - mem.mold = mem.mstr; - mem.mstr += mem.mtmp; - break; - case 'f' : // next - case 'n' : - case 0x0d : - mem.msiz = 256; - mem.mtmp = mem.msiz; - dump_w_err_ckeck(&ptr, &mem); - mem.mold = mem.mstr; - mem.mstr += 256; - break; - case 'q' : // quit - mem.mflg = 0xff; - break; - case 'b' : // Back to more - if ( mem.mold == 0 ){ - ; - } else { - mem.mold -= 256; - } - case 'k' : // keep previous address - mem.mstr = mem.mold; - mem.msiz = 256; - mem.mtmp = mem.msiz; - dump_w_err_ckeck(&ptr, &mem); - mem.mstr += 256; - break; - case 'a' : // start RAM top - mem.mstr = mem_range[3][0]; - mem.msiz =256; - mem.mold = 0; - mem.mtmp = 0; - mem.mflg = 0; - dump_w_err_ckeck(&ptr, &mem); - mem.mstr += 256; - break; - case 'o' : // start ROM top - mem.mstr = mem_range[0][0]; - mem.msiz =256; - mem.mold = 0; - mem.mtmp = 0; - mem.mflg = 0; - dump_w_err_ckeck(&ptr, &mem); - mem.mstr += 256; - break; - case 's' : - PRINTF(mmmsg1); - put_rn(); - PRINTF("%s0x%08lx to 0x%08lx ", rmsg0, mem_range[0][0], mem_range[0][1]); - put_rn(); - PRINTF("%s0x%08lx to 0x%08lx ", rmsg2, mem_range[1][0], mem_range[1][1]); - put_rn(); - PRINTF("%s0x%08lx to 0x%08lx ", rmsg3, mem_range[2][0], mem_range[2][1]); - put_rn(); - PRINTF("%s0x%08lx to 0x%08lx ", rmsg4, mem_range[3][0], mem_range[3][1]); - put_rn(); - PRINTF("%s0x%08lx to 0x%08lx ", rmsg5, mem_range[4][0], mem_range[4][1]); - put_rn(); - break; - case '?' : - PRINTF(mmmsg2); put_rn(); - PRINTF(mmmsg3); put_rn(); - PRINTF(mmmsg4); put_rn(); - PRINTF(mmmsg5); put_rn(); - PRINTF(mmmsg6); put_rn(); - PRINTF(mmmsg7); put_rn(); - PRINTF(mmmsg8); put_rn(); - PRINTF(mmmsg9); put_rn(); - break; - default: - PUTC('?'); - put_rn(); - } - } - PRINTF(mmmsg10); - put_rn(); - break; - //------------------------------------------------------------------------------------- - // Register - //------------------------------------------------------------------------------------- - case 'r' : - put_r(); - PRINTF(mrmsg0); - put_rn(); - mem.mflg = 0; - for (; mem.mflg != 0xff;) { - PRINTF("r>"); - ptr = linebuf; - get_line(ptr, buf_size); - put_r(); - switch(*ptr++){ - case 'u' : - switch(*ptr++){ - case '1' : - PRINTF("%s%s1%s", mrmsg1,mrmsg2,mrmsg1); - usart_reg(USART1); - break; - case '2' : - PRINTF("%s%s2%s", mrmsg1,mrmsg2,mrmsg1); - usart_reg(USART2); - break; - case '6' : - PRINTF("%s%s6%s", mrmsg1,mrmsg2,mrmsg1); - usart_reg(USART6); - break; - case '*' : - PRINTF( "%s & UART", mrmsg2 ); - put_rn(); - PRINTF("%s%s1%s", mrmsg1,mrmsg2,mrmsg1); - usart_reg(USART1); - PRINTF("%s%s2%s", mrmsg1,mrmsg2,mrmsg1); - usart_reg(USART2); - PRINTF("%s%s6%s", mrmsg1,mrmsg2,mrmsg1); - usart_reg(USART6); - break; - case '?' : - default: - PRINTF( mrmsg3 ); - put_rn(); - } - break; - case 'i' : - switch(*ptr++){ - case '1' : - PRINTF("%s%s1%s", mrmsg1,mrmsg4,mrmsg1); - i2c_reg( I2C1 ); - break; - case '2' : - PRINTF("%s%s2%s", mrmsg1,mrmsg4,mrmsg1);; - i2c_reg( I2C2 ); - break; - case '3' : - PRINTF("%s%s3%s", mrmsg1,mrmsg4,mrmsg1);; - i2c_reg( I2C3 ); - break; - case '*' : - PRINTF(mrmsg4); - put_rn(); - PRINTF("%s%s1%s", mrmsg1,mrmsg4,mrmsg1); - i2c_reg( I2C1 ); - PRINTF("%s%s2%s", mrmsg1,mrmsg4,mrmsg1); - i2c_reg( I2C2 ); - PRINTF("%s%s3%s", mrmsg1,mrmsg4,mrmsg1); - i2c_reg( I2C3 ); - break; - case '?' : - default: - PRINTF(mrmsg5); - put_rn(); - } - break; - case 's' : - switch(*ptr++){ - case '1' : - PRINTF("%s%s1%s", mrmsg1,mrmsg6,mrmsg1); - spi_reg( SPI1 ); - break; - case '2' : - PRINTF("%s%s2%s", mrmsg1,mrmsg6,mrmsg1); - spi_reg( SPI2 ); - break; - case '3' : - PRINTF("%s%s3%s", mrmsg1,mrmsg6,mrmsg1); - spi_reg( SPI3 ); - break; - case '4' : - PRINTF("%s%s4%s", mrmsg1,mrmsg6,mrmsg1); - spi_reg( SPI4 ); - break; - case '*' : - PRINTF(mrmsg6); - put_rn(); - PRINTF("%s%s1%s", mrmsg1,mrmsg6,mrmsg1); - spi_reg( SPI1 ); - PRINTF("%s%s2%s", mrmsg1,mrmsg6,mrmsg1); - spi_reg( SPI2 ); - PRINTF("%s%s3%s", mrmsg1,mrmsg6,mrmsg1); - spi_reg( SPI3 ); - PRINTF("%s%s4%s", mrmsg1,mrmsg6,mrmsg1); - spi_reg( SPI4 ); - break; - case '?' : - default: - PRINTF(mrmsg7); - put_rn(); - } - break; - case 't' : // - not_yet_impliment(); - break; - case 'a' : // - not_yet_impliment(); - break; - case 'd' : // - not_yet_impliment(); - break; - case 'w' : // - not_yet_impliment(); - break; - case 'l' : // - not_yet_impliment(); - break; - case 'c' : // - not_yet_impliment(); - break; - case 'x' : // - not_yet_impliment(); - break; - case 'y' : // - not_yet_impliment(); - break; - case '?' : - PRINTF("u - USART"); - put_rn(); - PRINTF("i - I2C"); - put_rn(); - PRINTF("s - SPI"); - put_rn(); - PRINTF("t - TIMER"); - put_rn(); - PRINTF("a - ADC"); - put_rn(); - PRINTF("d - DAC"); - put_rn(); - PRINTF("l - LDC"); - put_rn(); - PRINTF("w - WWDG"); - put_rn(); - PRINTF("c - COMP"); - put_rn(); - break; - case 'q' : // quit - mem.mflg = 0xff; - break; - default: - PUTC('?'); - put_rn(); - } - } - PRINTF(mrmsg8); - put_rn(); - break; - //------------------------------------------------------------------------------------- - // Port - //------------------------------------------------------------------------------------- - case 'p' : - put_r(); - PRINTF(mpmsg0); - put_rn(); - mem.mflg = 0; - for (; mem.mflg != 0xff;) { - PRINTF("p>"); - ptr = linebuf; - get_line(ptr, buf_size); - put_r(); - switch(*ptr){ - case 'a' : - case 'b' : - case 'c' : - case 'd' : - case 'e' : - case 'h' : - port_inf_one(ptr); - break; - case '*' : - rpt_port(); - break; - case '?' : - PRINTF(mpmsg1); - put_rn(); - break; - case 'q' : // quit - mem.mflg = 0xff; - break; - default: - PUTC('?'); - put_rn(); - } - } - PRINTF(mrmsg8); - put_rn(); - break; - //------------------------------------------------------------------------------------- - // System - //------------------------------------------------------------------------------------- - case 's' : // System related information - cpu_inf(ptr); - break; - //------------------------------------------------------------------------------------- - // Help - //------------------------------------------------------------------------------------- - case '?' : - hw_msg_hlp(); - break; - //------------------------------------------------------------------------------------- - // Return to main routine - //------------------------------------------------------------------------------------- - case 'q' : // Quit - put_r(); - PRINTF(mqmsg0); - put_rn(); - return 0; - default: - PRINTF("?"); - put_rn(); - } - } -}
diff -r db817fb05ba7 -r 58734155cd29 mon_hw.h --- a/mon_hw.h Sat Jul 12 11:55:37 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,132 +0,0 @@ -/* - * mbed Application program for the ST NUCLEO F401RE Board - * - * Copyright (c) 2010-2014 Kenji Arai / JH1PJL - * http://www.page.sannet.ne.jp/kenjia/index.html - * http://mbed.org/users/kenjiArai/ - * Created: July 7th, 2014 - * Ported: July 12th, 2014 from L152RE - * Revised: July 12th, 2014 - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE - * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -// ROM / Constant data --------------------------------------------------------------------------- -char *const mon_msg = "Monitor for mbed Nucleo F401RE created on "__DATE__""; - -char *const rmsg0 = "FLASH "; -char *const rmsg2 = "SYS-Mem "; -char *const rmsg3 = "OPTION "; -char *const rmsg4 = "SRAM "; -char *const rmsg5 = "IO "; -char *const rmsg6 = "Return to"; - -char *const xmsg0 = "Not implimented yet"; - -char *const rgmsg0 = " 7, 6, 5, 4, 3, 2, 1, 0"; -char *const rgmsg1 = "15,14,13,12,11,10, 9, 8,"; - -char *const hmsg0 = "m - Entry Memory Mode"; -char *const hmsg1 = "m>? -> Aditinal functions can see by ?"; -char *const hmsg2 = "r - Entry Register Mode"; -char *const hmsg3 = "r>? -> Aditinal functions can see by ?"; -char *const hmsg4 = "s - System Clock -> sf, System / CPU information -> sc"; -char *const hmsg5 = "q - Quit (back to called routine)"; -char *const hmsg6 = "p - Entry Port Mode"; -char *const hmsg7 = "p>? -> Aditinal functions can see by ?"; - -#if 0 -char *const amsg0 = "CPU = "; -char *const amsg1 = "Cortex-M3"; -char *const amsg2 = "Reach to out of range"; -char *const amsg3 = "Not in a memory area"; -char *const amsg4 = "ARM"; -char *const amsg5 = "NOT "; -char *const amsg6 = "Variant:"; -char *const amsg7 = "Revision:"; -#else -char *const amsg2 = "Reach to out of range"; -char *const amsg3 = "Not in a memory area"; -#endif - - -char *const cmsg0 = "Use MSI(internal RC)"; -char *const cmsg1 = "freq="; -char *const cmsg2 = "Use HSI(internal RC/High speed)"; -char *const cmsg3 = "Use HSE(External Xtal)"; -char *const cmsg4 = "Use PLL with"; -char *const cmsg5 = "??? following infromation is not valid !"; -char *const cmsg6 = "clock freq. ="; -char *const cmsg7 = "No clock"; -char *const cmsg8 = "Use LSE(external Xtal), 32768Hz"; -char *const cmsg9 = "Use LSI(internal RC/Low speed), RC=37000Hz"; -char *const cmsg10= "Use HSE(external Xtal & prescaler)"; -char *const cmsg11= "RTC/LCD Clock"; -char *const cmsg12= "Power Control"; - -char *const imsg2 = "-->Control Reg."; -char *const imsg3 = "-->Status Reg."; -char *const imsg4 = "-->Data Reg."; -char *const imsg5 = "-->Baud rate Reg."; -char *const imsg6 = "-->Own address Reg."; -char *const imsg7 = "-->Clock control Reg."; -char *const imsg8 = "-->TRISE Reg."; - -char *const rnmsg0 = " CR1--"; -char *const rnmsg1 = " CR2--"; -char *const rnmsg2 = " DR---"; -char *const rnmsg3 = " SR---"; -char *const rnmsg4 = " BRR--"; -char *const rnmsg5 = " SR1--"; -char *const rnmsg6 = " SR2--"; -char *const rnmsg7 = " OAR1-"; -char *const rnmsg8 = " OAR2-"; -char *const rnmsg9 = " CCR--"; -char *const rnmsg10 = " TRISE"; - -char *const pnmsg0 = "Port "; -// 0x00000000 0x0000 0x00000000 0x00000000 0x0000 0x0000 -char *const pnmsg1 = "Mode Out-type Out-speed Pup/dwn Input Output"; -char *const pnmsga = "GPIOA"; -char *const pnmsgb = "GPIOB"; -char *const pnmsgc = "GPIOC"; -char *const pnmsgd = "GPIOD"; -char *const pnmsge = "GPIOE"; -char *const pnmsgh = "GPIOH"; -char *const pnmsg2 = "Select GPIO"; -char *const pnmsg3 = " All"; -char *const pnmsg4 = "-->Output"; -char *const pnmsg5 = "-->Input"; -char *const pnmsg6 = "data"; - -char *const mmmsg0 = "Enter Memory Mode 1) d <address> [<count>], 2) s, 3) <ret> or f, 4) q, 5)?"; -char *const mmmsg1 = "Memory Configuration"; -char *const mmmsg2 = "d <address> [<count>] - Dump memory"; -char *const mmmsg3 = "s - Show memory structure "; -char *const mmmsg4 = "o - Dump memory / start from ROM top"; -char *const mmmsg5 = "a - Dump memory / start from RAM top"; -char *const mmmsg6 = "k - Dump memory / keep same 256bytes"; -char *const mmmsg7 = "b - Dump memory / before 256bytes"; -char *const mmmsg8 = "<RET> or f, n - Dump memory / next 256bytes"; -char *const mmmsg9 = "q - Exit memory mode"; -char *const mmmsg10 = "Return to Normal Mode"; - -char *const mrmsg0 = "Enter Register Mode u,i,s,t,a,d,l,w,c & ? for help"; -char *const mrmsg1 = "------"; -char *const mrmsg2 = "USART"; -char *const mrmsg3 = "Enter u1,u2,u6 and u* for all"; -char *const mrmsg4 = "I2C"; -char *const mrmsg5 = "Enter i1,i2,i3 and i* for all"; -char *const mrmsg6 = "SPI"; -char *const mrmsg7 = "Enter s1,s2,s3,s4 and s* for all"; -char *const mrmsg8 = "Return to Normal Mode"; - -char *const mpmsg0 = "Enter port a,b,c,d,e,h & * ? for help"; -char *const mpmsg1 = "port a,b,c,d,e,h & *"; - -char *const mqmsg0 = "Return to mon()"; -