Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bluepill 128kb support #516

Closed
Testato opened this issue Nov 25, 2016 · 11 comments · Fixed by #576
Closed

Bluepill 128kb support #516

Testato opened this issue Nov 25, 2016 · 11 comments · Fixed by #576

Comments

@Testato
Copy link

Testato commented Nov 25, 2016

the Bluepill board si very famous, it is the cheapest F103 board on the market (only 2$)
It have a 128K flash, this is another advantage, but it is a hidden advantage because, nobody know why, but is there two F103C8 on the market, one is 64KB and the other is 128KB.
The datasheet for C8 version tell that this is a 64KB, but if you try to upload until 128KB it work always, so probably the C8 64KB do not exist.

So may you use this "hack" officially ?
#305 (comment)

@xor-gate
Copy link
Member

xor-gate commented Dec 1, 2016

Sorry for the late answer, this seems weird. If it is undocumented by ST the stlink project can not support this.

@xor-gate xor-gate closed this as completed Dec 1, 2016
@Testato
Copy link
Author

Testato commented Dec 1, 2016

The stm32duino project, for example, officially support this, by creating two F103C8 board, the user can choose the right one.
Instead of integrate the mentioned hack, maybe there is a way for test the real Flash available on the chip befoure flash it ?
For example the integrated Serial bootloader of the F103C8 mcu correctly show the real Flash available.
If you want i can post the result

@xor-gate
Copy link
Member

xor-gate commented Dec 1, 2016

I'm not sure where you get this info but this is what I can find:

Where the encoding of the chip model is as follows:
https://github.com/xor-gate/stlink2/wiki/STM32-coding-matrix

Where STM32F103C8 decodes to:

  • C: 42 pins
  • 8: 64Kbyte flash

@Testato
Copy link
Author

Testato commented Dec 1, 2016

yes, i know that the datasheet for C8 version tell 64KB, it is a weird commercial bug :-)

## STM32F103C8 -------------------------
genericSTM32F103C.menu.device_variant.STM32F103C8=STM32F103C8 (20k RAM. 64k Flash)
genericSTM32F103C.menu.device_variant.STM32F103C8.build.cpu_flags=-DMCU_STM32F103C8
genericSTM32F103C.menu.device_variant.STM32F103C8.build.ldscript=ld/jtag_c8.ld
genericSTM32F103C.menu.device_variant.STM32F103C8.upload.maximum_size=65536
genericSTM32F103C.menu.device_variant.STM32F103C8.upload.ram.maximum_size=20480
genericSTM32F103C.menu.device_variant.STM32F103C8.upload.flash.maximum_size=65536

## STM32F103CB -------------------------
genericSTM32F103C.menu.device_variant.STM32F103CB=STM32F103CB (20k RAM. 128k Flash)
genericSTM32F103C.menu.device_variant.STM32F103CB.build.cpu_flags=-DMCU_STM32F103CB
genericSTM32F103C.menu.device_variant.STM32F103CB.build.ldscript=ld/jtag.ld
genericSTM32F103C.menu.device_variant.STM32F103CB.upload.maximum_size=131072
genericSTM32F103C.menu.device_variant.STM32F103CB.upload.ram.maximum_size=20480
genericSTM32F103C.menu.device_variant.STM32F103CB.upload.flash.maximum_size=131072

@Testato
Copy link
Author

Testato commented Dec 1, 2016

And this is the Bootloader message, it clearly tell that the MCU have 128KB.
I have personally two of this C8 board, and I can write untill 128KB without problem.

stm32flash 0.4
http://stm32flash.googlecode.com/
Using Parser : Raw BINARY
Interface serial_w32: 57600 8E1
Version      : 0x22
Option 1     : 0x00
Option 2     : 0x00
Device ID    : 0x0410 (Medium-density)
- RAM        : 20KiB  (512b reserved by bootloader)
- Flash      : 128KiB (sector size: 4x1024)
- Option RAM : 16b
- System RAM : 2KiB
Write to memory
Erasing memory
Wrote address 0x08001bc0 (100.00%) Done.

@Testato
Copy link
Author

Testato commented Dec 1, 2016

@Nightwalker-87
Copy link
Member

Reopening this as some CKS32F103C8T6 chips indeed come with 128 kB flash. A way should be found to deal with this properly.

@Nightwalker-87 Nightwalker-87 modified the milestones: v1.6.1, Feedback required Mar 20, 2020
@Nightwalker-87
Copy link
Member

@Testato: We may implement it in such a way that it is tied to the detection of CKS32F103C8T6 chips which come with 128k, as far as I'm aware of, but this clearly needs some investigation first. I agree with @xor-gate that we must ensure to stay addicted to official specs primarily.

@Nightwalker-87 Nightwalker-87 modified the milestones: Feedback required, v1.6.1 Mar 25, 2020
@Nightwalker-87 Nightwalker-87 changed the title Bluepill 128K support [feature] Bluepill 128kb support Mar 25, 2020
@hierophect
Copy link

hierophect commented Mar 26, 2020

@Nightwalker-87 I do not believe that this extra memory is restricted to the CKS32F103C8T6 - I believe I actually saw a confirmation from an ST rep that the true F103C8T6 chips had this extra memory, though I'm having trouble locating the thread now nevermind, it's actually linked earlier in this thread but has since been taken down.

It is also worth noting that the official ST Flash application will happily load up this chip with up to 128k of code, so this isn't unprecedented.

I'd speculate that the reason this is a priority for some is that the Bluepill is often considered to be a suitable entry-level board for various projects because of this memory bug, which allows it to host RTOS cores like MBED or Zephyr and frameworks like STM32Duino without being cramped for flash.

@hierophect
Copy link

hierophect commented Mar 26, 2020

The temp fix, for anyone who is interested, is to edit the src/common.c file, in the stlink_load_device_params() function, in the following text:

} else if (sl->chip_id == STLINK_CHIPID_STM32_L1_CAT2) {
    sl->flash_size = (flash_size & 0xff) * 1024;
} else if ((sl->chip_id & 0xFFF) == STLINK_CHIPID_STM32_L1_HIGH) {
    // 0 is 384k and 1 is 256k
    if ( flash_size == 0 ) {
        sl->flash_size = 384 * 1024;
    } else {
        sl->flash_size = 256 * 1024;
    }
} else {
    sl->flash_size = flash_size * 1024;
}

replacing the final else with

} else {
     sl->flash_size = flash_size * 1024;
     /* HACK for STM21F103C8T6 */
     if (sl->flash_size == 64 * 1024 && getenv("C8T6HACK"))
       sl->flash_size = 128 * 1024;
}

Recompile and install from source, and call with a preface to set an empty environmental variable: C8T6HACK= st-flash write etc

@Nightwalker-87 Nightwalker-87 modified the milestones: v1.6.1, v1.4.0 Mar 31, 2020
@Nightwalker-87 Nightwalker-87 changed the title [feature] Bluepill 128kb support Bluepill 128kb support Mar 31, 2020
@Nightwalker-87
Copy link
Member

Nightwalker-87 commented Mar 31, 2020

@hierophect: Surprise - Digging through the whole project revealed some interesting features, which seem to have been kicked into the long grass - without any documentation - sigh. However I think this is what you have been looking for. Sry to see that you obviously waited for nothing... :-(

@stlink-org stlink-org locked as resolved and limited conversation to collaborators Apr 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants