STM32 chip specs do not match the datasheet

memorymicrocontrollerstm32

I've recently purchased a couple of STM32L152R8T6 chips from a local electronics shop.
According to the page 11 of the datasheet, this chip is supposed to have 10K of SRAM and 64K of FLASH.
However, when I query one of those chips (that I've already soldered onto a perfboard, along with simple transistor UART 3.3v<>5v level shifter) with 'stm32flash', it responds with this:

$ stm32flash -b 115200 /dev/ttyACM0 
stm32flash 0.4

http://stm32flash.googlecode.com/

Interface serial_posix: 115200 8E1
Version      : 0x30
Option 1     : 0x00
Option 2     : 0x00
Device ID    : 0x0416 (L1xxx6(8/B))
- RAM        : 16KiB  (2048b reserved by bootloader)
- Flash      : 128KiB (sector size: 16x256)
- Option RAM : 16b
- System RAM : 4KiB

And the linker script from STM32L1xx Standard Peripheral Library v1.3.1, for Medium Density devices, sets the size of FLASH to 128K, and the size of RAM to 16K.

The questions are:

  1. Why memory sizes do not match the ones described in the datasheet?
  2. Do I have some dodgy/fake/counterfeit chip?
  3. What memory size should I state in the linker script? (that one is probably a bit offtopic).

I've also tried to use it with ST's own Flash Loader Demonstrator (through Windows 7 on VirtualBox VM, don't have it on the actual hardware, maybe I'll test that later), but it keeps saying that it's an "Unrecognized device… Please reset your device then try again".

I use an Arduino Mega 2560 as an USB<>UART bridge, using RX0/TX0 to connect to STM32. Of course, Arduino's AVR chip is disabled by wiring its /RESET to GND.
With such setup, I can easily, without any errors along the way, upload and verify (with stm32flash and a serial port) a simple program to blink a LED, and it will work. I've also played around with integrated DAC and ADCs, they also seem to work just fine (although a bit slower than I expected, but that's probably not related – I'm only starting with ST micros).

I've also stumbled upon this thread that might have an answer to this question, but I don't know if it explains why ST's own tool is not able to see the chip.

Best Answer

The device ID of your controller is the following:

   Device ID    : 0x0416 (L1xxx6(8/B))

and I think the key is this part: L1xxx6(8/B), this ID must be the same for STM32L152R8 and STM32L152RB devices.

If we have a look at ST's table of flash/RAM sizes, the STM32L152RB has 128K/16K.

enter image description here

I am not sure, maybe the SPL can only assign the RB values when this device ID is read.

You can give a try and set the 64K/10K values manually, and check if you can program the MCU.

I do not think that your ICs are fake, check the text on them to make sure it's an 8 and not a B.