<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    Zdravim,<br>
    u nejake starsi verze GCC jsem musel delat neco podobneho. Prekladac
    si myslel, ze adresa je pamet a ne zarizeni. Provadel tedy
    optimalizace, kde nemel. Pomohla novejsi verze GCC nebo pridani
    volatile na zakladni prvky<br>
    #define PERIPH_BASE           ((uint32_t volatile)0x40000000)
    /*!< Peripheral base address in the alias region */<br>
    <br>
    Jirka<br>
    <br>
    <br>
    <div class="moz-cite-prefix">Dne 03.11.2017 v 20:40 Jaroslav Buchta
      napsal(a):<br>
    </div>
    <blockquote type="cite"
      cite="mid:4e6ce0d6-c6d8-1535-97b1-878eb3bca691@hascomp.cz">
      <meta http-equiv="Context-Type" content="text/html; charset=utf-8">
      <div class="moz-cite-prefix">Tak jeste jednou, ta funkce taky
        nebyla OK, jedine, co pri optimalizaci asi pomuze spolehlive je
        <br>
        <b>volatile</b> uint32_t AH,AL,BH,BL,CH,CL;<br>
        Je mozne, ze to jinak prehodi instrukce tak, ze neni dodrzeno
        poradi zapisu do GPIO registru, i kdyz jsou volatile?<br>
        <br>
        <br>
        Dne 03.11.2017 v 20:19 Jaroslav Buchta napsal(a):<br>
      </div>
      <blockquote type="cite"
        cite="mid:1e9d2132-22c9-1fe6-67bd-1e03e8189325@hascomp.cz">
        <div class="moz-cite-prefix">Jeste koukam, ze GPIO_PIN_x je
          uint16_t ale tohle taky nepomuze:<br>
          <br>
          #define PREPAREDOREGS(A,B,C,v)    A =  ((v)&0x01) ?
          (uint32_t)TFT_D0_Pin : ((uint32_t)TFT_D0_Pin) << 16;\<br>
          Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  C =  ((v)&0x02) ?
          (uint32_t)TFT_D1_Pin : ((uint32_t)TFT_D1_Pin) << 16;\<br>
          Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  A |= ((v)&0x04) ?
          (uint32_t)TFT_D2_Pin : ((uint32_t)TFT_D2_Pin) << 16;\<br>
          Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  B =  ((v)&0x08) ?
          (uint32_t)TFT_D3_Pin : ((uint32_t)TFT_D3_Pin) << 16;\<br>
          Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  B |= ((v)&0x10) ?
          (uint32_t)TFT_D4_Pin : ((uint32_t)TFT_D4_Pin) << 16;\<br>
          Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  B |= ((v)&0x20) ?
          (uint32_t)TFT_D5_Pin : ((uint32_t)TFT_D5_Pin) << 16;\<br>
          Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  B |= ((v)&0x40) ?
          (uint32_t)TFT_D6_Pin : ((uint32_t)TFT_D6_Pin) << 16;\<br>
          Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  A |= ((v)&0x80) ?
          (uint32_t)TFT_D7_Pin : ((uint32_t)TFT_D7_Pin) << 16<br>
          <br>
          Dne 03.11.2017 v 20:08 Jaroslav Buchta napsal(a):<br>
        </div>
        <blockquote type="cite"
          cite="mid:aae1d506-23d6-e317-5c98-915f2b69bd43@hascomp.cz">Mam
          kod pro plneni displeje pripojeneho osmibitove k STM32F303,
          bity jsou namixovany na ruzne porty tak to neni uplne
          jednoduche. Po zapnuti optimalizace mi to zacne asi vynechavat
          nastaveni nekterych bitu, barvy jsou spatne, nefunguje to se
          zakomentovanym makrem APPLYDOREGS, tak jak to je to unguje OK.
          Pomuze take vypnout optimalizaci nebo AH,AL... definovat jako
          volatile. <br>
          <br>
          assembler je pri optimalizaci strasnej gulas, na prvni pohled
          se lisi kody pouzitim str vs str.w - jaky je v tom rozdil? Mel
          jsem za to, ze jen v delce kodu instrukce, kdyz jsou operace s
          registry... napr.: <br>
          <br>
          08001720:   str     r5, [r3, #24] <br>
          08001722:   str     r1, [r4, #24] <br>
          08001724:   str.w   r6, [r8, #24] <br>
          <br>
          Tusi nekdo cim to je? GPIOx->BSRR je snad definovano jako
          volatile uint32_t. Reseni mam ale znervoznuje me to... <br>
          <br>
          #pragma GCC push_options <br>
          #pragma GCC optimize ("O3") <br>
          <br>
          <br>
          #define PREPAREDOREGS(A,B,C,v)    A =  ((v)&0x01) ?
          TFT_D0_Pin : TFT_D0_Pin << 16;\ <br>
          Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  C =  ((v)&0x02) ?
          TFT_D1_Pin : TFT_D1_Pin << 16;\ <br>
          Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  A |= ((v)&0x04) ?
          TFT_D2_Pin : TFT_D2_Pin << 16;\ <br>
          Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  B =  ((v)&0x08) ?
          TFT_D3_Pin : TFT_D3_Pin << 16;\ <br>
          Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  B |= ((v)&0x10) ?
          TFT_D4_Pin : TFT_D4_Pin << 16;\ <br>
          Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  B |= ((v)&0x20) ?
          TFT_D5_Pin : TFT_D5_Pin << 16;\ <br>
          Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  B |= ((v)&0x40) ?
          TFT_D6_Pin : TFT_D6_Pin << 16;\ <br>
          Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  A |= ((v)&0x80) ?
          TFT_D7_Pin : TFT_D7_Pin << 16 <br>
          <br>
          #define APPLYDOREGS(A,B,C)    *(uint32_t
          *)(&GPIOA->BSRR) = A;\ <br>
          Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  *(uint32_t *)(&GPIOB->BSRR)
          = B;\ <br>
          Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  *(uint32_t *)(&GPIOC->BSRR)
          = C <br>
          <br>
          //#define APPLYDOREGS(A,B,C)    GPIOA->BSRR = A;\ <br>
          //    Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  GPIOB->BSRR = B;\ <br>
          //    Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  GPIOC->BSRR = C <br>
          <br>
          static void TftFillData (uint16_t w, int len) <br>
          { <br>
          Â Â Â  uint32_t AH,AL,BH,BL,CH,CL; <br>
          <br>
          Â Â Â  TFT_RS_TPYA_GPIO_Port->BRR = TFT_RS_TPYA_Pin; <br>
          Â Â Â  TFT_NCS_GPIO_Port->BRR = TFT_NCS_Pin; <br>
          Â Â Â  PREPAREDOREGS(AH, BH, CH, 0x2c); <br>
          Â Â Â  APPLYDOREGS(AH, BH, CH); <br>
          Â Â Â  TFT_NWR_TPXA_GPIO_Port->BRR = TFT_NWR_TPXA_Pin; <br>
          Â Â Â  __DSB(); <br>
          Â Â Â  __ISB(); <br>
          Â Â Â  TFT_NWR_TPXA_GPIO_Port->BSRR = TFT_NWR_TPXA_Pin; <br>
          <br>
          Â Â Â  TFT_RS_TPYA_GPIO_Port->BSRR = TFT_RS_TPYA_Pin; <br>
          Â Â Â  PREPAREDOREGS(AH, BH, CH, (uint8_t)(w >> 8)); <br>
          Â Â Â  PREPAREDOREGS(AL, BL, CL, (uint8_t)(w & 0xff)); <br>
          Â Â Â  while (len--) <br>
          Â Â Â  { <br>
          Â Â Â  Â Â Â  APPLYDOREGS(AH, BH, CH); <br>
          Â Â Â  Â Â Â  TFT_NWR_TPXA_GPIO_Port->BRR = TFT_NWR_TPXA_Pin; <br>
          Â Â Â  Â Â Â  __DSB(); <br>
          Â Â Â  Â Â Â  __ISB(); <br>
          Â Â Â  Â Â Â  TFT_NWR_TPXA_GPIO_Port->BSRR = TFT_NWR_TPXA_Pin; <br>
          <br>
          Â Â Â  Â Â Â  APPLYDOREGS(AL, BL, CL); <br>
          Â Â Â  Â Â Â  TFT_NWR_TPXA_GPIO_Port->BRR = TFT_NWR_TPXA_Pin; <br>
          Â Â Â  Â Â Â  __DSB(); <br>
          Â Â Â  Â Â Â  __ISB(); <br>
          Â Â Â  Â Â Â  TFT_NWR_TPXA_GPIO_Port->BSRR = TFT_NWR_TPXA_Pin; <br>
          Â Â Â  } <br>
          Â Â Â  TFT_NCS_GPIO_Port->BSRR = TFT_NCS_Pin; <br>
          } <br>
          <br>
          _______________________________________________ <br>
          HW-list mailing list  -  sponsored by <a
            class="moz-txt-link-abbreviated" href="http://www.HW.cz"
            moz-do-not-send="true">www.HW.cz</a> <br>
          <a class="moz-txt-link-abbreviated"
            href="mailto:Hw-list@list.hw.cz" moz-do-not-send="true">Hw-list@list.hw.cz</a>
          <br>
          <a class="moz-txt-link-freetext"
            href="http://list.hw.cz/mailman/listinfo/hw-list"
            moz-do-not-send="true">http://list.hw.cz/mailman/listinfo/hw-list</a>
          <br>
        </blockquote>
        <p><br>
        </p>
        <br>
        <fieldset class="mimeAttachmentHeader"></fieldset>
        <br>
        <pre wrap="">_______________________________________________
HW-list mailing list  -  sponsored by <a class="moz-txt-link-abbreviated" href="http://www.HW.cz" moz-do-not-send="true">www.HW.cz</a>
<a class="moz-txt-link-abbreviated" href="mailto:Hw-list@list.hw.cz" moz-do-not-send="true">Hw-list@list.hw.cz</a>
<a class="moz-txt-link-freetext" href="http://list.hw.cz/mailman/listinfo/hw-list" moz-do-not-send="true">http://list.hw.cz/mailman/listinfo/hw-list</a>
</pre>
      </blockquote>
      <p><br>
      </p>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
HW-list mailing list  -  sponsored by <a class="moz-txt-link-abbreviated" href="http://www.HW.cz">www.HW.cz</a>
<a class="moz-txt-link-abbreviated" href="mailto:Hw-list@list.hw.cz">Hw-list@list.hw.cz</a>
<a class="moz-txt-link-freetext" href="http://list.hw.cz/mailman/listinfo/hw-list">http://list.hw.cz/mailman/listinfo/hw-list</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>