Nuvoton 8051 compiler options other than Keil / IAR? - Page 1
Forum section: electronics / general

author: mutski
author_rank: Newbie
timestamp: November 11, 2020, 10:54:07 pm
content: Hi allHaving been in the Atmel AVR camp for 20 years now, and slowly migrating over to STM32 for some larger projects I've recently discovered Nuvoton. Mostly because I have a large project coming up and I was looking for large qty (> 10K) on LCSC. Their highest stocked chip right now is a Nuvoton MS51FB9AE and by god it's cheap! Not quite Paduak cheap but it's fully featured as least for what I need.All documentation I can find says to use either Keil or IAR compilers. However I find the free version 4K code size limit, well limiting. And I can't justify the massive cost these guys charge to buy it. I'm more than happy to pay for software, just don't like having to sacrifice 1st born child to do it. Does anybody have any other options? I really only need a compiler, I do all my debugging on real hardware.Many thanks - Matt

author: retiredfeline
author_rank: Frequent Contributor
timestamp: November 11, 2020, 11:31:02 pm
content: I'd be interested in what you find out too. Last I looked it is possible to write '51 code to compile with SDCC, but ISP requires the Nulink adapter. Some somewhat dated links of interest:https://jaycarlson.net/pf/nuvoton-n76/https://github.com/OpenNuvoton/Nuvoton_Toolshttps://github.com/OpenNuvoton/NuMicro-8051-Family(editing of BSP required for SDCC)

author: ebclr
author_rank: Super Contributor
timestamp: November 12, 2020, 12:39:08 am
content: https://www.silabs.com/developers/8-bit-8051-microcontroller-software-studiohttps://www.mikroe.com/compilers/compilers-8051https://www.instructables.com/8051-Programming-Using-Small-Device-C-Compiler-SDC/

author: PCB.Wiz
author_rank: Super Contributor
timestamp: November 12, 2020, 02:20:33 am
content: Quote from: mutski on November 11, 2020, 10:54:07 pmSure - look for SDCC compiler, mentioned above and download from herehttp://sdcc.sourceforge.net/

author: voltsandjolts
author_rank: Unknown
timestamp: November 12, 2020, 09:34:03 am
content: The SiLabs parts are a bit more expensive but you get Keil for free AFAIK.I imagine a lot of folks have moved on from C51 to ARM, maybe ask in Buy/Sell/Wanted list for old Keil license/dongle.

author: GromBeestje
author_rank: Frequent Contributor
timestamp: November 12, 2020, 01:44:35 pm
content: The last time I use a Keil 8051 license, it had an expiry date.

author: nctnico
author_rank: Super Contributor
timestamp: November 12, 2020, 08:00:11 pm
content: When it comes to the 8051 the Keil compiler is hard to beat. The amount of device specific optimisation it does is impressive. Then again I wouldn't use an 8051 nowadays unless when going for a really high volume. You'll need to spend time optimising the code too because an 8051 doesn't have much processor power to begin with. If the cost of the Keil compiler is a problem then it is likely better to use a cheap ARM microcontroller. At >10k units you likely can get interesting prices.

author: GromBeestje
author_rank: Frequent Contributor
timestamp: November 12, 2020, 09:43:33 pm
content: It might be good at optimising, but it ain't pleasant to write code for. The C parser is ancient. It only takes C89. For example you have to declare your variables at the beginning of the function, otherwise it's considered a syntax error.

author: mutski
author_rank: Newbie
timestamp: November 12, 2020, 10:04:45 pm
content: Thanks all. Will look at the options above.Quote from: nctnico on November 12, 2020, 08:00:11 pmThe product I'm using it on is super simple. It only reads a few ADC lines and controls an RGB LED to display status, with a single button also. I previously would have used a Tiny AVR but availability is getting an issue. 10K units is the first order we have, will most likely be a lot more. The main reason for trying to use this particular processor is availability and price. At around 10c per unit it's hard to beat, and my supplier has around 600K units in stock. What's the cheapest ARM chip you know of? And is there a free or cheap compiler for it? haha.The quote I got from Keil was around $6000. Kinda takes up the money we save by changing to the cheaper chip if I then have to pay those kind of software prices. Less than $1000 for software is a no brainer, but I struggle to ever spend that kind of money.Thanks all.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: November 12, 2020, 10:10:20 pm
content: Quote from: mutski on November 12, 2020, 10:04:45 pmIf it's that simple, write it in assembler.

author: voltsandjolts
author_rank: Unknown
timestamp: November 12, 2020, 10:25:33 pm
content: If it's that simple, the 4K code limit on the Keil demo should be more than enough. What are you gonna do with the spare 2KCA51 was around GBP1500 last time I bought it...2004 maybe. I see only PK51 is offered now but 6KUSD is a joke.

author: mutski
author_rank: Newbie
timestamp: November 12, 2020, 10:31:55 pm
content: Quote from: voltsandjolts on November 12, 2020, 10:25:33 pmI was surprised it didn't fit too!!! That actually tells you how inefficient the compiler is!! (or my code haha). Even some of the sample project code wouldn't fit. Add in a few timers and a UART for debugging and you're screwed.

author: voltsandjolts
author_rank: Unknown
timestamp: November 12, 2020, 10:35:45 pm
content: My mistake, the demo is 2K restricted, which is very mean of them.But C51 is an excellent tool - it's the only good thing left about 8051.

author: nctnico
author_rank: Super Contributor
timestamp: November 12, 2020, 10:51:28 pm
content: Quote from: mutski on November 12, 2020, 10:04:45 pmThere is GCC for ARM (maintained by ARM) which is completely free. Both ST and NXP have small, low cost ARM controllers. NXP's LPC802M001JDH16FP costs $0.34 in 10k units.One thing you need to seriously consider is how you are going to deal with silicon bugs and other mayhem that may arise from using cheap (partially specified / qualified) parts. You'll have to do a lot of testing to make sure you won't need to replace >10k units at some point due to reliability issues. Buying a part from a more established brand can help to avoid such pitfalls. I've had and seen serious problems with cheaper parts (from Sipex, Microchip and Atmel to name a few). I always factor in an insurance premium into the price of a product to cover a (partial) recall. The big boys do prototype runs of 200 to 1000 units, test the crap out of these units (which get scrapped after testing) before starting actual production.

author: mutski
author_rank: Newbie
timestamp: November 12, 2020, 11:06:36 pm
content: Quote from: nctnico on November 12, 2020, 10:51:28 pmAvailability is an issue though. Even direct from NXP they only have 883 in stock, with 26 week leadtime.

author: nctnico
author_rank: Super Contributor
timestamp: November 12, 2020, 11:12:50 pm
content: Is 26 weeks a problem? You'll need to develop the product anyway and do testing so by the time your production actually starts it will be a couple of months. Besides that I'd ask a distributor for a quotation and lead time to make sure instead of assuming that what is on a website is correct.

author: mutski
author_rank: Newbie
timestamp: November 12, 2020, 11:46:51 pm
content: Quote from: nctnico on November 12, 2020, 11:12:50 pm26 weeks! I wish I worked in your industry! I develop an average of 2 PCBs / week. Granted many are small. I usually have at least 10 on the go at any time in various stages of development. In 26 weeks I will have already forgotten about this product. A key component of any design I do is, "Is the part available NOW". This particular product I already have the prototype PCBs out being tested by the customer and will probably go to mass production in the next week or so.Thanks for the info I will look at the suggestions above over the weekend. - Cheers Matt

author: techman-001
author_rank: Frequent Contributor
timestamp: November 13, 2020, 02:56:14 am
content: Quote from: mikeselectricstuff on November 12, 2020, 10:10:20 pmA very good idea, but Assembler is low level, and let's face it, one writes the Assembly code runs it and if everything isn't just right, the result is a dead system, no sign of life, nothing, and this can be very frustrating.Fortunately Forth is another Free solution, it's interactive on the hardware so development is easy, and the Forth below builds fine on Linux and includes a Python based simulator as well. I just built it on a Debian 10 Linux box and it was very easy. It's perfect for a 8051 with 16KB Flash and 1KB Ram.git clonehttps://github.com/jamesbowman/8051forthThere is even a comprehensive 8051 book by William H Payne:https://archive.org/details/WilliamH.PayneAuth.EmbeddedControllerFORTHForThe8051FamilyBostonAcademicPress1990/mode/2up

author: PCB.Wiz
author_rank: Super Contributor
timestamp: November 13, 2020, 04:50:39 am
content: Quote from: mutski on November 12, 2020, 10:31:55 pmDid you try SDCC yet ? IIRC they recently added 64b float support to their C51There is also IAR version, this says their limited version is 4K, which may be enough :https://www.iar.com/iar-embedded-workbench/#!?architecture=8051I see these commentsNew device supportNuvoton: ML51 - ML51BB9AE, ML51DB9AE, ML51FB9AE, ML51OB9AE, ML51XB9AE, ML51EB9AE, ML51UB9AE, ML51PB9AE, ML51TB9AE, ML51EC0AE, ML51UC0AE, ML51PC0AE, ML51TC0AE, ML51LC0AE, ML51PD1AE, ML51MD1AE, ML51LD1AE, ML51SD1AE, MS51 - MS51FB9AE, MS51XB9AE, MS51XB9BE, MS51OB9AE, N76E013Nuvoton Nu-Link debug probe supportNuvoton Nu-Link support is now integrated into IAR Embedded Workbench for 8051.( I wonder what a N76E013 is ? some variant of N76E003 (there was a N76E002 ?)So maybe that means you can have Step DEBUG on the Nuvoton eval boards ? - that would be nice, as that's one thing SiLabs includes with their Keil compiler is the SiLabs Debug pathway.There is also a free PASCAL compiler for 8051 herehttps://turbo51.com/download-free-pascal-compiler-8051

author: westfw
author_rank: Super Contributor
timestamp: November 13, 2020, 07:54:41 am
content: QuoteModern 8051s aren't too bad. They've gone down from the 12 clocks/instruction to 1 or two, and clock rates have gone up (the cheap CH55x series say 8-16 times faster than a traditional 8051, and 24MHz clock.) That makes them more or less competitive with other 8bit CPUs.(Your chip may vary...) (Some of the SILabs chips go 100MHz!)

author: nctnico
author_rank: Super Contributor
timestamp: November 14, 2020, 12:55:19 am
content: Quote from: mutski on November 12, 2020, 11:46:51 pmI'm not saying 26 weeks is nice but for a high volume product I wouldn't feel comfortable without either doing a lot of testing of new (to me) components OR use components I know are good. Based on your question I assume the prototypes have different microcontrollers and you have no experience whatsoever with the Nuvoton chips. Make sure your boss (or customer) makes the choice between waiting or going for production with an unknown device so you can waive the blame.

author: james_s
author_rank: Super Contributor
timestamp: November 14, 2020, 06:09:49 am
content: Attiny AVR availability is an issue? I just checked Digikey and they have the ATTINY87-XUR in stock, over 58,000 pcs available immediately, how many do you need? If you want something smaller and cheaper they have 8,000 of the ATTINY202-SSFR in stock, only 40 cents each in single quantity. It seems a bit crazy to change microcontroller families if your needs are so basic that a tiny AVR can handle it, I've used AVRs for many years and like them because the whole toolchain is free with no limitations.I'm actually surprised gcc or something doesn't support 8051, that architecture is almost as old as I am and was one of the most popular embedded CPUs around at one time.

author: nctnico
author_rank: Super Contributor
timestamp: November 14, 2020, 11:00:08 am
content: Quote from: james_s on November 14, 2020, 06:09:49 amIf you look at the architecture then you'll understand why GCC doesn't support 8051 (and 8 bit PIC as well). These Harvard architectures with multiple memory areas require a totally different compiler and also a totally different style of programming. The microcontrollers have no stack and don't support pointers so this needs to be emulated.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: November 14, 2020, 05:25:38 pm
content: Have you looked at other uC families @ LCSC?For example, this Holtek part is 8ct in 500+ quantities.https://lcsc.com/product-detail/Others_Holtek-Semicon-HT68F001_C133382.htmlAn here is a 48ct (1000+) ARM Cortex-M0 part:https://lcsc.com/product-detail/mindmotion_MindMotion-Microelectronics-MM32F003NW_C316714.html30ct (1000+) STM8https://lcsc.com/product-detail/ST-Microelectronics_STMicroelectronics_STM8S001J3M3_STM8S001J3M3_C132355.html

author: james_s
author_rank: Super Contributor
timestamp: November 14, 2020, 06:20:22 pm
content: Quote from: nctnico on November 14, 2020, 11:00:08 amWell there's the "or something", with such a common architecture that has been around for so long, I'm surprised that there are not dozens of different compilers including some that are free or open source. There are certainly lots of random C compilers out there.

author: GromBeestje
author_rank: Frequent Contributor
timestamp: November 14, 2020, 07:41:27 pm
content: Wasn't the requirement >10K in stock? That doesn't hold for the ones you linked.

author: nctnico
author_rank: Super Contributor
timestamp: November 14, 2020, 08:14:55 pm
content: Quote from: james_s on November 14, 2020, 06:20:22 pmI guess you forgot the lengthy C versus assembler debates. Lots of people would program these kind of microcontrollers in assembler. It has only been a couple of years since these debates have stopped. In the end 8051 (and similar architectures) don't work very well for C so writing a compiler is very difficult & time consuming. There used a be several commercial C compilers for the 8051 out there but most of them where too crappy to be useful. A long time ago I bought Dave Dunfield's 8051 Micro-C compiler which turned out to be pretty useless in the end. Back then SDCC was better already.

author: james_s
author_rank: Super Contributor
timestamp: November 14, 2020, 09:07:07 pm
content: Quote from: GromBeestje on November 14, 2020, 07:41:27 pmI don't know, I didn't see the specific requirement but one of the ones I linked showed over 50k in stock.If one is building so many boards and using the same uC on a lot of them and relies on having such vast quantities available right now then it may make sense to purchase say 15k of them to have on hand, or however many is needed to buffer the typical lead times. There is also the option of buying from multiple suppliers, buy out whatever the cheapest place has and then fill in the gap with somebody else.

author: rhodges
author_rank: Frequent Contributor
timestamp: November 14, 2020, 10:45:55 pm
content: Since someone mentioned STM8S... I have libraries, test examples, and projects on github. Assuming you have SDCC with STM8 enabled, just type "make" to build.STM8S libraries code:https://github.com/unfrozen/stm8_libsSTM8S libraries wiki:https://github.com/unfrozen/stm8_libs/wikiSTM8S test and example code:https://github.com/unfrozen/stm8_testsOne thing I like about STM8S003, STM8S103, etc. is that it is very easy to write to EEPROM and Flash memory. Just unlock it and write anywhere. Block erase and write is faster, but if you just want to update one byte, that's fine too.

author: Joku
author_rank: Contributor
timestamp: November 15, 2020, 07:31:18 am
content: Hmm looks like STM8S would be a pretty safe path based on rhodges' post, and if STM8S003F3P6 can do the job it has nice current availability of 90,000pcs at just LCSC alone.Just depends how often you get these super basic high volume MCU projects really. Worth investing in something cheaper with less safe tooling and support and doco etc if you know you'll get these kind of projects semi-regularly. Personally I bloody wish I got these kind of projects lol.. since I almost never do I'd just do it on an STM32G03x and say well sorry Mr boss/client but immediate availability of large volumes for a first production run isn't how my industry rolls... if you want that for future production runs I can make it happen but it will cost you

author: GromBeestje
author_rank: Frequent Contributor
timestamp: November 15, 2020, 08:43:20 am
content: Quote from: james_s on November 14, 2020, 09:07:07 pmThen some has been buying in bulk, I see 1255, 1486 and 1344 avaialble.

author: chris_leyson
author_rank: Super Contributor
timestamp: November 15, 2020, 09:22:58 am
content: Not compiler related but I would be wary of using Nuvoton microcontrollers. Recently had an issue with Nuvoton MN101EF50D and power down reset. MN101EF50D has an "auto reset" function that can be enabled in hardware by setting a pin high. The data sheet implies that this will reset all of the I/O pins as VDD drops, in actual fact it does nothing other than speed up the reset capacitor discharge by pulling the NRST pin low. Reset occurs when VDD drops to around 1.4V or 1.3V and all of the port pins should go tri-state, however, some of the port pins are driven either high or low when they should be tri-state and in some circumstances this can cause mayhem. Had to fix the issue by applying a hard reset to the NRST pin whist VDD was within it's recommended operating range. Would recommend you use a reset supervisor on Nuvoton parts.

author: voltsandjolts
author_rank: Unknown
timestamp: November 15, 2020, 02:28:23 pm
content: Yeh, if you lose half a day debugging that kind of stuff, those MCUs don't look so cheap anymore.Time is money, after all.

author: westfw
author_rank: Super Contributor
timestamp: November 16, 2020, 02:38:23 am
content: QuoteThat's notexactlythe case. But they certainly don't implement stack/pointers/memory in the sort of "generic" way that gcc would like them to.(in particular, the "stack" is frequently not in "general purpose" memory.)

author: james_s
author_rank: Super Contributor
timestamp: November 16, 2020, 02:42:59 am
content: Quote from: GromBeestje on November 15, 2020, 08:43:20 amMaybe DK has a warehouse in Europe? I just checked now and I still see over 58k.

author: ale500
author_rank: Frequent Contributor
timestamp: November 26, 2020, 11:48:49 am
content: The keil compiler is also used for the PSoC3 uC included in PSoCCreator. I do not know if it is particular to that '51 derivative but the code generated is very suboptimal in comparison to what iar can produce. Their pointer handling is not mature. iar's is not always optimal but dumping the pointers in memory and not using the registers for more than one access ?

author: grantb5
author_rank: Regular Contributor
timestamp: March 15, 2022, 01:15:37 pm
content: I just finished a design with the OP's initial processor (Nuvoton MS51). I've used Keil a lot and am quite content with it (not excited, but can easily be productive). I found the whole experience to be pretty decent. Modern debugging even. Not impossible to find parts either. Keil has been doing C on 8051 for decades and they know all the tricks. No way I could create in assembler what this compiler can achieve ( nor would I want to). I believe SDCC targets this processor as well. There are lots of free licenses for Keil (both 8051 and ARM). And I don't mean key hacks or whatever. We use a lot of SILabs parts, so my compiler was licensed free already. All I had to do was install the Nuvoton "Keil Driver" package.I had ported this from and STM8 and the code density is twice as good on the 8051 than Cosmic generated for STM8. On the STM8S it took almost 8k to do what the MS51 fit in just over 4k. I didn't hate the STM8, but there are so few CPU registers that the C compiler is forever moving data in and out of RAM.

author: free_electron
author_rank: Super Contributor
timestamp: March 15, 2022, 02:01:38 pm
content: iar for 8051or mikroe compiler for 8051. they even have a basic compilermcs basic is also there.