Faking it with an STM32F103r8t6 - is there a DAC hiding here.

Generic boards that are not Maple or Maple mini clones, and don't contain the additional USB reset hardware
Post Reply
User avatar
ahull
Posts: 1597
Joined: Mon Apr 27, 2015 11:04 pm
Location: Sunny Scotland
Contact:

Faking it with an STM32F103r8t6 - is there a DAC hiding here.

Post by ahull » Mon Jan 02, 2017 10:52 pm

I was wondering what I code I need to change to experiment to find out if the DACs are actually present on an STM32F103R8T6 (or indeed on an STM32F103C8T6). Now before you all shout at me and say it hasn't got a DAC I *know* that I also know that the extra flash that is on my stm32f103c8t6 board is a figment of our collective imagination. Never the less I want to prove to myself that even if I write to the relevant DAC registers etc. nothing happens on an STM32F103R8T6 ... 'cos I would hate to think that STM are kidding us when they say the DAC isn't there, if it actually is. :twisted:
I can see that the resisters live in the memory map around 0x4000 7400 - 0x4000 77 on the STM32F103 variants that do have a DAC, so I was wondering... how do I prove whether the DAC exists or not. I think this question may have been asked before, but if so my Google Fu failed me as I can't find the answer.
- Andy Hull -

User avatar
RogerClark
Posts: 6918
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Faking it with an STM32F103r8t6 - is there a DAC hiding here.

Post by RogerClark » Tue Jan 03, 2017 8:55 am

Andy
Looking at the data sheet for the F103RC the DAC http://www.st.com/content/ccc/resource/ ... 191185.pdf

Page 32

The DAC would be on pins PA4 and PA5, so all you'd need to do is to set the board type to a F103RC or better and write some code to send data to the DAC and look on PA4 or PA5

I recall seeing some DAC code ages ago, as I have several boards that have DAC and I did test their operation (probably over a year ago)

However I suspect that the F103Cx does not contain the DAC hardware. (but there is no harm testing if it is present)

victor_pv
Posts: 1652
Joined: Mon Apr 27, 2015 12:12 pm

Re: Faking it with an STM32F103r8t6 - is there a DAC hiding here.

Post by victor_pv » Tue Jan 03, 2017 9:32 pm

ahull wrote:I was wondering what I code I need to change to experiment to find out if the DACs are actually present on an STM32F103R8T6 (or indeed on an STM32F103C8T6). Now before you all shout at me and say it hasn't got a DAC I *know* that I also know that the extra flash that is on my stm32f103c8t6 board is a figment of our collective imagination. Never the less I want to prove to myself that even if I write to the relevant DAC registers etc. nothing happens on an STM32F103R8T6 ... 'cos I would hate to think that STM are kidding us when they say the DAC isn't there, if it actually is. :twisted:
I can see that the resisters live in the memory map around 0x4000 7400 - 0x4000 77 on the STM32F103 variants that do have a DAC, so I was wondering... how do I prove whether the DAC exists or not. I think this question may have been asked before, but if so my Google Fu failed me as I can't find the answer.
I remember checking flash and RAM in an RBT6 and did not find any extra, but who knows about the peripherals...
Aren't the F100 used in the stlink clones supposed to lack the usb peripheral?

Just make sure to place your stack in a valid area of RAM if you try to compile for the RCT6, since the linker will place it at the top of the RCT6 RAM, which was not valid in the RBT on the tests I ran a year ago.

User avatar
ahull
Posts: 1597
Joined: Mon Apr 27, 2015 11:04 pm
Location: Sunny Scotland
Contact:

Re: Faking it with an STM32F103r8t6 - is there a DAC hiding here.

Post by ahull » Tue Jan 03, 2017 9:50 pm

victor_pv wrote:
ahull wrote:I was wondering what I code I need to change to experiment to find out if the DACs are actually present on an STM32F103R8T6 (or indeed on an STM32F103C8T6). Now before you all shout at me and say it hasn't got a DAC I *know* that I also know that the extra flash that is on my stm32f103c8t6 board is a figment of our collective imagination. Never the less I want to prove to myself that even if I write to the relevant DAC registers etc. nothing happens on an STM32F103R8T6 ... 'cos I would hate to think that STM are kidding us when they say the DAC isn't there, if it actually is. :twisted:
I can see that the resisters live in the memory map around 0x4000 7400 - 0x4000 77 on the STM32F103 variants that do have a DAC, so I was wondering... how do I prove whether the DAC exists or not. I think this question may have been asked before, but if so my Google Fu failed me as I can't find the answer.
I remember checking flash and RAM in an RBT6 and did not find any extra, but who knows about the peripherals...
Aren't the F100 used in the stlink clones supposed to lack the usb peripheral?

Just make sure to place your stack in a valid area of RAM if you try to compile for the RCT6, since the linker will place it at the top of the RCT6 RAM, which was not valid in the RBT on the tests I ran a year ago.
Good point. I might make a copy of the RCT6 with only 20K of RAM and 64K of flash and see if it likes that.
- Andy Hull -

User avatar
ahull
Posts: 1597
Joined: Mon Apr 27, 2015 11:04 pm
Location: Sunny Scotland
Contact:

Re: Faking it with an STM32F103r8t6 - is there a DAC hiding here.

Post by ahull » Tue Jan 10, 2017 4:24 pm

Well... slightly inconclusive.

I drilled down in to the code and as fas as I can tell all I should need to do is change...

Code: Select all

#    ifdef STM32_MEDIUM_DENSITY
#       define STM32_NR_INTERRUPTS      43
#       define STM32_TIMER_MASK         0x1E /* TIMER1--TIMER4 */
#       define STM32_HAVE_FSMC          0
#       define STM32_HAVE_DAC           0
#    elif defined(STM32_HIGH_DENSITY)
... to ...

Code: Select all

#    ifdef STM32_MEDIUM_DENSITY
#       define STM32_NR_INTERRUPTS      43
#       define STM32_TIMER_MASK         0x1E /* TIMER1--TIMER4 */
#       define STM32_HAVE_FSMC          0
#       define STM32_HAVE_DAC           1
#    elif defined(STM32_HIGH_DENSITY)

... in .../stm32duino/hardware/STM32F1/2016.12.26/system/libmaple/stm32f1/include/series/stm32.h

Which sort of works, in the sense that I can then run the following sketch

Code: Select all

/*
 * Simple DAC test.
 *
 * Author: Marti Bolivar <mbolivar@leaflabs.com>
 *
 * This file is released into the public domain.
 */
//# define STM32_HAVE_DAC    1
// #include <wirish/wirish.h>
#include <libmaple/dac.h>
#define BOARD_LED_PIN PC13

uint16 count = 0;

void setup() {
    pinMode(BOARD_LED_PIN, OUTPUT);
    digitalWrite(BOARD_LED_PIN, HIGH);

    Serial.begin(115200);
    Serial.println("**** Beginning DAC test");

    Serial.print("Init... ");
    pinMode(PA4,OUTPUT);
    pinMode(PA5,OUTPUT);
    
    dac_init(DAC, DAC_CH1 | DAC_CH2);
    Serial.println("Done.");
}

void loop() {
    
    delay(10);

    count += 1;
    if (count > 4095) {
        count = 0;
        toggleLED();
    }
    Serial.println(count);
    dac_write_channel(DAC, 1, 4095 - count);
    dac_write_channel(DAC, 2, count);
}

__attribute__((constructor)) void premain() {
    init();
}

int main(void) {
    setup();

    while (true) {
        loop();
    }
    return 0;
}

void toggleLED() {
  digitalWrite(BOARD_LED_PIN,(!digitalRead(BOARD_LED_PIN)));
}

However when I fire my multimeter between PA4 or PA5 and GND I don't see the voltage increasing as the value written to the DAC increases.
Does anybody have time to test the above code on a board that does have a DAC to see if they do see the voltage rising on those pins.
- Andy Hull -

User avatar
ahull
Posts: 1597
Joined: Mon Apr 27, 2015 11:04 pm
Location: Sunny Scotland
Contact:

Re: Faking it with an STM32F103r8t6 - is there a DAC hiding here.

Post by ahull » Tue Jan 10, 2017 5:03 pm

I dug out an STM32F103RC board and ran the same code (after a bit of mud wrestling with the bootloader :D )
On the RC board I clearly see the voltage rise on the multimeter, but not on the C8 ... I may do have to some more digging before I admit defeat though.
EDIT: Test was on a C8 (bluepill) and an RC, not as I previously stated an R8 and an RC.
Last edited by ahull on Thu Jan 12, 2017 8:26 pm, edited 1 time in total.
- Andy Hull -

User avatar
Pito
Posts: 1529
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: Faking it with an STM32F103r8t6 - is there a DAC hiding here.

Post by Pito » Tue Jan 10, 2017 5:16 pm

I may do have to some more digging before I admit defeat though.
With a strong acid mixture and microscope ? :)
Pukao Hats Cleaning Services Ltd.

User avatar
ahull
Posts: 1597
Joined: Mon Apr 27, 2015 11:04 pm
Location: Sunny Scotland
Contact:

Re: Faking it with an STM32F103r8t6 - is there a DAC hiding here.

Post by ahull » Tue Jan 10, 2017 11:33 pm

Pito wrote:
I may do have to some more digging before I admit defeat though.
With a strong acid mixture and microscope ? :)
Certainly a good quality die shot would help to answer the question. Since I'm kind of low on fuming nitric acid at the moment, I was thinking more of dumping the registers that the DAC uses and comparing the R8 with the RC to see if the registers exist. If so, then perhaps start prodding around in the "reserved" register area to see if I can break anything discover any differences.
- Andy Hull -

victor_pv
Posts: 1652
Joined: Mon Apr 27, 2015 12:12 pm

Re: Faking it with an STM32F103r8t6 - is there a DAC hiding here.

Post by victor_pv » Thu Jan 12, 2017 7:26 pm

ahull wrote:Well... slightly inconclusive.

I drilled down in to the code and as fas as I can tell all I should need to do is change...

Code: Select all

#    ifdef STM32_MEDIUM_DENSITY
#       define STM32_NR_INTERRUPTS      43
#       define STM32_TIMER_MASK         0x1E /* TIMER1--TIMER4 */
#       define STM32_HAVE_FSMC          0
#       define STM32_HAVE_DAC           0
#    elif defined(STM32_HIGH_DENSITY)
... to ...

Code: Select all

#    ifdef STM32_MEDIUM_DENSITY
#       define STM32_NR_INTERRUPTS      43
#       define STM32_TIMER_MASK         0x1E /* TIMER1--TIMER4 */
#       define STM32_HAVE_FSMC          0
#       define STM32_HAVE_DAC           1
#    elif defined(STM32_HIGH_DENSITY)

... in .../stm32duino/hardware/STM32F1/2016.12.26/system/libmaple/stm32f1/include/series/stm32.h

Which sort of works, in the sense that I can then run the following sketch

Code: Select all

/*
 * Simple DAC test.
 *
 * Author: Marti Bolivar <mbolivar@leaflabs.com>
 *
 * This file is released into the public domain.
 */
//# define STM32_HAVE_DAC    1
// #include <wirish/wirish.h>
#include <libmaple/dac.h>
#define BOARD_LED_PIN PC13

uint16 count = 0;

void setup() {
    pinMode(BOARD_LED_PIN, OUTPUT);
    digitalWrite(BOARD_LED_PIN, HIGH);

    Serial.begin(115200);
    Serial.println("**** Beginning DAC test");

    Serial.print("Init... ");
    pinMode(PA4,OUTPUT);
    pinMode(PA5,OUTPUT);
    
    dac_init(DAC, DAC_CH1 | DAC_CH2);
    Serial.println("Done.");
}

void loop() {
    
    delay(10);

    count += 1;
    if (count > 4095) {
        count = 0;
        toggleLED();
    }
    Serial.println(count);
    dac_write_channel(DAC, 1, 4095 - count);
    dac_write_channel(DAC, 2, count);
}

__attribute__((constructor)) void premain() {
    init();
}

int main(void) {
    setup();

    while (true) {
        loop();
    }
    return 0;
}

void toggleLED() {
  digitalWrite(BOARD_LED_PIN,(!digitalRead(BOARD_LED_PIN)));
}

However when I fire my multimeter between PA4 or PA5 and GND I don't see the voltage increasing as the value written to the DAC increases.
Does anybody have time to test the above code on a board that does have a DAC to see if they do see the voltage rising on those pins.
Perhaps you need to set the pins to Alternate function or something? or is that set by the core?
I have some RCT boards at home, I'll try to remember to test your code.

victor_pv
Posts: 1652
Joined: Mon Apr 27, 2015 12:12 pm

Re: Faking it with an STM32F103r8t6 - is there a DAC hiding here.

Post by victor_pv » Fri Jan 13, 2017 2:32 am

ok, so I loaded your sketch to one of my RFT boards, I dont have an oscilloscope, but with a debugger I can see the registers at 0x40007400 and several more going from that address changing every time the dac_write_channel executes, so the code should be working.

I should really assemble your pigoscope, but I haven't come thru a suitable pig yet :(

If I can find my multimeter in the meanwhile, I will try to see if I can read the voltage swing.

Post Reply