]> cloudbase.mooo.com Git - z180-stamp.git/commitdiff
Use internal clock HSI (instead of HSE)
authorLeo C <erbl259-lmu@yahoo.de>
Sun, 4 May 2014 14:05:59 +0000 (16:05 +0200)
committerLeo C <erbl259-lmu@yahoo.de>
Sun, 4 May 2014 14:05:59 +0000 (16:05 +0200)
Remap OSC_IN/OSC_OUT to PD0/PD1

stm32/z180-stamp-stm32.c

index 6751fe13dc8bc14c2320c3a93109ddf46c4d50ba..ce161d815f1769d8cb015f6f4dc98f82d5ab05a8 100644 (file)
 #define IDR    0x08
 
 
 #define IDR    0x08
 
 
-/*
-#define __ASM            __asm
-#define __STATIC_INLINE  static inline
-
-__attribute__((always_inline)) __STATIC_INLINE void __enable_irq(void)
-{
-  __ASM volatile ("cpsie i");
-}
-
-__attribute__((always_inline)) __STATIC_INLINE void __disable_irq(void)
-{
-  __ASM volatile ("cpsid i");
-}
-*/
-
-
 
 #include "z80-if.h"
 #include "hdrom.h"
 
 #include "z80-if.h"
 #include "hdrom.h"
@@ -101,14 +85,15 @@ volatile uint32_t Stat;
 
 static void clock_setup(void)
 {
 
 static void clock_setup(void)
 {
-       rcc_clock_setup_in_hse_8mhz_out_24mhz();
+       //rcc_clock_setup_in_hse_8mhz_out_24mhz();
+       rcc_clock_setup_in_hsi_out_24mhz();
 
        /* Enable clocks for:
                GPIO port A (for GPIO_USART1_TX and Button)
                GPIO port C (LEDs) 
                USART1
                TIM16 (RST-Pin) 
 
        /* Enable clocks for:
                GPIO port A (for GPIO_USART1_TX and Button)
                GPIO port C (LEDs) 
                USART1
                TIM16 (RST-Pin) 
-               TIM1  (IOE)
+               TIM1  (IOCS1)
           TODO: USART1 --> USART_CONSOLE
        */
        rcc_peripheral_enable_clock(&RCC_APB2ENR, 
           TODO: USART1 --> USART_CONSOLE
        */
        rcc_peripheral_enable_clock(&RCC_APB2ENR, 
@@ -123,7 +108,7 @@ static void clock_setup(void)
                        RCC_APB1ENR_TIM3EN);
 
        /* Enable clocks for:
                        RCC_APB1ENR_TIM3EN);
 
        /* Enable clocks for:
-               TIM3
+               DMA1
        */
        rcc_peripheral_enable_clock(&RCC_AHBENR, 
                        RCC_AHBENR_DMA1EN);
        */
        rcc_peripheral_enable_clock(&RCC_AHBENR, 
                        RCC_AHBENR_DMA1EN);
@@ -172,9 +157,12 @@ static void gpio_setup(void)
        /* Disable JTAG-DP, but leave SW-DP Enabled. (free PA15, PB3, PB4)
           Remap SPI1 to PB3, PB4, PB5 and PA15.
           Remap TIM3 (CH1/PC6, CH2/PC7, CH3/PC8, CH4/PC9)
        /* Disable JTAG-DP, but leave SW-DP Enabled. (free PA15, PB3, PB4)
           Remap SPI1 to PB3, PB4, PB5 and PA15.
           Remap TIM3 (CH1/PC6, CH2/PC7, CH3/PC8, CH4/PC9)
+          Port D0/Port D1 mapping on OSC_IN/OSC_OUT
        */
        gpio_primary_remap(AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_ON, 
        */
        gpio_primary_remap(AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_ON, 
-               AFIO_MAPR_SPI1_REMAP | AFIO_MAPR_TIM3_REMAP_FULL_REMAP);
+                       AFIO_MAPR_SPI1_REMAP
+                       | AFIO_MAPR_TIM3_REMAP_FULL_REMAP
+                       | AFIO_MAPR_PD01_REMAP);
 
        /* LEDs and User Button. */
        gpio_set_mode(LED_PORT, GPIO_MODE_OUTPUT_2_MHZ,
 
        /* LEDs and User Button. */
        gpio_set_mode(LED_PORT, GPIO_MODE_OUTPUT_2_MHZ,
@@ -432,8 +420,9 @@ void sys_tick_handler(void)
        if (count_ms == 1000) {
                count_ms = 0;
 
        if (count_ms == 1000) {
                count_ms = 0;
 
-               if (timeout_1s)
-                       --timeout_1s;
+               i = timeout_1s;
+               if (i)
+                       timeout_1s = i - 1;
        }
 }
 
        }
 }
 
@@ -452,7 +441,7 @@ void tim3_set(int mode)
        
        cc_mode = TIM_CCMR2_CC4S_OUT;
 
        
        cc_mode = TIM_CCMR2_CC4S_OUT;
 
-       TIM3_CR1 = TIM_CR1_CMS_EDGE | TIM_CR1_DIR_UP | TIM_CR1_OPM;
+       TIM3_CR1 = TIM_CR1_CMS_EDGE | TIM_CR1_DIR_UP /*| TIM_CR1_OPM */ ;
 
        if (mode < 0)
                cc_mode |= TIM_CCMR2_OC4M_FORCE_LOW;
 
        if (mode < 0)
                cc_mode |= TIM_CCMR2_OC4M_FORCE_LOW;
@@ -460,6 +449,7 @@ void tim3_set(int mode)
                cc_mode |= TIM_CCMR2_OC4M_FORCE_HIGH;
        else {
                TIM3_ARR = mode;
                cc_mode |= TIM_CCMR2_OC4M_FORCE_HIGH;
        else {
                TIM3_ARR = mode;
+               TIM3_CCR4 = mode/2;
                cc_mode |= TIM_CCMR2_OC4M_PWM2;
        }
                        
                cc_mode |= TIM_CCMR2_OC4M_PWM2;
        }
                        
@@ -548,7 +538,7 @@ uint8_t z80_get_byte(uint32_t adr)
 {
        uint8_t data;
        
 {
        uint8_t data;
        
-       z80_get_bus();
+       z80_request_bus();
        data = z80_read(adr),
        z80_release_bus();
        
        data = z80_read(adr),
        z80_release_bus();
        
@@ -560,7 +550,7 @@ uint8_t z80_get_byte(uint32_t adr)
 
 static void do_10ms(void) 
 {
 
 static void do_10ms(void) 
 {
-       for (uint8_t i = 0; i < 2; i++) {
+       for (uint_fast8_t i = 0; i < 2; i++) {
                switch (led_stat[i].mode) {
                case PULSE:
                        if (led_timer[i] == 0) {
                switch (led_stat[i].mode) {
                case PULSE:
                        if (led_timer[i] == 0) {
@@ -584,6 +574,28 @@ static void do_10ms(void)
        }
 }
 
        }
 }
 
+void wait_for_z80_init_done(void)
+{
+       uint8_t buf, out_i, in_i, mask;
+       int to;
+
+       timeout_1s = 10;
+       to = 0;
+       while (timeout_1s) {
+               if (to != timeout_1s) {
+                       buf = z80_get_byte(tx_fifo - 0);
+                       out_i = z80_get_byte(tx_fifo - 1);
+                       in_i = z80_get_byte(tx_fifo - 2);
+                       mask = z80_get_byte(tx_fifo - 3);
+                       printf(" %.2x  %.2x  %.2x  %.2x\n", buf, out_i, in_i, mask);
+                       to = timeout_1s;
+
+                       if ((out_i == 0) && (mask == 0x7f))
+                               timeout_1s = 0;
+               }
+       }
+}
+
 /*--------------------------------------------------------------------------*/
 
 int main(void)
 /*--------------------------------------------------------------------------*/
 
 int main(void)
@@ -600,8 +612,9 @@ int main(void)
        tim3_setup();
        setvbuf(stdout, NULL, _IONBF, 0);
        usart_setup();
        tim3_setup();
        setvbuf(stdout, NULL, _IONBF, 0);
        usart_setup();
-       printf("Hello World!\n");
+       printf("\n(STM32F100+HD64180)_stamp Tester\n");
 
 
+       z80_setup_io_infifo();
        z80_setup_bus();
        printf("z80_setup_bus done.\n");
 
        z80_setup_bus();
        printf("z80_setup_bus done.\n");
 
@@ -622,7 +635,7 @@ int main(void)
        printf("get bus...");
        z80_busreq(LOW);
        z80_reset(HIGH);
        printf("get bus...");
        z80_busreq(LOW);
        z80_reset(HIGH);
-       z80_get_bus();
+       z80_request_bus();
        printf(" got it!\n");
        
        z80_memset(0, 0x76, 0x80000);
        printf(" got it!\n");
        
        z80_memset(0, 0x76, 0x80000);
@@ -631,30 +644,13 @@ int main(void)
        
        z80_write_block((unsigned char *) hdrom, 0, hdrom_length);      
        z80_reset(LOW);
        
        z80_write_block((unsigned char *) hdrom, 0, hdrom_length);      
        z80_reset(LOW);
-       printf("bus released! ");
+       printf("bus released!\n");
        z80_release_bus();
        z80_reset(HIGH);
        printf(" reset released!\n");
        
        z80_release_bus();
        z80_reset(HIGH);
        printf(" reset released!\n");
        
-       timeout_1s = 6;
-       while (timeout_1s) {
-               static int to=0;
-               uint8_t b, rc, tc, m;
-               if (to != timeout_1s) {
-                       b  = z80_get_byte(tx_fifo-0),
-                       rc = z80_get_byte(tx_fifo-1),
-                       tc = z80_get_byte(tx_fifo-2),
-                       m  =z80_get_byte(tx_fifo-3);
-                       printf(" %.2x  %.2x  %.2x  %.2x\n",
-                               b, rc, tc, m);
-                       to = timeout_1s;
-
-                       if ((rc==0) && (m==0x7f))
-                               break;
-               }
-       }
-       z80_fifo_init();
+       wait_for_z80_init_done();
+       z80_memfifo_init();
        
        ledset(0, BLINK1, 50);
 
        
        ledset(0, BLINK1, 50);
 
@@ -670,8 +666,11 @@ int main(void)
 //             if (get_key_long(KEY0))
 //                     ledset(1, PULSE, 100);
                        
 //             if (get_key_long(KEY0))
 //                     ledset(1, PULSE, 100);
                        
-               if (get_key_short(KEY0))
+               if (get_key_short(KEY0)) {
                        z80_reset_pulse();
                        z80_reset_pulse();
+                       wait_for_z80_init_done();
+                       z80_memfifo_init();
+               }
 
 
 /*
 
 
 /*
@@ -729,15 +728,15 @@ int main(void)
                                        tim3_set(24000000/1000000 * 5); /* 5 us */
                                        break;
                                default:
                                        tim3_set(24000000/1000000 * 5); /* 5 us */
                                        break;
                                default:
-                                       z80_fifo_putc(fifo_out, c);
+                                       z80_memfifo_putc(fifo_out, c);
                        }
                }
 
                if (timeout_1s == 0) {
                
                        }
                }
 
                if (timeout_1s == 0) {
                
-                       while (z80_fifo_is_not_empty(fifo_in)) {
+                       while (!z80_memfifo_is_empty(fifo_in)) {
 //                             LED_GREEN_ON();
 //                             LED_GREEN_ON();
-                               c = z80_fifo_getc(fifo_in);
+                               c = z80_memfifo_getc(fifo_in);
                                putchar(c);
 //                             LED_GREEN_OFF();
                        }
                                putchar(c);
 //                             LED_GREEN_OFF();
                        }
@@ -745,8 +744,14 @@ int main(void)
                        timeout_1s = 1;
                }
                
                        timeout_1s = 1;
                }
                
-               while ((ch = z80_inbuf_getc()) >= 0)
+               while ((ch = z80_io_infifo_getc()) >= 0) {
+                       static int linepos;
+
+                       if (linepos == 0)
+                               printf("\n");
                        printf(" 0x%.2X ", ch);
                        printf(" 0x%.2X ", ch);
+                       linepos = (linepos + 1) % 16;
+               }
        }
 
        return 0;
        }
 
        return 0;